Start porting UML to nolibc
Subsystems (5)
v3 cover Start porting UML to nolibc
From: Benjamin Berg <[email protected]>
This patchset is an attempt to start a nolibc port of UML. The goal is to port UML to use nolibc in smaller chunks to make the switch more manageable.
Using nolibc has the advantage that it is a smaller runtime and it allows us to be in full control about all memory mappings that are done. Another libc on the other hand might map memory unaware of UML, causing collisions with the UML memory layout. Such mappings could even happen before UML has fully initialized (e.g. rseq being mapped into the physical or vmalloc memory areas).
There are three parts to this patchset:
* Two patches to use tools/include headers instead of kernel headers for userspace files.
* A few nolibc fixes and a new NOLIBC_NO_RUNTIME compile flag for it
* Finally nolibc build support for UML and switching two files while adding the appropriate support in nolibc itself.
v1 of this patchset was
https://lore.kernel.org/all/[email protected]
v2:
https://lore.kernel.org/all/[email protected]
Changes in v3:
- sys_ptrace is now not a varadic function
- improve printf %m implementation
- keep perror as function available with NOLIBC_IGNORE_ERRNO
- change syscall guard and fix i386 build
Changes in v2:
- add sys/uio.h and sys/ptrace.h to nolibc
- Use NOLIBC_NO_RUNTIME to disable nolibc startup code
- Fix out-of-tree build
- various small improvements and cleanups
Benjamin
Benjamin Berg (12):
tools compiler.h: fix __used definition
um: use tools/include for user files
tools/nolibc/stdio: let perror work when NOLIBC_IGNORE_ERRNO is set tools/nolibc/dirent: avoid errno in readdir_r tools/nolibc: implement %m if errno is not defined tools/nolibc: use __fallthrough__ rather than fallthrough tools/nolibc: add option to disable runtime
um: add infrastructure to build files using nolibc
um: use nolibc for the --showconfig implementation tools/nolibc: add uio.h with readv and writev tools/nolibc: add ptrace support
um: switch ptrace FP register access to nolibc
arch/um/Makefile | 38 ++++++++++++--- arch/um/include/shared/init.h | 2 +- arch/um/include/shared/os.h | 2 + arch/um/include/shared/user.h | 6 --- arch/um/kernel/Makefile | 2 +- arch/um/kernel/skas/stub.c | 1 + arch/um/kernel/skas/stub_exe.c | 4 +- arch/um/os-Linux/skas/process.c | 6 +-- arch/um/os-Linux/start_up.c | 4 +- arch/um/scripts/Makefile.rules | 10 +++- arch/x86/um/Makefile | 6 ++- arch/x86/um/os-Linux/Makefile | 5 +- arch/x86/um/os-Linux/registers.c | 20 ++------ arch/x86/um/user-offsets.c | 1 - tools/include/linux/compiler.h | 2 +- tools/include/nolibc/Makefile | 2 + tools/include/nolibc/arch-arm.h | 2 + tools/include/nolibc/arch-arm64.h | 2 + tools/include/nolibc/arch-loongarch.h | 2 + tools/include/nolibc/arch-m68k.h | 2 + tools/include/nolibc/arch-mips.h | 2 + tools/include/nolibc/arch-powerpc.h | 2 + tools/include/nolibc/arch-riscv.h | 2 + tools/include/nolibc/arch-s390.h | 2 + tools/include/nolibc/arch-sh.h | 2 + tools/include/nolibc/arch-sparc.h | 2 + tools/include/nolibc/arch-x86.h | 4 ++ tools/include/nolibc/compiler.h | 4 +- tools/include/nolibc/crt.h | 3 ++ tools/include/nolibc/dirent.h | 6 +-- tools/include/nolibc/nolibc.h | 2 + tools/include/nolibc/stackprotector.h | 2 + tools/include/nolibc/stdio.h | 10 +++- tools/include/nolibc/stdlib.h | 2 + tools/include/nolibc/sys.h | 3 +- tools/include/nolibc/sys/auxv.h | 3 ++ tools/include/nolibc/sys/ptrace.h | 44 ++++++++++++++++++ tools/include/nolibc/sys/uio.h | 49 ++++++++++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 11 +++++ 39 files changed, 221 insertions(+), 53 deletions(-) create mode 100644 tools/include/nolibc/sys/ptrace.h create mode 100644 tools/include/nolibc/sys/uio.h
Signature · 1 line
2.51.0
PATCH v3 1/12 tools compiler.h: fix __used definition
From: Benjamin Berg <[email protected]>
The define mapped to __attribute__((__unused__)) instead of using __used__. Having the wrong definition here may result in the linker incorrectly removing the symbol. Also, this now matches the definition in include/linux/compiler_attributes.h.
--- tools/include/linux/compiler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/include/linux/compiler.h +1 -1
@@ -127,7 +127,7 @@#endif #ifndef __used -# define __used __attribute__((__unused__)) +# define __used __attribute__((__used__))#endif #ifndef __packed
Signature · 1 line
2.51.0
PATCH v3 2/12 um: use tools/include for user files
In reply to Benjamin BergFrom: Benjamin Berg <[email protected]>
Using the kernel headers directly from the userspace parts of UML is problematic. Switch to use the headers from the tools/include subdirectory instead. These contain stripped down versions that work well for UML and only relatively small adjustments are needed to make it work.
This adds code to create two symlinks so that the userspace code can still find asm-offsets.h and user_constants.h. Other than that, some includes are moved into USER_CFLAGS instead of handling them in Makefile.rules.
---
v2:
- Fix out-of-tree building
--- arch/um/Makefile | 18 ++++++++++++------ arch/um/include/shared/init.h | 2 +- arch/um/include/shared/user.h | 5 ----- arch/um/kernel/skas/stub.c | 1 + arch/um/kernel/skas/stub_exe.c | 4 ++-- arch/um/os-Linux/skas/process.c | 6 ++---- arch/um/os-Linux/start_up.c | 4 ++-- arch/um/scripts/Makefile.rules | 2 +- arch/x86/um/Makefile | 6 ++++-- arch/x86/um/user-offsets.c | 1 - 10 files changed, 25 insertions(+), 24 deletions(-)
arch/um/Makefile +12 -6
@@ -42,7 +42,7 @@ include $(srctree)/$(HOST_DIR)/Makefile.um core-y += $(HOST_DIR)/um/ SHARED_HEADERS := $(ARCH_DIR)/include/shared -ARCH_INCLUDE := -I$(srctree)/$(SHARED_HEADERS) +ARCH_INCLUDE := -I$(srctree)/$(SHARED_HEADERS) -I$(objtree)/$(SHARED_HEADERS) ARCH_INCLUDE += -I$(srctree)/$(HOST_DIR)/um/shared KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/um
@@ -70,10 +70,13 @@ KBUILD_AFLAGS += $(ARCH_INCLUDE) USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \ $(ARCH_INCLUDE) $(MODE_INCLUDE) $(filter -I%,$(CFLAGS)) \ - -D_FILE_OFFSET_BITS=64 -idirafter $(srctree)/include \ - -idirafter $(objtree)/include -D__KERNEL__ -D__UM_HOST__ \ - -include $(srctree)/include/linux/compiler-version.h \ - -include $(srctree)/include/linux/kconfig.h + -idirafter $(srctree)/tools/include \ + -D__UM_HOST__ \ + -include $(srctree)/tools/include/linux/compiler.h \ + -include $(srctree)/tools/include/linux/kconfig.h \ + -include $(objtree)/include/generated/autoconf.h \ + -include $(srctree)/include/linux/kern_levels.h \ + -include $(srctree)/$(ARCH_DIR)/include/shared/user.h #This will adjust *FLAGS accordingly to the platform. include $(srctree)/$(ARCH_DIR)/Makefile-os-Linux
@@ -116,6 +119,9 @@ archheaders: archprepare: $(Q)$(MAKE) $(build)=$(HOST_DIR)/um include/generated/user_constants.h + $(Q)mkdir -p $(ARCH_DIR)/include/shared/generated + $(Q)ln -fs ../../../../../include/generated/user_constants.h $(ARCH_DIR)/include/shared/generated/ + $(Q)ln -fs ../../../../../include/generated/asm-offsets.h $(ARCH_DIR)/include/shared/generated/ LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static LINK-$(CONFIG_LD_SCRIPT_DYN) += -no-pie
@@ -147,7 +153,7 @@ export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE) $(CC_FLAGS_ # When cleaning we don't include .config, so we don't include # TT or skas makefiles and don't clean skas_ptregs.h. CLEAN_FILES += linux x.i gmon.out -MRPROPER_FILES += $(HOST_DIR)/include/generated +MRPROPER_FILES += $(HOST_DIR)/include/generated $(ARCH_DIR)/include/shared/generated archclean: @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
arch/um/include/shared/init.h +1 -1
@@ -41,7 +41,7 @@typedef int (*initcall_t )(void );typedef void (*exitcall_t )(void ); -#include <linux/compiler_types.h> +#define __section (section) __attribute__((__section__(section)))/* These are for everybody (although not all archs will actually discard it in modules) */
arch/um/include/shared/user.h +0 -5
@@ -16,13 +16,8 @@*/ #define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0])) -/* This is to get size_t and NULL */ -#ifndef __UM_HOST__#include <linux/types.h> -#else #include <stddef.h> -#include <sys/types.h> -#endif extern void panic (const char *fmt, ...) __attribute__ ((format (printf,1 ,2 )));
arch/um/kernel/skas/stub.c +1 -0
@@ -5,6 +5,7 @@#include <sysdep/stub.h> +#include <linux/init.h> #include <linux/futex.h> #include <sys/socket.h> #include <errno.h>
arch/um/kernel/skas/stub_exe.c +2 -2
@@ -4,8 +4,8 @@#include <asm/unistd.h> #include <sysdep/stub.h> #include <stub-data.h> -#include <linux/filter.h> -#include <linux/seccomp.h> +#include <uapi/linux/filter.h> +#include <uapi/linux/seccomp.h> #include <generated/asm-offsets.h> void _start (void );
arch/um/os-Linux/skas/process.c +2 -4
@@ -29,9 +29,7 @@#include <sysdep/stub.h> #include <sysdep/mcontext.h> #include <linux/futex.h> -#include <linux/threads.h> #include <timetravel.h> -#include <asm-generic/rwonce.h> #include "../internal.h" int is_skas_winch (int pid,int fd,void *data)
@@ -204,7 +202,7 @@ void wait_stub_done_seccomp(struct mm_id *mm_idp, int running, int wait_sigsys)* Either way, if PID is negative, then we have no * choice but to kill the task. */ -if (__READ_ONCE (mm_idp->pid) <0 ) +if (READ_ONCE (mm_idp->pid) <0 ) goto out_kill; ret = syscall(__NR_futex, &data->futex,
@@ -217,7 +215,7 @@ void wait_stub_done_seccomp(struct mm_id *mm_idp, int running, int wait_sigsys) } }while (data->futex ==FUTEX_IN_CHILD ); -if (__READ_ONCE (mm_idp->pid) <0 ) +if (READ_ONCE (mm_idp->pid) <0 ) goto out_kill; running =0 ;
arch/um/os-Linux/start_up.c +2 -2
@@ -28,8 +28,8 @@#include <stdbool.h> #include <stub-data.h> #include <sys/prctl.h> -#include <linux/seccomp.h> -#include <linux/filter.h> +#include <uapi/linux/seccomp.h> +#include <uapi/linux/filter.h> #include <sysdep/mcontext.h> #include <sysdep/stub.h> #include <registers.h>
arch/um/scripts/Makefile.rules +1 -1
@@ -9,7 +9,7 @@ USER_OBJS += $(filter %_user.o,$(obj-y) $(USER_SINGLE_OBJS)) USER_OBJS := $(foreach file,$(USER_OBJS),$(obj)/$(file)) $(USER_OBJS:.o=.%): \ - c_flags = -Wp,-MD,$(depfile) $(USER_CFLAGS) -include $(srctree)/include/linux/kern_levels.h -include user.h $(CFLAGS_$(basetarget).o) + c_flags = -Wp,-MD,$(depfile) $(USER_CFLAGS) $(CFLAGS_$(basetarget).o) # These are like USER_OBJS but filter USER_CFLAGS through unprofile instead of # using it directly.
arch/x86/um/Makefile +4 -2
@@ -38,8 +38,10 @@ subarch-$(CONFIG_MODULES) += ../kernel/module.o USER_OBJS := bugs_$(BITS).o ptrace_user.o fault.o -$(obj)/user-offsets.s: c_flags = -Wp,-MD,$(depfile) $(USER_CFLAGS) \ - -Iarch/x86/include/generated +$(obj)/user-offsets.s: c_flags = -Wp,-MD,$(depfile) $(USER_CFLAGS) \ + -Iarch/x86/include/generated \ + -include $(srctree)/include/linux/kbuild.h + targets += user-offsets.s include/generated/user_constants.h: $(obj)/user-offsets.s FORCE
arch/x86/um/user-offsets.c +0 -1
@@ -8,7 +8,6 @@#define __FRAME_OFFSETS#include <linux/ptrace.h> #include <asm/types.h> -#include <linux/kbuild.h> #define DEFINE_LONGS (sym, val) \ COMMENT(#val " / sizeof(unsigned long)"); \
Signature · 1 line
2.51.0
PATCH v3 3/12 tools/nolibc/stdio: let perror work when NOLIBC_IGNORE_ERRNO is set
In reply to Benjamin BergFrom: Benjamin Berg <[email protected]>
There is no errno variable when NOLIBC_IGNORE_ERRNO is defined. As such, simply print the message with "unknown error" rather than the integer value of errno.
---
v3:
- Change the message instead of removing perror entirely
--- tools/include/nolibc/stdio.h | 4 ++++ 1 file changed, 4 insertions(+)
tools/include/nolibc/stdio.h +4 -0
@@ -600,7 +600,11 @@ int sscanf(const char *str, const char *format, ...)static __attribute__((unused))void perror (const char *msg) { +#ifdef NOLIBC_IGNORE_ERRNO +fprintf (stderr,"%s%sunknown error\n" , (msg && *msg) ? msg :"" , (msg && *msg) ?": " :"" ); +#else fprintf (stderr,"%s%serrno=%d\n" , (msg && *msg) ? msg :"" , (msg && *msg) ?": " :"" , errno); +#endif } static __attribute__((unused))
Signature · 1 line
2.51.0
Re: [PATCH v3 03/12] tools/nolibc/stdio: let perror work when NOLIBC_IGNORE_ERRNO is set
Quoted 8 lines · Benjamin Berg
From: Benjamin Berg <[email protected]>
There is no errno variable when
NOLIBC_IGNORE_ERRNOis defined. As such, simply print the message with "unknown error" rather than the integer value of errno.Fixes acab7bcdb1bc ("tools/nolibc/stdio: add perror() to report the errno value")Signed-off-by Benjamin Berg <[email protected]>
Quoted 27 lines
---
v3:
- Change the message instead of removing perror entirely--- tools/include/nolibc/stdio.h | 4 ++++ 1 file changed, 4 insertions(+)tools/include/nolibc/stdio.h +4
-0@@ -600,7 +600,11 @@ int sscanf(const char *str, const char *format, ...)static __attribute__((unused))void perror (const char *msg) { +#ifdef NOLIBC_IGNORE_ERRNO +fprintf (stderr,"%s%sunknown error\n" , (msg && *msg) ? msg :"" , (msg && *msg) ?": " :"" ); +#else fprintf (stderr,"%s%serrno=%d\n" , (msg && *msg) ? msg :"" , (msg && *msg) ?": " :"" , errno); +#endif } static __attribute__((unused))Signature · 1 line
2.51.0
PATCH v3 4/12 tools/nolibc/dirent: avoid errno in readdir_r
In reply to Benjamin BergFrom: Benjamin Berg <[email protected]>
Using errno is not possible when NOLIBC_IGNORE_ERRNO is set. Use sys_lseek instead of lseek as that avoids using errno.
--- tools/include/nolibc/dirent.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/include/nolibc/dirent.h +3 -3
@@ -86,9 +86,9 @@ int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)* readdir() can only return one entry at a time. * Make sure the non-returned ones are not skipped. */ - ret =lseek (fd, ldir->d_off,SEEK_SET ); -if (ret ==-1 ) -return errno; + ret =sys_lseek (fd, ldir->d_off,SEEK_SET ); +if (ret <0 ) +return -ret; entry->d_ino = ldir->d_ino;/* the destination should always be big enough */
Signature · 1 line
2.51.0
PATCH v3 5/12 tools/nolibc: implement %m if errno is not defined
In reply to Benjamin BergFrom: Benjamin Berg <[email protected]>
For improved compatibility, print %m as "unknown error" when nolibc is compiled using NOLIBC_IGNORE_ERRNO.
--- tools/include/nolibc/stdio.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/include/nolibc/stdio.h +4 -2
@@ -321,11 +321,13 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const charif (!outstr) outstr="(null)" ; } -#ifndef NOLIBC_IGNORE_ERRNO else if (c =='m' ) { +#ifdef NOLIBC_IGNORE_ERRNO + outstr ="unknown error" ; +#else outstr =strerror (errno); - }#endif /* NOLIBC_IGNORE_ERRNO */ + }else if (c =='%' ) {/* queue it verbatim */ continue ;
Signature · 1 line
2.51.0
Re: [PATCH v3 05/12] tools/nolibc: implement %m if errno is not defined
Quoted 6 lines · Benjamin Berg
From: Benjamin Berg <[email protected]>
For improved compatibility, print %m as "unknown error" when nolibc is compiled using
NOLIBC_IGNORE_ERRNO.Signed-off-by Benjamin Berg <[email protected]>
Thanks for taking care of this.
Quoted 27 lines
--- tools/include/nolibc/stdio.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)tools/include/nolibc/stdio.h +4
-2@@ -321,11 +321,13 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const charif (!outstr) outstr="(null)" ; } -#ifndef NOLIBC_IGNORE_ERRNO else if (c =='m' ) { +#ifdef NOLIBC_IGNORE_ERRNO + outstr ="unknown error" ; +#else outstr =strerror (errno); - }#endif /* NOLIBC_IGNORE_ERRNO */ + }else if (c =='%' ) {/* queue it verbatim */ continue ;Signature · 1 line
2.51.0
PATCH v3 6/12 tools/nolibc: use __fallthrough__ rather than fallthrough
In reply to Benjamin BergFrom: Benjamin Berg <[email protected]>
Use the version of the attribute with underscores to avoid issues if fallthrough has been defined by another header file already.
--- tools/include/nolibc/compiler.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/include/nolibc/compiler.h +2 -2
@@ -41,8 +41,8 @@# define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))#endif /* __nolibc_has_attribute(no_stack_protector) */ -#if __nolibc_has_attribute (fallthrough) -# define __nolibc_fallthrough do { } while (0); __attribute__((fallthrough)) +#if __nolibc_has_attribute (__fallthrough__) +# define __nolibc_fallthrough do { } while (0); __attribute__((__fallthrough__))#else # define __nolibc_fallthrough do { } while (0)#endif /* __nolibc_has_attribute(fallthrough) */
Signature · 1 line
2.51.0
PATCH v3 7/12 tools/nolibc: add option to disable runtime
In reply to Benjamin BergFrom: Benjamin Berg <[email protected]>
In principle, it is possible to use nolibc for only some object files in a program. In that case, the startup code in _start and _start_c is not going to be used. Add the NOLIBC_NO_RUNTIME compile time option to disable it entirely and also remove anything that depends on it.
Doing this avoids warnings from modpost for UML as the _start_c code references the main function from the .init.text section while it is not inside .init itself.
---
v2:
- Renamed from NOLIBC_NO_STARTCODE to NOLIBC_NO_RUNTIME
- Put the #ifdef around relevant comments
--- tools/include/nolibc/arch-arm.h | 2 ++ tools/include/nolibc/arch-arm64.h | 2 ++ tools/include/nolibc/arch-loongarch.h | 2 ++ tools/include/nolibc/arch-m68k.h | 2 ++ tools/include/nolibc/arch-mips.h | 2 ++ tools/include/nolibc/arch-powerpc.h | 2 ++ tools/include/nolibc/arch-riscv.h | 2 ++ tools/include/nolibc/arch-s390.h | 2 ++ tools/include/nolibc/arch-sh.h | 2 ++ tools/include/nolibc/arch-sparc.h | 2 ++ tools/include/nolibc/arch-x86.h | 4 ++++ tools/include/nolibc/crt.h | 3 +++ tools/include/nolibc/stackprotector.h | 2 ++ tools/include/nolibc/stdlib.h | 2 ++ tools/include/nolibc/sys.h | 3 ++- tools/include/nolibc/sys/auxv.h | 3 +++ 16 files changed, 36 insertions(+), 1 deletion(-)
tools/include/nolibc/arch-arm.h +2 -0
@@ -184,6 +184,7 @@ _arg1; \ }) +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) {
@@ -193,5 +194,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s );__nolibc_entrypoint_epilogue (); } +#endif /* NOLIBC_NO_RUNTIME */ #endif /* _NOLIBC_ARCH_ARM_H */
tools/include/nolibc/arch-arm64.h +2 -0
@@ -141,6 +141,7 @@ _arg1; \ }) +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) {
@@ -150,4 +151,5 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s );__nolibc_entrypoint_epilogue (); } +#endif /* NOLIBC_NO_RUNTIME */ #endif /* _NOLIBC_ARCH_ARM64_H */
tools/include/nolibc/arch-loongarch.h +2 -0
@@ -142,6 +142,7 @@ _arg1; \ }) +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) {
@@ -151,5 +152,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s );__nolibc_entrypoint_epilogue (); } +#endif /* NOLIBC_NO_RUNTIME */ #endif /* _NOLIBC_ARCH_LOONGARCH_H */
tools/include/nolibc/arch-m68k.h +2 -0
@@ -128,6 +128,7 @@ _num; \ }) +#ifndef NOLIBC_NO_RUNTIME void _start (void ); void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) {
@@ -137,5 +138,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s );__nolibc_entrypoint_epilogue (); } +#endif /* NOLIBC_NO_RUNTIME */ #endif /* _NOLIBC_ARCH_M68K_H */
tools/include/nolibc/arch-mips.h +2 -0
@@ -245,6 +245,7 @@#endif /* _ABIO32 */ +#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)
@@ -266,5 +267,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector __ );__nolibc_entrypoint_epilogue (); } +#endif /* NOLIBC_NO_RUNTIME */ #endif /* _NOLIBC_ARCH_MIPS_H */
tools/include/nolibc/arch-powerpc.h +2 -0
@@ -183,6 +183,7 @@#endif #endif /* !__powerpc64__ */ +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) {
@@ -215,5 +216,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s#endif __nolibc_entrypoint_epilogue (); } +#endif /* NOLIBC_NO_RUNTIME */ #endif /* _NOLIBC_ARCH_POWERPC_H */
tools/include/nolibc/arch-riscv.h +2 -0
@@ -139,6 +139,7 @@ _arg1; \ }) +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) {
@@ -152,5 +153,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s );__nolibc_entrypoint_epilogue (); } +#endif /* NOLIBC_NO_RUNTIME */ #endif /* _NOLIBC_ARCH_RISCV_H */
tools/include/nolibc/arch-s390.h +2 -0
@@ -139,6 +139,7 @@ _arg1; \ }) +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) {
@@ -155,6 +156,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s );__nolibc_entrypoint_epilogue (); } +#endif /* NOLIBC_NO_RUNTIME */ struct s390_mmap_arg_struct {unsigned long addr;
tools/include/nolibc/arch-sh.h +2 -0
@@ -140,6 +140,7 @@ _ret; \ }) +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void _start_wrapper (void ); void __attribute__((weak,noreturn)) __nolibc_entrypoint __no_stack_protector _start_wrapper(void)
@@ -158,5 +159,6 @@ void __attribute__((weak,noreturn)) __nolibc_entrypoint __no_stack_protector _st );__nolibc_entrypoint_epilogue (); } +#endif /* NOLIBC_NO_RUNTIME */ #endif /* _NOLIBC_ARCH_SH_H */
tools/include/nolibc/arch-sparc.h +2 -0
@@ -152,6 +152,7 @@ _arg1; \ }) +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) {
@@ -169,6 +170,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s ); __nolibc_entrypoint_epilogue(); } +#endif /* NOLIBC_NO_RUNTIME */ static pid_t getpid (void );
tools/include/nolibc/arch-x86.h +4 -0
@@ -157,6 +157,7 @@ _eax; \ }) +#ifndef NOLIBC_NO_RUNTIME /* startup code */ /* * i386 System V ABI mandates:
@@ -176,6 +177,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s ); __nolibc_entrypoint_epilogue(); } +#endif /* NOLIBC_NO_RUNTIME */ #else /* !defined(__x86_64__) */
@@ -323,6 +325,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s _ret; \ }) +#ifndef NOLIBC_NO_RUNTIME /* startup code */ /* * x86-64 System V ABI mandates:
@@ -340,6 +343,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s ); __nolibc_entrypoint_epilogue(); } +#endif /* NOLIBC_NO_RUNTIME */ #define NOLIBC_ARCH_HAS_MEMMOVE void *memmove (void *dst,const void *src,size_t len);
tools/include/nolibc/crt.h +3 -0
@@ -7,6 +7,8 @@#ifndef _NOLIBC_CRT_H#define _NOLIBC_CRT_H +#ifndef NOLIBC_NO_RUNTIME +#include "compiler.h" char **environ __attribute__((weak));
@@ -88,4 +90,5 @@ void _start_c(long *sp)exit (exitcode); } +#endif /* NOLIBC_NO_RUNTIME */ #endif /* _NOLIBC_CRT_H */
tools/include/nolibc/stackprotector.h +2 -0
@@ -9,6 +9,7 @@#include "compiler.h" +#ifndef NOLIBC_NO_RUNTIME #if defined(_NOLIBC_STACKPROTECTOR)#include "sys.h"
@@ -49,5 +50,6 @@ static __no_stack_protector void __stack_chk_init(void)#else /* !defined(_NOLIBC_STACKPROTECTOR) */ static void __stack_chk_init (void ) {}#endif /* defined(_NOLIBC_STACKPROTECTOR) */ +#endif /* NOLIBC_NO_RUNTIME */ #endif /* _NOLIBC_STACKPROTECTOR_H */
tools/include/nolibc/stdlib.h +2 -0
@@ -100,6 +100,7 @@ void free(void *ptr)munmap (heap, heap->len); } +#ifndef NOLIBC_NO_RUNTIME /* getenv() tries to find the environment variable named <name> in the * environment array pointed to by global variable "environ" which must be * declared as a char **, and must be terminated by a NULL (it is recommended
@@ -122,6 +123,7 @@ char *getenv(const char *name) }return NULL ; } +#endif /* NOLIBC_NO_RUNTIME */ static __attribute__((unused))void *malloc (size_t len)
tools/include/nolibc/sys.h +2 -1
@@ -509,6 +509,7 @@ pid_t gettid(void)return sys_gettid (); } +#ifndef NOLIBC_NO_RUNTIME static unsigned long getauxval (unsigned long key);/*
@@ -520,7 +521,7 @@ int getpagesize(void) {return __sysret ((int )getauxval (AT_PAGESZ ) ?: -ENOENT ); } - +#endif /* NOLIBC_NO_RUNTIME */ /* * uid_t getuid(void);
tools/include/nolibc/sys/auxv.h +3 -0
@@ -10,6 +10,8 @@#ifndef _NOLIBC_SYS_AUXV_H#define _NOLIBC_SYS_AUXV_H +#ifndef NOLIBC_NO_RUNTIME +#include "../crt.h" static __attribute__((unused))
@@ -38,4 +40,5 @@ unsigned long getauxval(unsigned long type)return ret; } +#endif /* NOLIBC_NO_RUNTIME */ #endif /* _NOLIBC_SYS_AUXV_H */
Signature · 1 line
2.51.0
PATCH v3 8/12 um: add infrastructure to build files using nolibc
In reply to Benjamin BergFrom: Benjamin Berg <[email protected]>
Add NOLIBC_CFLAGS and NOLIBC_OBJS to build files against nolibc rather than libc. With this it is possible to move to nolibc in smaller steps.
Set NOLIBC_IGNORE_ERRNO, as the nolibc errno implementation is overly simple and cannot handle threading. nolibc provides sys_* functions that do not emulate the libc errno behaviour and can be used instead.
Leave the syscall definition for kernel code for now, but guard it as it is a macro in nolibc.
---
v3:
- Change the syscall guard to use __KERNEL__
v2:
- Do not include nolibc.h via CFLAGS
- Make syscall guard more explicit
- Remove __UM_NOLIBC__ define, it is not needed
- Fix out-of-tree building
--- arch/um/Makefile | 20 +++++++++++++++++++- arch/um/include/shared/os.h | 2 ++ arch/um/include/shared/user.h | 1 - arch/um/scripts/Makefile.rules | 8 +++++++- 4 files changed, 28 insertions(+), 3 deletions(-)
arch/um/Makefile +19 -1
@@ -78,6 +78,24 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \ -include $(srctree)/include/linux/kern_levels.h \ -include $(srctree)/$(ARCH_DIR)/include/shared/user.h +NOLIBC_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \ + $(ARCH_INCLUDE) $(MODE_INCLUDE) $(filter -I%,$(CFLAGS)) \ + -I $(srctree)/tools/include \ + -D__EXPORTED_HEADERS__ \ + -D__UM_HOST__ \ + -DNOLIBC_NO_RUNTIME \ + -DNOLIBC_IGNORE_ERRNO \ + -nostdlib -nostdinc -static \ + -I$(srctree)/include/uapi \ + -I$(srctree)/$(HOST_DIR)/include/uapi \ + -I$(objtree)/$(HOST_DIR)/include/generated/uapi \ + -I $(srctree)/tools/include/nolibc \ + -I $(srctree)/usr/include \ + -include $(objtree)/include/generated/autoconf.h \ + -include $(srctree)/tools/include/linux/kconfig.h \ + -include $(srctree)/include/linux/kern_levels.h \ + -include $(srctree)/$(ARCH_DIR)/include/shared/user.h + #This will adjust *FLAGS accordingly to the platform. include $(srctree)/$(ARCH_DIR)/Makefile-os-Linux
@@ -160,4 +178,4 @@ archclean: -o -name '*.gcov' \) -type f -print | xargs rm -f $(Q)$(MAKE) -f $(srctree)/Makefile ARCH=$(HEADER_ARCH) clean -export HEADER_ARCH SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING DEV_NULL_PATH +export HEADER_ARCH SUBARCH USER_CFLAGS NOLIBC_CFLAGS CFLAGS_NO_HARDENING DEV_NULL_PATH
arch/um/include/shared/os.h +2 -0
@@ -327,7 +327,9 @@ extern int __ignore_sigio_fd(int fd);/* tty.c */ extern int get_pty (void ); +#ifdef __KERNEL__long syscall (long number, ...); +#endif /* irqflags tracing */ extern void block_signals_trace (void );
arch/um/include/shared/user.h +0 -1
@@ -16,7 +16,6 @@*/ #define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0])) -#include <linux/types.h> #include <stddef.h> extern void panic (const char *fmt, ...)
arch/um/scripts/Makefile.rules +7 -1
@@ -11,6 +11,12 @@ USER_OBJS := $(foreach file,$(USER_OBJS),$(obj)/$(file)) $(USER_OBJS:.o=.%): \ c_flags = -Wp,-MD,$(depfile) $(USER_CFLAGS) $(CFLAGS_$(basetarget).o) +# Similar USER_OBJS but compiled against nolibc (may include kernel headers?) +NOLIBC_OBJS := $(foreach file,$(NOLIBC_OBJS),$(obj)/$(file)) + +$(NOLIBC_OBJS:.o=.%): \ + c_flags = -Wp,-MD,$(depfile) $(NOLIBC_CFLAGS) $(CFLAGS_$(basetarget).o) + # These are like USER_OBJS but filter USER_CFLAGS through unprofile instead of # using it directly. UNPROFILE_OBJS := $(foreach file,$(UNPROFILE_OBJS),$(obj)/$(file))
@@ -18,7 +24,7 @@ UNPROFILE_OBJS := $(foreach file,$(UNPROFILE_OBJS),$(obj)/$(file)) $(UNPROFILE_OBJS:.o=.%): \ c_flags = -Wp,-MD,$(depfile) $(call unprofile,$(USER_CFLAGS)) $(CFLAGS_$(basetarget).o) -$(USER_OBJS) $(UNPROFILE_OBJS): \ +$(USER_OBJS) $(NOLIBC_OBJS) $(UNPROFILE_OBJS): \ CHECKFLAGS := $(patsubst $(NOSTDINC_FLAGS),,$(CHECKFLAGS)) # The stubs can't try to call mcount or update basic block data
Signature · 1 line
2.51.0
Thomas Weißschuh
maintainerRe: [PATCH v3 08/12] um: add infrastructure to build files using nolibc
Quoted 41 lines · Benjamin Berg
From: Benjamin Berg <[email protected]>
Add
NOLIBC_CFLAGSandNOLIBC_OBJSto build files against nolibc rather than libc. With this it is possible to move to nolibc in smaller steps.Set
NOLIBC_IGNORE_ERRNO, as the nolibc errno implementation is overly simple and cannot handle threading. nolibc provides sys_* functions that do not emulate the libc errno behaviour and can be used instead.Leave the syscall definition for kernel code for now, but guard it as it is a macro in nolibc.
Signed-off-by Benjamin Berg <[email protected]>---
v3:
- Change the syscall guard to use__KERNEL__v2:
- Do not includenolibc.hvia CFLAGS
- Make syscall guard more explicit
- Remove__UM_NOLIBC__define, it is not needed
- Fix out-of-tree building--- arch/um/Makefile | 20 +++++++++++++++++++- arch/um/include/shared/os.h | 2 ++ arch/um/include/shared/user.h | 1 - arch/um/scripts/Makefile.rules | 8 +++++++- 4 files changed, 28 insertions(+), 3 deletions(-)arch/um/Makefile +3
-0@@ -78,6 +78,24 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \ -include $(srctree)/include/linux/kern_levels.h \ -include $(srctree)/$(ARCH_DIR)/include/shared/user.h +NOLIBC_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \ + $(ARCH_INCLUDE) $(MODE_INCLUDE) $(filter -I%,$(CFLAGS)) \ + -I $(srctree)/tools/include \
arch/um/Makefile USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \ · line 93
Quoted 10 lines
arch/um/Makefile +10
-0+ -D__EXPORTED_HEADERS__ \ + -D__UM_HOST__ \ + -DNOLIBC_NO_RUNTIME \ + -DNOLIBC_IGNORE_ERRNO \ + -nostdlib -nostdinc -static \ + -I$(srctree)/include/uapi \ + -I$(srctree)/$(HOST_DIR)/include/uapi \ + -I$(objtree)/$(HOST_DIR)/include/generated/uapi \ + -I $(srctree)/tools/include/nolibc \ + -I $(srctree)/usr/include \
This looks incorrect. The UAPI headers would be installed to $(objtree). But UML does not even use CONFIG_HEADERS_INSTALL.
Also the whitespace is inconsistent between different lines.
Quoted 14 lines
arch/um/Makefile +6
-1+ -include $(objtree)/include/generated/autoconf.h \ + -include $(srctree)/tools/include/linux/kconfig.h \ + -include $(srctree)/include/linux/kern_levels.h \ + -include $(srctree)/$(ARCH_DIR)/include/shared/user.h + #This will adjust *FLAGS accordingly to the platform. include $(srctree)/$(ARCH_DIR)/Makefile-os-Linux@@ -160,4 +178,4 @@ archclean: -o -name '*.gcov' \) -type f -print | xargs rm -f $(Q)$(MAKE) -f $(srctree)/Makefile ARCH=$(HEADER_ARCH) clean -export HEADER_ARCH SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING DEV_NULL_PATH +export HEADER_ARCH SUBARCH USER_CFLAGS NOLIBC_CFLAGS CFLAGS_NO_HARDENING DEV_NULL_PATH
(...)
PATCH v3 9/12 um: use nolibc for the --showconfig implementation
In reply to Benjamin BergFrom: Benjamin Berg <[email protected]>
This is one of the simplest files and it can be switched over to use nolibc without any modifications.
--- arch/um/kernel/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/um/kernel/Makefile +1 -1
@@ -26,7 +26,7 @@ obj-$(CONFIG_OF) += dtb.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-$(CONFIG_STACKTRACE) += stacktrace.o -USER_OBJS := config.o +NOLIBC_OBJS := config.o include $(srctree)/arch/um/scripts/Makefile.rules
Signature · 1 line
2.51.0
kernel test robot
build botRe: [PATCH v3 09/12] um: use nolibc for the --showconfig implementation
kernel test robot noticed the following build warnings:
Hi Benjamin,
kernel test robot noticed the following build warnings:
[auto build test WARNING on uml/next]
[also build test WARNING on uml/fixes shuah-kselftest/next shuah-kselftest/fixes linus/master v6.17-rc7 next-20250925] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Benjamin-Berg/tools-compiler-h-fix-__used-definition/20250924-222547 base: https://git.kernel.org/pub/scm/linux/kernel/git/uml/linux next patch link: https://lore.kernel.org/r/20250924142059.527768-10-benjamin%40sipsolutions.net patch subject: [PATCH v3 09/12] um: use nolibc for the --showconfig implementation
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: um-randconfig-r111-20250926 (https://download.01.org/0day-ci/archive/20250926/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250926/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/
sparse warnings: (new ones prefixed by >>)
command-line: note: in included file (through tools/include/nolibc/nolibc.h, tools/include/nolibc/stddef.h, arch/um/include/shared/user.h, builtin):
>> tools/include/nolibc/sys.h:109:29: sparse: sparse: Using plain integer as NULL pointer command-line: note: in included file (through tools/include/nolibc/nolibc.h, tools/include/nolibc/stddef.h, arch/um/include/shared/user.h, builtin): >> tools/include/nolibc/sys/reboot.h:31:16: sparse: sparse: Using plain integer as NULL pointer >> tools/include/nolibc/sys/reboot.h:31:16: sparse: sparse: Using plain integer as NULL pointer command-line: note: in included file (through tools/include/nolibc/nolibc.h, tools/include/nolibc/stddef.h, arch/um/include/shared/user.h, builtin): >> tools/include/nolibc/unistd.h:57:27: sparse: sparse: Using plain integer as NULL pointer tools/include/nolibc/unistd.h:57:30: sparse: sparse: Using plain integer as NULL pointer tools/include/nolibc/unistd.h:57:33: sparse: sparse: Using plain integer as NULL pointer tools/include/nolibc/unistd.h:70:27: sparse: sparse: Using plain integer as NULL pointer tools/include/nolibc/unistd.h:70:30: sparse: sparse: Using plain integer as NULL pointer tools/include/nolibc/unistd.h:70:33: sparse: sparse: Using plain integer as NULL pointer tools/include/nolibc/unistd.h:81:30: sparse: sparse: Using plain integer as NULL pointer tools/include/nolibc/unistd.h:81:33: sparse: sparse: Using plain integer as NULL pointer tools/include/nolibc/unistd.h:81:36: sparse: sparse: Using plain integer as NULL pointer command-line: note: in included file (through tools/include/nolibc/stdio.h, tools/include/nolibc/nolibc.h, tools/include/nolibc/stddef.h, ...): tools/include/nolibc/stdlib.h:56:6: sparse: sparse: symbol 'abort' redeclared with different type (different modifiers): tools/include/nolibc/stdlib.h:56:6: sparse: void extern [addressable] [noreturn] [toplevel] [unused] abort( ... ) tools/include/nolibc/stdlib.h:54:6: sparse: note: previously declared as: tools/include/nolibc/stdlib.h:54:6: sparse: void extern [addressable] [toplevel] abort( ... ) command-line: note: in included file (through tools/include/nolibc/nolibc.h, tools/include/nolibc/stddef.h, arch/um/include/shared/user.h, builtin): tools/include/nolibc/getopt.h:19:6: sparse: sparse: symbol 'optarg' was not declared. Should it be static? tools/include/nolibc/getopt.h:22:5: sparse: sparse: symbol 'optind' was not declared. Should it be static? tools/include/nolibc/getopt.h:22:17: sparse: sparse: symbol 'opterr' was not declared. Should it be static? tools/include/nolibc/getopt.h:22:29: sparse: sparse: symbol 'optopt' was not declared. Should it be static? >> tools/include/nolibc/getopt.h:81:26: sparse: sparse: Using plain integer as NULL pointer
vim +109 tools/include/nolibc/sys.h
bd8c8fbb866fe5 Willy Tarreau 2022-02-07 104
bd8c8fbb866fe5 Willy Tarreau 2022-02-07 105 static __attribute__((unused))
bd8c8fbb866fe5 Willy Tarreau 2022-02-07 106 void *sbrk(intptr_t inc)
bd8c8fbb866fe5 Willy Tarreau 2022-02-07 107 {
bd8c8fbb866fe5 Willy Tarreau 2022-02-07 108 /* first call to find current end */
4201cfce15fe35 Zhangjin Wu 2023-07-07 @109 void *ret = sys_brk(0);
4201cfce15fe35 Zhangjin Wu 2023-07-07 110
4201cfce15fe35 Zhangjin Wu 2023-07-07 111 if (ret && sys_brk(ret + inc) == ret + inc)
bd8c8fbb866fe5 Willy Tarreau 2022-02-07 112 return ret + inc;
bd8c8fbb866fe5 Willy Tarreau 2022-02-07 113
fb01ff635efd0a Willy Tarreau 2023-08-15 114 SET_ERRNO(ENOMEM);
fb01ff635efd0a Willy Tarreau 2023-08-15 115 return (void *)-1;
bd8c8fbb866fe5 Willy Tarreau 2022-02-07 116 }
bd8c8fbb866fe5 Willy Tarreau 2022-02-07 117 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Thomas Weißschuh
maintainerRe: [PATCH v3 09/12] um: use nolibc for the --showconfig implementation
Hi Benjamin,
Sep 26, 2025 15:57:43 kernel test robot <[email protected]>:
Quoted 23 lines
kernel test robot noticed the following build warnings:
[auto build test WARNING on uml/next]
[also build test WARNING on uml/fixes shuah-kselftest/next shuah-kselftest/fixes linus/master v6.17-rc7 next-20250925] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Benjamin-Berg/tools-compiler-h-fix-__used-definition/20250924-222547
base: https://git.kernel.org/pub/scm/linux/kernel/git/uml/linux next
patch link: https://lore.kernel.org/r/20250924142059.527768-10-benjamin%40sipsolutions.net
patch subject: [PATCH v3 09/12] um: use nolibc for the --showconfig implementation
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: um-randconfig-r111-20250926 (https://download.01.org/0day-ci/archive/20250926/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250926/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/
Quoted 5 lines
sparse warnings: (new ones prefixed by >>)
command-line: note: in included file (throughtools/include/nolibc/nolibc.h,tools/include/nolibc/stddef.h,arch/um/include/shared/user.h, builtin):Quoted 1 line
Quoted 1 line
tools/include/nolibc/sys.h:109:29: sparse: sparse: Using plain integer as NULL pointerunistd.h:70:30: sparse: sparse: Using plain integer as NULL pointer
tools/include/nolibc/unistd.h:70:33: sparse: sparse: Using plain integer as NULL pointer
Do you intend to work on your UML with nolibc patches this cycle?
If not I would fix these sparse warnings in the nolibc tree and also apply your nolibc patches.
Thomas
Re: [PATCH v3 09/12] um: use nolibc for the --showconfig implementation
Hi Thomas,
Quoted 46 lines · Thomas Weißschuh
Hi Benjamin,
Sep 26, 2025 15:57:43 kernel test robot <[email protected]>:
Quoted 42 lines
kernel test robot noticed the following build warnings:
[auto build test WARNING on uml/next]
[also build test WARNING on uml/fixes shuah-kselftest/next shuah- kselftest/fixes linus/master v6.17-rc7 next-20250925] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url:
https://github.com/intel-lab-lkp/linux/commits/Benjamin-Berg/tools-compiler-h-fix-__used-definition/20250924-222547
base:
https://git.kernel.org/pub/scm/linux/kernel/git/uml/linux next
patch link:
https://lore.kernel.org/r/20250924142059.527768-10-benjamin%40sipsolutions.net
patch subject: [PATCH v3 09/12] um: use nolibc for the --showconfig implementation
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: um-randconfig-r111-20250926
(https://download.01.org/0day-ci/archive/20250926/202509261452.g5pe
[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build):
(https://download.01.org/0day-ci/archive/20250926/202509261452.g5pe
[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tagsQuoted 3 lines
Reported-by kernel test robot <[email protected]>sparse warnings: (new ones prefixed by >>)
command-line: note: in included file (throughtools/include/nolibc/nolibc.h,tools/include/nolibc/stddef.h,arch/um/include/shared/user.h, builtin):Quoted 2 lines
Quoted 2 lines
tools/include/nolibc/sys.h:109:29: sparse: sparse: Using plain integer as NULL pointer
Quoted 8 lines
Quoted 4 lines
unistd.h:70:30: sparse: sparse: Using plain integer as NULL pointer
tools/include/nolibc/unistd.h:70:33: sparse: sparse: Using plain integer as NULL pointerDo you intend to work on your UML with nolibc patches this cycle? If not I would fix these sparse warnings in the nolibc tree and also apply your nolibc patches.
We are not in a hurry for the UML part and while it shouldn't be too much work, I obviously didn't get around to it in the last week.
So, feel free to pull the patches in via your tree. Then I'll submit the UML part again in the next cycle.
Benjamin
PATCH v3 10/12 tools/nolibc: add uio.h with readv and writev
In reply to Benjamin BergFrom: Benjamin Berg <[email protected]>
This is generally useful and struct iovec is also needed for other purposes such as ptrace.
--- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/nolibc.h | 1 + tools/include/nolibc/sys/uio.h | 49 ++++++++++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 9 ++++ 4 files changed, 60 insertions(+) create mode 100644 tools/include/nolibc/sys/uio.h
tools/include/nolibc/Makefile +1 -0
@@ -62,6 +62,7 @@ all_files := \ sys/time.h \ sys/timerfd.h \ sys/types.h \ + sys/uio.h \ sys/utsname.h \ sys/wait.h \ time.h \
tools/include/nolibc/nolibc.h +1 -0
@@ -109,6 +109,7 @@#include "sys/sysmacros.h" #include "sys/time.h" #include "sys/timerfd.h" +#include "sys/uio.h" #include "sys/utsname.h" #include "sys/wait.h" #include "ctype.h"
tools/include/nolibc/sys/uio.h new file +49 -0
49 lines not on this page · raw message
tools/testing/selftests/nolibc/nolibc-test.c +9 -0
@@ -25,6 +25,7 @@#include <sys/sysmacros.h> #include <sys/time.h> #include <sys/timerfd.h> +#include <sys/uio.h> #include <sys/utsname.h> #include <sys/wait.h> #include <dirent.h>
@@ -1283,6 +1284,10 @@ int run_syscall(int min, int max)int proc;int test;int tmp; +struct iovec iov_one = { + .iov_base = &tmp, + .iov_len =1 , + };int ret =0 ;void *p1, *p2;int has_gettid =1 ;
@@ -1395,6 +1400,10 @@ int run_syscall(int min, int max)CASE_TEST (waitpid_child);EXPECT_SYSER (1 ,waitpid (getpid (), &tmp,WNOHANG ),-1 ,ECHILD );break ;CASE_TEST (write_badf);EXPECT_SYSER (1 ,write (-1 , &tmp,1 ),-1 ,EBADF );break ;CASE_TEST (write_zero);EXPECT_SYSZR (1 ,write (1 , &tmp,0 ));break ; +CASE_TEST (readv_badf);EXPECT_SYSER (1 ,readv (-1 , &iov_one,1 ),-1 ,EBADF );break ; +CASE_TEST (readv_zero);EXPECT_SYSZR (1 ,readv (1 ,NULL ,0 ));break ; +CASE_TEST (writev_badf);EXPECT_SYSER (1 ,writev (-1 , &iov_one,1 ),-1 ,EBADF );break ; +CASE_TEST (writev_zero);EXPECT_SYSZR (1 ,writev (1 ,NULL ,0 ));break ;CASE_TEST (syscall_noargs);EXPECT_SYSEQ (1 ,syscall (__NR_getpid),getpid ());break ;CASE_TEST (syscall_args);EXPECT_SYSER (1 ,syscall (__NR_statx,0 ,NULL ,0 ,0 ,NULL ),-1 ,EFAULT );break ;CASE_TEST (namespace);EXPECT_SYSZR (euid0 && proc,test_namespace ());break ;
Signature · 1 line
2.51.0
PATCH v3 11/12 tools/nolibc: add ptrace support
In reply to Benjamin BergFrom: Benjamin Berg <[email protected]>
Add ptrace support, as it will be useful in UML.
---
v3:
- Only use variardic for ptrace and not for sys_ptrace
--- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/nolibc.h | 1 + tools/include/nolibc/sys/ptrace.h | 44 ++++++++++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 2 + 4 files changed, 48 insertions(+) create mode 100644 tools/include/nolibc/sys/ptrace.h
tools/include/nolibc/Makefile +1 -0
@@ -53,6 +53,7 @@ all_files := \ sys/mman.h \ sys/mount.h \ sys/prctl.h \ + sys/ptrace.h \ sys/random.h \ sys/reboot.h \ sys/resource.h \
tools/include/nolibc/nolibc.h +1 -0
@@ -101,6 +101,7 @@#include "sys/mman.h" #include "sys/mount.h" #include "sys/prctl.h" +#include "sys/ptrace.h" #include "sys/random.h" #include "sys/reboot.h" #include "sys/resource.h"
tools/include/nolibc/sys/ptrace.h new file +44 -0
44 lines not on this page · raw message
tools/testing/selftests/nolibc/nolibc-test.c +2 -0
@@ -17,6 +17,7 @@#include <sys/mman.h> #include <sys/mount.h> #include <sys/prctl.h> +#include <sys/ptrace.h> #include <sys/random.h> #include <sys/reboot.h> #include <sys/resource.h>
@@ -1404,6 +1405,7 @@ int run_syscall(int min, int max)CASE_TEST (readv_zero);EXPECT_SYSZR (1 ,readv (1 ,NULL ,0 ));break ;CASE_TEST (writev_badf);EXPECT_SYSER (1 ,writev (-1 , &iov_one,1 ),-1 ,EBADF );break ;CASE_TEST (writev_zero);EXPECT_SYSZR (1 ,writev (1 ,NULL ,0 ));break ; +CASE_TEST (ptrace);EXPECT_SYSER (1 ,ptrace (PTRACE_CONT ,getpid (),NULL ,NULL ),-1 ,ESRCH );break ;CASE_TEST (syscall_noargs);EXPECT_SYSEQ (1 ,syscall (__NR_getpid),getpid ());break ;CASE_TEST (syscall_args);EXPECT_SYSER (1 ,syscall (__NR_statx,0 ,NULL ,0 ,0 ,NULL ),-1 ,EFAULT );break ;CASE_TEST (namespace);EXPECT_SYSZR (euid0 && proc,test_namespace ());break ;
Signature · 1 line
2.51.0
Thomas Weißschuh
maintainerRe: [PATCH v3 11/12] tools/nolibc: add ptrace support
Quoted 16 lines · Benjamin Berg
From: Benjamin Berg <[email protected]>
Add ptrace support, as it will be useful in UML.
Signed-off-by Benjamin Berg <[email protected]>---
v3:
- Only use variardic for ptrace and not forsys_ptrace--- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/nolibc.h | 1 + tools/include/nolibc/sys/ptrace.h | 44 ++++++++++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 2 + 4 files changed, 48 insertions(+) create mode 100644 tools/include/nolibc/sys/ptrace.h
(...)
Quoted 35 lines
tools/include/nolibc/sys/ptrace.h new file +29
-0@@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* ptrace for NOLIBC +* Copyright (C) 2017-2021 Willy Tarreau <[email protected]> +* Copyright (C) 2025 Intel Corporation +*/ + +/* make sure to include all global symbols */ +#include "../nolibc.h" + +#ifndef _NOLIBC_SYS_PTRACE_H +#define _NOLIBC_SYS_PTRACE_H + +#include "../sys.h" +#include "uio.h" + + +#include <linux/ptrace.h> + +/* +* long ptrace(int op, pid_t pid, void *addr, void *data); +*/ +static __attribute__((unused)) +long sys_ptrace (int op,pid_t pid,void *addr,void *data) +{ +return my_syscall4 (__NR_ptrace, op, pid, addr, data); +} + +static __attribute__((unused))
tools/include/nolibc/sys/ptrace.h line 39
Quoted 10 lines
tools/include/nolibc/sys/ptrace.h new file +10
-0+ssize_t ptrace (int op,pid_t pid, ...) +{ +ssize_t ret; +va_list args; + +va_start (args, pid); + ret =__sysret (sys_ptrace (op, pid, + va_arg(args, void *), + va_arg(args, void *))); +va_end (args);
My understanding of the last discussion was not to use varargs here either. Instead I wanted to stick to the prototype from the manpage.
Quoted 5 lines
tools/include/nolibc/sys/ptrace.h new file +5
-0+ + return ret; +} + +#endif /* _NOLIBC_SYS_PTRACE_H */
(...)
PATCH v3 12/12 um: switch ptrace FP register access to nolibc
In reply to Benjamin BergFrom: Benjamin Berg <[email protected]>
The registers.c file only contains the routines for floating point register access in ptrace mode and initial size detection. After the addition of sys/uio.h and sys/ptrace.h to nolibc it can be moved to use it by using the sys_ptrace() wrapper.
---
v3:
- Cast argument to (void *)
- Remove unused sys/user.h include which does not exist in nolibc
v2:
- Use new sys_ptrace from nolibc
--- arch/x86/um/os-Linux/Makefile | 5 ++++- arch/x86/um/os-Linux/registers.c | 20 +++++--------------- 2 files changed, 9 insertions(+), 16 deletions(-)
arch/x86/um/os-Linux/Makefile +4 -1
@@ -3,10 +3,13 @@ # Licensed under the GPL # -obj-y = registers.o mcontext.o +obj-y = mcontext.o obj-$(CONFIG_X86_32) += tls.o USER_OBJS := $(obj-y) +obj-y += registers.o +NOLIBC_OBJS := registers.o + include $(srctree)/arch/um/scripts/Makefile.rules
arch/x86/um/os-Linux/registers.c +5 -15
@@ -7,9 +7,6 @@#include <errno.h> #include <stdlib.h> #include <sys/ptrace.h> -#ifdef __i386__ -#include <sys/user.h> -#endif #include <longjmp.h> #include <sysdep/ptrace_user.h> #include <sys/uio.h>
@@ -28,9 +25,7 @@ int get_fp_registers(int pid, unsigned long *regs) .iov_len = host_fp_size, }; -if (ptrace (PTRACE_GETREGSET , pid, ptrace_regset, &iov) <0 ) -return -errno; -return 0 ; +return sys_ptrace (PTRACE_GETREGSET , pid, (void *)ptrace_regset, &iov); }int put_fp_registers (int pid,unsigned long *regs)
@@ -40,9 +35,7 @@ int put_fp_registers(int pid, unsigned long *regs) .iov_len = host_fp_size, }; -if (ptrace (PTRACE_SETREGSET , pid, ptrace_regset, &iov) <0 ) -return -errno; -return 0 ; +return sys_ptrace (PTRACE_SETREGSET , pid, (void *)ptrace_regset, &iov); }int arch_init_registers (int pid)
@@ -60,9 +53,7 @@ int arch_init_registers(int pid)/* GDB has x86_xsave_length, which uses x86_cpuid_count */ ptrace_regset =NT_X86_XSTATE ; - ret =ptrace (PTRACE_GETREGSET , pid, ptrace_regset, &iov); -if (ret) - ret = -errno; + ret =sys_ptrace (PTRACE_GETREGSET , pid, (void *)ptrace_regset, &iov);if (ret == -ENODEV ) {#ifdef CONFIG_X86_32
@@ -71,9 +62,8 @@ int arch_init_registers(int pid) ptrace_regset =NT_PRFPREG ;#endif iov.iov_len =2 *1024 *1024 ; - ret =ptrace (PTRACE_GETREGSET , pid, ptrace_regset, &iov); -if (ret) - ret = -errno; + ret =sys_ptrace (PTRACE_GETREGSET , pid, + (void *)ptrace_regset, &iov); }munmap (iov.iov_base,2 *1024 *1024 );
Signature · 1 line
2.51.0