Skip to content

Commit 395b157

Browse files
committed
Merge tag 'linux_kselftest-nolibc-6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull nolibc updates from Shuah Khan: "Highlights: - Clang support (including LTO) Other Changes: - stdbool.h support - argc/argv/envp arguments for constructors - Small #include ordering fix" * tag 'linux_kselftest-nolibc-6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (21 commits) tools/nolibc: x86_64: use local label in memcpy/memmove tools/nolibc: stackprotector: mark implicitly used symbols as used tools/nolibc: crt: mark _start_c() as used selftests/nolibc: run-tests.sh: allow building through LLVM selftests/nolibc: use correct clang target for s390/systemz selftests/nolibc: don't use libgcc when building with clang selftests/nolibc: run-tests.sh: avoid overwriting CFLAGS_EXTRA selftests/nolibc: add cc-option compatible with clang cross builds selftests/nolibc: add support for LLVM= parameter selftests/nolibc: determine $(srctree) first selftests/nolibc: avoid passing NULL to printf("%s") selftests/nolibc: report failure if no testcase passed tools/nolibc: compiler: use attribute((naked)) if available tools/nolibc: move entrypoint specifics to compiler.h tools/nolibc: compiler: introduce __nolibc_has_attribute() tools/nolibc: powerpc: limit stack-protector workaround to GCC tools/nolibc: mips: load current function to $t9 tools/nolibc: arm: use clang-compatible asm syntax tools/nolibc: pass argc, argv and envp to constructors tools/nolibc: add stdbool.h header ...
2 parents d58db3f + 248f6b9 commit 395b157

19 files changed

+123
-67
lines changed

tools/include/nolibc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ all_files := \
3535
stackprotector.h \
3636
std.h \
3737
stdarg.h \
38+
stdbool.h \
3839
stdint.h \
3940
stdlib.h \
4041
string.h \

tools/include/nolibc/arch-aarch64.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@
142142
})
143143

144144
/* startup code */
145-
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
145+
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
146146
{
147147
__asm__ volatile (
148148
"mov x0, sp\n" /* save stack pointer to x0, as arg1 of _start_c */
149149
"and sp, x0, -16\n" /* sp must be 16-byte aligned in the callee */
150150
"bl _start_c\n" /* transfer to c runtime */
151151
);
152-
__builtin_unreachable();
152+
__nolibc_entrypoint_epilogue();
153153
}
154154
#endif /* _NOLIBC_ARCH_AARCH64_H */

tools/include/nolibc/arch-arm.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@
185185
})
186186

187187
/* startup code */
188-
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
188+
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
189189
{
190190
__asm__ volatile (
191-
"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 */
191+
"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 */
193193
"mov sp, ip\n"
194194
"bl _start_c\n" /* transfer to c runtime */
195195
);
196-
__builtin_unreachable();
196+
__nolibc_entrypoint_epilogue();
197197
}
198198

199199
#endif /* _NOLIBC_ARCH_ARM_H */

tools/include/nolibc/arch-i386.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
* 2) The deepest stack frame should be set to zero
163163
*
164164
*/
165-
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
165+
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
166166
{
167167
__asm__ volatile (
168168
"xor %ebp, %ebp\n" /* zero the stack frame */
@@ -174,7 +174,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
174174
"call _start_c\n" /* transfer to c runtime */
175175
"hlt\n" /* ensure it does not return */
176176
);
177-
__builtin_unreachable();
177+
__nolibc_entrypoint_epilogue();
178178
}
179179

180180
#endif /* _NOLIBC_ARCH_I386_H */

tools/include/nolibc/arch-loongarch.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@
149149
#endif
150150

151151
/* startup code */
152-
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
152+
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
153153
{
154154
__asm__ volatile (
155155
"move $a0, $sp\n" /* save stack pointer to $a0, as arg1 of _start_c */
156156
LONG_BSTRINS " $sp, $zero, 3, 0\n" /* $sp must be 16-byte aligned */
157157
"bl _start_c\n" /* transfer to c runtime */
158158
);
159-
__builtin_unreachable();
159+
__nolibc_entrypoint_epilogue();
160160
}
161161

162162
#endif /* _NOLIBC_ARCH_LOONGARCH_H */

tools/include/nolibc/arch-mips.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
})
180180

181181
/* startup code, note that it's called __start on MIPS */
182-
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector __start(void)
182+
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector __start(void)
183183
{
184184
__asm__ volatile (
185185
".set push\n"
@@ -194,11 +194,13 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
194194
"li $t0, -8\n"
195195
"and $sp, $sp, $t0\n" /* $sp must be 8-byte aligned */
196196
"addiu $sp, $sp, -16\n" /* the callee expects to save a0..a3 there */
197-
"jal _start_c\n" /* transfer to c runtime */
197+
"lui $t9, %hi(_start_c)\n" /* ABI requires current function address in $t9 */
198+
"ori $t9, %lo(_start_c)\n"
199+
"jalr $t9\n" /* transfer to c runtime */
198200
" nop\n" /* delayed slot */
199201
".set pop\n"
200202
);
201-
__builtin_unreachable();
203+
__nolibc_entrypoint_epilogue();
202204
}
203205

204206
#endif /* _NOLIBC_ARCH_MIPS_H */

tools/include/nolibc/arch-powerpc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
_ret; \
173173
})
174174

175-
#ifndef __powerpc64__
175+
#if !defined(__powerpc64__) && !defined(__clang__)
176176
/* FIXME: For 32-bit PowerPC, with newer gcc compilers (e.g. gcc 13.1.0),
177177
* "omit-frame-pointer" fails with __attribute__((no_stack_protector)) but
178178
* works with __attribute__((__optimize__("-fno-stack-protector")))
@@ -184,7 +184,7 @@
184184
#endif /* !__powerpc64__ */
185185

186186
/* startup code */
187-
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
187+
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
188188
{
189189
#ifdef __powerpc64__
190190
#if _CALL_ELF == 2
@@ -215,7 +215,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
215215
"bl _start_c\n" /* transfer to c runtime */
216216
);
217217
#endif
218-
__builtin_unreachable();
218+
__nolibc_entrypoint_epilogue();
219219
}
220220

221221
#endif /* _NOLIBC_ARCH_POWERPC_H */

tools/include/nolibc/arch-riscv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
})
141141

142142
/* startup code */
143-
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
143+
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
144144
{
145145
__asm__ volatile (
146146
".option push\n"
@@ -151,7 +151,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
151151
"andi sp, a0, -16\n" /* sp must be 16-byte aligned */
152152
"call _start_c\n" /* transfer to c runtime */
153153
);
154-
__builtin_unreachable();
154+
__nolibc_entrypoint_epilogue();
155155
}
156156

157157
#endif /* _NOLIBC_ARCH_RISCV_H */

tools/include/nolibc/arch-s390.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@
139139
})
140140

141141
/* startup code */
142-
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
142+
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
143143
{
144144
__asm__ volatile (
145145
"lgr %r2, %r15\n" /* save stack pointer to %r2, as arg1 of _start_c */
146146
"aghi %r15, -160\n" /* allocate new stackframe */
147147
"xc 0(8,%r15), 0(%r15)\n" /* clear backchain */
148148
"brasl %r14, _start_c\n" /* transfer to c runtime */
149149
);
150-
__builtin_unreachable();
150+
__nolibc_entrypoint_epilogue();
151151
}
152152

153153
struct s390_mmap_arg_struct {

tools/include/nolibc/arch-x86_64.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
* 2) The deepest stack frame should be zero (the %rbp).
162162
*
163163
*/
164-
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
164+
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
165165
{
166166
__asm__ volatile (
167167
"xor %ebp, %ebp\n" /* zero the stack frame */
@@ -170,7 +170,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
170170
"call _start_c\n" /* transfer to c runtime */
171171
"hlt\n" /* ensure it does not return */
172172
);
173-
__builtin_unreachable();
173+
__nolibc_entrypoint_epilogue();
174174
}
175175

176176
#define NOLIBC_ARCH_HAS_MEMMOVE
@@ -193,10 +193,10 @@ __asm__ (
193193
"movq %rdi, %rdx\n\t"
194194
"subq %rsi, %rdx\n\t"
195195
"cmpq %rcx, %rdx\n\t"
196-
"jb .Lbackward_copy\n\t"
196+
"jb 1f\n\t"
197197
"rep movsb\n\t"
198198
"retq\n"
199-
".Lbackward_copy:"
199+
"1:" /* backward copy */
200200
"leaq -1(%rdi, %rcx, 1), %rdi\n\t"
201201
"leaq -1(%rsi, %rcx, 1), %rsi\n\t"
202202
"std\n\t"

0 commit comments

Comments
 (0)