]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tools/nolibc: add stdarg.h header
authorThomas Weißschuh <linux@weissschuh.net>
Wed, 30 Aug 2023 15:07:12 +0000 (17:07 +0200)
committerThomas Weißschuh <linux@weissschuh.net>
Thu, 12 Oct 2023 19:13:52 +0000 (21:13 +0200)
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>
Signed-off-by: Willy Tarreau <w@1wt.eu>
tools/include/nolibc/Makefile
tools/include/nolibc/nolibc.h
tools/include/nolibc/stdarg.h [new file with mode: 0644]
tools/include/nolibc/stdio.h
tools/include/nolibc/sys.h

index 909b6eb500fe94578582c6097fb8dd4046dd316c..e69c26abe1ea5fdeb8e6e5c3ddcb3e05e700fa0c 100644 (file)
@@ -34,6 +34,7 @@ all_files := \
                signal.h \
                stackprotector.h \
                std.h \
+               stdarg.h \
                stdint.h \
                stdlib.h \
                string.h \
index 1f8d821000aca80c74784d77d879f95d5bc56e0c..989e707263a4faba22014175e4664a8fbef283e5 100644 (file)
  *            -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 (file)
index 0000000..c628b57
--- /dev/null
@@ -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 */
index cae402c11e5754dd4a6633494ec813202926d2f7..d7ef43973916c77853d9ae4f8ce75c9b3938ca58 100644 (file)
@@ -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"
 
index fdb6bd6c0e2fb85858c06eca03989982fd61c44d..b478750c90045080b78769d8b41bb701e04b74fb 100644 (file)
@@ -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"