Signed-off-by: Thomas Weißschuh linux@weissschuh.net --- Thomas Weißschuh (2): tools/nolibc: define time_t in terms of __kernel_old_time_t selftests/nolibc: add x32 test configuration
tools/include/nolibc/std.h | 4 +++- tools/testing/selftests/nolibc/Makefile.nolibc | 12 ++++++++++++ tools/testing/selftests/nolibc/run-tests.sh | 7 ++++++- 3 files changed, 21 insertions(+), 2 deletions(-) --- base-commit: 750aef513c610a37a13732ec64902428b839715e change-id: 20250712-nolibc-x32-796a9da4c9ed
Best regards,
Nolibc assumes that the kernel ABI is using a time values that are as large as a long integer. For most ABIs this holds true. But for x32 this is not correct, as it uses 32bit longs but 64bit times.
Also the 'struct stat' implementation of nolibc relies on timespec::tv_sec and time_t being the same type. While timespec::tv_sec comes from the kernel and is of type __kernel_old_time_t, time_t is defined within nolibc.
Switch to the __kernel_old_time_t to always get the correct type.
Signed-off-by: Thomas Weißschuh linux@weissschuh.net --- tools/include/nolibc/std.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/include/nolibc/std.h b/tools/include/nolibc/std.h index adda7333d12e7d2c336938ede1aaf215b4b93165..ba950f0e7338438823b4ee8c68a067391c719823 100644 --- a/tools/include/nolibc/std.h +++ b/tools/include/nolibc/std.h @@ -16,6 +16,8 @@ #include "stdint.h" #include "stddef.h"
+#include <linux/types.h> + /* those are commonly provided by sys/types.h */ typedef unsigned int dev_t; typedef unsigned long ino_t; @@ -27,6 +29,6 @@ typedef unsigned long nlink_t; typedef signed long off_t; typedef signed long blksize_t; typedef signed long blkcnt_t; -typedef signed long time_t; +typedef __kernel_old_time_t time_t;
#endif /* _NOLIBC_STD_H */
Nolibc supports the x32 ABI on x86. Add a testcase to make sure the support stays functional.
QEMU user does not have support for x32, so skip the test there.
Signed-off-by: Thomas Weißschuh linux@weissschuh.net --- tools/testing/selftests/nolibc/Makefile.nolibc | 12 ++++++++++++ tools/testing/selftests/nolibc/run-tests.sh | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/nolibc/Makefile.nolibc b/tools/testing/selftests/nolibc/Makefile.nolibc index 51ba853dd97eebed32f9808b0979460071f2514f..0fb759ba992ee6b1693b88f1b2e77463afa9f38b 100644 --- a/tools/testing/selftests/nolibc/Makefile.nolibc +++ b/tools/testing/selftests/nolibc/Makefile.nolibc @@ -47,6 +47,7 @@ XARCH_riscv = riscv64 XARCH = $(or $(XARCH_$(ARCH)),$(ARCH))
# map from user input variants to their kernel supported architectures +ARCH_x32 = x86 ARCH_armthumb = arm ARCH_ppc = powerpc ARCH_ppc64 = powerpc @@ -68,6 +69,7 @@ ARCH := $(or $(ARCH_$(XARCH)),$(XARCH)) # kernel image names by architecture IMAGE_i386 = arch/x86/boot/bzImage IMAGE_x86_64 = arch/x86/boot/bzImage +IMAGE_x32 = arch/x86/boot/bzImage IMAGE_x86 = arch/x86/boot/bzImage IMAGE_arm64 = arch/arm64/boot/Image IMAGE_arm = arch/arm/boot/zImage @@ -97,6 +99,7 @@ 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 @@ -122,6 +125,7 @@ DEFCONFIG_m68k = virt_defconfig DEFCONFIG_sh4 = rts7751r2dplus_defconfig DEFCONFIG = $(DEFCONFIG_$(XARCH))
+EXTRACONFIG_x32 = -e CONFIG_X86_X32_ABI EXTRACONFIG_arm = -e CONFIG_NAMESPACES EXTRACONFIG_armthumb = -e CONFIG_NAMESPACES EXTRACONFIG_m68k = -e CONFIG_BLK_DEV_INITRD @@ -134,6 +138,7 @@ 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 @@ -174,6 +179,7 @@ endif # QEMU_ARGS : some arch-specific args to pass to qemu QEMU_ARGS_i386 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_x86_64 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)" +QEMU_ARGS_x32 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_x86 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_arm64 = -M virt -cpu cortex-a53 -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_arm = -M virt -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" @@ -210,6 +216,7 @@ Q=@ endif
CFLAGS_i386 = $(call cc-option,-m32) +CFLAGS_x32 = -mx32 CFLAGS_arm = -marm CFLAGS_armthumb = -mthumb -march=armv6t2 CFLAGS_ppc = -m32 -mbig-endian -mno-vsx $(call cc-option,-mmultiple) @@ -236,6 +243,11 @@ LDFLAGS :=
LIBGCC := -lgcc
+ifeq ($(ARCH),x86) +# Not needed on x86, probably not present for x32 +LIBGCC := +endif + ifneq ($(LLVM),) # Not needed for clang LIBGCC := diff --git a/tools/testing/selftests/nolibc/run-tests.sh b/tools/testing/selftests/nolibc/run-tests.sh index 43eb30be316ae7bac7f0ba2c38b494a283833bec..e8af1fb505cf3573b4a6b37228dee764fe2e5277 100755 --- a/tools/testing/selftests/nolibc/run-tests.sh +++ b/tools/testing/selftests/nolibc/run-tests.sh @@ -18,7 +18,7 @@ test_mode=system werror=1 llvm= all_archs=( - i386 x86_64 + i386 x86_64 x32 arm64 arm armthumb mips32le mips32be mipsn32le mipsn32be mips64le mips64be ppc ppc64 ppc64le @@ -115,6 +115,7 @@ crosstool_arch() { mips*) echo mips;; s390*) echo s390;; sparc*) echo sparc64;; + x32*) echo x86_64;; *) echo "$1";; esac } @@ -192,6 +193,10 @@ test_arch() { echo "Unsupported configuration" return fi + if [ "$arch" = "x32" ] && [ "$test_mode" = "user" ]; then + echo "Unsupported configuration" + return + fi
mkdir -p "$build_dir" swallow_output "${MAKE[@]}" defconfig
linux-kselftest-mirror@lists.linaro.org