Skip to content

Commit 5d09f61

Browse files
committed
Merge tag 'linux_kselftest-nolibc-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull nolibc updates from Shuah Khan: - Support for PIC mode on MIPS - Support for getrlimit()/setrlimit() - Replace some custom declarations with UAPI includes - A new script "run-tests.sh" to run the testsuite over different architectures and configurations - A few non-functional code cleanups - Minor improvements to nolibc-test, primarily to support the test script * tag 'linux_kselftest-nolibc-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (22 commits) selftests/nolibc: disable coredump via setrlimit tools/nolibc: add support for getrlimit/setrlimit tools/nolibc: drop custom definition of struct rusage tools/nolibc: drop duplicated testcase ioctl_tiocinq tools/nolibc: annotate va_list printf formats selftests/nolibc: make result alignment more robust tools/nolibc: mips: add support for PIC selftests/nolibc: run-tests.sh: enable testing via qemu-user selftests/nolibc: introduce QEMU_ARCH_USER selftests/nolibc: fix testcase status alignment selftests/nolibc: add configuration for mipso32be selftests/nolibc: extraconfig support selftests/nolibc: explicitly specify ABI for MIPS selftests/nolibc: use XARCH for MIPS tools/nolibc: move MIPS ABI validation into arch-mips.h tools/nolibc: error out on unsupported architecture selftests/nolibc: add script to run testsuite selftests/nolibc: support out-of-tree builds selftests/nolibc: anchor paths in $(srcdir) if possible selftests/nolibc: use EFI -bios for LoongArch qemu ...
2 parents a7e4c6c + d543d9d commit 5d09f61

9 files changed

Lines changed: 318 additions & 50 deletions

File tree

tools/include/nolibc/arch-mips.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#include "compiler.h"
1111
#include "crt.h"
1212

13+
#if !defined(_ABIO32)
14+
#error Unsupported MIPS ABI
15+
#endif
16+
1317
/* Syscalls for MIPS ABI O32 :
1418
* - WARNING! there's always a delayed slot!
1519
* - WARNING again, the syntax is different, registers take a '$' and numbers
@@ -180,8 +184,13 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
180184
__asm__ volatile (
181185
".set push\n"
182186
".set noreorder\n"
183-
".option pic0\n"
187+
"bal 1f\n" /* prime $ra for .cpload */
188+
"nop\n"
189+
"1:\n"
190+
".cpload $ra\n"
184191
"move $a0, $sp\n" /* save stack pointer to $a0, as arg1 of _start_c */
192+
"addiu $sp, $sp, -4\n" /* space for .cprestore to store $gp */
193+
".cprestore 0\n"
185194
"li $t0, -8\n"
186195
"and $sp, $sp, $t0\n" /* $sp must be 8-byte aligned */
187196
"addiu $sp, $sp, -16\n" /* the callee expects to save a0..a3 there */

tools/include/nolibc/arch.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "arch-arm.h"
2424
#elif defined(__aarch64__)
2525
#include "arch-aarch64.h"
26-
#elif defined(__mips__) && defined(_ABIO32)
26+
#elif defined(__mips__)
2727
#include "arch-mips.h"
2828
#elif defined(__powerpc__)
2929
#include "arch-powerpc.h"
@@ -33,6 +33,8 @@
3333
#include "arch-s390.h"
3434
#elif defined(__loongarch__)
3535
#include "arch-loongarch.h"
36+
#else
37+
#error Unsupported Architecture
3638
#endif
3739

3840
#endif /* _NOLIBC_ARCH_H */

tools/include/nolibc/stdio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ char *fgets(char *s, int size, FILE *stream)
212212
* - %s
213213
* - unknown modifiers are ignored.
214214
*/
215-
static __attribute__((unused))
215+
static __attribute__((unused, format(printf, 2, 0)))
216216
int vfprintf(FILE *stream, const char *fmt, va_list args)
217217
{
218218
char escape, lpref, c;
@@ -318,7 +318,7 @@ int vfprintf(FILE *stream, const char *fmt, va_list args)
318318
return written;
319319
}
320320

321-
static __attribute__((unused))
321+
static __attribute__((unused, format(printf, 1, 0)))
322322
int vprintf(const char *fmt, va_list args)
323323
{
324324
return vfprintf(stdout, fmt, args);

tools/include/nolibc/sys.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/fcntl.h> /* for O_* and AT_* */
2222
#include <linux/stat.h> /* for statx() */
2323
#include <linux/prctl.h>
24+
#include <linux/resource.h>
2425

2526
#include "arch.h"
2627
#include "errno.h"
@@ -898,6 +899,43 @@ int reboot(int cmd)
898899
}
899900

900901

902+
/*
903+
* int getrlimit(int resource, struct rlimit *rlim);
904+
* int setrlimit(int resource, const struct rlimit *rlim);
905+
*/
906+
907+
static __attribute__((unused))
908+
int sys_prlimit64(pid_t pid, int resource,
909+
const struct rlimit64 *new_limit, struct rlimit64 *old_limit)
910+
{
911+
return my_syscall4(__NR_prlimit64, pid, resource, new_limit, old_limit);
912+
}
913+
914+
static __attribute__((unused))
915+
int getrlimit(int resource, struct rlimit *rlim)
916+
{
917+
struct rlimit64 rlim64;
918+
int ret;
919+
920+
ret = __sysret(sys_prlimit64(0, resource, NULL, &rlim64));
921+
rlim->rlim_cur = rlim64.rlim_cur;
922+
rlim->rlim_max = rlim64.rlim_max;
923+
924+
return ret;
925+
}
926+
927+
static __attribute__((unused))
928+
int setrlimit(int resource, const struct rlimit *rlim)
929+
{
930+
struct rlimit64 rlim64 = {
931+
.rlim_cur = rlim->rlim_cur,
932+
.rlim_max = rlim->rlim_max,
933+
};
934+
935+
return __sysret(sys_prlimit64(0, resource, &rlim64, NULL));
936+
}
937+
938+
901939
/*
902940
* int sched_yield(void);
903941
*/

tools/include/nolibc/types.h

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <linux/reboot.h> /* for LINUX_REBOOT_* */
1313
#include <linux/stat.h>
1414
#include <linux/time.h>
15+
#include <linux/wait.h>
16+
#include <linux/resource.h>
1517

1618

1719
/* Only the generic macros and types may be defined here. The arch-specific
@@ -108,9 +110,6 @@
108110
#define WTERMSIG(status) ((status) & 0x7f)
109111
#define WIFSIGNALED(status) ((status) - 1 < 0xff)
110112

111-
/* waitpid() flags */
112-
#define WNOHANG 1
113-
114113
/* standard exit() codes */
115114
#define EXIT_SUCCESS 0
116115
#define EXIT_FAILURE 1
@@ -180,26 +179,6 @@ struct linux_dirent64 {
180179
char d_name[];
181180
};
182181

183-
/* needed by wait4() */
184-
struct rusage {
185-
struct timeval ru_utime;
186-
struct timeval ru_stime;
187-
long ru_maxrss;
188-
long ru_ixrss;
189-
long ru_idrss;
190-
long ru_isrss;
191-
long ru_minflt;
192-
long ru_majflt;
193-
long ru_nswap;
194-
long ru_inblock;
195-
long ru_oublock;
196-
long ru_msgsnd;
197-
long ru_msgrcv;
198-
long ru_nsignals;
199-
long ru_nvcsw;
200-
long ru_nivcsw;
201-
};
202-
203182
/* The format of the struct as returned by the libc to the application, which
204183
* significantly differs from the format returned by the stat() syscall flavours.
205184
*/

tools/testing/selftests/nolibc/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/libc-test
44
/nolibc-test
55
/run.out
6+
/run.out.*
67
/sysroot/

tools/testing/selftests/nolibc/Makefile

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
# SPDX-License-Identifier: GPL-2.0
22
# Makefile for nolibc tests
33
include ../../../scripts/Makefile.include
4+
include ../../../scripts/utilities.mak
45
# We need this for the "cc-option" macro.
56
include ../../../build/Build.include
67

8+
ifneq ($(O),)
9+
ifneq ($(call is-absolute,$(O)),y)
10+
$(error Only absolute O= parameters are supported)
11+
endif
12+
endif
13+
714
# we're in ".../tools/testing/selftests/nolibc"
815
ifeq ($(srctree),)
916
srctree := $(patsubst %/tools/testing/selftests/,%,$(dir $(CURDIR)))
@@ -14,6 +21,8 @@ include $(srctree)/scripts/subarch.include
1421
ARCH = $(SUBARCH)
1522
endif
1623

24+
objtree ?= $(srctree)
25+
1726
# XARCH extends the kernel's ARCH with a few variants of the same
1827
# architecture that only differ by the configuration, the toolchain
1928
# and the Qemu program used. It is copied as-is into ARCH except for
@@ -31,12 +40,15 @@ endif
3140

3241
# configure default variants for target kernel supported architectures
3342
XARCH_powerpc = ppc
43+
XARCH_mips = mips32le
3444
XARCH = $(or $(XARCH_$(ARCH)),$(ARCH))
3545

3646
# map from user input variants to their kernel supported architectures
3747
ARCH_ppc = powerpc
3848
ARCH_ppc64 = powerpc
3949
ARCH_ppc64le = powerpc
50+
ARCH_mips32le = mips
51+
ARCH_mips32be = mips
4052
ARCH := $(or $(ARCH_$(XARCH)),$(XARCH))
4153

4254
# kernel image names by architecture
@@ -45,14 +57,15 @@ IMAGE_x86_64 = arch/x86/boot/bzImage
4557
IMAGE_x86 = arch/x86/boot/bzImage
4658
IMAGE_arm64 = arch/arm64/boot/Image
4759
IMAGE_arm = arch/arm/boot/zImage
48-
IMAGE_mips = vmlinuz
60+
IMAGE_mips32le = vmlinuz
61+
IMAGE_mips32be = vmlinuz
4962
IMAGE_ppc = vmlinux
5063
IMAGE_ppc64 = vmlinux
5164
IMAGE_ppc64le = arch/powerpc/boot/zImage
5265
IMAGE_riscv = arch/riscv/boot/Image
5366
IMAGE_s390 = arch/s390/boot/bzImage
5467
IMAGE_loongarch = arch/loongarch/boot/vmlinuz.efi
55-
IMAGE = $(IMAGE_$(XARCH))
68+
IMAGE = $(objtree)/$(IMAGE_$(XARCH))
5669
IMAGE_NAME = $(notdir $(IMAGE))
5770

5871
# default kernel configurations that appear to be usable
@@ -61,7 +74,8 @@ DEFCONFIG_x86_64 = defconfig
6174
DEFCONFIG_x86 = defconfig
6275
DEFCONFIG_arm64 = defconfig
6376
DEFCONFIG_arm = multi_v7_defconfig
64-
DEFCONFIG_mips = malta_defconfig
77+
DEFCONFIG_mips32le = malta_defconfig
78+
DEFCONFIG_mips32be = malta_defconfig
6579
DEFCONFIG_ppc = pmac32_defconfig
6680
DEFCONFIG_ppc64 = powernv_be_defconfig
6781
DEFCONFIG_ppc64le = powernv_defconfig
@@ -70,6 +84,9 @@ DEFCONFIG_s390 = defconfig
7084
DEFCONFIG_loongarch = defconfig
7185
DEFCONFIG = $(DEFCONFIG_$(XARCH))
7286

87+
EXTRACONFIG_mips32be = -d CONFIG_CPU_LITTLE_ENDIAN -e CONFIG_CPU_BIG_ENDIAN
88+
EXTRACONFIG = $(EXTRACONFIG_$(XARCH))
89+
7390
# optional tests to run (default = all)
7491
TEST =
7592

@@ -79,7 +96,8 @@ QEMU_ARCH_x86_64 = x86_64
7996
QEMU_ARCH_x86 = x86_64
8097
QEMU_ARCH_arm64 = aarch64
8198
QEMU_ARCH_arm = arm
82-
QEMU_ARCH_mips = mipsel # works with malta_defconfig
99+
QEMU_ARCH_mips32le = mipsel # works with malta_defconfig
100+
QEMU_ARCH_mips32be = mips
83101
QEMU_ARCH_ppc = ppc
84102
QEMU_ARCH_ppc64 = ppc64
85103
QEMU_ARCH_ppc64le = ppc64
@@ -88,20 +106,31 @@ QEMU_ARCH_s390 = s390x
88106
QEMU_ARCH_loongarch = loongarch64
89107
QEMU_ARCH = $(QEMU_ARCH_$(XARCH))
90108

109+
QEMU_ARCH_USER_ppc64le = ppc64le
110+
QEMU_ARCH_USER = $(or $(QEMU_ARCH_USER_$(XARCH)),$(QEMU_ARCH_$(XARCH)))
111+
112+
QEMU_BIOS_DIR = /usr/share/edk2/
113+
QEMU_BIOS_loongarch = $(QEMU_BIOS_DIR)/loongarch64/OVMF_CODE.fd
114+
115+
ifneq ($(QEMU_BIOS_$(XARCH)),)
116+
QEMU_ARGS_BIOS = -bios $(QEMU_BIOS_$(XARCH))
117+
endif
118+
91119
# QEMU_ARGS : some arch-specific args to pass to qemu
92120
QEMU_ARGS_i386 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)"
93121
QEMU_ARGS_x86_64 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)"
94122
QEMU_ARGS_x86 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)"
95123
QEMU_ARGS_arm64 = -M virt -cpu cortex-a53 -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
96124
QEMU_ARGS_arm = -M virt -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
97-
QEMU_ARGS_mips = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
125+
QEMU_ARGS_mips32le = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
126+
QEMU_ARGS_mips32be = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
98127
QEMU_ARGS_ppc = -M g3beige -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
99128
QEMU_ARGS_ppc64 = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
100129
QEMU_ARGS_ppc64le = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
101130
QEMU_ARGS_riscv = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
102131
QEMU_ARGS_s390 = -M s390-ccw-virtio -m 1G -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
103132
QEMU_ARGS_loongarch = -M virt -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
104-
QEMU_ARGS = $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_EXTRA)
133+
QEMU_ARGS = $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_BIOS) $(QEMU_ARGS_EXTRA)
105134

106135
# OUTPUT is only set when run from the main makefile, otherwise
107136
# it defaults to this nolibc directory.
@@ -118,7 +147,8 @@ CFLAGS_ppc = -m32 -mbig-endian -mno-vsx $(call cc-option,-mmultiple)
118147
CFLAGS_ppc64 = -m64 -mbig-endian -mno-vsx $(call cc-option,-mmultiple)
119148
CFLAGS_ppc64le = -m64 -mlittle-endian -mno-vsx $(call cc-option,-mabi=elfv2)
120149
CFLAGS_s390 = -m64
121-
CFLAGS_mips = -EL
150+
CFLAGS_mips32le = -EL -mabi=32 -fPIC
151+
CFLAGS_mips32be = -EB -mabi=32
122152
CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all))
123153
CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra \
124154
$(call cc-option,-fno-stack-protector) \
@@ -167,7 +197,8 @@ sysroot: sysroot/$(ARCH)/include
167197
sysroot/$(ARCH)/include:
168198
$(Q)rm -rf sysroot/$(ARCH) sysroot/sysroot
169199
$(QUIET_MKDIR)mkdir -p sysroot
170-
$(Q)$(MAKE) -C ../../../include/nolibc ARCH=$(ARCH) OUTPUT=$(CURDIR)/sysroot/ headers_standalone
200+
$(Q)$(MAKE) -C $(srctree) outputmakefile
201+
$(Q)$(MAKE) -C $(srctree)/tools/include/nolibc ARCH=$(ARCH) OUTPUT=$(CURDIR)/sysroot/ headers_standalone
171202
$(Q)mv sysroot/sysroot sysroot/$(ARCH)
172203

173204
ifneq ($(NOLIBC_SYSROOT),0)
@@ -177,7 +208,7 @@ nolibc-test: nolibc-test.c nolibc-test-linkage.c sysroot/$(ARCH)/include
177208
else
178209
nolibc-test: nolibc-test.c nolibc-test-linkage.c
179210
$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
180-
-nostdlib -static -include ../../../include/nolibc/nolibc.h nolibc-test.c nolibc-test-linkage.c -lgcc
211+
-nostdlib -static -include $(srctree)/tools/include/nolibc/nolibc.h nolibc-test.c nolibc-test-linkage.c -lgcc
181212
endif
182213

183214
libc-test: nolibc-test.c nolibc-test-linkage.c
@@ -195,11 +226,11 @@ run-nolibc-test: nolibc-test
195226

196227
# qemu user-land test
197228
run-user: nolibc-test
198-
$(Q)qemu-$(QEMU_ARCH) ./nolibc-test > "$(CURDIR)/run.out" || :
229+
$(Q)qemu-$(QEMU_ARCH_USER) ./nolibc-test > "$(CURDIR)/run.out" || :
199230
$(Q)$(REPORT) $(CURDIR)/run.out
200231

201232
initramfs.cpio: kernel nolibc-test
202-
$(QUIET_GEN)echo 'file /init nolibc-test 755 0 0' | $(srctree)/usr/gen_init_cpio - > initramfs.cpio
233+
$(QUIET_GEN)echo 'file /init nolibc-test 755 0 0' | $(objtree)/usr/gen_init_cpio - > initramfs.cpio
203234

204235
initramfs: nolibc-test
205236
$(QUIET_MKDIR)mkdir -p initramfs
@@ -208,21 +239,25 @@ initramfs: nolibc-test
208239

209240
defconfig:
210241
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare
242+
$(Q)if [ -n "$(EXTRACONFIG)" ]; then \
243+
$(srctree)/scripts/config --file $(objtree)/.config $(EXTRACONFIG); \
244+
$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) olddefconfig < /dev/null; \
245+
fi
211246

212247
kernel:
213-
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME)
248+
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) < /dev/null
214249

215250
kernel-standalone: initramfs
216-
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs
251+
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs < /dev/null
217252

218253
# run the tests after building the kernel
219254
run: kernel initramfs.cpio
220-
$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)/$(IMAGE)" -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
255+
$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
221256
$(Q)$(REPORT) $(CURDIR)/run.out
222257

223258
# re-run the tests from an existing kernel
224259
rerun:
225-
$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)/$(IMAGE)" -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
260+
$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
226261
$(Q)$(REPORT) $(CURDIR)/run.out
227262

228263
# report with existing test log

0 commit comments

Comments
 (0)