Skip to content

Commit 1c59d38

Browse files
committed
Merge tag 'linux-kselftest-nolibc-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull nolibc updates from Shuah Khan: "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" * tag 'linux-kselftest-nolibc-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (103 commits) tools/nolibc: avoid undesired casts in the __sysret() macro tools/nolibc: keep brk(), sbrk(), mmap() away from __sysret() tools/nolibc: silence ppc64 compile warnings selftests/nolibc: libc-test: use HOSTCC instead of CC tools/nolibc: stackprotector.h: make __stack_chk_init static selftests/nolibc: allow report with existing test log selftests/nolibc: add test support for ppc64 selftests/nolibc: add test support for ppc64le selftests/nolibc: add test support for ppc selftests/nolibc: add XARCH and ARCH mapping support tools/nolibc: add support for powerpc64 tools/nolibc: add support for powerpc MAINTAINERS: nolibc: add myself as co-maintainer selftests/nolibc: enable compiler warnings selftests/nolibc: don't strip nolibc-test selftests/nolibc: prevent out of bounds access in expect_vfprintf selftests/nolibc: use correct return type for read() and write() selftests/nolibc: avoid sign-compare warnings selftests/nolibc: avoid unused parameter warnings selftests/nolibc: make functions static if possible ...
2 parents 815c24a + 556fb71 commit 1c59d38

23 files changed

+1221
-1166
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15010,6 +15010,7 @@ F: include/linux/power/bq27xxx_battery.h
1501015010

1501115011
NOLIBC HEADER FILE
1501215012
M: Willy Tarreau <[email protected]>
15013+
M: Thomas Weißschuh <[email protected]>
1501315014
S: Maintained
1501415015
T: git git://git.kernel.org/pub/scm/linux/kernel/git/wtarreau/nolibc.git
1501515016
F: tools/include/nolibc/

tools/include/nolibc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ nolibc_arch := $(patsubst arm64,aarch64,$(ARCH))
2727
arch_file := arch-$(nolibc_arch).h
2828
all_files := \
2929
compiler.h \
30+
crt.h \
3031
ctype.h \
3132
errno.h \
3233
nolibc.h \

tools/include/nolibc/arch-aarch64.h

Lines changed: 19 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,7 @@
88
#define _NOLIBC_ARCH_AARCH64_H
99

1010
#include "compiler.h"
11-
12-
/* The struct returned by the newfstatat() syscall. Differs slightly from the
13-
* x86_64's stat one by field ordering, so be careful.
14-
*/
15-
struct sys_stat_struct {
16-
unsigned long st_dev;
17-
unsigned long st_ino;
18-
unsigned int st_mode;
19-
unsigned int st_nlink;
20-
unsigned int st_uid;
21-
unsigned int st_gid;
22-
23-
unsigned long st_rdev;
24-
unsigned long __pad1;
25-
long st_size;
26-
int st_blksize;
27-
int __pad2;
28-
29-
long st_blocks;
30-
long st_atime;
31-
unsigned long st_atime_nsec;
32-
long st_mtime;
33-
34-
unsigned long st_mtime_nsec;
35-
long st_ctime;
36-
unsigned long st_ctime_nsec;
37-
unsigned int __unused[2];
38-
};
11+
#include "crt.h"
3912

4013
/* Syscalls for AARCH64 :
4114
* - registers are 64-bit
@@ -56,8 +29,8 @@ struct sys_stat_struct {
5629
({ \
5730
register long _num __asm__ ("x8") = (num); \
5831
register long _arg1 __asm__ ("x0"); \
59-
\
60-
__asm__ volatile ( \
32+
\
33+
__asm__ volatile ( \
6134
"svc #0\n" \
6235
: "=r"(_arg1) \
6336
: "r"(_num) \
@@ -70,8 +43,8 @@ struct sys_stat_struct {
7043
({ \
7144
register long _num __asm__ ("x8") = (num); \
7245
register long _arg1 __asm__ ("x0") = (long)(arg1); \
73-
\
74-
__asm__ volatile ( \
46+
\
47+
__asm__ volatile ( \
7548
"svc #0\n" \
7649
: "=r"(_arg1) \
7750
: "r"(_arg1), \
@@ -86,8 +59,8 @@ struct sys_stat_struct {
8659
register long _num __asm__ ("x8") = (num); \
8760
register long _arg1 __asm__ ("x0") = (long)(arg1); \
8861
register long _arg2 __asm__ ("x1") = (long)(arg2); \
89-
\
90-
__asm__ volatile ( \
62+
\
63+
__asm__ volatile ( \
9164
"svc #0\n" \
9265
: "=r"(_arg1) \
9366
: "r"(_arg1), "r"(_arg2), \
@@ -103,8 +76,8 @@ struct sys_stat_struct {
10376
register long _arg1 __asm__ ("x0") = (long)(arg1); \
10477
register long _arg2 __asm__ ("x1") = (long)(arg2); \
10578
register long _arg3 __asm__ ("x2") = (long)(arg3); \
106-
\
107-
__asm__ volatile ( \
79+
\
80+
__asm__ volatile ( \
10881
"svc #0\n" \
10982
: "=r"(_arg1) \
11083
: "r"(_arg1), "r"(_arg2), "r"(_arg3), \
@@ -121,8 +94,8 @@ struct sys_stat_struct {
12194
register long _arg2 __asm__ ("x1") = (long)(arg2); \
12295
register long _arg3 __asm__ ("x2") = (long)(arg3); \
12396
register long _arg4 __asm__ ("x3") = (long)(arg4); \
124-
\
125-
__asm__ volatile ( \
97+
\
98+
__asm__ volatile ( \
12699
"svc #0\n" \
127100
: "=r"(_arg1) \
128101
: "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \
@@ -140,8 +113,8 @@ struct sys_stat_struct {
140113
register long _arg3 __asm__ ("x2") = (long)(arg3); \
141114
register long _arg4 __asm__ ("x3") = (long)(arg4); \
142115
register long _arg5 __asm__ ("x4") = (long)(arg5); \
143-
\
144-
__asm__ volatile ( \
116+
\
117+
__asm__ volatile ( \
145118
"svc #0\n" \
146119
: "=r" (_arg1) \
147120
: "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \
@@ -160,8 +133,8 @@ struct sys_stat_struct {
160133
register long _arg4 __asm__ ("x3") = (long)(arg4); \
161134
register long _arg5 __asm__ ("x4") = (long)(arg5); \
162135
register long _arg6 __asm__ ("x5") = (long)(arg6); \
163-
\
164-
__asm__ volatile ( \
136+
\
137+
__asm__ volatile ( \
165138
"svc #0\n" \
166139
: "=r" (_arg1) \
167140
: "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \
@@ -171,33 +144,13 @@ struct sys_stat_struct {
171144
_arg1; \
172145
})
173146

174-
char **environ __attribute__((weak));
175-
const unsigned long *_auxv __attribute__((weak));
176-
177147
/* startup code */
178-
void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
148+
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
179149
{
180150
__asm__ volatile (
181-
#ifdef _NOLIBC_STACKPROTECTOR
182-
"bl __stack_chk_init\n" /* initialize stack protector */
183-
#endif
184-
"ldr x0, [sp]\n" /* argc (x0) was in the stack */
185-
"add x1, sp, 8\n" /* argv (x1) = sp */
186-
"lsl x2, x0, 3\n" /* envp (x2) = 8*argc ... */
187-
"add x2, x2, 8\n" /* + 8 (skip null) */
188-
"add x2, x2, x1\n" /* + argv */
189-
"adrp x3, environ\n" /* x3 = &environ (high bits) */
190-
"str x2, [x3, #:lo12:environ]\n" /* store envp into environ */
191-
"mov x4, x2\n" /* search for auxv (follows NULL after last env) */
192-
"0:\n"
193-
"ldr x5, [x4], 8\n" /* x5 = *x4; x4 += 8 */
194-
"cbnz x5, 0b\n" /* and stop at NULL after last env */
195-
"adrp x3, _auxv\n" /* x3 = &_auxv (high bits) */
196-
"str x4, [x3, #:lo12:_auxv]\n" /* store x4 into _auxv */
197-
"and sp, x1, -16\n" /* sp must be 16-byte aligned in the callee */
198-
"bl main\n" /* main() returns the status code, we'll exit with it. */
199-
"mov x8, 93\n" /* NR_exit == 93 */
200-
"svc #0\n"
151+
"mov x0, sp\n" /* save stack pointer to x0, as arg1 of _start_c */
152+
"and sp, x0, -16\n" /* sp must be 16-byte aligned in the callee */
153+
"bl _start_c\n" /* transfer to c runtime */
201154
);
202155
__builtin_unreachable();
203156
}

tools/include/nolibc/arch-arm.h

Lines changed: 20 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,7 @@
88
#define _NOLIBC_ARCH_ARM_H
99

1010
#include "compiler.h"
11-
12-
/* The struct returned by the stat() syscall, 32-bit only, the syscall returns
13-
* exactly 56 bytes (stops before the unused array). In big endian, the format
14-
* differs as devices are returned as short only.
15-
*/
16-
struct sys_stat_struct {
17-
#if defined(__ARMEB__)
18-
unsigned short st_dev;
19-
unsigned short __pad1;
20-
#else
21-
unsigned long st_dev;
22-
#endif
23-
unsigned long st_ino;
24-
unsigned short st_mode;
25-
unsigned short st_nlink;
26-
unsigned short st_uid;
27-
unsigned short st_gid;
28-
29-
#if defined(__ARMEB__)
30-
unsigned short st_rdev;
31-
unsigned short __pad2;
32-
#else
33-
unsigned long st_rdev;
34-
#endif
35-
unsigned long st_size;
36-
unsigned long st_blksize;
37-
unsigned long st_blocks;
38-
39-
unsigned long st_atime;
40-
unsigned long st_atime_nsec;
41-
unsigned long st_mtime;
42-
unsigned long st_mtime_nsec;
43-
44-
unsigned long st_ctime;
45-
unsigned long st_ctime_nsec;
46-
unsigned long __unused[2];
47-
};
11+
#include "crt.h"
4812

4913
/* Syscalls for ARM in ARM or Thumb modes :
5014
* - registers are 32-bit
@@ -90,8 +54,8 @@ struct sys_stat_struct {
9054
({ \
9155
register long _num __asm__(_NOLIBC_SYSCALL_REG) = (num); \
9256
register long _arg1 __asm__ ("r0"); \
93-
\
94-
__asm__ volatile ( \
57+
\
58+
__asm__ volatile ( \
9559
_NOLIBC_THUMB_SET_R7 \
9660
"svc #0\n" \
9761
_NOLIBC_THUMB_RESTORE_R7 \
@@ -107,8 +71,8 @@ struct sys_stat_struct {
10771
({ \
10872
register long _num __asm__(_NOLIBC_SYSCALL_REG) = (num); \
10973
register long _arg1 __asm__ ("r0") = (long)(arg1); \
110-
\
111-
__asm__ volatile ( \
74+
\
75+
__asm__ volatile ( \
11276
_NOLIBC_THUMB_SET_R7 \
11377
"svc #0\n" \
11478
_NOLIBC_THUMB_RESTORE_R7 \
@@ -125,8 +89,8 @@ struct sys_stat_struct {
12589
register long _num __asm__(_NOLIBC_SYSCALL_REG) = (num); \
12690
register long _arg1 __asm__ ("r0") = (long)(arg1); \
12791
register long _arg2 __asm__ ("r1") = (long)(arg2); \
128-
\
129-
__asm__ volatile ( \
92+
\
93+
__asm__ volatile ( \
13094
_NOLIBC_THUMB_SET_R7 \
13195
"svc #0\n" \
13296
_NOLIBC_THUMB_RESTORE_R7 \
@@ -144,8 +108,8 @@ struct sys_stat_struct {
144108
register long _arg1 __asm__ ("r0") = (long)(arg1); \
145109
register long _arg2 __asm__ ("r1") = (long)(arg2); \
146110
register long _arg3 __asm__ ("r2") = (long)(arg3); \
147-
\
148-
__asm__ volatile ( \
111+
\
112+
__asm__ volatile ( \
149113
_NOLIBC_THUMB_SET_R7 \
150114
"svc #0\n" \
151115
_NOLIBC_THUMB_RESTORE_R7 \
@@ -164,8 +128,8 @@ struct sys_stat_struct {
164128
register long _arg2 __asm__ ("r1") = (long)(arg2); \
165129
register long _arg3 __asm__ ("r2") = (long)(arg3); \
166130
register long _arg4 __asm__ ("r3") = (long)(arg4); \
167-
\
168-
__asm__ volatile ( \
131+
\
132+
__asm__ volatile ( \
169133
_NOLIBC_THUMB_SET_R7 \
170134
"svc #0\n" \
171135
_NOLIBC_THUMB_RESTORE_R7 \
@@ -185,8 +149,8 @@ struct sys_stat_struct {
185149
register long _arg3 __asm__ ("r2") = (long)(arg3); \
186150
register long _arg4 __asm__ ("r3") = (long)(arg4); \
187151
register long _arg5 __asm__ ("r4") = (long)(arg5); \
188-
\
189-
__asm__ volatile ( \
152+
\
153+
__asm__ volatile ( \
190154
_NOLIBC_THUMB_SET_R7 \
191155
"svc #0\n" \
192156
_NOLIBC_THUMB_RESTORE_R7 \
@@ -207,8 +171,8 @@ struct sys_stat_struct {
207171
register long _arg4 __asm__ ("r3") = (long)(arg4); \
208172
register long _arg5 __asm__ ("r4") = (long)(arg5); \
209173
register long _arg6 __asm__ ("r5") = (long)(arg6); \
210-
\
211-
__asm__ volatile ( \
174+
\
175+
__asm__ volatile ( \
212176
_NOLIBC_THUMB_SET_R7 \
213177
"svc #0\n" \
214178
_NOLIBC_THUMB_RESTORE_R7 \
@@ -220,49 +184,14 @@ struct sys_stat_struct {
220184
_arg1; \
221185
})
222186

223-
224-
char **environ __attribute__((weak));
225-
const unsigned long *_auxv __attribute__((weak));
226-
227187
/* startup code */
228-
void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
188+
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
229189
{
230190
__asm__ volatile (
231-
#ifdef _NOLIBC_STACKPROTECTOR
232-
"bl __stack_chk_init\n" /* initialize stack protector */
233-
#endif
234-
"pop {%r0}\n" /* argc was in the stack */
235-
"mov %r1, %sp\n" /* argv = sp */
236-
237-
"add %r2, %r0, $1\n" /* envp = (argc + 1) ... */
238-
"lsl %r2, %r2, $2\n" /* * 4 ... */
239-
"add %r2, %r2, %r1\n" /* + argv */
240-
"ldr %r3, 1f\n" /* r3 = &environ (see below) */
241-
"str %r2, [r3]\n" /* store envp into environ */
242-
243-
"mov r4, r2\n" /* search for auxv (follows NULL after last env) */
244-
"0:\n"
245-
"mov r5, r4\n" /* r5 = r4 */
246-
"add r4, r4, #4\n" /* r4 += 4 */
247-
"ldr r5,[r5]\n" /* r5 = *r5 = *(r4-4) */
248-
"cmp r5, #0\n" /* and stop at NULL after last env */
249-
"bne 0b\n"
250-
"ldr %r3, 2f\n" /* r3 = &_auxv (low bits) */
251-
"str r4, [r3]\n" /* store r4 into _auxv */
252-
253-
"mov %r3, $8\n" /* AAPCS : sp must be 8-byte aligned in the */
254-
"neg %r3, %r3\n" /* callee, and bl doesn't push (lr=pc) */
255-
"and %r3, %r3, %r1\n" /* so we do sp = r1(=sp) & r3(=-8); */
256-
"mov %sp, %r3\n"
257-
258-
"bl main\n" /* main() returns the status code, we'll exit with it. */
259-
"movs r7, $1\n" /* NR_exit == 1 */
260-
"svc $0x00\n"
261-
".align 2\n" /* below are the pointers to a few variables */
262-
"1:\n"
263-
".word environ\n"
264-
"2:\n"
265-
".word _auxv\n"
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 */
193+
"mov sp, ip\n"
194+
"bl _start_c\n" /* transfer to c runtime */
266195
);
267196
__builtin_unreachable();
268197
}

0 commit comments

Comments
 (0)