aboutsummaryrefslogtreecommitdiff
path: root/tools/include/nolibc
AgeCommit message (Collapse)AuthorFilesLines
2023-08-23tools/nolibc: add pipe() and pipe2() supportYuan Tan1-0/+24
According to manual page [1], posix spec [2] and source code like arch/mips/kernel/syscall.c, for historic reasons, the sys_pipe() syscall on some architectures has an unusual calling convention. It returns results in two registers which means there is no need for it to do verify the validity of a userspace pointer argument. Historically that used to be expensive in Linux. These days the performance advantage is negligible. Nolibc doesn't support the unusual calling convention above, luckily Linux provides a generic sys_pipe2() with an additional flags argument from 2.6.27. If flags is 0, then pipe2() is the same as pipe(). So here we use sys_pipe2() to implement the pipe(). pipe2() is also provided to allow users to use flags argument on demand. [1]: https://man7.org/linux/man-pages/man2/pipe.2.html [2]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/pipe.html Suggested-by: Zhangjin Wu <[email protected]> Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Yuan Tan <[email protected]> Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc/stdio: add setvbuf() to set buffering modeRyan Roberts1-0/+24
Add a minimal implementation of setvbuf(), which error checks the mode argument (as required by spec) and returns. Since nolibc never buffers output, nothing needs to be done. The kselftest framework recently added a call to setvbuf(). As a result, any tests that use the kselftest framework and nolibc cause a compiler error due to missing function. This provides an urgent fix for the problem which is preventing arm64 testing on linux-next. Example: clang --target=aarch64-linux-gnu -fintegrated-as -Werror=unknown-warning-option -Werror=ignored-optimization-argument -Werror=option-ignored -Werror=unused-command-line-argument --target=aarch64-linux-gnu -fintegrated-as -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib \ -include ../../../../include/nolibc/nolibc.h -I../..\ -static -ffreestanding -Wall za-fork.c build/kselftest/arm64/fp/za-fork-asm.o -o build/kselftest/arm64/fp/za-fork In file included from <built-in>:1: In file included from ./../../../../include/nolibc/nolibc.h:97: In file included from ./../../../../include/nolibc/arch.h:25: ./../../../../include/nolibc/arch-aarch64.h:178:35: warning: unknown attribute 'optimize' ignored [-Wunknown-attributes] void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_stack_protector _start(void) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from za-fork.c:12: ../../kselftest.h:123:2: error: call to undeclared function 'setvbuf'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] setvbuf(stdout, NULL, _IOLBF, 0); ^ ../../kselftest.h:123:24: error: use of undeclared identifier '_IOLBF' setvbuf(stdout, NULL, _IOLBF, 0); ^ 1 warning and 2 errors generated. Signed-off-by: Ryan Roberts <[email protected]> Reported-by: Linux Kernel Functional Testing <[email protected]> Link: https://lore.kernel.org/linux-kselftest/CA+G9fYus3Z8r2cg3zLv8uH8MRrzLFVWdnor02SNr=rCz+_WGVg@mail.gmail.com/ Reviewed-by: Mark Brown <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: s390: shrink _start with _start_cZhangjin Wu1-31/+5
move most of the _start operations to _start_c(), include the stackprotector initialization. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: riscv: shrink _start with _start_cZhangjin Wu1-39/+5
move most of the _start operations to _start_c(), include the stackprotector initialization. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: loongarch: shrink _start with _start_cZhangjin Wu1-40/+4
move most of the _start operations to _start_c(), include the stackprotector initialization. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: mips: shrink _start with _start_cZhangjin Wu1-38/+8
move most of the _start operations to _start_c(), include the stackprotector initialization. Also clean up the instructions in delayed slots. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: x86_64: shrink _start with _start_cZhangjin Wu1-23/+6
move most of the _start operations to _start_c(), include the stackprotector initialization. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: i386: shrink _start with _start_cZhangjin Wu1-27/+7
move most of the _start operations to _start_c(), include the stackprotector initialization. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: aarch64: shrink _start with _start_cZhangjin Wu1-23/+4
move most of the _start operations to _start_c(), include the stackprotector initialization. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: arm: shrink _start with _start_cZhangjin Wu1-39/+5
move most of the _start operations to _start_c(), include the stackprotector initialization. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: crt.h: initialize stack protectorZhangjin Wu1-0/+4
As suggested by Thomas, It is able to move the stackprotector initialization from the assembly _start to the beginning of the new _start_c(). Let's call __stack_chk_init() in _start_c() as a preparation. Suggested-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: stackprotector.h: add empty __stack_chk_init for ↵Zhangjin Wu1-0/+2
!_NOLIBC_STACKPROTECTOR Let's define an empty __stack_chk_init for the !_NOLIBC_STACKPROTECTOR branch. This allows to remove #ifdef around every call of __stack_chk_init(). Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: add new crt.h with _start_cZhangjin Wu2-0/+58
As the environ and _auxv support added for nolibc, the assembly _start function becomes more and more complex and therefore makes the porting of nolibc to new architectures harder and harder. To simplify portability, this C version of _start_c() is added to do most of the assembly start operations in C, which reduces the complexity a lot and will eventually simplify the porting of nolibc to the new architectures. The new _start_c() only requires a stack pointer argument, it will find argc, argv, envp/environ and _auxv for us, and then call main(), finally, it exit() with main's return status. With this new _start_c(), the future new architectures only require to add very few assembly instructions. As suggested by Thomas, users may use a different signature of main (e.g. void main(void)), a _nolibc_main alias is added for main to silence the warning about potential conflicting types. As suggested by Willy, the code is carefully polished for both smaller size and better readability with local variables and the right types. Suggested-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Suggested-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: remove the old sys_stat supportZhangjin Wu9-248/+13
The statx manpage [1] shows that it has been supported from Linux 4.11 and glibc 2.28, the Linux support can be checked for all of the architectures with this command: $ git grep -r statx v4.11 arch/ include/uapi/asm-generic/unistd.h \ | grep -E "aarch64|arm|mips|s390|x86|:include/uapi" Besides riscv and loongarch, all of the nolibc supported architectures have added sys_statx from Linux v4.11. riscv is mainlined to v4.15, loongarch is mainlined to v5.19, both of them use the generic unistd.h, so, they have added sys_statx from their first mainline versions. The current oldest stable branch is v4.14, only reserving sys_statx still preserves compatibility with all of the supported stable branches, So, let's remove the old arch related and dependent sys_stat support completely. This is friendly to the future new architecture porting. [1]: https://man7.org/linux/man-pages/man2/statx.2.html Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: fix up startup failures for -O0 under gcc < 11.1.0Zhangjin Wu8-8/+8
As gcc doc [1] shows: Most optimizations are completely disabled at -O0 or if an -O level is not set on the command line, even if individual optimization flags are specified. Test result [2] shows, gcc>=11.1.0 deviates from the above description, but before gcc 11.1.0, "-O0" still forcely uses frame pointer in the _start function even if the individual optimize("omit-frame-pointer") flag is specified. The frame pointer related operations will change the stack pointer (e.g. In x86_64, an extra "push %rbp" will be inserted at the beginning of _start) and make it differs from the one we expected, as a result, break the whole startup function. To fix up this issue, as suggested by Thomas, the individual "Os" and "omit-frame-pointer" optimize flags are used together on _start function to disable frame pointer completely even if the -O0 is set on the command line. [1]: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html [2]: https://lore.kernel.org/lkml/[email protected]/ Suggested-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Fixes: 7f8548589661 ("tools/nolibc: make compiler and assembler agree on the section around _start") Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: arch-*.h: add missing space after ','Zhangjin Wu8-8/+8
Fix up such errors reported by scripts/checkpatch.pl: ERROR: space required after that ',' (ctx:VxV) #148: FILE: tools/include/nolibc/arch-aarch64.h:148: +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_stack_protector _start(void) ^ ERROR: space required after that ',' (ctx:VxV) #148: FILE: tools/include/nolibc/arch-aarch64.h:148: +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_stack_protector _start(void) ^ Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: completely remove optional environ supportThomas Weißschuh1-10/+2
In commit 52e423f5b93e ("tools/nolibc: export environ as a weak symbol on i386") and friends the asm startup logic was extended to directly populate the "environ" array. This makes it impossible for "environ" to be dropped by the linker. Therefore also drop the other logic to handle non-present "environ". Also add a testcase to validate the initialization of environ. Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: add rmdir() supportZhangjin Wu1-0/+22
a reverse operation of mkdir() is meaningful, add rmdir() here. required by nolibc-test to remove /proc while CONFIG_PROC_FS is not enabled. Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: types.h: add RB_ flags for reboot()Zhangjin Wu2-2/+11
Both glibc and musl provide RB_ flags via <sys/reboot.h> for reboot(), they don't need to include <linux/reboot.h>, let nolibc provide RB_ flags too. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: clean up sbrk() routineZhangjin Wu1-5/+4
Fix up the error reported by scripts/checkpatch.pl: ERROR: do not use assignment in if condition #95: FILE: tools/include/nolibc/sys.h:95: + if ((ret = sys_brk(0)) && (sys_brk(ret + inc) == ret + inc)) Apply the new generic __sysret() to merge the SET_ERRNO() and return lines. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: clean up mmap() routineZhangjin Wu2-23/+12
Do several cleanups together: - Since all supported architectures have my_syscall6() now, remove the #ifdef check. - Move the mmap() related macros to tools/include/nolibc/types.h and reuse most of them from <linux/mman.h> - Apply the new generic __sysret() to convert the calling of sys_map() to oneline code Note, since MAP_FAILED is -1 on Linux, so we can use the generic __sysret() which returns -1 upon error and still satisfy user land that checks for MAP_FAILED. Suggested-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: __sysret: support syscalls who return a pointerZhangjin Wu1-5/+12
No official reference states the errno range, here aligns with musl and glibc and uses [-MAX_ERRNO, -1] instead of all negative ones. - musl: src/internal/syscall_ret.c - glibc: sysdeps/unix/sysv/linux/sysdep.h The MAX_ERRNO used by musl and glibc is 4095, just like the one nolibc defined in tools/include/nolibc/errno.h. Suggested-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/lkml/ZKKdD%[email protected]/ Suggested-by: David Laight <[email protected]> Link: https://lore.kernel.org/linux-riscv/[email protected]/ Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: add missing my_syscall6() for mipsZhangjin Wu2-6/+30
It is able to pass the 6th argument like the 5th argument via the stack for mips, let's add a new my_syscall6() now, see [1] for details: The mips/o32 system call convention passes arguments 5 through 8 on the user stack. Both mmap() and pselect6() require my_syscall6(). [1]: https://man7.org/linux/man-pages/man2/syscall.2.html Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: arch-mips.h: shrink with _NOLIBC_SYSCALL_CLOBBERLISTZhangjin Wu1-12/+10
my_syscall<N> share the same long clobber list, define a macro for them. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: arch-loongarch.h: shrink with _NOLIBC_SYSCALL_CLOBBERLISTZhangjin Wu1-14/+9
my_syscall<N> share the same long clobber list, define a macro for them. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23toolc/nolibc: arch-*.h: clean up whitespaces after __asm__Zhangjin Wu8-54/+54
replace "__asm__ volatile" with "__asm__ volatile" and insert necessary whitespace before "\" to make sure the lines are aligned. $ sed -i -e 's/__asm__ volatile ( /__asm__ volatile ( /g' tools/include/nolibc/*.h Note, arch-s390.h uses post-tab instead of post-whitespaces, must avoid insert whitespace just before the tabs: $ sed -i -e 's/__asm__ volatile (\t/__asm__ volatile (\t/g' tools/include/nolibc/arch-*.h Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-23tools/nolibc: arch-*.h: fix up code indent errorsZhangjin Wu5-39/+39
More than 8 whitespaces of the code indent are replaced with "tab + whitespaces" to fix up such errors reported by scripts/checkpatch.pl: ERROR: code indent should use tabs where possible #64: FILE: tools/include/nolibc/arch-mips.h:64: +^I \$ ERROR: code indent should use tabs where possible #72: FILE: tools/include/nolibc/arch-mips.h:72: +^I "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" \$ This command is used: $ sed -i -e '/^\t* /{s/ /\t/g}' tools/include/nolibc/arch-*.h Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-06tools/nolibc: unistd.h: reorder the syscall macrosZhangjin Wu1-2/+2
Tune the macros in the using order and align most of them. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-06tools/nolibc: sys.h: apply __sysret() helperZhangjin Wu1-310/+44
Use __sysret() to shrink most of the library routines to oneline code. Removed 266 lines of duplicated code. Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-06tools/nolibc: unistd.h: apply __sysret() helperZhangjin Wu1-10/+1
Use __sysret() to shrink the whole _syscall() to oneline code. Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-06tools/nolibc: sys.h: add a syscall return helperZhangjin Wu1-0/+10
Most of the library routines share the same syscall return logic: In general, a 0 return value indicates success. A -1 return value indicates an error, and an error number is stored in errno. [1] Let's add a __sysret() helper for the above logic to simplify the coding and shrink the code lines too. Thomas suggested to use inline function instead of macro for __sysret(). Willy suggested to make __sysret() be always inline. [1]: https://man7.org/linux/man-pages/man2/syscall.2.html Suggested-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/linux-riscv/[email protected]/ Suggested-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/linux-riscv/[email protected]/ Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-06tools/nolibc: fix up undeclared syscall macros with #ifdef and -ENOSYSZhangjin Wu1-0/+12
Compiling nolibc for rv32 got such errors: nolibc/sysroot/riscv/include/sys.h: In function ‘sys_gettimeofday’: nolibc/sysroot/riscv/include/sys.h:557:21: error: ‘__NR_gettimeofday’ undeclared (first use in this function); did you mean ‘sys_gettimeofday’? 557 | return my_syscall2(__NR_gettimeofday, tv, tz); | ^~~~~~~~~~~~~~~~~ nolibc/sysroot/riscv/include/sys.h: In function ‘sys_lseek’: nolibc/sysroot/riscv/include/sys.h:675:21: error: ‘__NR_lseek’ undeclared (first use in this function) 675 | return my_syscall3(__NR_lseek, fd, offset, whence); | ^~~~~~~~~~ nolibc/sysroot/riscv/include/sys.h: In function ‘sys_wait4’: nolibc/sysroot/riscv/include/sys.h:1341:21: error: ‘__NR_wait4’ undeclared (first use in this function) 1341 | return my_syscall4(__NR_wait4, pid, status, options, rusage); If a syscall macro is not supported by a target platform, wrap it with '#ifdef' and 'return -ENOSYS' for the '#else' branch, which lets the other syscalls work as-is and allows developers to fix up the test failures reported by nolibc-test one by one later. This wraps all of the failed syscall macros with '#ifdef' and 'return -ENOSYS' for the '#else' branch, so, all of the undeclared failures are fixed. Suggested-by: Arnd Bergmann <[email protected]> Link: https://lore.kernel.org/linux-riscv/[email protected]/ Reviewed-by: Arnd Bergmann <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-08-06tools/nolibc: fix up #error compile failures with -ENOSYSZhangjin Wu1-13/+13
Compiling nolibc for rv32 got such errors: In file included from nolibc/sysroot/riscv/include/nolibc.h:99, from nolibc/sysroot/riscv/include/errno.h:26, from nolibc/sysroot/riscv/include/stdio.h:14, from tools/testing/selftests/nolibc/nolibc-test.c:12: nolibc/sysroot/riscv/include/sys.h:946:2: error: #error Neither __NR_ppoll nor __NR_poll defined, cannot implement sys_poll() 946 | #error Neither __NR_ppoll nor __NR_poll defined, cannot implement sys_poll() | ^~~~~ nolibc/sysroot/riscv/include/sys.h:1062:2: error: #error None of __NR_select, __NR_pselect6, nor __NR__newselect defined, cannot implement sys_select() 1062 | #error None of __NR_select, __NR_pselect6, nor __NR__newselect defined, cannot implement sys_select() If a syscall is not supported by a target platform, 'return -ENOSYS' is better than '#error', which lets the other syscalls work as-is and allows developers to fix up the test failures reported by nolibc-test one by one later. This converts all of the '#error' to 'return -ENOSYS', so, all of the '#error' failures are fixed. Suggested-by: Arnd Bergmann <[email protected]> Link: https://lore.kernel.org/linux-riscv/[email protected]/ Reviewed-by: Arnd Bergmann <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
2023-06-09tools/nolibc: open: fix up compile warning for armZhangjin Wu1-1/+1
In function ‘open’: nolibc/sysroot/arm/include/sys.h:919:23: warning: ‘mode_t’ {aka ‘short unsigned int’} is promoted to ‘int’ when passed through ‘...’ 919 | mode = va_arg(args, mode_t); | ^ nolibc/sysroot/arm/include/sys.h:919:23: note: (so you should pass ‘int’ not ‘mode_t’ {aka ‘short unsigned int’} to ‘va_arg’) nolibc/sysroot/arm/include/sys.h:919:23: note: if this code is reached, the program will abort Signed-off-by: Zhangjin Wu <[email protected]> Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09tools/nolibc: arm: add missing my_syscall6Zhangjin Wu1-0/+23
This is required by the coming removal of the oldselect and newselect support. pselect6/pselect6_time64 will be used unconditionally, they have 6 arguments. Suggested-by: Arnd Bergmann <[email protected]> Link: https://lore.kernel.org/linux-riscv/[email protected]/ Signed-off-by: Zhangjin Wu <[email protected]> Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09selftests/nolibc: not include limits.h for nolibcZhangjin Wu1-0/+14
When compile nolibc-test.c with 2.31 glibc, we got such error: In file included from /usr/riscv64-linux-gnu/include/sys/cdefs.h:452, from /usr/riscv64-linux-gnu/include/features.h:461, from /usr/riscv64-linux-gnu/include/bits/libc-header-start.h:33, from /usr/riscv64-linux-gnu/include/limits.h:26, from /usr/lib/gcc-cross/riscv64-linux-gnu/9/include/limits.h:194, from /usr/lib/gcc-cross/riscv64-linux-gnu/9/include/syslimits.h:7, from /usr/lib/gcc-cross/riscv64-linux-gnu/9/include/limits.h:34, from /labs/linux-lab/src/linux-stable/tools/testing/selftests/nolibc/nolibc-test.c:6: /usr/riscv64-linux-gnu/include/bits/wordsize.h:28:3: error: #error "rv32i-based targets are not supported" 28 | # error "rv32i-based targets are not supported" Glibc (>= 2.33) commit 5b6113d62efa ("RISC-V: Support the 32-bit ABI implementation") fixed up above error. As suggested by Thomas, defining INT_MIN/INT_MAX for nolibc can remove the including of limits.h, and therefore no above error. of course, the other libcs still require limits.h, move it to the right place. The LONG_MIN/LONG_MAX are also defined too. Suggested-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/linux-riscv/[email protected]/ Signed-off-by: Zhangjin Wu <[email protected]> Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09tools/nolibc: ensure fast64 integer types have 64 bitsThomas Weißschuh1-5/+5
On 32bit platforms size_t is not enough to represent [u]int_fast64_t. Fixes: 3e9fd4e9a1d5 ("tools/nolibc: add integer types and integer limit macros") Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09tools/nolibc: ppoll/ppoll_time64: add a missing argumentZhangjin Wu1-1/+1
The ppoll and ppoll_time64 syscalls have 5 arguments, but we only provide 4, align with kernel and add the missing sigsetsize argument. Because the sigmask is NULL, the last sigsetsize argument is ignored, keep it as 0 here is safe enough. Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09tools/nolibc: support nanoseconds in stat()Thomas Weißschuh2-33/+39
Keep backwards compatibility through unions. The compatibility macros like #define st_atime st_atim.tv_sec as documented in stat(3type) don't work for nolibc because it would break with other stat-like structures that contain the field st_atime. The stx_atime, stx_mtime, stx_ctime are in type of 'struct statx_timestamp', which is incompatible with 'struct timespec', should be converted explicitly. /* include/uapi/linux/stat.h */ struct statx_timestamp { __s64 tv_sec; __u32 tv_nsec; __s32 __reserved; }; /* include/uapi/linux/time.h */ struct timespec { __kernel_old_time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ }; Signed-off-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/linux-riscv/[email protected]/ Co-authored-by: Zhangjin Wu <[email protected]> Signed-off-by: Zhangjin Wu <[email protected]> [wt: squashed Zhangjin & Thomas' patches into one to preserve "bisectability"] Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09tools/nolibc: add support for prctl()Thomas Weißschuh1-0/+27
It will be used to disable core dumps from the child spawned to validate the stack protector functionality. Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09tools/nolibc: s390: disable stackprotector in _startThomas Weißschuh1-1/+3
s390 does not support the "global" stack protector mode that is implemented in nolibc. Now that nolibc detects if stack protectors are enabled at runtime it could happen that a future compiler does indeed use global mode on and nolibc would compile but segfault at runtime. To avoid this hypothetic case and to align s390 with the other architectures disable stack protectors when compiling _start(). Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09tools/nolibc: fix segfaults on compilers without attribute no_stack_protectorThomas Weißschuh9-8/+18
Not all compilers, notably GCC < 10, have support for __attribute__((no_stack_protector)). Fall back to a mechanism that also works there. Tested with GCC 9.5.0 from kernel.org crosstools. Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09tools/nolibc: add autodetection for stackprotector supportThomas Weißschuh10-28/+40
The stackprotector support in nolibc should be enabled iff it is also enabled in the compiler. Use the preprocessor defines added by gcc and clang if stackprotector support is enable to automatically do so in nolibc. This completely removes the need for any user-visible API. To avoid inlining the lengthy preprocessor check into every user introduce a new header compiler.h that abstracts the logic away. As the define NOLIBC_STACKPROTECTOR is now not user-relevant anymore prefix it with an underscore. Suggested-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09tools/nolibc: reformat list of headers to be installedThomas Weißschuh1-2/+16
This makes it easier to add and remove more entries in the future without creating spurious diff hunks. Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09tools/nolibc: ensure stack protector guard is never zeroThomas Weißschuh1-2/+3
The all-zero pattern is one of the more probable out-of-bound writes so add a special case to not accidentally accept it. Also it enables the reliable detection of stack protector initialization during testing. Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09tools/nolibc: x86_64: disable stack protector for _startThomas Weißschuh1-1/+1
This was forgotten in the original submission. It is unknown why it worked for x86_64 on some compiler without this attribute. Reported-by: Willy Tarreau <[email protected]> Closes: https://lore.kernel.org/lkml/[email protected]/ Fixes: 0d8c461adbc4 ("tools/nolibc: x86_64: add stackprotector support") Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09tools/nolibc: fix typo pint -> pointThomas Weißschuh1-1/+1
Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09tools/nolibc: riscv: add stackprotector supportThomas Weißschuh1-1/+6
Signed-off-by: Thomas Weißschuh <[email protected]> Acked-by: Palmer Dabbelt <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09tools/nolibc: mips: add stackprotector supportThomas Weißschuh1-1/+7
Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
2023-06-09tools/nolibc: loongarch: add stackprotector supportThomas Weißschuh1-1/+6
Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>