Skip to content

Commit f129b61

Browse files
committed
Merge tag 'urgent-nolibc.2023.01.09a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu
Pull nolibc fixes from Paul McKenney: - The fd_set structure was incorrectly defined as arrays of u32 instead of long, which breaks BE64. Fix courtesy of Sven Schnelle. - S_ISxxx macros were incorrectly testing the bits after applying them instead of bitwise ANDing S_FMT with the value. Fix from Warner Losh. - The mips code was randomly broken due to an unprotected "noreorder" directive in the _start code that could prevent the assembler from filling delayed slots. This in turn resulted in random other instructions being placed into those slots. Fix courtesy of Willy Tarreau. - The current nolibc header layout refrains from including files that are not explicitly included by the code using nolibc. Unfortunately, this causes build failures when such files contain definitions that are used (for example) by libgcc. Example definitions include raise() and memset(), which are called by some architectures, but only at certain optimization levels. Fix courtesy of Willy Tarreau. - gcc 11.3 in ARM thumb2 mode at -O2 recognized a memset() construction inside the memset() definition. The compiler replaced this construction with a call to... memset(). Userland cannot be forced to build with -ffreestanding, so an empty asm() statement was introduced into the loop the loop in order to prevent the compiler from making this unproductive transformation. Fix courtesy of Willy Tarreau. - Most of the O_* macros were wrong on RISCV because their octal values were coded as hexadecimal. This resulted in the getdents64() selftest failing. Fix courtesy of Willy Tarreau. This was tested on x86_64, i386, armv5, armv7, thumb1, thumb2, mips and riscv, all at -O0, -Os and -O3. * tag 'urgent-nolibc.2023.01.09a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu: tools/nolibc: fix the O_* fcntl/open macro definitions for riscv tools/nolibc: prevent gcc from making memset() loop over itself tools/nolibc: fix missing includes causing build issues at -O0 tools/nolibc: restore mips branch ordering in the _start block tools/nolibc: Fix S_ISxxx macros nolibc: fix fd_set type
2 parents c757fc9 + 00b18da commit f129b61

File tree

12 files changed

+79
-38
lines changed

12 files changed

+79
-38
lines changed

tools/include/nolibc/arch-mips.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ struct sys_stat_struct {
192192
__asm__ (".section .text\n"
193193
".weak __start\n"
194194
".set nomips16\n"
195+
".set push\n"
195196
".set noreorder\n"
196197
".option pic0\n"
197198
".ent __start\n"
@@ -210,6 +211,7 @@ __asm__ (".section .text\n"
210211
"li $v0, 4001\n" // NR_exit == 4001
211212
"syscall\n"
212213
".end __start\n"
214+
".set pop\n"
213215
"");
214216

215217
#endif // _NOLIBC_ARCH_MIPS_H

tools/include/nolibc/arch-riscv.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
#define O_RDONLY 0
1212
#define O_WRONLY 1
1313
#define O_RDWR 2
14-
#define O_CREAT 0x100
15-
#define O_EXCL 0x200
16-
#define O_NOCTTY 0x400
17-
#define O_TRUNC 0x1000
18-
#define O_APPEND 0x2000
19-
#define O_NONBLOCK 0x4000
20-
#define O_DIRECTORY 0x200000
14+
#define O_CREAT 0x40
15+
#define O_EXCL 0x80
16+
#define O_NOCTTY 0x100
17+
#define O_TRUNC 0x200
18+
#define O_APPEND 0x400
19+
#define O_NONBLOCK 0x800
20+
#define O_DIRECTORY 0x10000
2121

2222
struct sys_stat_struct {
2323
unsigned long st_dev; /* Device. */

tools/include/nolibc/ctype.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,7 @@ int ispunct(int c)
9696
return isgraph(c) && !isalnum(c);
9797
}
9898

99+
/* make sure to include all global symbols */
100+
#include "nolibc.h"
101+
99102
#endif /* _NOLIBC_CTYPE_H */

tools/include/nolibc/errno.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ static int errno;
2424
*/
2525
#define MAX_ERRNO 4095
2626

27+
/* make sure to include all global symbols */
28+
#include "nolibc.h"
29+
2730
#endif /* _NOLIBC_ERRNO_H */

tools/include/nolibc/signal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ int raise(int signal)
1919
return sys_kill(sys_getpid(), signal);
2020
}
2121

22+
/* make sure to include all global symbols */
23+
#include "nolibc.h"
24+
2225
#endif /* _NOLIBC_SIGNAL_H */

tools/include/nolibc/stdio.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,7 @@ void perror(const char *msg)
303303
fprintf(stderr, "%s%serrno=%d\n", (msg && *msg) ? msg : "", (msg && *msg) ? ": " : "", errno);
304304
}
305305

306+
/* make sure to include all global symbols */
307+
#include "nolibc.h"
308+
306309
#endif /* _NOLIBC_STDIO_H */

tools/include/nolibc/stdlib.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,7 @@ char *u64toa(uint64_t in)
419419
return itoa_buffer;
420420
}
421421

422+
/* make sure to include all global symbols */
423+
#include "nolibc.h"
424+
422425
#endif /* _NOLIBC_STDLIB_H */

tools/include/nolibc/string.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ void *memset(void *dst, int b, size_t len)
8888
{
8989
char *p = dst;
9090

91-
while (len--)
91+
while (len--) {
92+
/* prevent gcc from recognizing memset() here */
93+
asm volatile("");
9294
*(p++) = b;
95+
}
9396
return dst;
9497
}
9598

@@ -285,4 +288,7 @@ char *strrchr(const char *s, int c)
285288
return (char *)ret;
286289
}
287290

291+
/* make sure to include all global symbols */
292+
#include "nolibc.h"
293+
288294
#endif /* _NOLIBC_STRING_H */

tools/include/nolibc/sys.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,5 +1243,7 @@ ssize_t write(int fd, const void *buf, size_t count)
12431243
return ret;
12441244
}
12451245

1246+
/* make sure to include all global symbols */
1247+
#include "nolibc.h"
12461248

12471249
#endif /* _NOLIBC_SYS_H */

tools/include/nolibc/time.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ time_t time(time_t *tptr)
2525
return tv.tv_sec;
2626
}
2727

28+
/* make sure to include all global symbols */
29+
#include "nolibc.h"
30+
2831
#endif /* _NOLIBC_TIME_H */

0 commit comments

Comments
 (0)