mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 01:32:21 +02:00
nolibc changes for 7.2
Highlights: * New architectures: OpenRISC and 32-bit parisc * New library functionality: alloca(), assert(), creat() and ftruncate() * Automatic large file support * Proper 64-bit system call argument passing on x32 and MIPS N32 * Cleanups of the testmatrix * Various bugfixes and cleanups -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQTg4lxklFHAidmUs57B+h1jyw5bOAUCai5uXwAKCRDB+h1jyw5b OND2AP9tiHFoTxtVjCm9nl5YnngL6Hb1jxEJJuAhyRGG3XMd+AEA0wzA0IdSBRGM d99EqrECYHNRdFUMYdmTTus9L/4f5g4= =Yaqn -----END PGP SIGNATURE----- Merge tag 'nolibc-20260614-for-7.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/nolibc/linux-nolibc Pull nolibc updates from Thomas Weißschuh: - New architectures: OpenRISC and 32-bit parisc - New library functionality: alloca(), assert(), creat() and ftruncate() - Automatic large file support - Proper 64-bit system call argument passing on x32 and MIPS N32 - Cleanups of the testmatrix - Various bugfixes and cleanups * tag 'nolibc-20260614-for-7.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/nolibc/linux-nolibc: (37 commits) selftests/nolibc: test against -Wwrite-strings selftests/nolibc: use mutable buffer for execve() argv string tools/nolibc: cast default values of program_invocation_name tools/nolibc: add ftruncate() tools/nolibc: add a helper to split a 64-bit argument into 32-bit halves selftests/nolibc: enable CONFIG_TMPFS for sparc32 tools/nolibc: stackprotector: Avoid stalling program startup if crng is not init yet tools/nolibc: getopt: Fix potential out of bounds access selftests/nolibc: test open mode handling tools/nolibc: always pass mode to open syscall tools/nolibc: split open mode handling into a macro tools/nolibc: split implicit open flags into a macro tools/nolibc: add support for 32-bit parisc selftests/nolibc: avoid function pointer comparisons tools/nolibc: add support for OpenRISC / or1k selftests/nolibc: use vmlinux for MIPS tests selftests/nolibc: trim IMAGE mappings selftests/nolibc: trim DEFCONFIG mappings selftests/nolibc: trim QEMU_ARCH mappings selftests/nolibc: use QEMU_ARCH for QEMU_ARCH_USER ...
This commit is contained in:
commit
966240b990
|
|
@ -17,9 +17,11 @@ endif
|
|||
# it defaults to this nolibc directory.
|
||||
OUTPUT ?= $(CURDIR)/
|
||||
|
||||
architectures := arm arm64 loongarch m68k mips powerpc riscv s390 sh sparc x86
|
||||
architectures := arm arm64 loongarch m68k mips openrisc parisc powerpc riscv s390 sh sparc x86
|
||||
arch_files := arch.h $(addsuffix .h, $(addprefix arch-, $(architectures)))
|
||||
all_files := \
|
||||
alloca.h \
|
||||
assert.h \
|
||||
byteswap.h \
|
||||
compiler.h \
|
||||
crt.h \
|
||||
|
|
|
|||
15
tools/include/nolibc/alloca.h
Normal file
15
tools/include/nolibc/alloca.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
|
||||
/*
|
||||
* alloca() for NOLIBC
|
||||
* Copyright (C) 2026 Thomas Weißschuh <linux@weissschuh.net>
|
||||
*/
|
||||
|
||||
/* make sure to include all global symbols */
|
||||
#include "nolibc.h"
|
||||
|
||||
#ifndef _NOLIBC_ALLOCA_H
|
||||
#define _NOLIBC_ALLOCA_H
|
||||
|
||||
#define alloca(size) __builtin_alloca(size)
|
||||
|
||||
#endif /* _NOLIBC_ALLOCA_H */
|
||||
|
|
@ -7,8 +7,11 @@
|
|||
#ifndef _NOLIBC_ARCH_ARM_H
|
||||
#define _NOLIBC_ARCH_ARM_H
|
||||
|
||||
#include <linux/unistd.h>
|
||||
|
||||
#include "compiler.h"
|
||||
#include "crt.h"
|
||||
#include "std.h"
|
||||
|
||||
/* Syscalls for ARM in ARM or Thumb modes :
|
||||
* - registers are 32-bit
|
||||
|
|
@ -186,7 +189,7 @@
|
|||
|
||||
#ifndef NOLIBC_NO_RUNTIME
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
"mov r0, sp\n" /* save stack pointer to %r0, as arg1 of _start_c */
|
||||
|
|
@ -196,4 +199,11 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
|
|||
}
|
||||
#endif /* NOLIBC_NO_RUNTIME */
|
||||
|
||||
static __attribute__((unused))
|
||||
int _sys_ftruncate64(int fd, uint32_t length0, uint32_t length1)
|
||||
{
|
||||
return __nolibc_syscall4(__NR_ftruncate64, fd, 0, length0, length1);
|
||||
}
|
||||
#define _sys_ftruncate64 _sys_ftruncate64
|
||||
|
||||
#endif /* _NOLIBC_ARCH_ARM_H */
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@
|
|||
|
||||
#ifndef NOLIBC_NO_RUNTIME
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
"mov x0, sp\n" /* save stack pointer to x0, as arg1 of _start_c */
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@
|
|||
|
||||
#ifndef NOLIBC_NO_RUNTIME
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
"move $a0, $sp\n" /* save stack pointer to $a0, as arg1 of _start_c */
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@
|
|||
|
||||
#ifndef NOLIBC_NO_RUNTIME
|
||||
void _start(void);
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
"movel %sp, %sp@-\n"
|
||||
|
|
|
|||
|
|
@ -7,8 +7,11 @@
|
|||
#ifndef _NOLIBC_ARCH_MIPS_H
|
||||
#define _NOLIBC_ARCH_MIPS_H
|
||||
|
||||
#include <linux/unistd.h>
|
||||
|
||||
#include "compiler.h"
|
||||
#include "crt.h"
|
||||
#include "std.h"
|
||||
|
||||
#if !defined(_ABIO32) && !defined(_ABIN32) && !defined(_ABI64)
|
||||
#error Unsupported MIPS ABI
|
||||
|
|
@ -55,6 +58,8 @@
|
|||
#define _NOLIBC_SYSCALL_STACK_RESERVE "addiu $sp, $sp, -32\n"
|
||||
#define _NOLIBC_SYSCALL_STACK_UNRESERVE "addiu $sp, $sp, 32\n"
|
||||
|
||||
#define _NOLIBC_SYSCALL_REG register long
|
||||
|
||||
#else /* _ABIN32 || _ABI64 */
|
||||
|
||||
/* binutils, GCC and clang disagree about register aliases, use numbers instead. */
|
||||
|
|
@ -66,12 +71,14 @@
|
|||
#define _NOLIBC_SYSCALL_STACK_RESERVE
|
||||
#define _NOLIBC_SYSCALL_STACK_UNRESERVE
|
||||
|
||||
#define _NOLIBC_SYSCALL_REG register long long
|
||||
|
||||
#endif /* _ABIO32 */
|
||||
|
||||
#define __nolibc_syscall0(num) \
|
||||
({ \
|
||||
register long _num __asm__ ("v0") = (num); \
|
||||
register long _arg4 __asm__ ("a3"); \
|
||||
_NOLIBC_SYSCALL_REG _num __asm__ ("v0") = (num); \
|
||||
_NOLIBC_SYSCALL_REG _arg4 __asm__ ("a3"); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
_NOLIBC_SYSCALL_STACK_RESERVE \
|
||||
|
|
@ -86,9 +93,9 @@
|
|||
|
||||
#define __nolibc_syscall1(num, arg1) \
|
||||
({ \
|
||||
register long _num __asm__ ("v0") = (num); \
|
||||
register long _arg1 __asm__ ("a0") = (long)(arg1); \
|
||||
register long _arg4 __asm__ ("a3"); \
|
||||
_NOLIBC_SYSCALL_REG _num __asm__ ("v0") = (num); \
|
||||
_NOLIBC_SYSCALL_REG _arg1 __asm__ ("a0") = __nolibc_arg_to_reg(arg1); \
|
||||
_NOLIBC_SYSCALL_REG _arg4 __asm__ ("a3"); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
_NOLIBC_SYSCALL_STACK_RESERVE \
|
||||
|
|
@ -104,10 +111,10 @@
|
|||
|
||||
#define __nolibc_syscall2(num, arg1, arg2) \
|
||||
({ \
|
||||
register long _num __asm__ ("v0") = (num); \
|
||||
register long _arg1 __asm__ ("a0") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("a1") = (long)(arg2); \
|
||||
register long _arg4 __asm__ ("a3"); \
|
||||
_NOLIBC_SYSCALL_REG _num __asm__ ("v0") = (num); \
|
||||
_NOLIBC_SYSCALL_REG _arg1 __asm__ ("a0") = __nolibc_arg_to_reg(arg1); \
|
||||
_NOLIBC_SYSCALL_REG _arg2 __asm__ ("a1") = __nolibc_arg_to_reg(arg2); \
|
||||
_NOLIBC_SYSCALL_REG _arg4 __asm__ ("a3"); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
_NOLIBC_SYSCALL_STACK_RESERVE \
|
||||
|
|
@ -123,11 +130,11 @@
|
|||
|
||||
#define __nolibc_syscall3(num, arg1, arg2, arg3) \
|
||||
({ \
|
||||
register long _num __asm__ ("v0") = (num); \
|
||||
register long _arg1 __asm__ ("a0") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("a1") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("a2") = (long)(arg3); \
|
||||
register long _arg4 __asm__ ("a3"); \
|
||||
_NOLIBC_SYSCALL_REG _num __asm__ ("v0") = (num); \
|
||||
_NOLIBC_SYSCALL_REG _arg1 __asm__ ("a0") = __nolibc_arg_to_reg(arg1); \
|
||||
_NOLIBC_SYSCALL_REG _arg2 __asm__ ("a1") = __nolibc_arg_to_reg(arg2); \
|
||||
_NOLIBC_SYSCALL_REG _arg3 __asm__ ("a2") = __nolibc_arg_to_reg(arg3); \
|
||||
_NOLIBC_SYSCALL_REG _arg4 __asm__ ("a3"); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
_NOLIBC_SYSCALL_STACK_RESERVE \
|
||||
|
|
@ -143,11 +150,11 @@
|
|||
|
||||
#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \
|
||||
({ \
|
||||
register long _num __asm__ ("v0") = (num); \
|
||||
register long _arg1 __asm__ ("a0") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("a1") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("a2") = (long)(arg3); \
|
||||
register long _arg4 __asm__ ("a3") = (long)(arg4); \
|
||||
_NOLIBC_SYSCALL_REG _num __asm__ ("v0") = (num); \
|
||||
_NOLIBC_SYSCALL_REG _arg1 __asm__ ("a0") = __nolibc_arg_to_reg(arg1); \
|
||||
_NOLIBC_SYSCALL_REG _arg2 __asm__ ("a1") = __nolibc_arg_to_reg(arg2); \
|
||||
_NOLIBC_SYSCALL_REG _arg3 __asm__ ("a2") = __nolibc_arg_to_reg(arg3); \
|
||||
_NOLIBC_SYSCALL_REG _arg4 __asm__ ("a3") = __nolibc_arg_to_reg(arg4); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
_NOLIBC_SYSCALL_STACK_RESERVE \
|
||||
|
|
@ -165,12 +172,12 @@
|
|||
|
||||
#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \
|
||||
({ \
|
||||
register long _num __asm__ ("v0") = (num); \
|
||||
register long _arg1 __asm__ ("a0") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("a1") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("a2") = (long)(arg3); \
|
||||
register long _arg4 __asm__ ("a3") = (long)(arg4); \
|
||||
register long _arg5 = (long)(arg5); \
|
||||
_NOLIBC_SYSCALL_REG _num __asm__ ("v0") = (num); \
|
||||
_NOLIBC_SYSCALL_REG _arg1 __asm__ ("a0") = __nolibc_arg_to_reg(arg1); \
|
||||
_NOLIBC_SYSCALL_REG _arg2 __asm__ ("a1") = __nolibc_arg_to_reg(arg2); \
|
||||
_NOLIBC_SYSCALL_REG _arg3 __asm__ ("a2") = __nolibc_arg_to_reg(arg3); \
|
||||
_NOLIBC_SYSCALL_REG _arg4 __asm__ ("a3") = __nolibc_arg_to_reg(arg4); \
|
||||
_NOLIBC_SYSCALL_REG _arg5 = __nolibc_arg_to_reg(arg5); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
_NOLIBC_SYSCALL_STACK_RESERVE \
|
||||
|
|
@ -187,13 +194,13 @@
|
|||
|
||||
#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \
|
||||
({ \
|
||||
register long _num __asm__ ("v0") = (num); \
|
||||
register long _arg1 __asm__ ("a0") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("a1") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("a2") = (long)(arg3); \
|
||||
register long _arg4 __asm__ ("a3") = (long)(arg4); \
|
||||
register long _arg5 = (long)(arg5); \
|
||||
register long _arg6 = (long)(arg6); \
|
||||
_NOLIBC_SYSCALL_REG _num __asm__ ("v0") = (num); \
|
||||
_NOLIBC_SYSCALL_REG _arg1 __asm__ ("a0") = __nolibc_arg_to_reg(arg1); \
|
||||
_NOLIBC_SYSCALL_REG _arg2 __asm__ ("a1") = __nolibc_arg_to_reg(arg2); \
|
||||
_NOLIBC_SYSCALL_REG _arg3 __asm__ ("a2") = __nolibc_arg_to_reg(arg3); \
|
||||
_NOLIBC_SYSCALL_REG _arg4 __asm__ ("a3") = __nolibc_arg_to_reg(arg4); \
|
||||
_NOLIBC_SYSCALL_REG _arg5 = __nolibc_arg_to_reg(arg5); \
|
||||
_NOLIBC_SYSCALL_REG _arg6 = __nolibc_arg_to_reg(arg6); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
_NOLIBC_SYSCALL_STACK_RESERVE \
|
||||
|
|
@ -214,12 +221,12 @@
|
|||
|
||||
#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \
|
||||
({ \
|
||||
register long _num __asm__ ("v0") = (num); \
|
||||
register long _arg1 __asm__ ("$4") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("$5") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("$6") = (long)(arg3); \
|
||||
register long _arg4 __asm__ ("$7") = (long)(arg4); \
|
||||
register long _arg5 __asm__ ("$8") = (long)(arg5); \
|
||||
_NOLIBC_SYSCALL_REG _num __asm__ ("v0") = (num); \
|
||||
_NOLIBC_SYSCALL_REG _arg1 __asm__ ("$4") = __nolibc_arg_to_reg(arg1); \
|
||||
_NOLIBC_SYSCALL_REG _arg2 __asm__ ("$5") = __nolibc_arg_to_reg(arg2); \
|
||||
_NOLIBC_SYSCALL_REG _arg3 __asm__ ("$6") = __nolibc_arg_to_reg(arg3); \
|
||||
_NOLIBC_SYSCALL_REG _arg4 __asm__ ("$7") = __nolibc_arg_to_reg(arg4); \
|
||||
_NOLIBC_SYSCALL_REG _arg5 __asm__ ("$8") = __nolibc_arg_to_reg(arg5); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"syscall\n" \
|
||||
|
|
@ -233,13 +240,13 @@
|
|||
|
||||
#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \
|
||||
({ \
|
||||
register long _num __asm__ ("v0") = (num); \
|
||||
register long _arg1 __asm__ ("$4") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("$5") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("$6") = (long)(arg3); \
|
||||
register long _arg4 __asm__ ("$7") = (long)(arg4); \
|
||||
register long _arg5 __asm__ ("$8") = (long)(arg5); \
|
||||
register long _arg6 __asm__ ("$9") = (long)(arg6); \
|
||||
_NOLIBC_SYSCALL_REG _num __asm__ ("v0") = (num); \
|
||||
_NOLIBC_SYSCALL_REG _arg1 __asm__ ("$4") = __nolibc_arg_to_reg(arg1); \
|
||||
_NOLIBC_SYSCALL_REG _arg2 __asm__ ("$5") = __nolibc_arg_to_reg(arg2); \
|
||||
_NOLIBC_SYSCALL_REG _arg3 __asm__ ("$6") = __nolibc_arg_to_reg(arg3); \
|
||||
_NOLIBC_SYSCALL_REG _arg4 __asm__ ("$7") = __nolibc_arg_to_reg(arg4); \
|
||||
_NOLIBC_SYSCALL_REG _arg5 __asm__ ("$8") = __nolibc_arg_to_reg(arg5); \
|
||||
_NOLIBC_SYSCALL_REG _arg6 __asm__ ("$9") = __nolibc_arg_to_reg(arg6); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"syscall\n" \
|
||||
|
|
@ -257,7 +264,7 @@
|
|||
#ifndef NOLIBC_NO_RUNTIME
|
||||
/* startup code, note that it's called __start on MIPS */
|
||||
void __start(void);
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector __start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector __start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
"move $a0, $sp\n" /* save stack pointer to $a0, as arg1 of _start_c */
|
||||
|
|
@ -278,4 +285,13 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector __
|
|||
}
|
||||
#endif /* NOLIBC_NO_RUNTIME */
|
||||
|
||||
#if defined(_ABIO32)
|
||||
static __attribute__((unused))
|
||||
int _sys_ftruncate64(int fd, uint32_t length0, uint32_t length1)
|
||||
{
|
||||
return __nolibc_syscall4(__NR_ftruncate64, fd, 0, length0, length1);
|
||||
}
|
||||
#define _sys_ftruncate64 _sys_ftruncate64
|
||||
#endif
|
||||
|
||||
#endif /* _NOLIBC_ARCH_MIPS_H */
|
||||
|
|
|
|||
160
tools/include/nolibc/arch-openrisc.h
Normal file
160
tools/include/nolibc/arch-openrisc.h
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
|
||||
/*
|
||||
* OpenRISC specific definitions for NOLIBC
|
||||
* Copyright (C) 2026 Thomas Weißschuh <linux@weissschuh.net>
|
||||
*/
|
||||
|
||||
#ifndef _NOLIBC_ARCH_OPENRISC_H
|
||||
#define _NOLIBC_ARCH_OPENRISC_H
|
||||
|
||||
#include "compiler.h"
|
||||
#include "crt.h"
|
||||
|
||||
/*
|
||||
* Syscalls for OpenRISC:
|
||||
* - syscall number is passed in r11
|
||||
* - arguments are in r3, r4, r5, r6, r7, r8
|
||||
* - the system call is performed by calling l.sys 1
|
||||
* - syscall return value is in r11
|
||||
*/
|
||||
|
||||
#define _NOLIBC_SYSCALL_CLOBBERLIST \
|
||||
"r12", "r13", "r15", "r17", "r19", "r21", "r23", "r25", "r27", "r29", "r31", "memory"
|
||||
|
||||
#define __nolibc_syscall0(num) \
|
||||
({ \
|
||||
register long _num __asm__ ("r11") = (num); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"l.sys 1\n" \
|
||||
: "+r"(_num) \
|
||||
: \
|
||||
: "r3", "r4", "r5", "r6", "r7", "r8", \
|
||||
_NOLIBC_SYSCALL_CLOBBERLIST \
|
||||
); \
|
||||
_num; \
|
||||
})
|
||||
|
||||
#define __nolibc_syscall1(num, arg1) \
|
||||
({ \
|
||||
register long _num __asm__ ("r11") = (num); \
|
||||
register long _arg1 __asm__ ("r3") = (long)(arg1); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"l.sys 1\n" \
|
||||
: "+r"(_num) \
|
||||
: "r"(_arg1) \
|
||||
: "r4", "r5", "r6", "r7", "r8", _NOLIBC_SYSCALL_CLOBBERLIST \
|
||||
); \
|
||||
_num; \
|
||||
})
|
||||
|
||||
#define __nolibc_syscall2(num, arg1, arg2) \
|
||||
({ \
|
||||
register long _num __asm__ ("r11") = (num); \
|
||||
register long _arg1 __asm__ ("r3") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("r4") = (long)(arg2); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"l.sys 1\n" \
|
||||
: "+r"(_num) \
|
||||
: "r"(_arg1), "r"(_arg2) \
|
||||
: "r5", "r6", "r7", "r8", _NOLIBC_SYSCALL_CLOBBERLIST \
|
||||
); \
|
||||
_num; \
|
||||
})
|
||||
|
||||
#define __nolibc_syscall3(num, arg1, arg2, arg3) \
|
||||
({ \
|
||||
register long _num __asm__ ("r11") = (num); \
|
||||
register long _arg1 __asm__ ("r3") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("r4") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("r5") = (long)(arg3); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"l.sys 1\n" \
|
||||
: "+r"(_num) \
|
||||
: "r"(_arg1), "r"(_arg2), "r"(_arg3) \
|
||||
: "r6", "r7", "r8", _NOLIBC_SYSCALL_CLOBBERLIST \
|
||||
); \
|
||||
_num; \
|
||||
})
|
||||
|
||||
#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \
|
||||
({ \
|
||||
register long _num __asm__ ("r11") = (num); \
|
||||
register long _arg1 __asm__ ("r3") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("r4") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("r5") = (long)(arg3); \
|
||||
register long _arg4 __asm__ ("r6") = (long)(arg4); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"l.sys 1\n" \
|
||||
: "+r"(_num) \
|
||||
: "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4) \
|
||||
: "r7", "r8", _NOLIBC_SYSCALL_CLOBBERLIST \
|
||||
); \
|
||||
_num; \
|
||||
})
|
||||
|
||||
#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \
|
||||
({ \
|
||||
register long _num __asm__ ("r11") = (num); \
|
||||
register long _arg1 __asm__ ("r3") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("r4") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("r5") = (long)(arg3); \
|
||||
register long _arg4 __asm__ ("r6") = (long)(arg4); \
|
||||
register long _arg5 __asm__ ("r7") = (long)(arg5); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"l.sys 1\n" \
|
||||
: "+r"(_num) \
|
||||
: "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5) \
|
||||
: "r8", _NOLIBC_SYSCALL_CLOBBERLIST \
|
||||
); \
|
||||
_num; \
|
||||
})
|
||||
|
||||
#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \
|
||||
({ \
|
||||
register long _num __asm__ ("r11") = (num); \
|
||||
register long _arg1 __asm__ ("r3") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("r4") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("r5") = (long)(arg3); \
|
||||
register long _arg4 __asm__ ("r6") = (long)(arg4); \
|
||||
register long _arg5 __asm__ ("r7") = (long)(arg5); \
|
||||
register long _arg6 __asm__ ("r8") = (long)(arg6); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"l.sys 1\n" \
|
||||
: "+r"(_num) \
|
||||
: "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \
|
||||
"r"(_arg6) \
|
||||
: _NOLIBC_SYSCALL_CLOBBERLIST \
|
||||
); \
|
||||
_num; \
|
||||
})
|
||||
|
||||
#ifndef NOLIBC_NO_RUNTIME
|
||||
/* startup code */
|
||||
void _start_wrapper(void);
|
||||
void __attribute__((weak,noreturn))
|
||||
__nolibc_entrypoint __nolibc_no_stack_protector
|
||||
_start_wrapper(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
".global _start\n" /* The C function will have a prologue, */
|
||||
".type _start, @function\n" /* corrupting "sp/r1" */
|
||||
".weak _start\n"
|
||||
"_start:\n"
|
||||
|
||||
"l.jal _start_c\n" /* transfer to c runtime */
|
||||
"l.or r3,r1,r1\n" /* save stack pointer to r3, as arg1 of _start_c */
|
||||
|
||||
".size _start, .-_start\n"
|
||||
);
|
||||
__nolibc_entrypoint_epilogue();
|
||||
}
|
||||
#endif /* NOLIBC_NO_RUNTIME */
|
||||
|
||||
#endif /* _NOLIBC_ARCH_OPENRISC_H */
|
||||
185
tools/include/nolibc/arch-parisc.h
Normal file
185
tools/include/nolibc/arch-parisc.h
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
|
||||
/*
|
||||
* parisc/hppa (32-bit) specific definitions for NOLIBC
|
||||
* Copyright (C) 2026 Thomas Weißschuh <linux@weissschuh.net>
|
||||
*/
|
||||
|
||||
#ifndef _NOLIBC_ARCH_PARISC_H
|
||||
#define _NOLIBC_ARCH_PARISC_H
|
||||
|
||||
#if defined(__LP64__)
|
||||
#error 64-bit not supported
|
||||
#endif
|
||||
|
||||
#include "compiler.h"
|
||||
#include "crt.h"
|
||||
|
||||
/* Syscalls for parisc :
|
||||
* - syscall number is passed in r20
|
||||
* - arguments are in r26 to r21
|
||||
* - the system call is performed by calling "ble 0x100(%sr2, %r0)",
|
||||
* the instruction after that is in the delay slot and executed before
|
||||
* the jump to 0x100 actually happens, use it to load the syscall number
|
||||
* - syscall return comes in r28
|
||||
* - the arguments are cast to long and assigned into the target
|
||||
* registers which are then simply passed as registers to the asm code,
|
||||
* so that we don't have to experience issues with register constraints.
|
||||
*/
|
||||
|
||||
#define _NOLIBC_SYSCALL_CLOBBERLIST \
|
||||
"memory", "%r1", "%r2", "%r4", "%r20", "%r29", "%r31"
|
||||
|
||||
#define __nolibc_syscall0(num) \
|
||||
({ \
|
||||
register long _ret __asm__ ("r28"); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"ble 0x100(%%sr2, %%r0)\n\t" \
|
||||
"copy %1, %%r20\n\t" \
|
||||
: "=r"(_ret) \
|
||||
: "r"(num) \
|
||||
: _NOLIBC_SYSCALL_CLOBBERLIST, \
|
||||
"%r21", "%r22", "%r23", "%r24", "%r25", "%r26" \
|
||||
); \
|
||||
_ret; \
|
||||
})
|
||||
|
||||
#define __nolibc_syscall1(num, arg1) \
|
||||
({ \
|
||||
register long _ret __asm__ ("r28"); \
|
||||
register long _arg1 __asm__ ("r26") = (long)(arg1); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"ble 0x100(%%sr2, %%r0)\n\t" \
|
||||
"copy %2, %%r20\n\t" \
|
||||
: "=r"(_ret), \
|
||||
"+r"(_arg1) \
|
||||
: "r"(num) \
|
||||
: _NOLIBC_SYSCALL_CLOBBERLIST, \
|
||||
"%r21", "%r22", "%r23", "%r24", "%r25" \
|
||||
); \
|
||||
_ret; \
|
||||
})
|
||||
|
||||
#define __nolibc_syscall2(num, arg1, arg2) \
|
||||
({ \
|
||||
register long _ret __asm__ ("r28"); \
|
||||
register long _arg1 __asm__ ("r26") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("r25") = (long)(arg2); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"ble 0x100(%%sr2, %%r0)\n\t" \
|
||||
"copy %3, %%r20\n\t" \
|
||||
: "=r"(_ret), \
|
||||
"+r"(_arg1), "+r"(_arg2) \
|
||||
: "r"(num) \
|
||||
: _NOLIBC_SYSCALL_CLOBBERLIST, \
|
||||
"%r21", "%r22", "%r23", "%r24" \
|
||||
); \
|
||||
_ret; \
|
||||
})
|
||||
|
||||
#define __nolibc_syscall3(num, arg1, arg2, arg3) \
|
||||
({ \
|
||||
register long _ret __asm__ ("r28"); \
|
||||
register long _arg1 __asm__ ("r26") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("r25") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("r24") = (long)(arg3); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"ble 0x100(%%sr2, %%r0)\n\t" \
|
||||
"copy %4, %%r20\n\t" \
|
||||
: "=r"(_ret), \
|
||||
"+r"(_arg1), "+r"(_arg2), "+r"(_arg3) \
|
||||
: "r"(num) \
|
||||
: _NOLIBC_SYSCALL_CLOBBERLIST, \
|
||||
"%r21", "%r22", "%r23" \
|
||||
); \
|
||||
_ret; \
|
||||
})
|
||||
|
||||
#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \
|
||||
({ \
|
||||
register long _ret __asm__ ("r28"); \
|
||||
register long _arg1 __asm__ ("r26") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("r25") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("r24") = (long)(arg3); \
|
||||
register long _arg4 __asm__ ("r23") = (long)(arg4); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"ble 0x100(%%sr2, %%r0)\n\t" \
|
||||
"copy %5, %%r20\n\t" \
|
||||
: "=r"(_ret), \
|
||||
"+r"(_arg1), "+r"(_arg2), "+r"(_arg3), "+r"(_arg4) \
|
||||
: "r"(num) \
|
||||
: _NOLIBC_SYSCALL_CLOBBERLIST, \
|
||||
"%r21", "%r22" \
|
||||
); \
|
||||
_ret; \
|
||||
})
|
||||
|
||||
#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \
|
||||
({ \
|
||||
register long _ret __asm__ ("r28"); \
|
||||
register long _arg1 __asm__ ("r26") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("r25") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("r24") = (long)(arg3); \
|
||||
register long _arg4 __asm__ ("r23") = (long)(arg4); \
|
||||
register long _arg5 __asm__ ("r22") = (long)(arg5); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"ble 0x100(%%sr2, %%r0)\n\t" \
|
||||
"copy %6, %%r20\n\t" \
|
||||
: "=r"(_ret), \
|
||||
"+r"(_arg1), "+r"(_arg2), "+r"(_arg3), "+r"(_arg4), \
|
||||
"+r"(_arg5) \
|
||||
: "r"(num) \
|
||||
: _NOLIBC_SYSCALL_CLOBBERLIST, \
|
||||
"%r21" \
|
||||
); \
|
||||
_ret; \
|
||||
})
|
||||
|
||||
#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \
|
||||
({ \
|
||||
register long _ret __asm__ ("r28"); \
|
||||
register long _arg1 __asm__ ("r26") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("r25") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("r24") = (long)(arg3); \
|
||||
register long _arg4 __asm__ ("r23") = (long)(arg4); \
|
||||
register long _arg5 __asm__ ("r22") = (long)(arg5); \
|
||||
register long _arg6 __asm__ ("r21") = (long)(arg6); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"ble 0x100(%%sr2, %%r0)\n\t" \
|
||||
"copy %7, %%r20\n\t" \
|
||||
: "=r"(_ret), \
|
||||
"+r"(_arg1), "+r"(_arg2), "+r"(_arg3), "+r"(_arg4), \
|
||||
"+r"(_arg5), "+r"(_arg6) \
|
||||
: "r"(num) \
|
||||
: _NOLIBC_SYSCALL_CLOBBERLIST \
|
||||
); \
|
||||
_ret; \
|
||||
})
|
||||
|
||||
#ifndef NOLIBC_NO_RUNTIME
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
".import $global$\n" /* Set up the dp register */
|
||||
"ldil L%$global$, %dp\n"
|
||||
"ldo R%$global$(%r27), %dp\n"
|
||||
|
||||
"b _start_c\n" /* Call _start_c, the load below is executed first */
|
||||
|
||||
"ldo -4(%r24), %r26\n" /* The sp register is special on parisc.
|
||||
* r24 points to argv. Subtract 4 to get &argc.
|
||||
* Pass that as first argument to _start_c.
|
||||
*/
|
||||
);
|
||||
__nolibc_entrypoint_epilogue();
|
||||
}
|
||||
#endif /* NOLIBC_NO_RUNTIME */
|
||||
|
||||
#endif /* _NOLIBC_ARCH_PARISC_H */
|
||||
|
|
@ -7,8 +7,11 @@
|
|||
#ifndef _NOLIBC_ARCH_POWERPC_H
|
||||
#define _NOLIBC_ARCH_POWERPC_H
|
||||
|
||||
#include <linux/unistd.h>
|
||||
|
||||
#include "compiler.h"
|
||||
#include "crt.h"
|
||||
#include "std.h"
|
||||
|
||||
/* Syscalls for PowerPC :
|
||||
* - stack is 16-byte aligned
|
||||
|
|
@ -177,15 +180,15 @@
|
|||
* "omit-frame-pointer" fails with __attribute__((no_stack_protector)) but
|
||||
* works with __attribute__((__optimize__("-fno-stack-protector")))
|
||||
*/
|
||||
#ifdef __no_stack_protector
|
||||
#undef __no_stack_protector
|
||||
#define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
|
||||
#ifdef __nolibc_no_stack_protector
|
||||
#undef __nolibc_no_stack_protector
|
||||
#define __nolibc_no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
|
||||
#endif
|
||||
#endif /* !__powerpc64__ */
|
||||
|
||||
#ifndef NOLIBC_NO_RUNTIME
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void)
|
||||
{
|
||||
#ifdef __powerpc64__
|
||||
#if _CALL_ELF == 2
|
||||
|
|
@ -218,4 +221,13 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
|
|||
}
|
||||
#endif /* NOLIBC_NO_RUNTIME */
|
||||
|
||||
#if !defined(__powerpc64__)
|
||||
static __attribute__((unused))
|
||||
int _sys_ftruncate64(int fd, uint32_t length0, uint32_t length1)
|
||||
{
|
||||
return __nolibc_syscall4(__NR_ftruncate64, fd, 0, length0, length1);
|
||||
}
|
||||
#define _sys_ftruncate64 _sys_ftruncate64
|
||||
#endif
|
||||
|
||||
#endif /* _NOLIBC_ARCH_POWERPC_H */
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@
|
|||
|
||||
#ifndef NOLIBC_NO_RUNTIME
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
".option push\n"
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@
|
|||
|
||||
#ifndef NOLIBC_NO_RUNTIME
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
"lgr %r2, %r15\n" /* save stack pointer to %r2, as arg1 of _start_c */
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@
|
|||
#ifndef NOLIBC_NO_RUNTIME
|
||||
/* startup code */
|
||||
void _start_wrapper(void);
|
||||
void __attribute__((weak,noreturn)) __nolibc_entrypoint __no_stack_protector _start_wrapper(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start_wrapper(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
".global _start\n" /* The C function will have a prologue, */
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@
|
|||
|
||||
#ifndef NOLIBC_NO_RUNTIME
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@
|
|||
* 2) The deepest stack frame should be set to zero
|
||||
*
|
||||
*/
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
"xor %ebp, %ebp\n" /* zero the stack frame */
|
||||
|
|
@ -202,8 +202,8 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
|
|||
|
||||
#define __nolibc_syscall0(num) \
|
||||
({ \
|
||||
long _ret; \
|
||||
register long _num __asm__ ("rax") = (num); \
|
||||
long long _ret; \
|
||||
register long long _num __asm__ ("rax") = (num); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"syscall\n" \
|
||||
|
|
@ -216,9 +216,9 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
|
|||
|
||||
#define __nolibc_syscall1(num, arg1) \
|
||||
({ \
|
||||
long _ret; \
|
||||
register long _num __asm__ ("rax") = (num); \
|
||||
register long _arg1 __asm__ ("rdi") = (long)(arg1); \
|
||||
long long _ret; \
|
||||
register long long _num __asm__ ("rax") = (num); \
|
||||
register long long _arg1 __asm__ ("rdi") = __nolibc_arg_to_reg(arg1); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"syscall\n" \
|
||||
|
|
@ -232,10 +232,10 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
|
|||
|
||||
#define __nolibc_syscall2(num, arg1, arg2) \
|
||||
({ \
|
||||
long _ret; \
|
||||
register long _num __asm__ ("rax") = (num); \
|
||||
register long _arg1 __asm__ ("rdi") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("rsi") = (long)(arg2); \
|
||||
long long _ret; \
|
||||
register long long _num __asm__ ("rax") = (num); \
|
||||
register long long _arg1 __asm__ ("rdi") = __nolibc_arg_to_reg(arg1); \
|
||||
register long long _arg2 __asm__ ("rsi") = __nolibc_arg_to_reg(arg2); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"syscall\n" \
|
||||
|
|
@ -249,11 +249,11 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
|
|||
|
||||
#define __nolibc_syscall3(num, arg1, arg2, arg3) \
|
||||
({ \
|
||||
long _ret; \
|
||||
register long _num __asm__ ("rax") = (num); \
|
||||
register long _arg1 __asm__ ("rdi") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("rsi") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("rdx") = (long)(arg3); \
|
||||
long long _ret; \
|
||||
register long long _num __asm__ ("rax") = (num); \
|
||||
register long long _arg1 __asm__ ("rdi") = __nolibc_arg_to_reg(arg1); \
|
||||
register long long _arg2 __asm__ ("rsi") = __nolibc_arg_to_reg(arg2); \
|
||||
register long long _arg3 __asm__ ("rdx") = __nolibc_arg_to_reg(arg3); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"syscall\n" \
|
||||
|
|
@ -267,12 +267,12 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
|
|||
|
||||
#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \
|
||||
({ \
|
||||
long _ret; \
|
||||
register long _num __asm__ ("rax") = (num); \
|
||||
register long _arg1 __asm__ ("rdi") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("rsi") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("rdx") = (long)(arg3); \
|
||||
register long _arg4 __asm__ ("r10") = (long)(arg4); \
|
||||
long long _ret; \
|
||||
register long long _num __asm__ ("rax") = (num); \
|
||||
register long long _arg1 __asm__ ("rdi") = __nolibc_arg_to_reg(arg1); \
|
||||
register long long _arg2 __asm__ ("rsi") = __nolibc_arg_to_reg(arg2); \
|
||||
register long long _arg3 __asm__ ("rdx") = __nolibc_arg_to_reg(arg3); \
|
||||
register long long _arg4 __asm__ ("r10") = __nolibc_arg_to_reg(arg4); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"syscall\n" \
|
||||
|
|
@ -286,13 +286,13 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
|
|||
|
||||
#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \
|
||||
({ \
|
||||
long _ret; \
|
||||
register long _num __asm__ ("rax") = (num); \
|
||||
register long _arg1 __asm__ ("rdi") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("rsi") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("rdx") = (long)(arg3); \
|
||||
register long _arg4 __asm__ ("r10") = (long)(arg4); \
|
||||
register long _arg5 __asm__ ("r8") = (long)(arg5); \
|
||||
long long _ret; \
|
||||
register long long _num __asm__ ("rax") = (num); \
|
||||
register long long _arg1 __asm__ ("rdi") = __nolibc_arg_to_reg(arg1); \
|
||||
register long long _arg2 __asm__ ("rsi") = __nolibc_arg_to_reg(arg2); \
|
||||
register long long _arg3 __asm__ ("rdx") = __nolibc_arg_to_reg(arg3); \
|
||||
register long long _arg4 __asm__ ("r10") = __nolibc_arg_to_reg(arg4); \
|
||||
register long long _arg5 __asm__ ("r8") = __nolibc_arg_to_reg(arg5); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"syscall\n" \
|
||||
|
|
@ -306,14 +306,14 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
|
|||
|
||||
#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \
|
||||
({ \
|
||||
long _ret; \
|
||||
register long _num __asm__ ("rax") = (num); \
|
||||
register long _arg1 __asm__ ("rdi") = (long)(arg1); \
|
||||
register long _arg2 __asm__ ("rsi") = (long)(arg2); \
|
||||
register long _arg3 __asm__ ("rdx") = (long)(arg3); \
|
||||
register long _arg4 __asm__ ("r10") = (long)(arg4); \
|
||||
register long _arg5 __asm__ ("r8") = (long)(arg5); \
|
||||
register long _arg6 __asm__ ("r9") = (long)(arg6); \
|
||||
long long _ret; \
|
||||
register long long _num __asm__ ("rax") = (num); \
|
||||
register long long _arg1 __asm__ ("rdi") = __nolibc_arg_to_reg(arg1); \
|
||||
register long long _arg2 __asm__ ("rsi") = __nolibc_arg_to_reg(arg2); \
|
||||
register long long _arg3 __asm__ ("rdx") = __nolibc_arg_to_reg(arg3); \
|
||||
register long long _arg4 __asm__ ("r10") = __nolibc_arg_to_reg(arg4); \
|
||||
register long long _arg5 __asm__ ("r8") = __nolibc_arg_to_reg(arg5); \
|
||||
register long long _arg6 __asm__ ("r9") = __nolibc_arg_to_reg(arg6); \
|
||||
\
|
||||
__asm__ volatile ( \
|
||||
"syscall\n" \
|
||||
|
|
@ -333,7 +333,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
|
|||
* 2) The deepest stack frame should be zero (the %rbp).
|
||||
*
|
||||
*/
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
"xor %ebp, %ebp\n" /* zero the stack frame */
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@
|
|||
#include "arch-m68k.h"
|
||||
#elif defined(__sh__)
|
||||
#include "arch-sh.h"
|
||||
#elif defined(__or1k__)
|
||||
#include "arch-openrisc.h"
|
||||
#elif defined(__hppa__)
|
||||
#include "arch-parisc.h"
|
||||
#else
|
||||
#error Unsupported Architecture
|
||||
#endif
|
||||
|
|
|
|||
36
tools/include/nolibc/assert.h
Normal file
36
tools/include/nolibc/assert.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
|
||||
/*
|
||||
* Assert for NOLIBC
|
||||
* Copyright (C) 2026 Thomas Weißschuh <linux@weissschuh.net>
|
||||
*/
|
||||
|
||||
/* make sure to include all global symbols */
|
||||
#include "nolibc.h"
|
||||
|
||||
#ifndef _NOLIBC_ASSERT_H
|
||||
#define _NOLIBC_ASSERT_H
|
||||
|
||||
#include "errno.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#endif /* _NOLIBC_ASSERT_H */
|
||||
|
||||
/* NDEBUG needs to be evaluated on *each* inclusion */
|
||||
#ifdef assert
|
||||
#undef assert
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define assert(expr) \
|
||||
({ \
|
||||
if (!(expr)) { \
|
||||
fprintf(stderr, "%s: %s:%d: %s: Assertion `%s' failed.\n", \
|
||||
program_invocation_short_name, __FILE__, __LINE__, __func__, \
|
||||
#expr); \
|
||||
abort(); \
|
||||
} \
|
||||
})
|
||||
#else
|
||||
#define assert(expr) ((void)0)
|
||||
#endif
|
||||
|
|
@ -36,9 +36,9 @@
|
|||
#endif /* defined(__SSP__) ... */
|
||||
|
||||
#if __nolibc_has_attribute(no_stack_protector)
|
||||
# define __no_stack_protector __attribute__((no_stack_protector))
|
||||
# define __nolibc_no_stack_protector __attribute__((no_stack_protector))
|
||||
#else
|
||||
# define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
|
||||
# define __nolibc_no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
|
||||
#endif /* __nolibc_has_attribute(no_stack_protector) */
|
||||
|
||||
#if __nolibc_has_attribute(__fallthrough__)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
#ifndef _NOLIBC_CRT_H
|
||||
#define _NOLIBC_CRT_H
|
||||
|
||||
#define __nolibc_arg_to_reg(_a) \
|
||||
__builtin_choose_expr(__builtin_classify_type(_a) == __builtin_classify_type(NULL), \
|
||||
(unsigned long)(_a), (_a))
|
||||
|
||||
#ifndef NOLIBC_NO_RUNTIME
|
||||
|
||||
#include "compiler.h"
|
||||
|
|
@ -47,7 +51,7 @@ char *__nolibc_program_invocation_short_name(char *long_name)
|
|||
#endif /* NOLIBC_IGNORE_ERRNO */
|
||||
|
||||
void _start_c(long *sp);
|
||||
__attribute__((weak,used)) __nolibc_no_sanitize_undefined
|
||||
__attribute__((weak,used)) __nolibc_no_sanitize_undefined __nolibc_no_stack_protector
|
||||
void _start_c(long *sp)
|
||||
{
|
||||
long argc;
|
||||
|
|
@ -89,7 +93,7 @@ void _start_c(long *sp)
|
|||
|
||||
/* find _auxv */
|
||||
for (auxv = (void *)envp; *auxv++;)
|
||||
;
|
||||
__asm__("");
|
||||
_auxv = auxv;
|
||||
|
||||
#ifndef NOLIBC_IGNORE_ERRNO
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@
|
|||
#ifndef NOLIBC_IGNORE_ERRNO
|
||||
#define SET_ERRNO(v) do { errno = (v); } while (0)
|
||||
int errno __attribute__((weak));
|
||||
char *program_invocation_name __attribute__((weak)) = "";
|
||||
char *program_invocation_short_name __attribute__((weak)) = "";
|
||||
char *program_invocation_name __attribute__((weak)) = (char *)"";
|
||||
char *program_invocation_short_name __attribute__((weak)) = (char *)"";
|
||||
#else
|
||||
#define SET_ERRNO(v) do { } while (0)
|
||||
#define program_invocation_name ""
|
||||
|
|
|
|||
|
|
@ -14,6 +14,20 @@
|
|||
#include "types.h"
|
||||
#include "sys.h"
|
||||
|
||||
#define __nolibc_open_flags(_flags) ((_flags) | O_LARGEFILE)
|
||||
|
||||
#define __nolibc_open_mode(_flags) \
|
||||
({ \
|
||||
mode_t _mode; \
|
||||
va_list args; \
|
||||
\
|
||||
va_start(args, (_flags)); \
|
||||
_mode = va_arg(args, mode_t); \
|
||||
va_end(args); \
|
||||
\
|
||||
_mode; \
|
||||
})
|
||||
|
||||
/*
|
||||
* int openat(int dirfd, const char *path, int flags[, mode_t mode]);
|
||||
*/
|
||||
|
|
@ -27,17 +41,8 @@ int _sys_openat(int dirfd, const char *path, int flags, mode_t mode)
|
|||
static __attribute__((unused))
|
||||
int openat(int dirfd, const char *path, int flags, ...)
|
||||
{
|
||||
mode_t mode = 0;
|
||||
|
||||
if (flags & O_CREAT) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, flags);
|
||||
mode = va_arg(args, mode_t);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
return __sysret(_sys_openat(dirfd, path, flags, mode));
|
||||
return __sysret(_sys_openat(dirfd, path, __nolibc_open_flags(flags),
|
||||
__nolibc_open_mode(flags)));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -53,17 +58,17 @@ int _sys_open(const char *path, int flags, mode_t mode)
|
|||
static __attribute__((unused))
|
||||
int open(const char *path, int flags, ...)
|
||||
{
|
||||
mode_t mode = 0;
|
||||
return __sysret(_sys_open(path, __nolibc_open_flags(flags), __nolibc_open_mode(flags)));
|
||||
}
|
||||
|
||||
if (flags & O_CREAT) {
|
||||
va_list args;
|
||||
/*
|
||||
* int creat(const char *path, mode_t mode);
|
||||
*/
|
||||
|
||||
va_start(args, flags);
|
||||
mode = va_arg(args, mode_t);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
return __sysret(_sys_open(path, flags, mode));
|
||||
static __attribute__((unused))
|
||||
int creat(const char *path, mode_t mode)
|
||||
{
|
||||
return open(path, O_CREAT | O_WRONLY | O_TRUNC, mode);
|
||||
}
|
||||
|
||||
#endif /* _NOLIBC_FCNTL_H */
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ int getopt(int argc, char * const argv[], const char *optstring)
|
|||
d = optstring[i++];
|
||||
} while (d && d != c);
|
||||
|
||||
if (d != c || c == ':') {
|
||||
if (!d || d != c || c == ':') {
|
||||
optopt = c;
|
||||
if (optstring[0] != ':' && opterr)
|
||||
fprintf(stderr, "%s: unrecognized option: %c\n", argv[0], *optchar);
|
||||
|
|
|
|||
|
|
@ -133,6 +133,8 @@
|
|||
#include "err.h"
|
||||
#include "byteswap.h"
|
||||
#include "endian.h"
|
||||
#include "assert.h"
|
||||
#include "alloca.h"
|
||||
|
||||
/* Used by programs to avoid std includes */
|
||||
#define NOLIBC
|
||||
|
|
|
|||
|
|
@ -40,9 +40,10 @@ void __stack_chk_fail_local(void)
|
|||
__attribute__((weak,used,section(".data.nolibc_stack_chk")))
|
||||
uintptr_t __stack_chk_guard;
|
||||
|
||||
static __no_stack_protector void __stack_chk_init(void)
|
||||
static __nolibc_no_stack_protector void __stack_chk_init(void)
|
||||
{
|
||||
__nolibc_syscall3(__NR_getrandom, &__stack_chk_guard, sizeof(__stack_chk_guard), 0);
|
||||
__nolibc_syscall3(__NR_getrandom, &__stack_chk_guard, sizeof(__stack_chk_guard),
|
||||
GRND_INSECURE | GRND_NONBLOCK);
|
||||
/* a bit more randomness in case getrandom() fails, ensure the guard is never 0 */
|
||||
if (__stack_chk_guard != (uintptr_t) &__stack_chk_guard)
|
||||
__stack_chk_guard ^= (uintptr_t) &__stack_chk_guard;
|
||||
|
|
|
|||
|
|
@ -45,16 +45,41 @@
|
|||
: __sysret_arg; /* return original value */ \
|
||||
})
|
||||
|
||||
/* Syscall ENOSYS helper: Avoids unused-parameter warnings and provides a
|
||||
* debugging hook.
|
||||
/* Syscall ENOSYS helper: Avoids unused-parameter warnings, provides compile
|
||||
* time validation and a debugging hook.
|
||||
*/
|
||||
|
||||
#if defined(NOLIBC_COMPILE_TIME_ENOSYS)
|
||||
static __inline__ int __nolibc_enosys(const char *syscall, ...)
|
||||
{
|
||||
(void)syscall;
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
#elif __nolibc_has_attribute(error)
|
||||
__attribute__((error("system call not implemented")))
|
||||
extern int __nolibc_enosys(const char *syscall, ...);
|
||||
|
||||
#else
|
||||
static __inline__ int __nolibc_enosys(const char *syscall, ...)
|
||||
{
|
||||
extern int __nolibc_enosys_error;
|
||||
(void)syscall;
|
||||
|
||||
return __nolibc_enosys_error;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Helper for 32-bit machines where a 64-bit syscall arg needs to be split into
|
||||
* two 32-bit parts while making sure the order of the low/high parts are correct
|
||||
* for the endianness:
|
||||
* __NOLIBC_LLARGPART(x, 0), __NOLIBC_LLARGPART(x, 1)
|
||||
*/
|
||||
#define __NOLIBC_LLARGPART(_arg, _part) \
|
||||
(((union { long long ll; long l[2]; }) { .ll = _arg }).l[_part])
|
||||
|
||||
|
||||
/* Functions in this file only describe syscalls. They're declared static so
|
||||
* that the compiler usually decides to inline them while still being allowed
|
||||
|
|
@ -87,7 +112,7 @@ static __inline__ int __nolibc_enosys(const char *syscall, ...)
|
|||
static __attribute__((unused))
|
||||
void *_sys_brk(void *addr)
|
||||
{
|
||||
return (void *)__nolibc_syscall1(__NR_brk, addr);
|
||||
return (void *)(unsigned long)__nolibc_syscall1(__NR_brk, addr);
|
||||
}
|
||||
|
||||
static __attribute__((unused))
|
||||
|
|
@ -597,12 +622,18 @@ int link(const char *old, const char *new)
|
|||
static __attribute__((unused))
|
||||
off_t _sys_lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
#if defined(__NR_llseek)
|
||||
#if defined(__NR_llseek) || defined(__NR__llseek)
|
||||
__kernel_loff_t loff = 0;
|
||||
int ret, nr_llseek;
|
||||
off_t result;
|
||||
int ret;
|
||||
|
||||
ret = __nolibc_syscall5(__NR_llseek, fd, offset >> 32, (uint32_t)offset, &loff, whence);
|
||||
#if defined(__NR_llseek)
|
||||
nr_llseek = __NR_llseek;
|
||||
#else
|
||||
nr_llseek = __NR__llseek;
|
||||
#endif
|
||||
|
||||
ret = __nolibc_syscall5(nr_llseek, fd, offset >> 32, (uint32_t)offset, &loff, whence);
|
||||
if (ret < 0)
|
||||
result = ret;
|
||||
else
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ void *_sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
|
|||
n = __NR_mmap;
|
||||
#endif
|
||||
|
||||
return (void *)__nolibc_syscall6(n, addr, length, prot, flags, fd, offset);
|
||||
return (void *)(unsigned long)__nolibc_syscall6(n, addr, length, prot, flags, fd, offset);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -46,8 +46,8 @@ void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
|
|||
static __attribute__((unused))
|
||||
void *_sys_mremap(void *old_address, size_t old_size, size_t new_size, int flags, void *new_address)
|
||||
{
|
||||
return (void *)__nolibc_syscall5(__NR_mremap, old_address, old_size,
|
||||
new_size, flags, new_address);
|
||||
return (void *)(unsigned long)__nolibc_syscall5(__NR_mremap, old_address, old_size,
|
||||
new_size, flags, new_address);
|
||||
}
|
||||
|
||||
static __attribute__((unused))
|
||||
|
|
|
|||
|
|
@ -48,6 +48,30 @@ int access(const char *path, int amode)
|
|||
return faccessat(AT_FDCWD, path, amode, 0);
|
||||
}
|
||||
|
||||
#if !defined(_sys_ftruncate64) && defined(__NR_ftruncate64)
|
||||
static __attribute__((unused))
|
||||
int _sys_ftruncate64(int fd, uint32_t length0, uint32_t length1)
|
||||
{
|
||||
return __nolibc_syscall3(__NR_ftruncate64, fd, length0, length1);
|
||||
}
|
||||
#define _sys_ftruncate64 _sys_ftruncate64
|
||||
#endif
|
||||
|
||||
static __attribute__((unused))
|
||||
int _sys_ftruncate(int fd, off_t length)
|
||||
{
|
||||
#if defined(_sys_ftruncate64)
|
||||
return _sys_ftruncate64(fd, __NOLIBC_LLARGPART(length, 0), __NOLIBC_LLARGPART(length, 1));
|
||||
#else
|
||||
return __nolibc_syscall2(__NR_ftruncate, fd, length);
|
||||
#endif
|
||||
}
|
||||
|
||||
static __attribute__((unused))
|
||||
int ftruncate(int fd, off_t length)
|
||||
{
|
||||
return __sysret(_sys_ftruncate(fd, length));
|
||||
}
|
||||
|
||||
static __attribute__((unused))
|
||||
int msleep(unsigned int msecs)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ _CFLAGS_STACKPROTECTOR ?= $(call try-run, \
|
|||
$(__CFLAGS_STACKPROTECTOR))
|
||||
_CFLAGS_SANITIZER ?= $(call cc-option,-fsanitize=undefined -fsanitize-trap=all)
|
||||
CFLAGS_NOLIBC_TEST ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 \
|
||||
-W -Wall -Wextra -Wundef \
|
||||
-W -Wall -Wextra -Wundef -Wwrite-strings \
|
||||
$(call cc-option,-fno-stack-protector) $(call cc-option,-Wmissing-prototypes) \
|
||||
$(_CFLAGS_STACKPROTECTOR) $(_CFLAGS_SANITIZER)
|
||||
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ ARCH_s390x = s390
|
|||
ARCH_sparc32 = sparc
|
||||
ARCH_sparc64 = sparc
|
||||
ARCH_sh4 = sh
|
||||
ARCH_parisc32 = parisc
|
||||
ARCH := $(or $(ARCH_$(XARCH)),$(XARCH))
|
||||
|
||||
# kernel image names by architecture
|
||||
|
|
@ -74,33 +75,18 @@ IMAGE_x86 = arch/x86/boot/bzImage
|
|||
IMAGE_arm64 = arch/arm64/boot/Image
|
||||
IMAGE_arm = arch/arm/boot/zImage
|
||||
IMAGE_armthumb = arch/arm/boot/zImage
|
||||
IMAGE_mips32le = vmlinuz
|
||||
IMAGE_mips32be = vmlinuz
|
||||
IMAGE_mipsn32le = vmlinuz
|
||||
IMAGE_mipsn32be = vmlinuz
|
||||
IMAGE_mips64le = vmlinuz
|
||||
IMAGE_mips64be = vmlinuz
|
||||
IMAGE_ppc = vmlinux
|
||||
IMAGE_ppc64 = vmlinux
|
||||
IMAGE_ppc64le = arch/powerpc/boot/zImage
|
||||
IMAGE_riscv = arch/riscv/boot/Image
|
||||
IMAGE_riscv32 = arch/riscv/boot/Image
|
||||
IMAGE_riscv64 = arch/riscv/boot/Image
|
||||
IMAGE_s390x = arch/s390/boot/bzImage
|
||||
IMAGE_loongarch = arch/loongarch/boot/vmlinuz.efi
|
||||
IMAGE_sparc32 = arch/sparc/boot/image
|
||||
IMAGE_sparc64 = arch/sparc/boot/image
|
||||
IMAGE_m68k = vmlinux
|
||||
IMAGE_sh4 = arch/sh/boot/zImage
|
||||
IMAGE = $(objtree)/$(IMAGE_$(XARCH))
|
||||
IMAGE = $(objtree)/$(or $(IMAGE_$(XARCH)),vmlinux)
|
||||
IMAGE_NAME = $(notdir $(IMAGE))
|
||||
|
||||
# default kernel configurations that appear to be usable
|
||||
DEFCONFIG_i386 = defconfig
|
||||
DEFCONFIG_x86_64 = defconfig
|
||||
DEFCONFIG_x32 = defconfig
|
||||
DEFCONFIG_x86 = defconfig
|
||||
DEFCONFIG_arm64 = defconfig
|
||||
DEFCONFIG_arm = multi_v7_defconfig
|
||||
DEFCONFIG_armthumb = multi_v7_defconfig
|
||||
DEFCONFIG_mips32le = malta_defconfig
|
||||
|
|
@ -112,20 +98,18 @@ DEFCONFIG_mips64be = malta_defconfig generic/64r2.config generic/eb.config
|
|||
DEFCONFIG_ppc = pmac32_defconfig
|
||||
DEFCONFIG_ppc64 = powernv_be_defconfig
|
||||
DEFCONFIG_ppc64le = powernv_defconfig
|
||||
DEFCONFIG_riscv = defconfig
|
||||
DEFCONFIG_riscv32 = rv32_defconfig
|
||||
DEFCONFIG_riscv64 = defconfig
|
||||
DEFCONFIG_s390x = defconfig
|
||||
DEFCONFIG_loongarch = defconfig
|
||||
DEFCONFIG_sparc32 = sparc32_defconfig
|
||||
DEFCONFIG_sparc64 = sparc64_defconfig
|
||||
DEFCONFIG_m68k = virt_defconfig
|
||||
DEFCONFIG_sh4 = rts7751r2dplus_defconfig
|
||||
DEFCONFIG = $(DEFCONFIG_$(XARCH))
|
||||
DEFCONFIG_openrisc = virt_defconfig
|
||||
DEFCONFIG = $(or $(DEFCONFIG_$(XARCH)),defconfig)
|
||||
|
||||
EXTRACONFIG_x32 = -e CONFIG_X86_X32_ABI
|
||||
EXTRACONFIG_arm = -e CONFIG_NAMESPACES
|
||||
EXTRACONFIG_armthumb = -e CONFIG_NAMESPACES
|
||||
EXTRACONFIG_sparc32 = -e CONFIG_TMPFS
|
||||
EXTRACONFIG_m68k = -e CONFIG_BLK_DEV_INITRD
|
||||
EXTRACONFIG_sh4 = -e CONFIG_BLK_DEV_INITRD -e CONFIG_CMDLINE_FROM_BOOTLOADER
|
||||
EXTRACONFIG = $(EXTRACONFIG_$(XARCH))
|
||||
|
|
@ -134,37 +118,27 @@ EXTRACONFIG = $(EXTRACONFIG_$(XARCH))
|
|||
TEST =
|
||||
|
||||
# QEMU_ARCH: arch names used by qemu
|
||||
QEMU_ARCH_i386 = i386
|
||||
QEMU_ARCH_x86_64 = x86_64
|
||||
QEMU_ARCH_x32 = x86_64
|
||||
QEMU_ARCH_x86 = x86_64
|
||||
QEMU_ARCH_arm64 = aarch64
|
||||
QEMU_ARCH_arm = arm
|
||||
QEMU_ARCH_armthumb = arm
|
||||
QEMU_ARCH_mips32le = mipsel # works with malta_defconfig
|
||||
QEMU_ARCH_mips32be = mips
|
||||
QEMU_ARCH_mips32be = mips
|
||||
QEMU_ARCH_mipsn32le = mips64el
|
||||
QEMU_ARCH_mipsn32be = mips64
|
||||
QEMU_ARCH_mips64le = mips64el
|
||||
QEMU_ARCH_mips64be = mips64
|
||||
QEMU_ARCH_ppc = ppc
|
||||
QEMU_ARCH_ppc64 = ppc64
|
||||
QEMU_ARCH_ppc64le = ppc64
|
||||
QEMU_ARCH_riscv = riscv64
|
||||
QEMU_ARCH_riscv32 = riscv32
|
||||
QEMU_ARCH_riscv64 = riscv64
|
||||
QEMU_ARCH_s390x = s390x
|
||||
QEMU_ARCH_loongarch = loongarch64
|
||||
QEMU_ARCH_sparc32 = sparc
|
||||
QEMU_ARCH_sparc64 = sparc64
|
||||
QEMU_ARCH_m68k = m68k
|
||||
QEMU_ARCH_sh4 = sh4
|
||||
QEMU_ARCH = $(QEMU_ARCH_$(XARCH))
|
||||
QEMU_ARCH_openrisc = or1k
|
||||
QEMU_ARCH_parisc32 = hppa
|
||||
QEMU_ARCH = $(or $(QEMU_ARCH_$(XARCH)),$(XARCH))
|
||||
|
||||
QEMU_ARCH_USER_ppc64le = ppc64le
|
||||
QEMU_ARCH_USER_mipsn32le = mipsn32el
|
||||
QEMU_ARCH_USER_mipsn32be = mipsn32
|
||||
QEMU_ARCH_USER = $(or $(QEMU_ARCH_USER_$(XARCH)),$(QEMU_ARCH_$(XARCH)))
|
||||
QEMU_ARCH_USER = $(or $(QEMU_ARCH_USER_$(XARCH)),$(QEMU_ARCH))
|
||||
|
||||
QEMU_BIOS_DIR = /usr/share/edk2/
|
||||
QEMU_BIOS_loongarch = $(QEMU_BIOS_DIR)/loongarch64/OVMF_CODE.fd
|
||||
|
|
@ -190,7 +164,6 @@ QEMU_ARGS_mips64be = -M malta -cpu 5KEc -append "panic=-1 $(TEST:%=NOLIBC_TEST
|
|||
QEMU_ARGS_ppc = -M g3beige -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
|
||||
QEMU_ARGS_ppc64 = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
|
||||
QEMU_ARGS_ppc64le = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
|
||||
QEMU_ARGS_riscv = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
|
||||
QEMU_ARGS_riscv32 = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
|
||||
QEMU_ARGS_riscv64 = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
|
||||
QEMU_ARGS_s390x = -M s390-ccw-virtio -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
|
||||
|
|
@ -199,6 +172,8 @@ QEMU_ARGS_sparc32 = -M SS-5 -m 256M -append "console=ttyS0,115200 panic=-1 $(
|
|||
QEMU_ARGS_sparc64 = -M sun4u -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
|
||||
QEMU_ARGS_m68k = -M virt -append "console=ttyGF0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
|
||||
QEMU_ARGS_sh4 = -M r2d -serial file:/dev/stdout -append "console=ttySC1,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
|
||||
QEMU_ARGS_openrisc = -M virt -m 512M -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
|
||||
QEMU_ARGS_parisc32 = -M B160L -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
|
||||
QEMU_ARGS = -m 1G $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_BIOS) $(QEMU_ARGS_EXTRA)
|
||||
|
||||
# OUTPUT is only set when run from the main makefile, otherwise
|
||||
|
|
@ -215,6 +190,7 @@ CFLAGS_i386 = $(call cc-option,-m32)
|
|||
CFLAGS_x32 = -mx32
|
||||
CFLAGS_arm = -marm
|
||||
CFLAGS_armthumb = -mthumb -march=armv6t2
|
||||
CFLAGS_parisc32 = -mfast-indirect-calls
|
||||
CFLAGS_ppc = -m32 -mbig-endian -mno-vsx $(call cc-option,-mmultiple)
|
||||
CFLAGS_ppc64 = -m64 -mbig-endian -mno-vsx $(call cc-option,-mmultiple)
|
||||
CFLAGS_ppc64le = -m64 -mlittle-endian -mno-vsx $(call cc-option,-mabi=elfv2)
|
||||
|
|
@ -233,6 +209,7 @@ CFLAGS_XARCH = $(CFLAGS_$(XARCH))
|
|||
endif
|
||||
|
||||
LDLIBS_ppc = $(if $(LLVM),,-lgcc)
|
||||
LDLIBS_openrisc = $(if $(LLVM),,-lgcc)
|
||||
LDLIBS = $(LDLIBS_$(XARCH))
|
||||
|
||||
include Makefile.include
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#define _GNU_SOURCE
|
||||
#define _LARGEFILE64_SOURCE
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
|
||||
/* libc-specific include files
|
||||
* The program may be built in 3 ways:
|
||||
|
|
@ -45,6 +46,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <byteswap.h>
|
||||
#include <endian.h>
|
||||
#include <alloca.h>
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
|
||||
|
||||
|
|
@ -647,20 +649,25 @@ int expect_str_buf_eq(size_t expr, const char *buf, size_t val, int llen, const
|
|||
return 0;
|
||||
}
|
||||
|
||||
enum strtox_func {
|
||||
strtox_func_strtol,
|
||||
strtox_func_strtoul,
|
||||
};
|
||||
|
||||
#define EXPECT_STRTOX(cond, func, input, base, expected, chars, expected_errno) \
|
||||
do { if (!(cond)) result(llen, SKIPPED); else ret += expect_strtox(llen, func, input, base, expected, chars, expected_errno); } while (0)
|
||||
do { if (!(cond)) result(llen, SKIPPED); else ret += expect_strtox(llen, strtox_func_ ## func, input, base, expected, chars, expected_errno); } while (0)
|
||||
|
||||
static __attribute__((unused))
|
||||
int expect_strtox(int llen, void *func, const char *input, int base, intmax_t expected, int expected_chars, int expected_errno)
|
||||
int expect_strtox(int llen, enum strtox_func func, const char *input, int base, intmax_t expected, int expected_chars, int expected_errno)
|
||||
{
|
||||
char *endptr;
|
||||
int actual_errno, actual_chars;
|
||||
intmax_t r;
|
||||
|
||||
errno = 0;
|
||||
if (func == strtol) {
|
||||
if (func == strtox_func_strtol) {
|
||||
r = strtol(input, &endptr, base);
|
||||
} else if (func == strtoul) {
|
||||
} else if (func == strtox_func_strtoul) {
|
||||
r = strtoul(input, &endptr, base);
|
||||
} else {
|
||||
result(llen, FAIL);
|
||||
|
|
@ -797,7 +804,7 @@ int test_getdents64(const char *dir)
|
|||
int fd, ret;
|
||||
int err;
|
||||
|
||||
ret = fd = open(dir, O_RDONLY | O_DIRECTORY, 0);
|
||||
ret = fd = open(dir, O_RDONLY | O_DIRECTORY);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
|
|
@ -1010,6 +1017,57 @@ int test_fork(enum fork_type type)
|
|||
}
|
||||
}
|
||||
|
||||
int test_ftruncate(void)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
int ret, fd;
|
||||
|
||||
ret = ftruncate(-1, 0);
|
||||
if (ret != -1 || errno != EBADF) {
|
||||
errno = EINVAL;
|
||||
return __LINE__;
|
||||
}
|
||||
|
||||
fd = memfd_create(__func__, 0);
|
||||
if (fd == -1)
|
||||
return __LINE__;
|
||||
|
||||
/*
|
||||
* This also tests that the high 32-bit half is passed through correctly.
|
||||
* If it gets lost, the kernel will see a positive number and not fail.
|
||||
*/
|
||||
ret = ftruncate(fd, -1);
|
||||
if (!(ret == -1 && errno == EINVAL)) {
|
||||
if (ret == 0)
|
||||
errno = EINVAL;
|
||||
ret = __LINE__;
|
||||
goto end;
|
||||
}
|
||||
|
||||
ret = ftruncate(fd, 42);
|
||||
if (ret != 0) {
|
||||
ret = __LINE__;
|
||||
goto end;
|
||||
}
|
||||
|
||||
ret = fstat(fd, &stat_buf);
|
||||
if (ret != 0) {
|
||||
ret = __LINE__;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (stat_buf.st_size != 42) {
|
||||
errno = EINVAL;
|
||||
ret = __LINE__;
|
||||
goto end;
|
||||
}
|
||||
|
||||
end:
|
||||
close(fd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int test_stat_timestamps(void)
|
||||
{
|
||||
struct stat st;
|
||||
|
|
@ -1298,6 +1356,45 @@ int test_openat(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int test_open_mode(void)
|
||||
{
|
||||
const mode_t mode = 0444;
|
||||
struct stat stat_buf;
|
||||
int fd, ret;
|
||||
|
||||
fd = open("/tmp", O_TMPFILE | O_RDWR, mode);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
|
||||
ret = fstat(fd, &stat_buf);
|
||||
close(fd);
|
||||
|
||||
if (ret == -1)
|
||||
return -1;
|
||||
|
||||
if ((stat_buf.st_mode & 0777) != mode)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_nolibc_enosys(void)
|
||||
{
|
||||
if (true)
|
||||
return 0;
|
||||
|
||||
#if defined(NOLIBC)
|
||||
/*
|
||||
* __nolibc_enosys() will fail the compilation.
|
||||
* Make sure it can be optimized away if not actually called.
|
||||
*/
|
||||
if (__nolibc_enosys("something") != -ENOSYS)
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_namespace(void)
|
||||
{
|
||||
int original_ns, new_ns, ret;
|
||||
|
|
@ -1364,6 +1461,52 @@ int test_namespace(void)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int test_large_file(void)
|
||||
{
|
||||
off_t large_seek = ((off_t)UINT32_MAX) + 100;
|
||||
int fd, ret, saved_errno;
|
||||
ssize_t written;
|
||||
off_t off;
|
||||
|
||||
#if defined(__mips__) && defined(_ABIN32)
|
||||
/* https://lore.kernel.org/qemu-devel/fed03914-a95a-4522-a432-f129264cb2ac@t-8ch.de/ */
|
||||
if (getpid() != 1)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
if (large_seek < UINT32_MAX) {
|
||||
errno = EOVERFLOW;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fd = open("/tmp", O_TMPFILE | O_RDWR, 0644);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
|
||||
off = lseek(fd, large_seek, SEEK_CUR);
|
||||
if (off == -1) {
|
||||
ret = off;
|
||||
goto out;
|
||||
} else if (off != large_seek) {
|
||||
errno = ERANGE;
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
written = write(fd, "1", 1);
|
||||
if (written == -1) {
|
||||
ret = written;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
out:
|
||||
saved_errno = errno;
|
||||
close(fd);
|
||||
errno = saved_errno;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Run syscall tests between IDs <min> and <max>.
|
||||
* Return 0 on success, non-zero on failure.
|
||||
*/
|
||||
|
|
@ -1441,12 +1584,13 @@ int run_syscall(int min, int max)
|
|||
CASE_TEST(dup2_m1); tmp = dup2(-1, 100); EXPECT_SYSER(1, tmp, -1, EBADF); if (tmp != -1) close(tmp); break;
|
||||
CASE_TEST(dup3_0); tmp = dup3(0, 100, 0); EXPECT_SYSNE(1, tmp, -1); close(tmp); break;
|
||||
CASE_TEST(dup3_m1); tmp = dup3(-1, 100, 0); EXPECT_SYSER(1, tmp, -1, EBADF); if (tmp != -1) close(tmp); break;
|
||||
CASE_TEST(execve_root); EXPECT_SYSER(1, execve("/", (char*[]){ [0] = "/", [1] = NULL }, NULL), -1, EACCES); break;
|
||||
CASE_TEST(execve_root); EXPECT_SYSER(1, execve("/", (char*[]){ [0] = (char []){"/"}, [1] = NULL }, NULL), -1, EACCES); break;
|
||||
CASE_TEST(fchdir_stdin); EXPECT_SYSER(1, fchdir(STDIN_FILENO), -1, ENOTDIR); break;
|
||||
CASE_TEST(fchdir_badfd); EXPECT_SYSER(1, fchdir(-1), -1, EBADF); break;
|
||||
CASE_TEST(file_stream); EXPECT_SYSZR(1, test_file_stream()); break;
|
||||
CASE_TEST(file_stream_wsr); EXPECT_SYSZR(1, test_file_stream_wsr()); break;
|
||||
CASE_TEST(fork); EXPECT_SYSZR(1, test_fork(FORK_STANDARD)); break;
|
||||
CASE_TEST(ftruncate); EXPECT_SYSZR(1, test_ftruncate()); break;
|
||||
CASE_TEST(getdents64_root); EXPECT_SYSNE(1, test_getdents64("/"), -1); break;
|
||||
CASE_TEST(getdents64_null); EXPECT_SYSER(1, test_getdents64("/dev/null"), -1, ENOTDIR); break;
|
||||
CASE_TEST(directories); EXPECT_SYSZR(is_nolibc && proc, test_dirent()); break;
|
||||
|
|
@ -1466,9 +1610,11 @@ int run_syscall(int min, int max)
|
|||
CASE_TEST(munmap_bad); EXPECT_SYSER(1, munmap(NULL, 0), -1, EINVAL); break;
|
||||
CASE_TEST(mmap_munmap_good); EXPECT_SYSZR(1, test_mmap_munmap()); break;
|
||||
CASE_TEST(nanosleep); ts.tv_nsec = -1; EXPECT_SYSER(1, nanosleep(&ts, NULL), -1, EINVAL); break;
|
||||
CASE_TEST(nolibc_enosys); EXPECT_ZR(is_nolibc, test_nolibc_enosys()); break;
|
||||
CASE_TEST(open_tty); EXPECT_SYSNE(1, tmp = open("/dev/null", O_RDONLY), -1); if (tmp != -1) close(tmp); break;
|
||||
CASE_TEST(open_blah); EXPECT_SYSER(1, tmp = open("/proc/self/blah", O_RDONLY), -1, ENOENT); if (tmp != -1) close(tmp); break;
|
||||
CASE_TEST(openat_dir); EXPECT_SYSZR(1, test_openat()); break;
|
||||
CASE_TEST(open_mode); EXPECT_SYSZR(1, test_open_mode()); break;
|
||||
CASE_TEST(pipe); EXPECT_SYSZR(1, test_pipe()); break;
|
||||
CASE_TEST(poll_null); EXPECT_SYSZR(1, poll(NULL, 0, 0)); break;
|
||||
CASE_TEST(poll_stdout); EXPECT_SYSNE(1, ({ struct pollfd fds = { 1, POLLOUT, 0}; poll(&fds, 1, 0); }), -1); break;
|
||||
|
|
@ -1508,6 +1654,7 @@ int run_syscall(int min, int max)
|
|||
CASE_TEST(_syscall_noargs); EXPECT_SYSEQ(is_nolibc, _syscall(__NR_getpid), getpid()); break;
|
||||
CASE_TEST(_syscall_args); EXPECT_SYSEQ(is_nolibc, _syscall(__NR_statx, 0, NULL, 0, 0, NULL), -EFAULT); break;
|
||||
CASE_TEST(namespace); EXPECT_SYSZR(euid0 && proc, test_namespace()); break;
|
||||
CASE_TEST(largefile); EXPECT_SYSZR(1, test_large_file()); break;
|
||||
case __LINE__:
|
||||
return ret; /* must be last */
|
||||
/* note: do not set any defaults so as to permit holes above */
|
||||
|
|
@ -1516,6 +1663,18 @@ int run_syscall(int min, int max)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int test_alloca(void)
|
||||
{
|
||||
uint64_t *x;
|
||||
|
||||
x = alloca(sizeof(*x));
|
||||
|
||||
*x = 0x1234;
|
||||
__asm__ ("" : "+r" (x));
|
||||
|
||||
return *x - 0x1234;
|
||||
}
|
||||
|
||||
int test_difftime(void)
|
||||
{
|
||||
if (difftime(200., 100.) != 100.)
|
||||
|
|
@ -1731,6 +1890,7 @@ int run_stdlib(int min, int max)
|
|||
CASE_TEST(toupper_noop); EXPECT_EQ(1, toupper('A'), 'A'); break;
|
||||
CASE_TEST(abs); EXPECT_EQ(1, abs(-10), 10); break;
|
||||
CASE_TEST(abs_noop); EXPECT_EQ(1, abs(10), 10); break;
|
||||
CASE_TEST(alloca); EXPECT_ZR(1, test_alloca()); break;
|
||||
CASE_TEST(difftime); EXPECT_ZR(1, test_difftime()); break;
|
||||
CASE_TEST(memchr_foobar6_o); EXPECT_STREQ(1, memchr("foobar", 'o', 6), "oobar"); break;
|
||||
CASE_TEST(memchr_foobar3_b); EXPECT_STRZR(1, memchr("foobar", 'b', 3)); break;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ all_archs=(
|
|||
i386 x86_64 x32
|
||||
arm64 arm armthumb
|
||||
mips32le mips32be mipsn32le mipsn32be mips64le mips64be
|
||||
openrisc
|
||||
ppc ppc64 ppc64le
|
||||
riscv32 riscv64
|
||||
s390x
|
||||
|
|
@ -28,6 +29,7 @@ all_archs=(
|
|||
sparc32 sparc64
|
||||
m68k
|
||||
sh4
|
||||
parisc32
|
||||
)
|
||||
archs="${all_archs[@]}"
|
||||
|
||||
|
|
@ -107,6 +109,7 @@ crosstool_arch() {
|
|||
case "$1" in
|
||||
arm64) echo aarch64;;
|
||||
armthumb) echo arm;;
|
||||
openrisc) echo or1k;;
|
||||
ppc) echo powerpc;;
|
||||
ppc64) echo powerpc64;;
|
||||
ppc64le) echo powerpc64;;
|
||||
|
|
@ -116,6 +119,7 @@ crosstool_arch() {
|
|||
s390*) echo s390;;
|
||||
sparc*) echo sparc64;;
|
||||
x32*) echo x86_64;;
|
||||
parisc32) echo hppa;;
|
||||
*) echo "$1";;
|
||||
esac
|
||||
}
|
||||
|
|
@ -173,6 +177,10 @@ test_arch() {
|
|||
fi
|
||||
MAKE=(make -f Makefile.nolibc -j"${nproc}" XARCH="${arch}" CROSS_COMPILE="${cross_compile}" LLVM="${llvm}" O="${build_dir}")
|
||||
|
||||
if [ "$arch" = "parisc32" ]; then
|
||||
MAKE+=("CROSS32CC=${cross_compile}gcc")
|
||||
fi
|
||||
|
||||
case "$test_mode" in
|
||||
'system')
|
||||
test_target=run
|
||||
|
|
@ -185,7 +193,7 @@ test_arch() {
|
|||
exit 1
|
||||
esac
|
||||
printf '%-15s' "$arch:"
|
||||
if [ "$arch" = "m68k" -o "$arch" = "sh4" ] && [ "$llvm" = "1" ]; then
|
||||
if [ "$arch" = "m68k" -o "$arch" = "sh4" -o "$arch" = "openrisc" -o "$arch" = "parisc32" ] && [ "$llvm" = "1" ]; then
|
||||
echo "Unsupported configuration"
|
||||
return
|
||||
fi
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user