Skip to content

Commit 418beca

Browse files
committed
Merge tag 'nolibc-20250308-for-6.15-1' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu
Pull nolibc updates from Paul McKenney: - 32bit s390 support - opendir() and friends - openat() support - sscanf() support - various cleanups [ Paul has just forwarded the pull request from Thomas Weißschuh, so the tag signature is from Thomas, not Paul - Linus ] * tag 'nolibc-20250308-for-6.15-1' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu: (26 commits) tools/nolibc: don't use asm/ UAPI headers selftests/nolibc: stop testing constructor order selftests/nolibc: use O_RDONLY flag instead of 0 tools/nolibc: drop outdated example from overview comment tools/nolibc: process open() vararg as mode_t tools/nolibc: always use openat(2) instead of open(2) tools/nolibc: add support for openat(2) selftests/nolibc: add armthumb configuration selftests/nolibc: explicitly enable ARM mode Revert "selftests: kselftest: Fix build failure with NOLIBC" tools/nolibc: add support for [v]sscanf() tools/nolibc: add support for 32-bit s390 selftests/nolibc: rename s390 to s390x selftests/nolibc: only run constructor tests on nolibc selftests/nolibc: split up architecture list in run-tests.sh tools/nolibc: add support for directory access tools/nolibc: add support for sys_llseek() selftests/nolibc: always keep test kernel configuration up to date selftests/nolibc: execute defconfig before other targets selftests/nolibc: drop call to mrproper target ...
2 parents bcb0442 + bceb739 commit 418beca

File tree

19 files changed

+457
-56
lines changed

19 files changed

+457
-56
lines changed

tools/include/nolibc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ all_files := \
2929
compiler.h \
3030
crt.h \
3131
ctype.h \
32+
dirent.h \
3233
errno.h \
3334
nolibc.h \
3435
signal.h \

tools/include/nolibc/arch-mips.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
})
180180

181181
/* startup code, note that it's called __start on MIPS */
182+
void __start(void);
182183
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector __start(void)
183184
{
184185
__asm__ volatile (

tools/include/nolibc/arch-s390.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
#ifndef _NOLIBC_ARCH_S390_H
77
#define _NOLIBC_ARCH_S390_H
8-
#include <asm/signal.h>
9-
#include <asm/unistd.h>
8+
#include <linux/signal.h>
9+
#include <linux/unistd.h>
1010

1111
#include "compiler.h"
1212
#include "crt.h"
@@ -143,8 +143,13 @@
143143
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
144144
{
145145
__asm__ volatile (
146+
#ifdef __s390x__
146147
"lgr %r2, %r15\n" /* save stack pointer to %r2, as arg1 of _start_c */
147148
"aghi %r15, -160\n" /* allocate new stackframe */
149+
#else
150+
"lr %r2, %r15\n"
151+
"ahi %r15, -96\n"
152+
#endif
148153
"xc 0(8,%r15), 0(%r15)\n" /* clear backchain */
149154
"brasl %r14, _start_c\n" /* transfer to c runtime */
150155
);

tools/include/nolibc/arch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "arch-powerpc.h"
3030
#elif defined(__riscv)
3131
#include "arch-riscv.h"
32-
#elif defined(__s390x__)
32+
#elif defined(__s390x__) || defined(__s390__)
3333
#include "arch-s390.h"
3434
#elif defined(__loongarch__)
3535
#include "arch-loongarch.h"

tools/include/nolibc/crt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
char **environ __attribute__((weak));
1111
const unsigned long *_auxv __attribute__((weak));
1212

13+
void _start(void);
1314
static void __stack_chk_init(void);
1415
static void exit(int);
1516

@@ -22,6 +23,7 @@ extern void (*const __init_array_end[])(int, char **, char**) __attribute__((wea
2223
extern void (*const __fini_array_start[])(void) __attribute__((weak));
2324
extern void (*const __fini_array_end[])(void) __attribute__((weak));
2425

26+
void _start_c(long *sp);
2527
__attribute__((weak,used))
2628
void _start_c(long *sp)
2729
{

tools/include/nolibc/dirent.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
2+
/*
3+
* Directory access for NOLIBC
4+
* Copyright (C) 2025 Thomas Weißschuh <linux@weissschuh.net>
5+
*/
6+
7+
#ifndef _NOLIBC_DIRENT_H
8+
#define _NOLIBC_DIRENT_H
9+
10+
#include "stdint.h"
11+
#include "types.h"
12+
13+
#include <linux/limits.h>
14+
15+
struct dirent {
16+
ino_t d_ino;
17+
char d_name[NAME_MAX + 1];
18+
};
19+
20+
/* See comment of FILE in stdio.h */
21+
typedef struct {
22+
char dummy[1];
23+
} DIR;
24+
25+
static __attribute__((unused))
26+
DIR *fdopendir(int fd)
27+
{
28+
if (fd < 0) {
29+
SET_ERRNO(EBADF);
30+
return NULL;
31+
}
32+
return (DIR *)(intptr_t)~fd;
33+
}
34+
35+
static __attribute__((unused))
36+
DIR *opendir(const char *name)
37+
{
38+
int fd;
39+
40+
fd = open(name, O_RDONLY);
41+
if (fd == -1)
42+
return NULL;
43+
return fdopendir(fd);
44+
}
45+
46+
static __attribute__((unused))
47+
int closedir(DIR *dirp)
48+
{
49+
intptr_t i = (intptr_t)dirp;
50+
51+
if (i >= 0) {
52+
SET_ERRNO(EBADF);
53+
return -1;
54+
}
55+
return close(~i);
56+
}
57+
58+
static __attribute__((unused))
59+
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
60+
{
61+
char buf[sizeof(struct linux_dirent64) + NAME_MAX + 1];
62+
struct linux_dirent64 *ldir = (void *)buf;
63+
intptr_t i = (intptr_t)dirp;
64+
int fd, ret;
65+
66+
if (i >= 0)
67+
return EBADF;
68+
69+
fd = ~i;
70+
71+
ret = sys_getdents64(fd, ldir, sizeof(buf));
72+
if (ret < 0)
73+
return -ret;
74+
if (ret == 0) {
75+
*result = NULL;
76+
return 0;
77+
}
78+
79+
/*
80+
* getdents64() returns as many entries as fit the buffer.
81+
* readdir() can only return one entry at a time.
82+
* Make sure the non-returned ones are not skipped.
83+
*/
84+
ret = lseek(fd, ldir->d_off, SEEK_SET);
85+
if (ret == -1)
86+
return errno;
87+
88+
entry->d_ino = ldir->d_ino;
89+
/* the destination should always be big enough */
90+
strlcpy(entry->d_name, ldir->d_name, sizeof(entry->d_name));
91+
*result = entry;
92+
return 0;
93+
}
94+
95+
/* make sure to include all global symbols */
96+
#include "nolibc.h"
97+
98+
#endif /* _NOLIBC_DIRENT_H */

tools/include/nolibc/errno.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#ifndef _NOLIBC_ERRNO_H
88
#define _NOLIBC_ERRNO_H
99

10-
#include <asm/errno.h>
10+
#include <linux/errno.h>
1111

1212
#ifndef NOLIBC_IGNORE_ERRNO
1313
#define SET_ERRNO(v) do { errno = (v); } while (0)

tools/include/nolibc/nolibc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
* - The third level is the libc call definition. It exposes the lower raw
3232
* sys_<name>() calls in a way that looks like what a libc usually does,
3333
* takes care of specific input values, and of setting errno upon error.
34-
* There can be minor variations compared to standard libc calls. For
35-
* example the open() call always takes 3 args here.
34+
* There can be minor variations compared to standard libc calls.
3635
*
3736
* The errno variable is declared static and unused. This way it can be
3837
* optimized away if not used. However this means that a program made of
@@ -105,6 +104,7 @@
105104
#include "string.h"
106105
#include "time.h"
107106
#include "stackprotector.h"
107+
#include "dirent.h"
108108

109109
/* Used by programs to avoid std includes */
110110
#define NOLIBC

tools/include/nolibc/signal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "sys.h"
1414

1515
/* This one is not marked static as it's needed by libgcc for divide by zero */
16+
int raise(int signal);
1617
__attribute__((weak,unused,section(".text.nolibc_raise")))
1718
int raise(int signal)
1819
{

tools/include/nolibc/stackprotector.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* triggering stack protector errors themselves
1919
*/
2020

21+
void __stack_chk_fail(void);
2122
__attribute__((weak,used,noreturn,section(".text.nolibc_stack_chk")))
2223
void __stack_chk_fail(void)
2324
{
@@ -28,6 +29,7 @@ void __stack_chk_fail(void)
2829
for (;;);
2930
}
3031

32+
void __stack_chk_fail_local(void);
3133
__attribute__((weak,noreturn,section(".text.nolibc_stack_chk")))
3234
void __stack_chk_fail_local(void)
3335
{

0 commit comments

Comments
 (0)