Skip to content

Commit 015a99f

Browse files
committed
Merge tag 'nolibc-20250526-for-6.16-1' of git://git.kernel.org/pub/scm/linux/kernel/git/nolibc/linux-nolibc
Pull nolibc updates from Thomas Weißschuh: - New supported architectures: m68k, SPARC (32 and 64 bit) - Compatibility with kselftest_harness.h - A more robust mechanism to include all of nolibc from each header - Split existing features into new headers to simplify adoption - Compatibility with UBSAN and it is used in the testsuite - Many small new features focussing on usage in kselftests * tag 'nolibc-20250526-for-6.16-1' of git://git.kernel.org/pub/scm/linux/kernel/git/nolibc/linux-nolibc: (83 commits) selftests: harness: Stop using setjmp()/longjmp() selftests: harness: Add "variant" and "self" to test metadata selftests: harness: Add teardown callback to test metadata selftests: harness: Move teardown conditional into test metadata selftests: harness: Don't set setup_completed for fixtureless tests selftests: harness: Implement test timeouts through pidfd selftests: harness: Remove dependency on libatomic selftests: harness: Remove inline qualifier for wrappers selftests: harness: Mark functions without prototypes static selftests: harness: Ignore unused variant argument warning selftests: harness: Use C89 comment style selftests: harness: Add kselftest harness selftest selftests/nolibc: drop include guards around standard headers tools/nolibc: move NULL and offsetof() to sys/stddef.h tools/nolibc: move uname() and friends to sys/utsname.h tools/nolibc: move makedev() and friends to sys/sysmacros.h tools/nolibc: move getrlimit() and friends to sys/resource.h tools/nolibc: move reboot() to sys/reboot.h tools/nolibc: move prctl() to sys/prctl.h tools/nolibc: move mount() to sys/mount.h ...
2 parents 3e443d1 + 869c788 commit 015a99f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2629
-662
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21971,6 +21971,7 @@ F: include/linux/seccomp.h
2197121971
F: include/uapi/linux/seccomp.h
2197221972
F: kernel/seccomp.c
2197321973
F: tools/testing/selftests/kselftest_harness.h
21974+
F: tools/testing/selftests/kselftest_harness/
2197421975
F: tools/testing/selftests/seccomp/*
2197521976
K: \bsecure_computing
2197621977
K: \bTIF_SECCOMP\b

tools/include/nolibc/Makefile

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,41 @@ all_files := \
3030
crt.h \
3131
ctype.h \
3232
dirent.h \
33+
elf.h \
3334
errno.h \
35+
fcntl.h \
36+
getopt.h \
3437
limits.h \
38+
math.h \
3539
nolibc.h \
40+
poll.h \
41+
sched.h \
3642
signal.h \
3743
stackprotector.h \
3844
std.h \
3945
stdarg.h \
4046
stdbool.h \
47+
stddef.h \
4148
stdint.h \
4249
stdlib.h \
4350
string.h \
4451
sys.h \
52+
sys/auxv.h \
53+
sys/ioctl.h \
54+
sys/mman.h \
55+
sys/mount.h \
56+
sys/prctl.h \
57+
sys/random.h \
58+
sys/reboot.h \
59+
sys/resource.h \
60+
sys/stat.h \
61+
sys/syscall.h \
62+
sys/sysmacros.h \
63+
sys/time.h \
64+
sys/timerfd.h \
65+
sys/types.h \
66+
sys/utsname.h \
67+
sys/wait.h \
4568
time.h \
4669
types.h \
4770
unistd.h \
@@ -72,7 +95,7 @@ help:
7295
headers:
7396
$(Q)mkdir -p $(OUTPUT)sysroot
7497
$(Q)mkdir -p $(OUTPUT)sysroot/include
75-
$(Q)cp $(all_files) $(OUTPUT)sysroot/include/
98+
$(Q)cp --parents $(all_files) $(OUTPUT)sysroot/include/
7699
$(Q)if [ "$(ARCH)" = "x86" ]; then \
77100
sed -e \
78101
's,^#ifndef _NOLIBC_ARCH_X86_64_H,#if !defined(_NOLIBC_ARCH_X86_64_H) \&\& defined(__x86_64__),' \
@@ -91,5 +114,14 @@ headers_standalone: headers
91114
$(Q)$(MAKE) -C $(srctree) headers
92115
$(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
93116

117+
# GCC uses "s390", clang "systemz"
118+
CLANG_CROSS_FLAGS := $(subst --target=s390-linux,--target=systemz-linux,$(CLANG_CROSS_FLAGS))
119+
120+
headers_check: headers_standalone
121+
for header in $(filter-out crt.h std.h,$(all_files)); do \
122+
$(CC) $(CLANG_CROSS_FLAGS) -Wall -Werror -nostdinc -fsyntax-only -x c /dev/null \
123+
-I$(or $(objtree),$(srctree))/usr/include -include $$header -include $$header || exit 1; \
124+
done
125+
94126
clean:
95127
$(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot"

tools/include/nolibc/arch-aarch64.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
146146
{
147147
__asm__ volatile (
148148
"mov x0, sp\n" /* save stack pointer to x0, as arg1 of _start_c */
149-
"and sp, x0, -16\n" /* sp must be 16-byte aligned in the callee */
150149
"bl _start_c\n" /* transfer to c runtime */
151150
);
152151
__nolibc_entrypoint_epilogue();

tools/include/nolibc/arch-arm.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
189189
{
190190
__asm__ volatile (
191191
"mov r0, sp\n" /* save stack pointer to %r0, as arg1 of _start_c */
192-
"and ip, r0, #-8\n" /* sp must be 8-byte aligned in the callee */
193-
"mov sp, ip\n"
194192
"bl _start_c\n" /* transfer to c runtime */
195193
);
196194
__nolibc_entrypoint_epilogue();

tools/include/nolibc/arch-i386.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
167167
__asm__ volatile (
168168
"xor %ebp, %ebp\n" /* zero the stack frame */
169169
"mov %esp, %eax\n" /* save stack pointer to %eax, as arg1 of _start_c */
170-
"add $12, %esp\n" /* avoid over-estimating after the 'and' & 'sub' below */
171-
"and $-16, %esp\n" /* the %esp must be 16-byte aligned on 'call' */
172170
"sub $12, %esp\n" /* sub 12 to keep it aligned after the push %eax */
173171
"push %eax\n" /* push arg1 on stack to support plain stack modes too */
174172
"call _start_c\n" /* transfer to c runtime */

tools/include/nolibc/arch-loongarch.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,11 @@
142142
_arg1; \
143143
})
144144

145-
#if __loongarch_grlen == 32
146-
#define LONG_BSTRINS "bstrins.w"
147-
#else /* __loongarch_grlen == 64 */
148-
#define LONG_BSTRINS "bstrins.d"
149-
#endif
150-
151145
/* startup code */
152146
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
153147
{
154148
__asm__ volatile (
155149
"move $a0, $sp\n" /* save stack pointer to $a0, as arg1 of _start_c */
156-
LONG_BSTRINS " $sp, $zero, 3, 0\n" /* $sp must be 16-byte aligned */
157150
"bl _start_c\n" /* transfer to c runtime */
158151
);
159152
__nolibc_entrypoint_epilogue();

tools/include/nolibc/arch-m68k.h

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
2+
/*
3+
* m68k specific definitions for NOLIBC
4+
* Copyright (C) 2025 Daniel Palmer<[email protected]>
5+
*
6+
* Roughly based on one or more of the other arch files.
7+
*
8+
*/
9+
10+
#ifndef _NOLIBC_ARCH_M68K_H
11+
#define _NOLIBC_ARCH_M68K_H
12+
13+
#include "compiler.h"
14+
#include "crt.h"
15+
16+
#define _NOLIBC_SYSCALL_CLOBBERLIST "memory"
17+
18+
#define my_syscall0(num) \
19+
({ \
20+
register long _num __asm__ ("d0") = (num); \
21+
\
22+
__asm__ volatile ( \
23+
"trap #0\n" \
24+
: "+r"(_num) \
25+
: "r"(_num) \
26+
: _NOLIBC_SYSCALL_CLOBBERLIST \
27+
); \
28+
_num; \
29+
})
30+
31+
#define my_syscall1(num, arg1) \
32+
({ \
33+
register long _num __asm__ ("d0") = (num); \
34+
register long _arg1 __asm__ ("d1") = (long)(arg1); \
35+
\
36+
__asm__ volatile ( \
37+
"trap #0\n" \
38+
: "+r"(_num) \
39+
: "r"(_arg1) \
40+
: _NOLIBC_SYSCALL_CLOBBERLIST \
41+
); \
42+
_num; \
43+
})
44+
45+
#define my_syscall2(num, arg1, arg2) \
46+
({ \
47+
register long _num __asm__ ("d0") = (num); \
48+
register long _arg1 __asm__ ("d1") = (long)(arg1); \
49+
register long _arg2 __asm__ ("d2") = (long)(arg2); \
50+
\
51+
__asm__ volatile ( \
52+
"trap #0\n" \
53+
: "+r"(_num) \
54+
: "r"(_arg1), "r"(_arg2) \
55+
: _NOLIBC_SYSCALL_CLOBBERLIST \
56+
); \
57+
_num; \
58+
})
59+
60+
#define my_syscall3(num, arg1, arg2, arg3) \
61+
({ \
62+
register long _num __asm__ ("d0") = (num); \
63+
register long _arg1 __asm__ ("d1") = (long)(arg1); \
64+
register long _arg2 __asm__ ("d2") = (long)(arg2); \
65+
register long _arg3 __asm__ ("d3") = (long)(arg3); \
66+
\
67+
__asm__ volatile ( \
68+
"trap #0\n" \
69+
: "+r"(_num) \
70+
: "r"(_arg1), "r"(_arg2), "r"(_arg3) \
71+
: _NOLIBC_SYSCALL_CLOBBERLIST \
72+
); \
73+
_num; \
74+
})
75+
76+
#define my_syscall4(num, arg1, arg2, arg3, arg4) \
77+
({ \
78+
register long _num __asm__ ("d0") = (num); \
79+
register long _arg1 __asm__ ("d1") = (long)(arg1); \
80+
register long _arg2 __asm__ ("d2") = (long)(arg2); \
81+
register long _arg3 __asm__ ("d3") = (long)(arg3); \
82+
register long _arg4 __asm__ ("d4") = (long)(arg4); \
83+
\
84+
__asm__ volatile ( \
85+
"trap #0\n" \
86+
: "+r" (_num) \
87+
: "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4) \
88+
: _NOLIBC_SYSCALL_CLOBBERLIST \
89+
); \
90+
_num; \
91+
})
92+
93+
#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \
94+
({ \
95+
register long _num __asm__ ("d0") = (num); \
96+
register long _arg1 __asm__ ("d1") = (long)(arg1); \
97+
register long _arg2 __asm__ ("d2") = (long)(arg2); \
98+
register long _arg3 __asm__ ("d3") = (long)(arg3); \
99+
register long _arg4 __asm__ ("d4") = (long)(arg4); \
100+
register long _arg5 __asm__ ("d5") = (long)(arg5); \
101+
\
102+
__asm__ volatile ( \
103+
"trap #0\n" \
104+
: "+r" (_num) \
105+
: "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5) \
106+
: _NOLIBC_SYSCALL_CLOBBERLIST \
107+
); \
108+
_num; \
109+
})
110+
111+
#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \
112+
({ \
113+
register long _num __asm__ ("d0") = (num); \
114+
register long _arg1 __asm__ ("d1") = (long)(arg1); \
115+
register long _arg2 __asm__ ("d2") = (long)(arg2); \
116+
register long _arg3 __asm__ ("d3") = (long)(arg3); \
117+
register long _arg4 __asm__ ("d4") = (long)(arg4); \
118+
register long _arg5 __asm__ ("d5") = (long)(arg5); \
119+
register long _arg6 __asm__ ("a0") = (long)(arg6); \
120+
\
121+
__asm__ volatile ( \
122+
"trap #0\n" \
123+
: "+r" (_num) \
124+
: "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \
125+
"r"(_arg6) \
126+
: _NOLIBC_SYSCALL_CLOBBERLIST \
127+
); \
128+
_num; \
129+
})
130+
131+
void _start(void);
132+
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
133+
{
134+
__asm__ volatile (
135+
"movel %sp, %sp@-\n"
136+
"jsr _start_c\n"
137+
);
138+
__nolibc_entrypoint_epilogue();
139+
}
140+
141+
#endif /* _NOLIBC_ARCH_M68K_H */

tools/include/nolibc/arch-powerpc.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,13 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
201201

202202
__asm__ volatile (
203203
"mr 3, 1\n" /* save stack pointer to r3, as arg1 of _start_c */
204-
"clrrdi 1, 1, 4\n" /* align the stack to 16 bytes */
205204
"li 0, 0\n" /* zero the frame pointer */
206205
"stdu 1, -32(1)\n" /* the initial stack frame */
207206
"bl _start_c\n" /* transfer to c runtime */
208207
);
209208
#else
210209
__asm__ volatile (
211210
"mr 3, 1\n" /* save stack pointer to r3, as arg1 of _start_c */
212-
"clrrwi 1, 1, 4\n" /* align the stack to 16 bytes */
213211
"li 0, 0\n" /* zero the frame pointer */
214212
"stwu 1, -16(1)\n" /* the initial stack frame */
215213
"bl _start_c\n" /* transfer to c runtime */

tools/include/nolibc/arch-riscv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
148148
"lla gp, __global_pointer$\n"
149149
".option pop\n"
150150
"mv a0, sp\n" /* save stack pointer to a0, as arg1 of _start_c */
151-
"andi sp, a0, -16\n" /* sp must be 16-byte aligned */
152151
"call _start_c\n" /* transfer to c runtime */
153152
);
154153
__nolibc_entrypoint_epilogue();

0 commit comments

Comments
 (0)