nolibc for 6.12-rc1
Subsystems (3)
Shuah Khan
maintainerHi Linus,
Please pull the following nolibc update for Linux 6.12-rc1.
This nolibc update for Linux 6.12-rc1 consists of:
Highlights
----------
* Clang support (including LTO)
Other Changes
-------------
* stdbool.h support
* argc/argv/envp arguments for constructors
* Small #include ordering fix
Test Results:
Passed:tools/testing/selftests/nolibc/run-tests.sh tools/testing/selftests/nolibc/run-tests.sh -m user
diff is attached.
thanks,
-- Shuah
----------------------------------------------------------------
The following changes since commit 8400291e289ee6b2bf9779ff1c83a291501f017b:
Linux 6.11-rc1 (2024-07-28 14:19:55 -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.12-rc1
for you to fetch changes up to 248f6b935bbd8f7bc211cce2b6fd76be4c449848:
Merge tag 'nolibc-20240824-for-6.12-1' of https://git.kernel.org/pub/scm/linux/kernel/git/nolibc/linux-nolibc into nolibc (2024-08-27 06:43:34 -0600)
----------------------------------------------------------------
linux_kselftest-nolibc-6.12-rc1
This nolibc update for Linux 6.12-rc1 consists of:
Highlights
----------
* Clang support (including LTO)
Other Changes
-------------
* stdbool.h support
* argc/argv/envp arguments for constructors
* Small #include ordering fix
----------------------------------------------------------------
Shuah Khan (1):
Merge tag 'nolibc-20240824-for-6.12-1' of https://git.kernel.org/pub/scm/linux/kernel/git/nolibc/linux-nolibc into nolibc
Thomas Weißschuh (21):
tools/nolibc: include arch.h from string.h tools/nolibc: add stdbool.h header
tools/nolibc: pass argc, argv and envp to constructors tools/nolibc: arm: use clang-compatible asm syntax tools/nolibc: mips: load current function to $t9 tools/nolibc: powerpc: limit stack-protector workaround to GCC tools/nolibc: compiler: introduce __nolibc_has_attribute() tools/nolibc: move entrypoint specifics to compiler.h tools/nolibc: compiler: use attribute((naked)) if available selftests/nolibc: report failure if no testcase passed selftests/nolibc: avoid passing NULL to printf("%s") selftests/nolibc: determine $(srctree) first selftests/nolibc: add support for LLVM= parameter selftests/nolibc: add cc-option compatible with clang cross builds selftests/nolibc: run-tests.sh: avoid overwriting CFLAGS_EXTRA selftests/nolibc: don't use libgcc when building with clang selftests/nolibc: use correct clang target for s390/systemz selftests/nolibc: run-tests.sh: allow building through LLVM tools/nolibc: crt: mark _start_c() as used tools/nolibc: stackprotector: mark implicitly used symbols as used tools/nolibc: x86_64: use local label in memcpy/memmove
tools/include/nolibc/Makefile | 1 + tools/include/nolibc/arch-aarch64.h | 4 +-- tools/include/nolibc/arch-arm.h | 8 +++--- tools/include/nolibc/arch-i386.h | 4 +-- tools/include/nolibc/arch-loongarch.h | 4 +-- tools/include/nolibc/arch-mips.h | 8 ++++-- tools/include/nolibc/arch-powerpc.h | 6 ++-- tools/include/nolibc/arch-riscv.h | 4 +-- tools/include/nolibc/arch-s390.h | 4 +-- tools/include/nolibc/arch-x86_64.h | 8 +++--- tools/include/nolibc/compiler.h | 24 +++++++++++----- tools/include/nolibc/crt.h | 25 +++++++++-------- tools/include/nolibc/nolibc.h | 3 +- tools/include/nolibc/stackprotector.h | 4 +-- tools/include/nolibc/stdbool.h | 16 +++++++++++ tools/include/nolibc/string.h | 1 + tools/testing/selftests/nolibc/Makefile | 41 +++++++++++++++++++--------- tools/testing/selftests/nolibc/nolibc-test.c | 9 +++--- tools/testing/selftests/nolibc/run-tests.sh | 16 ++++++++--- 19 files changed, 123 insertions(+), 67 deletions(-) create mode 100644 tools/include/nolibc/stdbool.h
----------------------------------------------------------------
tools/include/nolibc/Makefile +1 -0
@@ -35,6 +35,7 @@ all_files := \ stackprotector.h \ std.h \ stdarg.h \ + stdbool.h \ stdint.h \ stdlib.h \ string.h \
tools/include/nolibc/arch-aarch64.h +2 -2
@@ -142,13 +142,13 @@ })/* startup code */ -void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) { __asm__volatile ("mov x0, sp\n" /* save stack pointer to x0, as arg1 of _start_c */ "and sp, x0, -16\n" /* sp must be 16-byte aligned in the callee */ "bl _start_c\n" /* transfer to c runtime */ ); -__builtin_unreachable (); +__nolibc_entrypoint_epilogue (); }#endif /* _NOLIBC_ARCH_AARCH64_H */
tools/include/nolibc/arch-arm.h +4 -4
@@ -185,15 +185,15 @@ })/* startup code */ -void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) { __asm__volatile ( -"mov %r0, sp\n" /* save stack pointer to %r0, as arg1 of _start_c */ -"and ip, %r0, #-8\n" /* sp must be 8-byte aligned in the callee */ +"mov r0, sp\n" /* save stack pointer to %r0, as arg1 of _start_c */ +"and ip, r0, #-8\n" /* sp must be 8-byte aligned in the callee */ "mov sp, ip\n" "bl _start_c\n" /* transfer to c runtime */ ); -__builtin_unreachable (); +__nolibc_entrypoint_epilogue (); }#endif /* _NOLIBC_ARCH_ARM_H */
tools/include/nolibc/arch-i386.h +2 -2
@@ -162,7 +162,7 @@* 2) The deepest stack frame should be set to zero * */ -void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) { __asm__volatile ( "xor %ebp, %ebp\n" /* zero the stack frame */
@@ -174,7 +174,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_"call _start_c\n" /* transfer to c runtime */ "hlt\n" /* ensure it does not return */ ); - __builtin_unreachable(); + __nolibc_entrypoint_epilogue(); }#endif /* _NOLIBC_ARCH_I386_H */
tools/include/nolibc/arch-loongarch.h +2 -2
@@ -149,14 +149,14 @@#endif /* startup code */ -void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) { __asm__volatile ("move $a0, $sp\n" /* save stack pointer to $a0, as arg1 of _start_c */ LONG_BSTRINS " $sp, $zero, 3, 0\n" /* $sp must be 16-byte aligned */ "bl _start_c\n" /* transfer to c runtime */ ); -__builtin_unreachable (); +__nolibc_entrypoint_epilogue (); }#endif /* _NOLIBC_ARCH_LOONGARCH_H */
tools/include/nolibc/arch-mips.h +5 -3
@@ -179,7 +179,7 @@ })/* startup code, note that it's called __start on MIPS */ -void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector __start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector __start(void) { __asm__volatile ( ".set push\n"
@@ -194,11 +194,13 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_"li $t0, -8\n" "and $sp, $sp, $t0\n" /* $sp must be 8-byte aligned */ "addiu $sp, $sp, -16\n" /* the callee expects to save a0..a3 there */ -"jal _start_c\n" /* transfer to c runtime */ +"lui $t9, %hi(_start_c)\n" /* ABI requires current function address in $t9 */ +"ori $t9, %lo(_start_c)\n" +"jalr $t9\n" /* transfer to c runtime */ " nop\n" /* delayed slot */ ".set pop\n" ); - __builtin_unreachable(); + __nolibc_entrypoint_epilogue(); }#endif /* _NOLIBC_ARCH_MIPS_H */
tools/include/nolibc/arch-powerpc.h +3 -3
@@ -172,7 +172,7 @@ _ret; \ }) -#ifndef __powerpc64__ +#if !defined(__powerpc64__) && !defined(__clang__)/* FIXME: For 32-bit PowerPC, with newer gcc compilers (e.g. gcc 13.1.0), * "omit-frame-pointer" fails with __attribute__((no_stack_protector)) but * works with __attribute__((__optimize__("-fno-stack-protector")))
@@ -184,7 +184,7 @@#endif /* !__powerpc64__ */ /* startup code */ -void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) {#ifdef __powerpc64__#if _CALL_ELF ==2
@@ -215,7 +215,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_"bl _start_c\n" /* transfer to c runtime */ );#endif - __builtin_unreachable(); + __nolibc_entrypoint_epilogue(); }#endif /* _NOLIBC_ARCH_POWERPC_H */
tools/include/nolibc/arch-riscv.h +2 -2
@@ -140,7 +140,7 @@ })/* startup code */ -void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) { __asm__volatile ( ".option push\n"
@@ -151,7 +151,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_"andi sp, a0, -16\n" /* sp must be 16-byte aligned */ "call _start_c\n" /* transfer to c runtime */ ); - __builtin_unreachable(); + __nolibc_entrypoint_epilogue(); }#endif /* _NOLIBC_ARCH_RISCV_H */
tools/include/nolibc/arch-s390.h +2 -2
@@ -139,7 +139,7 @@ })/* startup code */ -void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) { __asm__volatile ( "lgr %r2, %r15\n" /* save stack pointer to %r2, as arg1 of _start_c */
@@ -147,7 +147,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_"xc 0(8,%r15), 0(%r15)\n" /* clear backchain */ "brasl %r14, _start_c\n" /* transfer to c runtime */ ); -__builtin_unreachable (); +__nolibc_entrypoint_epilogue (); }struct s390_mmap_arg_struct {
tools/include/nolibc/arch-x86_64.h +4 -4
@@ -161,7 +161,7 @@* 2) The deepest stack frame should be zero (the %rbp). * */ -void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) { __asm__volatile ( "xor %ebp, %ebp\n" /* zero the stack frame */
@@ -170,7 +170,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_"call _start_c\n" /* transfer to c runtime */ "hlt\n" /* ensure it does not return */ ); -__builtin_unreachable (); +__nolibc_entrypoint_epilogue (); }#define NOLIBC_ARCH_HAS_MEMMOVE
@@ -193,10 +193,10 @@ __asm__ ("movq %rdi, %rdx\n\t" "subq %rsi, %rdx\n\t" "cmpq %rcx, %rdx\n\t" -"jb .Lbackward_copy\n\t" +"jb 1f\n\t" "rep movsb\n\t" "retq\n" -".Lbackward_copy:" +"1:" /* backward copy */ "leaq -1(%rdi, %rcx, 1), %rdi\n\t" "leaq -1(%rsi, %rcx, 1), %rsi\n\t" "std\n\t"
tools/include/nolibc/compiler.h +17 -7
@@ -6,20 +6,30 @@#ifndef _NOLIBC_COMPILER_H#define _NOLIBC_COMPILER_H +#if defined(__has_attribute) +# define __nolibc_has_attribute (attr) __has_attribute(attr) +#else +# define __nolibc_has_attribute (attr) 0 +#endif + +#if __nolibc_has_attribute (naked) +# define __nolibc_entrypoint __attribute__((naked)) +# define __nolibc_entrypoint_epilogue () +#else +# define __nolibc_entrypoint __attribute__((optimize("Os", "omit-frame-pointer"))) +# define __nolibc_entrypoint_epilogue () __builtin_unreachable() +#endif /* __nolibc_has_attribute(naked) */ +#if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__) || defined(__SSP_EXPLICIT__)#define _NOLIBC_STACKPROTECTOR#endif /* defined(__SSP__) ... */ -#if defined(__has_attribute) -# if __has_attribute (no_stack_protector) -# define __no_stack_protector __attribute__((no_stack_protector)) -# else -# define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector"))) -# endif +#if __nolibc_has_attribute (no_stack_protector) +# define __no_stack_protector __attribute__((no_stack_protector))#else # define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector"))) -#endif /* defined(__has_attribute) */ +#endif /* __nolibc_has_attribute(no_stack_protector) */ #endif /* _NOLIBC_COMPILER_H */
tools/include/nolibc/crt.h +13 -12
@@ -13,23 +13,24 @@ const unsigned long *_auxv __attribute__((weak));static void __stack_chk_init (void );static void exit (int ); -extern void (*const __preinit_array_start[])(void ) __attribute__((weak)); -extern void (*const __preinit_array_end[])(void ) __attribute__((weak)); +extern void (*const __preinit_array_start[])(int ,char **,char **) __attribute__((weak)); +extern void (*const __preinit_array_end[])(int ,char **,char **) __attribute__((weak)); -extern void (*const __init_array_start[])(void ) __attribute__((weak)); -extern void (*const __init_array_end[])(void ) __attribute__((weak)); +extern void (*const __init_array_start[])(int ,char **,char **) __attribute__((weak)); +extern void (*const __init_array_end[])(int ,char **,char **) __attribute__((weak));extern void (*const __fini_array_start[])(void ) __attribute__((weak));extern void (*const __fini_array_end[])(void ) __attribute__((weak)); -__attribute__((weak)) +__attribute__((weak,used))void _start_c (long *sp) {long argc;char **argv;char **envp;int exitcode; -void (*const *func)(void ); +void (*const *ctor_func)(int ,char **,char **); +void (*const *dtor_func)(void );const unsigned long *auxv;/* silence potential warning: conflicting types for 'main' */ int _nolibc_main (int ,char **,char **) __asm__ ("main" );
@@ -66,16 +67,16 @@ void _start_c(long *sp) ; _auxv = auxv; -for (func = __preinit_array_start; func < __preinit_array_end; func++) - (*func)(); -for (func = __init_array_start; func < __init_array_end; func++) - (*func)(); +for (ctor_func = __preinit_array_start; ctor_func < __preinit_array_end; ctor_func++) + (*ctor_func)(argc, argv, envp); +for (ctor_func = __init_array_start; ctor_func < __init_array_end; ctor_func++) + (*ctor_func)(argc, argv, envp);/* go to application */ exitcode =_nolibc_main (argc, argv, envp); -for (func = __fini_array_end; func > __fini_array_start;) - (*--func)(); +for (dtor_func = __fini_array_end; dtor_func > __fini_array_start;) + (*--dtor_func)();exit (exitcode); }
tools/include/nolibc/nolibc.h +2 -1
@@ -74,7 +74,8 @@* -I../nolibc -o hello hello.c -lgcc * * The available standard (but limited) include files are: -* ctype.h, errno.h, signal.h, stdarg.h, stdio.h, stdlib.h, string.h, time.h +* ctype.h, errno.h, signal.h, stdarg.h, stdbool.h stdio.h, stdlib.h, +* string.h, time.h * * In addition, the following ones are expected to be provided by the compiler: * float.h, stddef.h
tools/include/nolibc/stackprotector.h +2 -2
@@ -18,7 +18,7 @@* triggering stack protector errors themselves */ -__attribute__((weak,noreturn,section (".text.nolibc_stack_chk" ))) +__attribute__((weak,used,noreturn,section (".text.nolibc_stack_chk" )))void __stack_chk_fail (void ) {pid_t pid;
@@ -34,7 +34,7 @@ void __stack_chk_fail_local(void)__stack_chk_fail (); } -__attribute__((weak,section (".data.nolibc_stack_chk" ))) +__attribute__((weak,used,section (".data.nolibc_stack_chk" )))uintptr_t __stack_chk_guard; static __no_stack_protector void __stack_chk_init(void)
tools/include/nolibc/stdbool.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* Boolean types support for NOLIBC +* Copyright (C) 2024 Thomas Weißschuh <[email protected]> +*/ + +#ifndef _NOLIBC_STDBOOL_H +#define _NOLIBC_STDBOOL_H + +#define bool _Bool +#define true 1 +#define false 0 + +#define __bool_true_false_are_defined 1 + +#endif /* _NOLIBC_STDBOOL_H */
tools/include/nolibc/string.h +1 -0
@@ -7,6 +7,7 @@#ifndef _NOLIBC_STRING_H#define _NOLIBC_STRING_H +#include "arch.h" #include "std.h" static void *malloc (size_t len);
tools/testing/selftests/nolibc/Makefile +28 -13
74 lines not on this page · raw message
tools/testing/selftests/nolibc/nolibc-test.c +5 -4
@@ -542,7 +542,7 @@ int expect_strzr(const char *expr, int llen) {int ret =0 ; - llen +=printf (" = <%s> " , expr); + llen +=printf (" = <%s> " , expr ? expr :"(null)" );if (expr) { ret =1 ;result (llen,FAIL );
@@ -561,7 +561,7 @@ int expect_strnz(const char *expr, int llen) {int ret =0 ; - llen +=printf (" = <%s> " , expr); + llen +=printf (" = <%s> " , expr ? expr :"(null)" );if (!expr) { ret =1 ;result (llen,FAIL );
@@ -686,9 +686,10 @@ static void constructor1(void) } __attribute__((constructor)) -static void constructor2 (void ) +static void constructor2 (int argc,char **argv,char **envp) { - constructor_test_value *=2 ; +if (argc && argv && envp) + constructor_test_value *=2 ; }int run_startup (int min,int max)
tools/testing/selftests/nolibc/run-tests.sh +12 -4
@@ -15,10 +15,11 @@ download_location="${cache_dir}/crosstools/" build_location="$(realpath "${cache_dir}"/nolibc-tests/)" perform_download=0 test_mode=system -CFLAGS_EXTRA="-Werror" +werror=1 +llvm= archs="i386 x86_64 arm64 arm mips32le mips32be ppc ppc64 ppc64le riscv s390 loongarch" -TEMP=$(getopt -o 'j:d:c:b:a:m:peh' -n "$0" -- "$@") +TEMP=$(getopt -o 'j:d:c:b:a:m:pelh' -n "$0" -- "$@") eval set -- "$TEMP" unset TEMP
@@ -42,6 +43,7 @@ Options: -b [DIR] Build location (default: ${build_location}) -m [MODE] Test mode user/system (default: ${test_mode}) -e Disable -Werror + -l Build with LLVM/clang EOF }
@@ -69,7 +71,10 @@ while true; do test_mode="$2" shift 2; continue ;; '-e') - CFLAGS_EXTRA="" + werror=0 + shift; continue ;; + '-l') + llvm=1 shift; continue ;; '-h') print_usage
@@ -140,7 +145,10 @@ test_arch() { ct_abi=$(crosstool_abi "$1") cross_compile=$(realpath "${download_location}gcc-${crosstool_version}-nolibc/${ct_arch}-${ct_abi}/bin/${ct_arch}-${ct_abi}-") build_dir="${build_location}/${arch}" - MAKE=(make -j"${nproc}" XARCH="${arch}" CROSS_COMPILE="${cross_compile}" O="${build_dir}") + if [ "$werror" -ne 0 ]; then + CFLAGS_EXTRA="$CFLAGS_EXTRA -Werror" + fi + MAKE=(make -j"${nproc}" XARCH="${arch}" CROSS_COMPILE="${cross_compile}" LLVM="${llvm}" O="${build_dir}") mkdir -p "$build_dir" if [ "$test_mode" = "system" ] && [ ! -f "${build_dir}/.config" ]; then
The pull request you sent on Mon, 16 Sep 2024 17:37:52 -0600:
The pull request you sent on Mon, 16 Sep 2024 17:37:52 -0600:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftesttags/linux_kselftest-nolibc-6.12-rc1
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/395b15778e8f1b580334c558c9a6e9f1b28fcc76
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html