nolibc changes for Linux 6.6-rc1
Subsystems (3)
Shuah Khan
maintainerHi Linus,
Please pull the nolibc update for Linux 6.6-rc1. This is the first nolibc pull request since Paul and I took on the administrative maintainer role going forward.
Please see notes at the end on two conflicts. Build and nolibc tests were run on next.
This nolibc update for Linux 6.6-rc1 consists of:
Nolibc:
- improved portability by removing build errors with -ENOSYS
- added syscall6() on MIPS to support pselect6() and mmap()
- added setvbuf(), rmdir(), pipe(), pipe2()
- add support for ppc/ppc64
- environ is no longer optional
- fixed frame pointer issues at -O0
- dropped sys_stat() in favor of sys_statx()
- centralized _start_c() to remove lots of asm code
- switched size_t to __SIZE_TYPE__
Selftests:
- improved status reporting (success/warning/failure counts, path to log file)
- various code cleanups (indent, unused variables, ...)
- more consistent test numbering
- enabled compiler warnings
- dropped unreliable chmod_net test
- improved reliability (create /dev/zero & /tmp, rely less on /proc)
- new tests (brk/sbrk/mmap/munmap)
- improved compatibility with musl
- new run-nolibc-test target to build and run natively
- new run-libc-test target to build and run against native libc
- made the cmdline parser more reliable against boolean arguments
- dropped dependency on memfd for vfprintf() test
- nolibc-test is no longer stripped
- added support for extending ARCH via XARCH
Other:
- add Thomas as co-maintainer
Please note that these patches have been in next for a couple of weeks. I had to do a rebase to drop a vfs patch to resolve conflict with vfs-brauner tree last week.
We still have the following conflicts with vfs-brauner tree and the fix is in next.
tools/testing/selftests/nolibc/nolibc-test.c
between commit:
49319832de90 ("selftests/nolibc: drop test chmod_net")
from the vfs-brauner tree and commit:
148e9718e2a2 ("selftests/nolibc: add chmod_argv0 test")
from the nolibc tree.
A second note on conflict with mm-tree and the fix is in next:
tools/include/nolibc/stdio.h
between commit:
08d959738a95 ("selftests: line buffer test program's stdout")
from the mm-stable tree and commits:
65ff4d19f792 ("tools/nolibc/stdio: add setvbuf() to set buffering mode") 2e00a8fc4f47 ("tools/nolibc: setvbuf: avoid unused parameter warnings")
from the nolibc tree.
diff is attached.
thanks,
-- Shuah
----------------------------------------------------------------
The following changes since commit 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5:
Linux 6.5-rc1 (2023-07-09 13:53:13 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest tags/linux-kselftest-nolibc-6.6-rc1
for you to fetch changes up to 556fb7131e03b0283672fb40f6dc2d151752aaa7:
tools/nolibc: avoid undesired casts in the __sysret() macro (2023-08-23 05:17:07 +0200)
----------------------------------------------------------------
linux-kselftest-nolibc-6.6-rc1
This nolibc update for Linux 6.6-rc1 consists of:
Nolibc:
- improved portability by removing build errors with -ENOSYS
- added syscall6() on MIPS to support pselect6() and mmap()
- added setvbuf(), rmdir(), pipe(), pipe2()
- add support for ppc/ppc64
- environ is no longer optional
- fixed frame pointer issues at -O0
- dropped sys_stat() in favor of sys_statx()
- centralized _start_c() to remove lots of asm code
- switched size_t to __SIZE_TYPE__
Selftests:
- improved status reporting (success/warning/failure counts, path to log file)
- various code cleanups (indent, unused variables, ...)
- more consistent test numbering
- enabled compiler warnings
- dropped unreliable chmod_net test
- improved reliability (create /dev/zero & /tmp, rely less on /proc)
- new tests (brk/sbrk/mmap/munmap)
- improved compatibility with musl
- new run-nolibc-test target to build and run natively
- new run-libc-test target to build and run against native libc
- made the cmdline parser more reliable against boolean arguments
- dropped dependency on memfd for vfprintf() test
- nolibc-test is no longer stripped
- added support for extending ARCH via XARCH
Other:
- add Thomas as co-maintainer
----------------------------------------------------------------
Ryan Roberts (1):
tools/nolibc/stdio: add setvbuf() to set buffering mode
Thomas Weißschuh (21):
selftests/nolibc: simplify call to ioperm tools/nolibc: completely remove optional environ support selftests/nolibc: make evaluation of test conditions selftests/nolibc: simplify status printing selftests/nolibc: avoid gaps in test numbers selftests/nolibc: avoid buffer underrun in space printing tools/nolibc: drop unused variables
tools/nolibc: fix return type of getpagesize() tools/nolibc: setvbuf: avoid unused parameter warnings tools/nolibc: sys: avoid implicit sign cast tools/nolibc: stdint: use __SIZE_TYPE__ for size_t selftests/nolibc: drop unused variables selftests/nolibc: mark test helpers as potentially unused selftests/nolibc: make functions static if possible selftests/nolibc: avoid unused parameter warnings selftests/nolibc: avoid sign-compare warnings selftests/nolibc: use correct return type for read() and write() selftests/nolibc: prevent out of bounds access in expect_vfprintf selftests/nolibc: don't strip nolibc-test selftests/nolibc: enable compiler warnings
MAINTAINERS: nolibc: add myself as co-maintainer
Willy Tarreau (3):
selftests/nolibc: avoid warnings during intptr tests tools/nolibc: keep brk(), sbrk(), mmap() away from __sysret() tools/nolibc: avoid undesired casts in the __sysret() macro
Yuan Tan (2):
tools/nolibc: add pipe() and pipe2() support selftests/nolibc: add testcase for pipe
Zhangjin Wu (76):
selftests/nolibc: add a standalone test report macro
selftests/nolibc: always print the path to test log file selftests/nolibc: restore the failed tests print
tools/nolibc: fix up #error compile failures with -ENOSYS
tools/nolibc: fix up undeclared syscall macros with #ifdef and -ENOSYS tools/nolibc: sys.h: add a syscall return helper
tools/nolibc: unistd.h: apply __sysret() helper
tools/nolibc: sys.h: apply __sysret() helper
tools/nolibc: unistd.h: reorder the syscall macros
tools/nolibc: arch-*.h: fix up code indent errors
toolc/nolibc: arch-*.h: clean up whitespaces after __asm__ tools/nolibc: arch-loongarch.h: shrink with _NOLIBC_SYSCALL_CLOBBERLIST tools/nolibc: arch-mips.h: shrink with _NOLIBC_SYSCALL_CLOBBERLIST tools/nolibc: add missing my_syscall6() for mips
tools/nolibc: __sysret: support syscalls who return a pointer tools/nolibc: clean up mmap() routine
tools/nolibc: clean up sbrk() routine
selftests/nolibc: export argv0 for some tests
selftests/nolibc: prepare: create /dev/zero
selftests/nolibc: add EXPECT_PTREQ, EXPECT_PTRNE and EXPECT_PTRER selftests/nolibc: add sbrk_0 to test current brk getting selftests/nolibc: add mmap_bad test case
selftests/nolibc: add munmap_bad test case
selftests/nolibc: add mmap_munmap_good test case
selftests/nolibc: add run-libc-test target
selftests/nolibc: stat_fault: silence NULL argument warning with glibc selftests/nolibc: gettid: restore for glibc and musl
selftests/nolibc: add _LARGEFILE64_SOURCE for musl
selftests/nolibc: fix up int_fast16/32_t test cases for musl tools/nolibc: types.h: add RB_ flags for reboot()
selftests/nolibc: prefer <sys/reboot.h> to <linux/reboot.h> selftests/nolibc: fix up kernel parameters support
selftests/nolibc: link_cross: use /proc/self/cmdline
tools/nolibc: add rmdir() support
selftests/nolibc: add a new rmdir() test case
selftests/nolibc: fix up failures when CONFIG_PROC_FS=n selftests/nolibc: prepare /tmp for tests that need to write selftests/nolibc: vfprintf: remove MEMFD_CREATE dependency selftests/nolibc: chdir_root: restore current path after test selftests/nolibc: stat_timestamps: remove procfs dependency selftests/nolibc: chroot_exe: remove procfs dependency selftests/nolibc: add chmod_argv0 test
selftests/nolibc: report: print a summarized test status selftests/nolibc: report: print total tests
selftests/nolibc: report: align passed, skipped and failed selftests/nolibc: report: extrude the test status line selftests/nolibc: report: add newline before test failures tools/nolibc: arch-*.h: add missing space after ','
tools/nolibc: fix up startup failures for -O0 under gcc < 11.1.0 tools/nolibc: remove the old sys_stat support
tools/nolibc: add new crt.h with _start_c
tools/nolibc: stackprotector.h: add empty __stack_chk_init for !_NOLIBC_STACKPROTECTOR tools/nolibc: crt.h: initialize stack protector
tools/nolibc: arm: shrink _start with _start_c
tools/nolibc: aarch64: shrink _start with _start_c
tools/nolibc: i386: shrink _start with _start_c
tools/nolibc: x86_64: shrink _start with _start_c
tools/nolibc: mips: shrink _start with _start_c
tools/nolibc: loongarch: shrink _start with _start_c
tools/nolibc: riscv: shrink _start with _start_c
tools/nolibc: s390: shrink _start with _start_c
selftests/nolibc: add EXPECT_PTRGE, EXPECT_PTRGT, EXPECT_PTRLE, EXPECT_PTRLT selftests/nolibc: add testcases for startup code
selftests/nolibc: allow run nolibc-test locally
selftests/nolibc: allow test -include /path/to/nolibc.h selftests/nolibc: mmap_munmap_good: fix up return value
tools/nolibc: add support for powerpc
tools/nolibc: add support for powerpc64
selftests/nolibc: add XARCH and ARCH mapping support
selftests/nolibc: add test support for ppc
selftests/nolibc: add test support for ppc64le
selftests/nolibc: add test support for ppc64
selftests/nolibc: allow report with existing test log
tools/nolibc: stackprotector.h: make __stack_chk_init static selftests/nolibc: libc-test: use HOSTCC instead of CC
tools/nolibc: silence ppc64 compile warnings
MAINTAINERS | 1 + tools/include/nolibc/Makefile | 1 + tools/include/nolibc/arch-aarch64.h | 85 +--- tools/include/nolibc/arch-arm.h | 111 +---- tools/include/nolibc/arch-i386.h | 86 +--- tools/include/nolibc/arch-loongarch.h | 83 +--- tools/include/nolibc/arch-mips.h | 147 +++---- tools/include/nolibc/arch-powerpc.h | 221 ++++++++++ tools/include/nolibc/arch-riscv.h | 83 +--- tools/include/nolibc/arch-s390.h | 77 +--- tools/include/nolibc/arch-x86_64.h | 86 +--- tools/include/nolibc/arch.h | 2 + tools/include/nolibc/crt.h | 61 +++ tools/include/nolibc/nolibc.h | 9 +- tools/include/nolibc/stackprotector.h | 5 +- tools/include/nolibc/stdint.h | 2 +- tools/include/nolibc/stdio.h | 27 ++ tools/include/nolibc/stdlib.h | 12 +- tools/include/nolibc/sys.h | 534 +++++++---------------- tools/include/nolibc/types.h | 22 +- tools/include/nolibc/unistd.h | 13 +- tools/testing/selftests/nolibc/Makefile | 111 +++-- tools/testing/selftests/nolibc/nolibc-test.c | 608 ++++++++++++++++++++------- 23 files changed, 1221 insertions(+), 1166 deletions(-) create mode 100644 tools/include/nolibc/arch-powerpc.h create mode 100644 tools/include/nolibc/crt.h
----------------------------------------------------------------
MAINTAINERS +1 -0
@@ -14979,6 +14979,7 @@ F: include/linux/power/bq27xxx_battery.h NOLIBC HEADER FILE M: Willy Tarreau <[email protected]> +M: Thomas Weißschuh <[email protected]> S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/wtarreau/nolibc.git F: tools/include/nolibc/
tools/include/nolibc/Makefile +1 -0
@@ -27,6 +27,7 @@ nolibc_arch := $(patsubst arm64,aarch64,$(ARCH)) arch_file := arch-$(nolibc_arch).h all_files := \ compiler.h \ + crt.h \ ctype.h \ errno.h \ nolibc.h \
tools/include/nolibc/arch-aarch64.h +19 -66
142 lines not on this page · raw message
tools/include/nolibc/arch-arm.h +20 -91
168 lines not on this page · raw message
tools/include/nolibc/arch-i386.h +20 -66
142 lines not on this page · raw message
tools/include/nolibc/arch-loongarch.h +21 -62
176 lines not on this page · raw message
tools/include/nolibc/arch-mips.h +56 -91
238 lines not on this page · raw message
tools/include/nolibc/arch-powerpc.h new file +221 -0
221 lines not on this page · raw message
tools/include/nolibc/arch-riscv.h +13 -70
143 lines not on this page · raw message
tools/include/nolibc/arch-s390.h +13 -64
134 lines not on this page · raw message
tools/include/nolibc/arch-x86_64.h +21 -65
148 lines not on this page · raw message
tools/include/nolibc/arch.h +2 -0
@@ -25,6 +25,8 @@#include "arch-aarch64.h" #elif defined(__mips__) && defined(_ABIO32)#include "arch-mips.h" +#elif defined(__powerpc__) +#include "arch-powerpc.h" #elif defined(__riscv)#include "arch-riscv.h" #elif defined(__s390x__)
tools/include/nolibc/crt.h new file +61 -0
61 lines not on this page · raw message
tools/include/nolibc/nolibc.h +4 -5
@@ -13,11 +13,10 @@* Syscalls are split into 3 levels: * - The lower level is the arch-specific syscall() definition, consisting in * assembly code in compound expressions. These are called my_syscall0() to -* my_syscall6() depending on the number of arguments. The MIPS -* implementation is limited to 5 arguments. All input arguments are cast -* to a long stored in a register. These expressions always return the -* syscall's return value as a signed long value which is often either a -* pointer or the negated errno value. +* my_syscall6() depending on the number of arguments. All input arguments +* are castto a long stored in a register. These expressions always return +* the syscall's return value as a signed long value which is often either +* a pointer or the negated errno value. * * - The second level is mostly architecture-independent. It is made of * static functions called sys_<name>() which rely on my_syscallN()
tools/include/nolibc/stackprotector.h +3 -2
@@ -37,14 +37,15 @@ void __stack_chk_fail_local(void) __attribute__((weak,section (".data.nolibc_stack_chk" )))uintptr_t __stack_chk_guard; -__attribute__((weak,section (".text.nolibc_stack_chk" )))__no_stack_protector -void __stack_chk_init(void) +static __no_stack_protector void __stack_chk_init(void) {my_syscall3 (__NR_getrandom, &__stack_chk_guard,sizeof (__stack_chk_guard),0 );/* a bit more randomness in case getrandom() fails, ensure the guard is never 0 */ if (__stack_chk_guard != (uintptr_t ) &__stack_chk_guard) __stack_chk_guard ^= (uintptr_t ) &__stack_chk_guard; } +#else /* !defined(_NOLIBC_STACKPROTECTOR) */ +static void __stack_chk_init (void ) {}#endif /* defined(_NOLIBC_STACKPROTECTOR) */ #endif /* _NOLIBC_STACKPROTECTOR_H */
tools/include/nolibc/stdint.h +1 -1
@@ -15,7 +15,7 @@ typedef unsigned int uint32_t;typedef signed int int32_t ;typedef unsigned long long uint64_t ;typedef signed long long int64_t ; -typedef unsigned long size_t ; +typedef __SIZE_TYPE__ size_t ;typedef signed long ssize_t ;typedef unsigned long uintptr_t ;typedef signed long intptr_t ;
tools/include/nolibc/stdio.h +27 -0
@@ -21,6 +21,11 @@#define EOF (-1)#endif +/* Buffering mode used by setvbuf. */ +#define _IOFBF 0/* Fully buffered. */ +#define _IOLBF 1/* Line buffered. */ +#define _IONBF 2/* No buffering. */ +/* just define FILE as a non-empty type. The value of the pointer gives * the FD: FILE=~fd for fd>=0 or NULL for fd<0. This way positive FILE * are immediately identified as abnormal entries (i.e. possible copies
@@ -350,6 +355,28 @@ void perror(const char *msg)fprintf (stderr,"%s%serrno=%d\n" , (msg && *msg) ? msg :"" , (msg && *msg) ?": " :"" , errno); } +static __attribute__((unused)) +int setvbuf (FILE *stream __attribute__((unused)), +char *buf __attribute__((unused)), +int mode, +size_t size __attribute__((unused))) +{ +/* +* nolibc does not support buffering so this is a nop. Just check mode +* is valid as required by the spec. +*/ +switch (mode) { +case _IOFBF: +case _IOLBF: +case _IONBF: +break ; +default : +return EOF ; + } + +return 0 ; +} +/* make sure to include all global symbols */ #include "nolibc.h"
tools/include/nolibc/stdlib.h +2 -10
@@ -83,11 +83,10 @@ void free(void *ptr)* declared as a char **, and must be terminated by a NULL (it is recommended * to set this variable to the "envp" argument of main()). If the requested * environment variable exists its value is returned otherwise NULL is -* returned. getenv() is forcefully inlined so that the reference to "environ" -* will be dropped if unused, even at -O0. +* returned. */ static __attribute__((unused)) -char *_getenv (const char *name,char **environ) +char *getenv (const char *name) {int idx, i;
@@ -102,13 +101,6 @@ char *_getenv(const char *name, char **environ)return NULL ; } -static __inline__ __attribute__((unused,always_inline)) -char *getenv (const char *name) -{ -extern char **environ; -return _getenv (name, environ); -} -static __attribute__((unused))unsigned long getauxval (unsigned long type) {
tools/include/nolibc/sys.h +147 -387
946 lines not on this page · raw message
tools/include/nolibc/types.h +19 -3
@@ -8,13 +8,15 @@#define _NOLIBC_TYPES_H#include "std.h" -#include <linux/time.h> +#include <linux/mman.h> +#include <linux/reboot.h> /* for LINUX_REBOOT_* */ #include <linux/stat.h> +#include <linux/time.h> /* Only the generic macros and types may be defined here. The arch-specific -* ones such as the O_RDONLY and related macros used by fcntl() and open(), or -* the layout of sys_stat_struct must not be defined here. +* ones such as the O_RDONLY and related macros used by fcntl() and open() +* must not be defined here. */ /* stat flags (WARNING, octal here). We need to check for an existing
@@ -81,11 +83,25 @@#define MAXPATHLEN (PATH_MAX)#endif +/* flags for mmap */ +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif +/* whence values for lseek() */ #define SEEK_SET 0#define SEEK_CUR 1#define SEEK_END 2 +/* flags for reboot */ +#define RB_AUTOBOOT LINUX_REBOOT_CMD_RESTART +#define RB_HALT_SYSTEM LINUX_REBOOT_CMD_HALT +#define RB_ENABLE_CAD LINUX_REBOOT_CMD_CAD_ON +#define RB_DISABLE_CAD LINUX_REBOOT_CMD_CAD_OFF +#define RB_POWER_OFF LINUX_REBOOT_CMD_POWER_OFF +#define RB_SW_SUSPEND LINUX_REBOOT_CMD_SW_SUSPEND +#define RB_KEXEC LINUX_REBOOT_CMD_KEXEC +/* Macros used on waitpid()'s return status */ #define WEXITSTATUS (status) (((status) & 0xff00) >> 8)#define WIFEXITED (status) (((status) & 0x7f) == 0)
tools/include/nolibc/unistd.h +2 -11
@@ -56,18 +56,9 @@ int tcsetpgrp(int fd, pid_t pid)return ioctl (fd,TIOCSPGRP , &pid); } -#define _syscall (N , ...) \ -({ \ - long _ret = my_syscall##N(__VA_ARGS__); \ - if (_ret < 0) { \ - SET_ERRNO(-_ret); \ - _ret = -1; \ - } \ - _ret; \ -}) - -#define _syscall_narg (...) __syscall_narg(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0)#define __syscall_narg (_0, _1, _2, _3, _4, _5, _6,N , ...) N +#define _syscall_narg (...) __syscall_narg(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0) +#define _syscall (N , ...) __sysret(my_syscall##N(__VA_ARGS__))#define _syscall_n (N , ...) _syscall(N, __VA_ARGS__)#define syscall (...) _syscall_n(_syscall_narg(__VA_ARGS__), ##__VA_ARGS__)
tools/testing/selftests/nolibc/Makefile +84 -27
205 lines not on this page · raw message
tools/testing/selftests/nolibc/nolibc-test.c +463 -145
86 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
The pull request you sent on Mon, 28 Aug 2023 12:32:58 -0600:
The pull request you sent on Mon, 28 Aug 2023 12:32:58 -0600:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftesttags/linux-kselftest-nolibc-6.6-rc1
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/1c59d383390f970b891b503b7f79b63a02db2ec5
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html