* [PATCH v2 0/2] nolibc: remove reliance on system headers
@ 2023-08-30 15:07 Thomas Weißschuh
2023-08-30 15:07 ` [PATCH v2 1/2] tools/nolibc: add stdarg.h header Thomas Weißschuh
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2023-08-30 15:07 UTC (permalink / raw)
To: Willy Tarreau, Shuah Khan
Cc: Zhangjin Wu, Yuan Tan, linux-kernel, linux-kselftest,
Thomas Weißschuh
This was prompted by the discussion about output directory support with
O=.
It seems sometimes we were pulling in system headers making testing
annoying and unreliable.
Willy:
I did not implement the '#ifdef va_start` guard that we discussed
before. In my understanding the latest agreement does not need it
anymore. Please let me know if this is incorrect.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Changes in v2:
- Adapt comment in nolibc.h
- <stdarg.h> -> "stdarg.h"
- Link to v1: https://lore.kernel.org/r/20230827-nolibc-nostdinc-v1-0-995d1811f1f3@weissschuh.net
---
Thomas Weißschuh (2):
tools/nolibc: add stdarg.h header
selftests/nolibc: use -nostdinc for nolibc-test
tools/include/nolibc/Makefile | 1 +
tools/include/nolibc/nolibc.h | 4 ++--
tools/include/nolibc/stdarg.h | 16 ++++++++++++++++
tools/include/nolibc/stdio.h | 3 +--
tools/include/nolibc/sys.h | 2 +-
tools/testing/selftests/nolibc/Makefile | 2 +-
6 files changed, 22 insertions(+), 6 deletions(-)
---
base-commit: 556fb7131e03b0283672fb40f6dc2d151752aaa7
change-id: 20230827-nolibc-nostdinc-203908130d67
Best regards,
--
Thomas Weißschuh <linux@weissschuh.net>
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v2 1/2] tools/nolibc: add stdarg.h header 2023-08-30 15:07 [PATCH v2 0/2] nolibc: remove reliance on system headers Thomas Weißschuh @ 2023-08-30 15:07 ` Thomas Weißschuh 2023-08-30 15:07 ` [PATCH v2 2/2] selftests/nolibc: use -nostdinc for nolibc-test Thomas Weißschuh 2023-08-30 20:48 ` [PATCH v2 0/2] nolibc: remove reliance on system headers Willy Tarreau 2 siblings, 0 replies; 6+ messages in thread From: Thomas Weißschuh @ 2023-08-30 15:07 UTC (permalink / raw) To: Willy Tarreau, Shuah Khan Cc: Zhangjin Wu, Yuan Tan, linux-kernel, linux-kselftest, Thomas Weißschuh This allows nolic to work with `-nostdinc` avoiding any reliance on system headers. The implementation has been lifted from musl libc 1.2.4. There is already an implementation of stdarg.h in include/linux/stdarg.h but that is GPL licensed and therefore not suitable for nolibc. The used compiler builtins have been validated to be at least available since GCC 4.1.2 and clang 3.0.0. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/nolibc.h | 4 ++-- tools/include/nolibc/stdarg.h | 16 ++++++++++++++++ tools/include/nolibc/stdio.h | 3 +-- tools/include/nolibc/sys.h | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 909b6eb500fe..e69c26abe1ea 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -34,6 +34,7 @@ all_files := \ signal.h \ stackprotector.h \ std.h \ + stdarg.h \ stdint.h \ stdlib.h \ string.h \ diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index 1f8d821000ac..989e707263a4 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -74,10 +74,10 @@ * -I../nolibc -o hello hello.c -lgcc * * The available standard (but limited) include files are: - * ctype.h, errno.h, signal.h, stdio.h, stdlib.h, string.h, time.h + * ctype.h, errno.h, signal.h, stdarg.h, stdio.h, stdlib.h, string.h, time.h * * In addition, the following ones are expected to be provided by the compiler: - * float.h, stdarg.h, stddef.h + * float.h, stddef.h * * The following ones which are part to the C standard are not provided: * assert.h, locale.h, math.h, setjmp.h, limits.h diff --git a/tools/include/nolibc/stdarg.h b/tools/include/nolibc/stdarg.h new file mode 100644 index 000000000000..c628b5783da6 --- /dev/null +++ b/tools/include/nolibc/stdarg.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * Variadic argument support for NOLIBC + * Copyright (C) 2005-2020 Rich Felker, et al. + */ + +#ifndef _NOLIBC_STDARG_H +#define _NOLIBC_STDARG_H + +typedef __builtin_va_list va_list; +#define va_start(v, l) __builtin_va_start(v, l) +#define va_end(v) __builtin_va_end(v) +#define va_arg(v, l) __builtin_va_arg(v, l) +#define va_copy(d, s) __builtin_va_copy(d, s) + +#endif /* _NOLIBC_STDARG_H */ diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index cae402c11e57..d7ef43973916 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -7,13 +7,12 @@ #ifndef _NOLIBC_STDIO_H #define _NOLIBC_STDIO_H -#include <stdarg.h> - #include "std.h" #include "arch.h" #include "errno.h" #include "types.h" #include "sys.h" +#include "stdarg.h" #include "stdlib.h" #include "string.h" diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index fdb6bd6c0e2f..b478750c9004 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -7,7 +7,6 @@ #ifndef _NOLIBC_SYS_H #define _NOLIBC_SYS_H -#include <stdarg.h> #include "std.h" /* system includes */ @@ -25,6 +24,7 @@ #include "arch.h" #include "errno.h" +#include "stdarg.h" #include "types.h" -- 2.42.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] selftests/nolibc: use -nostdinc for nolibc-test 2023-08-30 15:07 [PATCH v2 0/2] nolibc: remove reliance on system headers Thomas Weißschuh 2023-08-30 15:07 ` [PATCH v2 1/2] tools/nolibc: add stdarg.h header Thomas Weißschuh @ 2023-08-30 15:07 ` Thomas Weißschuh 2023-08-30 20:48 ` [PATCH v2 0/2] nolibc: remove reliance on system headers Willy Tarreau 2 siblings, 0 replies; 6+ messages in thread From: Thomas Weißschuh @ 2023-08-30 15:07 UTC (permalink / raw) To: Willy Tarreau, Shuah Khan Cc: Zhangjin Wu, Yuan Tan, linux-kernel, linux-kselftest, Thomas Weißschuh Avoid any accidental reliance on system includes. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- tools/testing/selftests/nolibc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index dfe66776a331..689658f81a19 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -170,7 +170,7 @@ sysroot/$(ARCH)/include: ifneq ($(NOLIBC_SYSROOT),0) nolibc-test: nolibc-test.c sysroot/$(ARCH)/include $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \ - -nostdlib -static -Isysroot/$(ARCH)/include $< -lgcc + -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include $< -lgcc else nolibc-test: nolibc-test.c $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \ -- 2.42.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] nolibc: remove reliance on system headers 2023-08-30 15:07 [PATCH v2 0/2] nolibc: remove reliance on system headers Thomas Weißschuh 2023-08-30 15:07 ` [PATCH v2 1/2] tools/nolibc: add stdarg.h header Thomas Weißschuh 2023-08-30 15:07 ` [PATCH v2 2/2] selftests/nolibc: use -nostdinc for nolibc-test Thomas Weißschuh @ 2023-08-30 20:48 ` Willy Tarreau 2023-08-31 4:12 ` Zhangjin Wu 2 siblings, 1 reply; 6+ messages in thread From: Willy Tarreau @ 2023-08-30 20:48 UTC (permalink / raw) To: Thomas Weißschuh Cc: Shuah Khan, Zhangjin Wu, Yuan Tan, linux-kernel, linux-kselftest On Wed, Aug 30, 2023 at 05:07:11PM +0200, Thomas Weißschuh wrote: > This was prompted by the discussion about output directory support with > O=. > It seems sometimes we were pulling in system headers making testing > annoying and unreliable. > > Willy: > > I did not implement the '#ifdef va_start` guard that we discussed > before. In my understanding the latest agreement does not need it > anymore. Please let me know if this is incorrect. No that's fine given your goal of including just "nolibc.h" and no other regular include file, I agree. I've just merged it and pushed it to the -next branch. Thank you Thomas! Willy ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] nolibc: remove reliance on system headers 2023-08-30 20:48 ` [PATCH v2 0/2] nolibc: remove reliance on system headers Willy Tarreau @ 2023-08-31 4:12 ` Zhangjin Wu 2023-08-31 5:31 ` Willy Tarreau 0 siblings, 1 reply; 6+ messages in thread From: Zhangjin Wu @ 2023-08-31 4:12 UTC (permalink / raw) To: w; +Cc: falcon, linux-kernel, linux-kselftest, linux, shuah, tanyuan [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain; charset=UTF-8, Size: 1221 bytes --] Hi, Willy > On Wed, Aug 30, 2023 at 05:07:11PM +0200, Thomas Weißschuh wrote: > > This was prompted by the discussion about output directory support with > > O=. > > It seems sometimes we were pulling in system headers making testing > > annoying and unreliable. > > > > Willy: > > > > I did not implement the '#ifdef va_start` guard that we discussed > > before. In my understanding the latest agreement does not need it > > anymore. Please let me know if this is incorrect. > > No that's fine given your goal of including just "nolibc.h" and no > other regular include file, I agree. I've just merged it and pushed > it to the -next branch. > > Thank you Thomas! > Willy > > Subject: [PATCH v2 1/2] tools/nolibc: add stdarg.h header > > This allows nolic to work with `-nostdinc` avoiding any reliance on > system headers. > A little typo in above commit message: nolic -> nolibc. Thanks, Zhangjin > The implementation has been lifted from musl libc 1.2.4. > There is already an implementation of stdarg.h in include/linux/stdarg.h > but that is GPL licensed and therefore not suitable for nolibc. > > The used compiler builtins have been validated to be at least available > since GCC 4.1.2 and clang 3.0.0. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] nolibc: remove reliance on system headers 2023-08-31 4:12 ` Zhangjin Wu @ 2023-08-31 5:31 ` Willy Tarreau 0 siblings, 0 replies; 6+ messages in thread From: Willy Tarreau @ 2023-08-31 5:31 UTC (permalink / raw) To: Zhangjin Wu; +Cc: linux-kernel, linux-kselftest, linux, shuah, tanyuan On Thu, Aug 31, 2023 at 12:12:02PM +0800, Zhangjin Wu wrote: > > Subject: [PATCH v2 1/2] tools/nolibc: add stdarg.h header > > > > This allows nolic to work with `-nostdinc` avoiding any reliance on > > system headers. > > > > A little typo in above commit message: nolic -> nolibc. Yeah I noticed and forgot to fix it. Will probably do it next time I have the opportunity to touch that branch ;-) Willy ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-08-31 5:32 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-08-30 15:07 [PATCH v2 0/2] nolibc: remove reliance on system headers Thomas Weißschuh 2023-08-30 15:07 ` [PATCH v2 1/2] tools/nolibc: add stdarg.h header Thomas Weißschuh 2023-08-30 15:07 ` [PATCH v2 2/2] selftests/nolibc: use -nostdinc for nolibc-test Thomas Weißschuh 2023-08-30 20:48 ` [PATCH v2 0/2] nolibc: remove reliance on system headers Willy Tarreau 2023-08-31 4:12 ` Zhangjin Wu 2023-08-31 5:31 ` Willy Tarreau
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).