From nobody Thu Oct 2 00:49:26 2025 Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CC8435957; Wed, 24 Sep 2025 14:21:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723715; cv=none; b=gqs4f/MrjxsuhXins44zx/Dy/NrU24ispF8nQ3I08nPgRtZUqTNdMUTOb+IJxISAF3KmhetCX5minEDzdswDmuK+QOE7yvnb5LphYAqu82DvkRceU4EtsWkNR+1NQjilIK7iDQwgii/Tmm6Lb+qUKQ4gDHxUN+C79adoswtd04A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723715; c=relaxed/simple; bh=OnThKVkAxTbvu2cs4FLMAMZ+dEhCwYFgliP6EBhRpLM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hBy8o1l3TglhfeCzY7kFopky296+vupGLQCK3giYnJprfnIuWWfQMJlEDKRaMzWjnI/DNKaSbXJnv7lNeTKvuLwBNp+4s6E2+bpQV1j7/h2pnPjoG/10f9SJnMrqmspQg/MFCVLpXOw9gzucjwlKi39SqmvUkZeA0ELMMP2ri34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=Ttlpp2+r; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="Ttlpp2+r" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=w0zvkyHycNf62ji7JboPNe59KMTBMZPeiYVTw++Mcio=; t=1758723713; x=1759933313; b=Ttlpp2+rDDtU1UIjZZ4aTRH9guCEs5a09nfPhM+5G1A7CHP tYdxOpg/rfr8jzd6IgT9YNBMLdxjomqTvqHi/xZCNSUwCqaGGK3IGTE9Mfs/7njPk7VPW0wmnhrk0 IjzCiMGNlYdTIrEHcel05kwMbvQnwetfmumidHLeXc6NTdbpwJd5U7XoHiKVu3tSTqJMTRher9DfT HDSYZcymn8ShIyH4qGZkA95aEGc1LWN30VklWrm4qfx+XlsRkX7i3rJnZMWQWQmVIR8US1XeF7q19 sCggR8yJurxVyZkvBBE6mhZw2UwZqIwJ0DZUC0IKHa4RYKCjDi6cQCek8Evn3XOw==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1v1QNQ-000000090Bz-3BPc; Wed, 24 Sep 2025 16:21:49 +0200 From: Benjamin Berg To: linux-um@lists.infradead.org, Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kselftest@vger.kernel.org, Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Benjamin Berg Subject: [PATCH v3 01/12] tools compiler.h: fix __used definition Date: Wed, 24 Sep 2025 16:20:48 +0200 Message-ID: <20250924142059.527768-2-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250924142059.527768-1-benjamin@sipsolutions.net> References: <20250924142059.527768-1-benjamin@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-malware-bazaar: not-scanned From: Benjamin Berg 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. Fixes: e58e871becec ("tools/lib/lockdep: Remove private kernel headers") Signed-off-by: Benjamin Berg Reviewed-by: Thomas Wei=C3=9Fschuh --- tools/include/linux/compiler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h index 33411ca0cc90..b2c40621d441 100644 --- a/tools/include/linux/compiler.h +++ b/tools/include/linux/compiler.h @@ -127,7 +127,7 @@ #endif =20 #ifndef __used -# define __used __attribute__((__unused__)) +# define __used __attribute__((__used__)) #endif =20 #ifndef __packed --=20 2.51.0 From nobody Thu Oct 2 00:49:26 2025 Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 172E0305946; Wed, 24 Sep 2025 14:21:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723715; cv=none; b=sQ5vGgEb+6ZbxQ86/0RMYyOvu3pKLhEOqlPoAhF8FkzhVMRDaYrsjuH3ohots7j6Nxcs58SlmCQ+91YBoHUIBK8XITrAAxkn3/j9WYJ9M/k9kj5TscmYOaWeZFt2X4+trggfuuQOLT31thkt57zvzWDIxprTPcjGtFgTU59Qfso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723715; c=relaxed/simple; bh=wcLrD0WS5YjvvCsdm8gr/2mkmWKC74LSIzDcH4K3Lmw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PhzunPocXuJqRyMsbUEpXvNnIV323tO/EHjhp4VL4MF7gIi6w+gmK/FN3DiFEwHq64ALv4/95Zx/E0HAtWVTyfm17Jrm3QY4iwRLcizJrifDpxiKSQ7teiN5a/IGhA/kSbwMJvdfpT+kLCWVp+a5ADQRQDbMCtw0Ox0GL7Gy2Yk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=feSh+1pl; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="feSh+1pl" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=XKawjy2bKBrQJPdin7KqQUscEYPsaoP0832vtVrwP/Q=; t=1758723714; x=1759933314; b=feSh+1plSjYTRVJYJU2w9WYP9whRtHMI2oBIWwpeL1VILTI /Rl7hQGgZjeeYqNyH+Dagg627NAzPwCnk7dSlCkvr96NbEpy9ANdAiDonAKEbdqgWpvkKzP2lnLly nPnkDOYuuWDXrdhBFcXbsZbvMPlt24/pMbuC96ZTb+ukFfIknVeAUUSv2MxhRP8tJhCOmXnBDoSML loHbd5Q8z6Hdv3gbie4hB8GbMDN9RWUwu626DKnjwe9LJ0JhDoPKvqBJeguwIEL+jdrtweTGogiNA vWJm4mmrTLHT7wWZPVTKpFFqVP6Q6FlKPF4ibqWmP0DJNERyzXxx2hVdFXaSdrTQ==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1v1QNR-000000090Bz-32AA; Wed, 24 Sep 2025 16:21:50 +0200 From: Benjamin Berg To: linux-um@lists.infradead.org, Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kselftest@vger.kernel.org, Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Benjamin Berg Subject: [PATCH v3 02/12] um: use tools/include for user files Date: Wed, 24 Sep 2025 16:20:49 +0200 Message-ID: <20250924142059.527768-3-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250924142059.527768-1-benjamin@sipsolutions.net> References: <20250924142059.527768-1-benjamin@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Benjamin Berg 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. Signed-off-by: Benjamin Berg --- 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(-) diff --git a/arch/um/Makefile b/arch/um/Makefile index 7be0143b5ba3..f7c509262568 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -42,7 +42,7 @@ include $(srctree)/$(HOST_DIR)/Makefile.um core-y +=3D $(HOST_DIR)/um/ =20 SHARED_HEADERS :=3D $(ARCH_DIR)/include/shared -ARCH_INCLUDE :=3D -I$(srctree)/$(SHARED_HEADERS) +ARCH_INCLUDE :=3D -I$(srctree)/$(SHARED_HEADERS) -I$(objtree)/$(SHARED_HEA= DERS) ARCH_INCLUDE +=3D -I$(srctree)/$(HOST_DIR)/um/shared KBUILD_CPPFLAGS +=3D -I$(srctree)/$(HOST_DIR)/um =20 @@ -70,10 +70,13 @@ KBUILD_AFLAGS +=3D $(ARCH_INCLUDE) =20 USER_CFLAGS =3D $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFL= AGS))) \ $(ARCH_INCLUDE) $(MODE_INCLUDE) $(filter -I%,$(CFLAGS)) \ - -D_FILE_OFFSET_BITS=3D64 -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 =20 #This will adjust *FLAGS accordingly to the platform. include $(srctree)/$(ARCH_DIR)/Makefile-os-Linux @@ -116,6 +119,9 @@ archheaders: =20 archprepare: $(Q)$(MAKE) $(build)=3D$(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)/inc= lude/shared/generated/ =20 LINK-$(CONFIG_LD_SCRIPT_STATIC) +=3D -static LINK-$(CONFIG_LD_SCRIPT_DYN) +=3D -no-pie @@ -147,7 +153,7 @@ export CFLAGS_vmlinux :=3D $(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 +=3D linux x.i gmon.out -MRPROPER_FILES +=3D $(HOST_DIR)/include/generated +MRPROPER_FILES +=3D $(HOST_DIR)/include/generated $(ARCH_DIR)/include/shar= ed/generated =20 archclean: @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \ diff --git a/arch/um/include/shared/init.h b/arch/um/include/shared/init.h index 1a659e2e8cc3..d201705bedb3 100644 --- a/arch/um/include/shared/init.h +++ b/arch/um/include/shared/init.h @@ -41,7 +41,7 @@ typedef int (*initcall_t)(void); typedef void (*exitcall_t)(void); =20 -#include +#define __section(section) __attribute__((__section__(section))) =20 /* These are for everybody (although not all archs will actually discard it in modules) */ diff --git a/arch/um/include/shared/user.h b/arch/um/include/shared/user.h index 139eb78a4767..c9b853e1282f 100644 --- a/arch/um/include/shared/user.h +++ b/arch/um/include/shared/user.h @@ -16,13 +16,8 @@ */ #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) =20 -/* This is to get size_t and NULL */ -#ifndef __UM_HOST__ #include -#else #include -#include -#endif =20 extern void panic(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); diff --git a/arch/um/kernel/skas/stub.c b/arch/um/kernel/skas/stub.c index 67cab46a602c..6c9bb1511ea2 100644 --- a/arch/um/kernel/skas/stub.c +++ b/arch/um/kernel/skas/stub.c @@ -5,6 +5,7 @@ =20 #include =20 +#include #include #include #include diff --git a/arch/um/kernel/skas/stub_exe.c b/arch/um/kernel/skas/stub_exe.c index cbafaa684e66..0563838c01d1 100644 --- a/arch/um/kernel/skas/stub_exe.c +++ b/arch/um/kernel/skas/stub_exe.c @@ -4,8 +4,8 @@ #include #include #include -#include -#include +#include +#include #include =20 void _start(void); diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/proces= s.c index 78f48fa9db8b..8ad7e863af97 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c @@ -29,9 +29,7 @@ #include #include #include -#include #include -#include #include "../internal.h" =20 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 r= unning, 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; =20 ret =3D syscall(__NR_futex, &data->futex, @@ -217,7 +215,7 @@ void wait_stub_done_seccomp(struct mm_id *mm_idp, int r= unning, int wait_sigsys) } } while (data->futex =3D=3D FUTEX_IN_CHILD); =20 - if (__READ_ONCE(mm_idp->pid) < 0) + if (READ_ONCE(mm_idp->pid) < 0) goto out_kill; =20 running =3D 0; diff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c index a827c2e01aa5..8971f4fdddab 100644 --- a/arch/um/os-Linux/start_up.c +++ b/arch/um/os-Linux/start_up.c @@ -28,8 +28,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/arch/um/scripts/Makefile.rules b/arch/um/scripts/Makefile.rules index a8b7d9dab0a6..b4a2e0058503 100644 --- a/arch/um/scripts/Makefile.rules +++ b/arch/um/scripts/Makefile.rules @@ -9,7 +9,7 @@ USER_OBJS +=3D $(filter %_user.o,$(obj-y) $(USER_SINGLE_OBJ= S)) USER_OBJS :=3D $(foreach file,$(USER_OBJS),$(obj)/$(file)) =20 $(USER_OBJS:.o=3D.%): \ - c_flags =3D -Wp,-MD,$(depfile) $(USER_CFLAGS) -include $(srctree)/include= /linux/kern_levels.h -include user.h $(CFLAGS_$(basetarget).o) + c_flags =3D -Wp,-MD,$(depfile) $(USER_CFLAGS) $(CFLAGS_$(basetarget).o) =20 # These are like USER_OBJS but filter USER_CFLAGS through unprofile instea= d of # using it directly. diff --git a/arch/x86/um/Makefile b/arch/x86/um/Makefile index b42c31cd2390..d8a120bace25 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -38,8 +38,10 @@ subarch-$(CONFIG_MODULES) +=3D ../kernel/module.o =20 USER_OBJS :=3D bugs_$(BITS).o ptrace_user.o fault.o =20 -$(obj)/user-offsets.s: c_flags =3D -Wp,-MD,$(depfile) $(USER_CFLAGS) \ - -Iarch/x86/include/generated +$(obj)/user-offsets.s: c_flags =3D -Wp,-MD,$(depfile) $(USER_CFLAGS) \ + -Iarch/x86/include/generated \ + -include $(srctree)/include/linux/kbuild.h + targets +=3D user-offsets.s =20 include/generated/user_constants.h: $(obj)/user-offsets.s FORCE diff --git a/arch/x86/um/user-offsets.c b/arch/x86/um/user-offsets.c index d6e1cd9956bf..74fc9763b76e 100644 --- a/arch/x86/um/user-offsets.c +++ b/arch/x86/um/user-offsets.c @@ -8,7 +8,6 @@ #define __FRAME_OFFSETS #include #include -#include =20 #define DEFINE_LONGS(sym, val) \ COMMENT(#val " / sizeof(unsigned long)"); \ --=20 2.51.0 From nobody Thu Oct 2 00:49:26 2025 Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EFBB3064A1; Wed, 24 Sep 2025 14:21:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723716; cv=none; b=Z4Z74M2/Aphmozc6uPyPhUjHLQ8d8+0Fua404uAKXUdfUH/8bsi+oU30tMEjtTMpgTZPLMupJrBaB4+MTn8s35GhLbE1xLxKHLdx5ZIhd9z8JkAkYZHnE2JLgpukERnc7JbwZCIlz8j+hpfsIo0w+TJT76nY+13yivuTQLgqMDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723716; c=relaxed/simple; bh=1IvQbjw8+XR1qV62teqrY+kea2Kmn19VdAe6m4o0g1E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZHGOt9GSn9iNwAps9kK/zeyWxtMkiNAYBP0RzsC7UFvO7x5tGENNODa12EG7qQbk8RcZ1dXssD7A9QAQJV9wo5+XgehzI0oe6v8nNml9M1160pd9yG25a9fYmtAG/d1QSkqPVp2eMYiSTUDLA2bA2RygPfA39FAKNBQTgtoKZxM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=PR9yPJiu; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="PR9yPJiu" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=6yjSl7NQvkiVEY35fXfoYnNnDHpwXZHvAt2SFrR0I98=; t=1758723715; x=1759933315; b=PR9yPJiuL8RtmcvSTwKmVDkrQEM1RT6Qj8q6X5pIv2deXK4 ZJ3+ydsx+4dZ3JGwnv4DJQj4uaIfDgBgme1AYXQ+94cijTlM2u2dREzpbpNW+49ZRX2eApRM8GWvQ u0dcASSf7g8SSfpmmJ0dtAC/tPl+ZmgY8dzi/uqZtyNANgQbQvyiMilAphvSbj84vgLPUGiZrCUKZ rDuAlTB980tT/JbzLbM20OCIDoOTgcvMRXRIClKw/3p4AtaupPeqAKKBzqNZ41x5gZ4Tj6C6DN2ev hGbhRHUbdvmsWKFwKFF42l0qYiHURHiJuVHh5ivAXvIXID6xWqswwafugS4SpToQ==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1v1QNT-000000090Bz-1Esg; Wed, 24 Sep 2025 16:21:51 +0200 From: Benjamin Berg To: linux-um@lists.infradead.org, Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kselftest@vger.kernel.org, Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Benjamin Berg Subject: [PATCH v3 03/12] tools/nolibc/stdio: let perror work when NOLIBC_IGNORE_ERRNO is set Date: Wed, 24 Sep 2025 16:20:50 +0200 Message-ID: <20250924142059.527768-4-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250924142059.527768-1-benjamin@sipsolutions.net> References: <20250924142059.527768-1-benjamin@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Benjamin Berg 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. Fixes: acab7bcdb1bc ("tools/nolibc/stdio: add perror() to report the errno = value") Signed-off-by: Benjamin Berg Acked-by: Thomas Wei=C3=9Fschuh --- v3: - Change the message instead of removing perror entirely --- tools/include/nolibc/stdio.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 7630234408c5..724d05ce6962 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -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=3D%d\n", (msg && *msg) ? msg : "", (msg && *ms= g) ? ": " : "", errno); +#endif } =20 static __attribute__((unused)) --=20 2.51.0 From nobody Thu Oct 2 00:49:26 2025 Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04EF8306D21; Wed, 24 Sep 2025 14:21:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723717; cv=none; b=VFw2cMe7znnBApXdiegrPAlrmp5G3UnDb5Exh3XYXsF/yM3gulAFPpBpof+ZLZHVcjePTcpLPAiWMnW+h4D4JlmwZk0/m94Wsz82YUs64mj+nCl8InBbkuvzjIFXDB/UA04TLnXAIWXNXgCB8DtFMRflBDa5dv93QkzcXAhbcF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723717; c=relaxed/simple; bh=VzHe7plOCC4IM2A9hgSWmbnT6yiWBw5g/7UEoOBTe0U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TUkayLQ7+65NGxRZ71vunckUqygN8zD9UEsIARm1E7T6ME9mreW9bvpFBza9ZsKGHwbp8IaqYWOnWQAKg2WLX+eWeY5sn7s4bxuAtGQD3OiI99HrQW+5WSAcJkTBP9G0K4jPvn5aos7PsRG+EiNDn3jZW/pgCFkopFnd9yEwmEI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=Uwr1vlVd; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="Uwr1vlVd" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=z10b0FVwCq0i5SVTTgonk/hnK8AmJrJFJmxu+fzz9NI=; t=1758723716; x=1759933316; b=Uwr1vlVdAdQeZeHHQjEqGvwZgHzJaaL/Uro6GS4OHKb7/zr YDKfxcwRhSwXuOg5JRNeAb9e7znF2SuI1slAPl5rVkIsh2Oi8uLM8KBy1ZKG6aKZ1/CDBaUX/iUC8 k2ZFEMYgPHuPA7qce7TDlPEfTnXmpF8p+MCA1i6lYXLTOlI1/nHBswN9m/5kjOPzmbvCnKe4pu6Hz T8acmPLXotkB4pUxtx4DAVD7Ck0zS3HrwkibSFdzijfIHYq56trVYftwilmlfDaE5WKy+NIVUNf8x yPj1nA+IJPrGyrZaOdtf08bAE3dlKNcNQFFfbZjMhU80lU1YnyuyRxZpz6OVh2KQ==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1v1QNU-000000090Bz-0suP; Wed, 24 Sep 2025 16:21:52 +0200 From: Benjamin Berg To: linux-um@lists.infradead.org, Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kselftest@vger.kernel.org, Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Benjamin Berg Subject: [PATCH v3 04/12] tools/nolibc/dirent: avoid errno in readdir_r Date: Wed, 24 Sep 2025 16:20:51 +0200 Message-ID: <20250924142059.527768-5-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250924142059.527768-1-benjamin@sipsolutions.net> References: <20250924142059.527768-1-benjamin@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-malware-bazaar: not-scanned From: Benjamin Berg Using errno is not possible when NOLIBC_IGNORE_ERRNO is set. Use sys_lseek instead of lseek as that avoids using errno. Fixes: 665fa8dea90d ("tools/nolibc: add support for directory access") Signed-off-by: Benjamin Berg Acked-by: Thomas Wei=C3=9Fschuh --- tools/include/nolibc/dirent.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/include/nolibc/dirent.h b/tools/include/nolibc/dirent.h index 758b95c48e7a..61a122a60327 100644 --- a/tools/include/nolibc/dirent.h +++ b/tools/include/nolibc/dirent.h @@ -86,9 +86,9 @@ int readdir_r(DIR *dirp, struct dirent *entry, struct dir= ent **result) * readdir() can only return one entry at a time. * Make sure the non-returned ones are not skipped. */ - ret =3D lseek(fd, ldir->d_off, SEEK_SET); - if (ret =3D=3D -1) - return errno; + ret =3D sys_lseek(fd, ldir->d_off, SEEK_SET); + if (ret < 0) + return -ret; =20 entry->d_ino =3D ldir->d_ino; /* the destination should always be big enough */ --=20 2.51.0 From nobody Thu Oct 2 00:49:26 2025 Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 766683090DD; Wed, 24 Sep 2025 14:21:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723719; cv=none; b=SG6rcDKV6TJZc4qrlNyNGpHNsxslJeDdzuSZhybMP18186dsIs3cWAyF/T4vDzbpBnBu2/ybkf0ugV/JCTqngPrbz/6U6FHtxZ5cWzMn93RSBv+JjvU4sPye6v3B2rPVIxbnP6JIV3Ba+G3IxkC4vS5vZs45+8oXG8TBUaeRFH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723719; c=relaxed/simple; bh=Xiw19+7GfrtOjXlL4v7+tqa0Ibj+6W6IJ0mJnnK0hic=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LeRGlE7X93yHqFQ01Pjcty636xb5z+GdPAXdx3aTyBGiXiVYEdBL2va6DNznyIFIUpYKCiRmU2+QiwhH28a43XKj+Ipf2mAvHclGqlGdiG+AH0qJ5/FkW7NNcEqRHDbkRCzKmeNWW1TftHSU6GPrWf5/7Wt1ps3+0efQuWUk584= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=DoD/7jQd; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="DoD/7jQd" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=SesBRyEDdeL4b2WR08hExbhuW4gCAOOUoslrVli4iZo=; t=1758723717; x=1759933317; b=DoD/7jQdUrtp1JJD1HN+IKrkbW1Xdt42UOQpILwSwL2NyVl Ax1uMf1gv8xWc102VVvcXCFu3jphupIe7eREsY1VLz+ehW1KxL8ChVkLKU00rCY2FnO6VUwQ4nA+8 sK8r2+SycI5SvCjIwFcoD5UDCySfH6Siyu74hbNa3fjPSsOM+4fHj3DAkqTTVyev2MW6AlGeR5I0y eiFkRYkgc/9p4RHj+go7GU2Fj04iwntKuHrOFI8Rkdl+Z84/EhHdfF9DgQMWqCP/VINDErxc/XnfT bRQT2oKYFMKYoGkEdLXuWaj2OPt56kxIwTI8ofc5rrc7hwtMpJOkGKmFQOMygWeA==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1v1QNV-000000090Bz-1qiK; Wed, 24 Sep 2025 16:21:53 +0200 From: Benjamin Berg To: linux-um@lists.infradead.org, Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kselftest@vger.kernel.org, Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Benjamin Berg Subject: [PATCH v3 05/12] tools/nolibc: implement %m if errno is not defined Date: Wed, 24 Sep 2025 16:20:52 +0200 Message-ID: <20250924142059.527768-6-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250924142059.527768-1-benjamin@sipsolutions.net> References: <20250924142059.527768-1-benjamin@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Benjamin Berg For improved compatibility, print %m as "unknown error" when nolibc is compiled using NOLIBC_IGNORE_ERRNO. Signed-off-by: Benjamin Berg Acked-by: Thomas Wei=C3=9Fschuh --- tools/include/nolibc/stdio.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 724d05ce6962..1f16dab2ac88 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -321,11 +321,13 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t s= tate, size_t n, const char if (!outstr) outstr=3D"(null)"; } -#ifndef NOLIBC_IGNORE_ERRNO else if (c =3D=3D 'm') { +#ifdef NOLIBC_IGNORE_ERRNO + outstr =3D "unknown error"; +#else outstr =3D strerror(errno); - } #endif /* NOLIBC_IGNORE_ERRNO */ + } else if (c =3D=3D '%') { /* queue it verbatim */ continue; --=20 2.51.0 From nobody Thu Oct 2 00:49:26 2025 Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AE50309EEC; Wed, 24 Sep 2025 14:21:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723719; cv=none; b=ogDBGz6PBwI+YFV0mrdost4atJSjQOV2b0yITVFIoc9wiTqz/kW4qWbj4qTlgJwmzAByXQl3nEVxW4cIQks2+B1sYXOsf6ScV+ZvV6G4jKKQGughatnS0W2ZsHkzPfH8RLgF2CROOnABATq7ynQO1zRbbAJdVnycQHP1guEf2Dk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723719; c=relaxed/simple; bh=8uFM5QahYXW7uNN8id5O/6sxqvaTOGEeRZfPDBxEGMw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ct8HKYqcXHTt6r9ZHfeMq8YR7BsUrsLr9YWsppAsYNPedA3k2HgRhWySKyYpqCROx7zBf5Ux+Ah07UkDpynHEJn3PQiLsg7SOvBFDYNzK3qgI8gmjmiB46P1i+PAiQCsUHXnoC13jw0UXBR4dmhIc0v6nkWDpW5OmKOCEy6EMTM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=OZkCqtTz; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="OZkCqtTz" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=I1cm2is+Xgw+x+T3m8uuoGo4E722CtwyukEZGpVjsa4=; t=1758723718; x=1759933318; b=OZkCqtTztxY7ACUKNQkRyE36R+oafvh63VHuaKeQ3xihxIR ulg8Bi8u+/5uoGJiTnGqT3GSS339iMo4C7obBj3eKqbbA/4B+xtvIbETMYE2qI72pyeXAes+QyWfa /tvfjaXUBMzKmsEveywUeV7mizVASOvPESX4zz7D8L/uheskkykjxW/XMZgWOzOWDi6rZnCsjS9cX 3gEgQE2WdCHmTPpN8mq1I/GpgnhjOePWkB1Nt0lU8ODh5kIL7Ng5r+WAUy/wokmG6dwT7yAMhPcMn R04t2/I/T9sBC+0eXVyuvoOwZaQ216gHZg7g+2qHa2+WBS3XC6nb0To2yJehaNow==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1v1QNW-000000090Bz-3KBY; Wed, 24 Sep 2025 16:21:55 +0200 From: Benjamin Berg To: linux-um@lists.infradead.org, Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kselftest@vger.kernel.org, Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Benjamin Berg Subject: [PATCH v3 06/12] tools/nolibc: use __fallthrough__ rather than fallthrough Date: Wed, 24 Sep 2025 16:20:53 +0200 Message-ID: <20250924142059.527768-7-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250924142059.527768-1-benjamin@sipsolutions.net> References: <20250924142059.527768-1-benjamin@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-malware-bazaar: not-scanned From: Benjamin Berg Use the version of the attribute with underscores to avoid issues if fallthrough has been defined by another header file already. Signed-off-by: Benjamin Berg Acked-by: Thomas Wei=C3=9Fschuh --- tools/include/nolibc/compiler.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compile= r.h index 369cfb5a0e78..87090bbc53e0 100644 --- a/tools/include/nolibc/compiler.h +++ b/tools/include/nolibc/compiler.h @@ -41,8 +41,8 @@ # define __no_stack_protector __attribute__((__optimize__("-fno-stack-pro= tector"))) #endif /* __nolibc_has_attribute(no_stack_protector) */ =20 -#if __nolibc_has_attribute(fallthrough) -# define __nolibc_fallthrough do { } while (0); __attribute__((fallthroug= h)) +#if __nolibc_has_attribute(__fallthrough__) +# define __nolibc_fallthrough do { } while (0); __attribute__((__fallthro= ugh__)) #else # define __nolibc_fallthrough do { } while (0) #endif /* __nolibc_has_attribute(fallthrough) */ --=20 2.51.0 From nobody Thu Oct 2 00:49:26 2025 Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0187A30AABE; Wed, 24 Sep 2025 14:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723721; cv=none; b=fbHwwpDWeah6X5x1jeXwqVW+qRwJE0XTAPqeHzz7MLU7oR3FnHfkKL5uK83SMae0qMRgpkiDyKKNgiNZ9Dl2+cPrLsy+cjpVsse98Lwv+VdZFItGFYgBziUDuIKisd/Jx1TPGescLcwLdtxu4f0eGp9YNsuMIYPmKgagYzvAehE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723721; c=relaxed/simple; bh=GrnSWl/l6y6I1yY3ttS/AbrG2ZKFPiMaWugibMXrygQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZB+KoC1hjGrivFTbWhLzafunxiqt0x6GAkoveDcEcIfgrfN361Cmt4ua5uFuTAStFiGnBafxgqwSYLZquOA/hfnuQ/Wd9Wzra+w+pAkdtELG4WXedwT9KVhUK+gjHsu7LMUNdlEfO+KxkxtC7302nGy4Yw8T7JuFKc2AGwVWC2w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=VNAvVfqp; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="VNAvVfqp" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=Wyrt4ywsUa30dSsyTR71hnWg6bMqqctOayCDw74qBv4=; t=1758723719; x=1759933319; b=VNAvVfqp95RH8Ow6+yY5gAD/cQLMtMmxBO9JKZuK5oFT71Z OgIxjLcwtkcs2jiFijH12928i6Z0wylqyQ+OuUjdqe0fknrTLcVLmzX1TkjF7P4RuV4lichDYneIj TTEtsJSTKNRFbWbUPq6yIP5lwpqQk0usmLE+MXjEDJHo/K1wtq6Fmbia9nyrnchsul9YVQY3vSFW2 ffpWe/3/lPZQ6ms0Qn32SGAygnFrFOq30m5ZW8y+zp0hx1bIO1hWRB2BbFfkP9ISCx4Z9AnJNSXiy 6BsMsa+2ZXmYdTg8bgvpa2JH3bAJkoIVokiR0SoSkDFdSql4AD7ejo0/6OJjvvlg==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1v1QNY-000000090Bz-01ju; Wed, 24 Sep 2025 16:21:56 +0200 From: Benjamin Berg To: linux-um@lists.infradead.org, Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kselftest@vger.kernel.org, Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Benjamin Berg Subject: [PATCH v3 07/12] tools/nolibc: add option to disable runtime Date: Wed, 24 Sep 2025 16:20:54 +0200 Message-ID: <20250924142059.527768-8-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250924142059.527768-1-benjamin@sipsolutions.net> References: <20250924142059.527768-1-benjamin@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-malware-bazaar: not-scanned From: Benjamin Berg 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. Signed-off-by: Benjamin Berg Acked-by: Thomas Wei=C3=9Fschuh --- 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(-) diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-ar= m.h index 1f66e7e5a444..251c42579028 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -184,6 +184,7 @@ _arg1; \ }) =20 +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protec= tor _start(void) { @@ -193,5 +194,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoin= t __no_stack_protector _s ); __nolibc_entrypoint_epilogue(); } +#endif /* NOLIBC_NO_RUNTIME */ =20 #endif /* _NOLIBC_ARCH_ARM_H */ diff --git a/tools/include/nolibc/arch-arm64.h b/tools/include/nolibc/arch-= arm64.h index 02a3f74c8ec8..080a55a7144e 100644 --- a/tools/include/nolibc/arch-arm64.h +++ b/tools/include/nolibc/arch-arm64.h @@ -141,6 +141,7 @@ _arg1; \ }) =20 +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protec= tor _start(void) { @@ -150,4 +151,5 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoin= t __no_stack_protector _s ); __nolibc_entrypoint_epilogue(); } +#endif /* NOLIBC_NO_RUNTIME */ #endif /* _NOLIBC_ARCH_ARM64_H */ diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/a= rch-loongarch.h index 5511705303ea..c894176c3f89 100644 --- a/tools/include/nolibc/arch-loongarch.h +++ b/tools/include/nolibc/arch-loongarch.h @@ -142,6 +142,7 @@ _arg1; \ }) =20 +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protec= tor _start(void) { @@ -151,5 +152,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoin= t __no_stack_protector _s ); __nolibc_entrypoint_epilogue(); } +#endif /* NOLIBC_NO_RUNTIME */ =20 #endif /* _NOLIBC_ARCH_LOONGARCH_H */ diff --git a/tools/include/nolibc/arch-m68k.h b/tools/include/nolibc/arch-m= 68k.h index 6dac1845f298..2a4fbada5e79 100644 --- a/tools/include/nolibc/arch-m68k.h +++ b/tools/include/nolibc/arch-m68k.h @@ -128,6 +128,7 @@ _num; \ }) =20 +#ifndef NOLIBC_NO_RUNTIME void _start(void); void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protec= tor _start(void) { @@ -137,5 +138,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoin= t __no_stack_protector _s ); __nolibc_entrypoint_epilogue(); } +#endif /* NOLIBC_NO_RUNTIME */ =20 #endif /* _NOLIBC_ARCH_M68K_H */ diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-m= ips.h index 0cbac63b249a..a72506ceec6b 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -245,6 +245,7 @@ =20 #endif /* _ABIO32 */ =20 +#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_protec= tor __start(void) @@ -266,5 +267,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoin= t __no_stack_protector __ ); __nolibc_entrypoint_epilogue(); } +#endif /* NOLIBC_NO_RUNTIME */ =20 #endif /* _NOLIBC_ARCH_MIPS_H */ diff --git a/tools/include/nolibc/arch-powerpc.h b/tools/include/nolibc/arc= h-powerpc.h index 204564bbcd32..e0c7e0b81f7c 100644 --- a/tools/include/nolibc/arch-powerpc.h +++ b/tools/include/nolibc/arch-powerpc.h @@ -183,6 +183,7 @@ #endif #endif /* !__powerpc64__ */ =20 +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protec= tor _start(void) { @@ -215,5 +216,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoin= t __no_stack_protector _s #endif __nolibc_entrypoint_epilogue(); } +#endif /* NOLIBC_NO_RUNTIME */ =20 #endif /* _NOLIBC_ARCH_POWERPC_H */ diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-= riscv.h index 885383a86c38..1c00cacf57e1 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -139,6 +139,7 @@ _arg1; \ }) =20 +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protec= tor _start(void) { @@ -152,5 +153,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoin= t __no_stack_protector _s ); __nolibc_entrypoint_epilogue(); } +#endif /* NOLIBC_NO_RUNTIME */ =20 #endif /* _NOLIBC_ARCH_RISCV_H */ diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/arch-s= 390.h index df4c3cc713ac..6237211385c0 100644 --- a/tools/include/nolibc/arch-s390.h +++ b/tools/include/nolibc/arch-s390.h @@ -139,6 +139,7 @@ _arg1; \ }) =20 +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protec= tor _start(void) { @@ -155,6 +156,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoin= t __no_stack_protector _s ); __nolibc_entrypoint_epilogue(); } +#endif /* NOLIBC_NO_RUNTIME */ =20 struct s390_mmap_arg_struct { unsigned long addr; diff --git a/tools/include/nolibc/arch-sh.h b/tools/include/nolibc/arch-sh.h index a96b8914607e..7a421197d104 100644 --- a/tools/include/nolibc/arch-sh.h +++ b/tools/include/nolibc/arch-sh.h @@ -140,6 +140,7 @@ _ret; \ }) =20 +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void _start_wrapper(void); void __attribute__((weak,noreturn)) __nolibc_entrypoint __no_stack_protect= or _start_wrapper(void) @@ -158,5 +159,6 @@ void __attribute__((weak,noreturn)) __nolibc_entrypoint= __no_stack_protector _st ); __nolibc_entrypoint_epilogue(); } +#endif /* NOLIBC_NO_RUNTIME */ =20 #endif /* _NOLIBC_ARCH_SH_H */ diff --git a/tools/include/nolibc/arch-sparc.h b/tools/include/nolibc/arch-= sparc.h index ca420d843e25..2ebb5686e105 100644 --- a/tools/include/nolibc/arch-sparc.h +++ b/tools/include/nolibc/arch-sparc.h @@ -152,6 +152,7 @@ _arg1; \ }) =20 +#ifndef NOLIBC_NO_RUNTIME /* startup code */ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protec= tor _start(void) { @@ -169,6 +170,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoin= t __no_stack_protector _s ); __nolibc_entrypoint_epilogue(); } +#endif /* NOLIBC_NO_RUNTIME */ =20 static pid_t getpid(void); =20 diff --git a/tools/include/nolibc/arch-x86.h b/tools/include/nolibc/arch-x8= 6.h index d3efc0c3b8ad..11abb8bd7eec 100644 --- a/tools/include/nolibc/arch-x86.h +++ b/tools/include/nolibc/arch-x86.h @@ -157,6 +157,7 @@ _eax; \ }) =20 +#ifndef NOLIBC_NO_RUNTIME /* startup code */ /* * i386 System V ABI mandates: @@ -176,6 +177,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoin= t __no_stack_protector _s ); __nolibc_entrypoint_epilogue(); } +#endif /* NOLIBC_NO_RUNTIME */ =20 #else /* !defined(__x86_64__) */ =20 @@ -323,6 +325,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoin= t __no_stack_protector _s _ret; \ }) =20 +#ifndef NOLIBC_NO_RUNTIME /* startup code */ /* * x86-64 System V ABI mandates: @@ -340,6 +343,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoin= t __no_stack_protector _s ); __nolibc_entrypoint_epilogue(); } +#endif /* NOLIBC_NO_RUNTIME */ =20 #define NOLIBC_ARCH_HAS_MEMMOVE void *memmove(void *dst, const void *src, size_t len); diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h index 961cfe777c35..d9262998dae9 100644 --- a/tools/include/nolibc/crt.h +++ b/tools/include/nolibc/crt.h @@ -7,6 +7,8 @@ #ifndef _NOLIBC_CRT_H #define _NOLIBC_CRT_H =20 +#ifndef NOLIBC_NO_RUNTIME + #include "compiler.h" =20 char **environ __attribute__((weak)); @@ -88,4 +90,5 @@ void _start_c(long *sp) exit(exitcode); } =20 +#endif /* NOLIBC_NO_RUNTIME */ #endif /* _NOLIBC_CRT_H */ diff --git a/tools/include/nolibc/stackprotector.h b/tools/include/nolibc/s= tackprotector.h index c71a2c257177..7123aa056cb0 100644 --- a/tools/include/nolibc/stackprotector.h +++ b/tools/include/nolibc/stackprotector.h @@ -9,6 +9,7 @@ =20 #include "compiler.h" =20 +#ifndef NOLIBC_NO_RUNTIME #if defined(_NOLIBC_STACKPROTECTOR) =20 #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 */ =20 #endif /* _NOLIBC_STACKPROTECTOR_H */ diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h index 5fd99a480f82..f184e108ed0a 100644 --- a/tools/include/nolibc/stdlib.h +++ b/tools/include/nolibc/stdlib.h @@ -100,6 +100,7 @@ void free(void *ptr) munmap(heap, heap->len); } =20 +#ifndef NOLIBC_NO_RUNTIME /* getenv() tries to find the environment variable named 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 recommen= ded @@ -122,6 +123,7 @@ char *getenv(const char *name) } return NULL; } +#endif /* NOLIBC_NO_RUNTIME */ =20 static __attribute__((unused)) void *malloc(size_t len) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 295e71d34aba..a48f5117bfce 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -509,6 +509,7 @@ pid_t gettid(void) return sys_gettid(); } =20 +#ifndef NOLIBC_NO_RUNTIME static unsigned long getauxval(unsigned long key); =20 /* @@ -520,7 +521,7 @@ int getpagesize(void) { return __sysret((int)getauxval(AT_PAGESZ) ?: -ENOENT); } - +#endif /* NOLIBC_NO_RUNTIME */ =20 /* * uid_t getuid(void); diff --git a/tools/include/nolibc/sys/auxv.h b/tools/include/nolibc/sys/aux= v.h index c52463d6c18d..0e98325e7347 100644 --- a/tools/include/nolibc/sys/auxv.h +++ b/tools/include/nolibc/sys/auxv.h @@ -10,6 +10,8 @@ #ifndef _NOLIBC_SYS_AUXV_H #define _NOLIBC_SYS_AUXV_H =20 +#ifndef NOLIBC_NO_RUNTIME + #include "../crt.h" =20 static __attribute__((unused)) @@ -38,4 +40,5 @@ unsigned long getauxval(unsigned long type) return ret; } =20 +#endif /* NOLIBC_NO_RUNTIME */ #endif /* _NOLIBC_SYS_AUXV_H */ --=20 2.51.0 From nobody Thu Oct 2 00:49:26 2025 Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 326D7306B06; Wed, 24 Sep 2025 14:22:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723725; cv=none; b=bg6HfTTDVhfxa2yFJuaq2DoUwjGsv20aeIx0Ys7ggJgDeCxF4WkGekSwtXoA7uvFEX9Ffh18qdz8BT7phXLnwPaDczMsIJPhGpVks1SKkknvm3q32zozEE2nTN1GA1mEq1r9GUozwZ/hf7Ve1q7mscRJ7Lawx55X8AQXGZqb4M4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723725; c=relaxed/simple; bh=8bMnRYFdkzIrNPDO3xYUQlZ8A7wFLDXUvacn4AXaKi0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cyXNhbnjUqs7UlM6WBgOm6Vp3QjcSzY4UKwXsmnLmC64ds4Xa+jjV7rBMW+9Uoa4bHw52sYaqhTut1T9eTxd52c6OThNWHTQABZCOo6XFc6s+9dc3GmmEz4cs7FxN688EiTCiHeh8bM0GW27gRJlGZpeUp02vER4dRLZ+psJOgk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=BphDSxbn; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="BphDSxbn" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=t7nIw84Rl79y66+K3kgQqOWSKjjzBQe7De/659OAugM=; t=1758723723; x=1759933323; b=BphDSxbn2tbjenKvtDLL9Gf0agC12CssRXMWIJkfOlRH9pc oSG1e3VP+Gg+qoTPL67sFI5K4WTWHecAjVpTsWHz/NgNP7VBb/gs+18Wpg9voY2Jmv5K8zf0Tur6x IUCMwwMUBZ4yoqw/+nngHIDDHioue6TcpzGyWgysPgRJA9xDjY1bY78lj97B6eIoY+ert1A69BJZb FF3BesT9o/D8evXoqhFDLIerie2Xx5nIciazKgMzdGimNtO8mIXWrbSxG2tXkP/mQawyLYie5vMG7 1TCN4K+pI1eI/xEtRAPAnIs8H6ea0+oz82ovah8YpVMzecU9JrgdMZEl6ooSVeqw==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1v1QNZ-000000090Bz-1P4q; Wed, 24 Sep 2025 16:21:58 +0200 From: Benjamin Berg To: linux-um@lists.infradead.org, Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kselftest@vger.kernel.org, Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Benjamin Berg Subject: [PATCH v3 08/12] um: add infrastructure to build files using nolibc Date: Wed, 24 Sep 2025 16:20:55 +0200 Message-ID: <20250924142059.527768-9-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250924142059.527768-1-benjamin@sipsolutions.net> References: <20250924142059.527768-1-benjamin@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Benjamin Berg 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. Signed-off-by: Benjamin Berg --- 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(-) diff --git a/arch/um/Makefile b/arch/um/Makefile index f7c509262568..c3a81df50911 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -78,6 +78,24 @@ USER_CFLAGS =3D $(patsubst $(KERNEL_DEFINES),,$(patsubst= -I%,,$(KBUILD_CFLAGS))) \ -include $(srctree)/include/linux/kern_levels.h \ -include $(srctree)/$(ARCH_DIR)/include/shared/user.h =20 +NOLIBC_CFLAGS =3D $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_C= FLAGS))) \ + $(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 =20 @@ -160,4 +178,4 @@ archclean: -o -name '*.gcov' \) -type f -print | xargs rm -f $(Q)$(MAKE) -f $(srctree)/Makefile ARCH=3D$(HEADER_ARCH) clean =20 -export HEADER_ARCH SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING DEV_NULL_PATH +export HEADER_ARCH SUBARCH USER_CFLAGS NOLIBC_CFLAGS CFLAGS_NO_HARDENING D= EV_NULL_PATH diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index b35cc8ce333b..5dae5635b1f8 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -327,7 +327,9 @@ extern int __ignore_sigio_fd(int fd); /* tty.c */ extern int get_pty(void); =20 +#ifdef __KERNEL__ long syscall(long number, ...); +#endif =20 /* irqflags tracing */ extern void block_signals_trace(void); diff --git a/arch/um/include/shared/user.h b/arch/um/include/shared/user.h index c9b853e1282f..e32bdd032029 100644 --- a/arch/um/include/shared/user.h +++ b/arch/um/include/shared/user.h @@ -16,7 +16,6 @@ */ #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) =20 -#include #include =20 extern void panic(const char *fmt, ...) diff --git a/arch/um/scripts/Makefile.rules b/arch/um/scripts/Makefile.rules index b4a2e0058503..5f07551935c3 100644 --- a/arch/um/scripts/Makefile.rules +++ b/arch/um/scripts/Makefile.rules @@ -11,6 +11,12 @@ USER_OBJS :=3D $(foreach file,$(USER_OBJS),$(obj)/$(file= )) $(USER_OBJS:.o=3D.%): \ c_flags =3D -Wp,-MD,$(depfile) $(USER_CFLAGS) $(CFLAGS_$(basetarget).o) =20 +# Similar USER_OBJS but compiled against nolibc (may include kernel header= s?) +NOLIBC_OBJS :=3D $(foreach file,$(NOLIBC_OBJS),$(obj)/$(file)) + +$(NOLIBC_OBJS:.o=3D.%): \ + c_flags =3D -Wp,-MD,$(depfile) $(NOLIBC_CFLAGS) $(CFLAGS_$(basetarget).o) + # These are like USER_OBJS but filter USER_CFLAGS through unprofile instea= d of # using it directly. UNPROFILE_OBJS :=3D $(foreach file,$(UNPROFILE_OBJS),$(obj)/$(file)) @@ -18,7 +24,7 @@ UNPROFILE_OBJS :=3D $(foreach file,$(UNPROFILE_OBJS),$(ob= j)/$(file)) $(UNPROFILE_OBJS:.o=3D.%): \ c_flags =3D -Wp,-MD,$(depfile) $(call unprofile,$(USER_CFLAGS)) $(CFLAGS_= $(basetarget).o) =20 -$(USER_OBJS) $(UNPROFILE_OBJS): \ +$(USER_OBJS) $(NOLIBC_OBJS) $(UNPROFILE_OBJS): \ CHECKFLAGS :=3D $(patsubst $(NOSTDINC_FLAGS),,$(CHECKFLAGS)) =20 # The stubs can't try to call mcount or update basic block data --=20 2.51.0 From nobody Thu Oct 2 00:49:26 2025 Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09B4230C103; Wed, 24 Sep 2025 14:22:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723726; cv=none; b=jrZYaywjhnUWO4eDUZ5snbIy7NaVTU47ZMqEMbUdXAJCxyCa2nysPJ02cFKXSXYEP8h9iN+8mt2GqYZFU63aIGyRj28urhuzIyHaC98566sSaIOoy1d127d2345btber/wb22EC/6R4TawtIOJo75rK5qEltzSV+z4anas+K7zI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723726; c=relaxed/simple; bh=+1XbHYWO44eiLyr3lQME0rhVVOh0E9r61o4FckS2Ch8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PjA9v8UjyYT3cqg7r0iDZwsYoThItFc3sDe3WZrXe3RDCxQejfb1p2G0W0HUYcePYtTmA71l7ufabJk9QWitUZJqDBUtE7FP0Z6VjJ1OwCxKgGddCFeFSxJV0loAQKwG5DI53nQ3mekbww9OwBlyjMFp7UDGkPXC6J2q178Aows= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=iv8lUdYd; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="iv8lUdYd" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=UVHwzh9sHs6Xo02VEWpZXjxZy4cbskfDXgmFGFBhsbs=; t=1758723725; x=1759933325; b=iv8lUdYdX32b5Ebb8gzJHRE3E37CWRZQILwpiM7Jl7B2QDt F6XWSgc0pj74RIbvB26o+AR6GOHddgxhHVRcKOQteBcDq68WVOE7KyPYm16sJiCCDnshcTU3dxfRi y5Q9UDriebRm7rMvEQ1Gm0pvuEFgh9k6c+/mKEhxtF4FBZweLbWpZxzpivhuRzIYRq1TAvA0gstTZ EEQVsBFdo3DidnWBGLKQb+0uvaM6Qqd6+3akm/PfJLH1bp+QEaDiMHzR1zbgAc6FCQmgKp6gO01WE WQEidVOWwp4Hqby6rEbyAVq2j5HTOU/wiuhIGCa921cZwHwjf5FDuc7qOxTClLCg==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1v1QNa-000000090Bz-44BP; Wed, 24 Sep 2025 16:21:59 +0200 From: Benjamin Berg To: linux-um@lists.infradead.org, Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kselftest@vger.kernel.org, Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Benjamin Berg Subject: [PATCH v3 09/12] um: use nolibc for the --showconfig implementation Date: Wed, 24 Sep 2025 16:20:56 +0200 Message-ID: <20250924142059.527768-10-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250924142059.527768-1-benjamin@sipsolutions.net> References: <20250924142059.527768-1-benjamin@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Benjamin Berg This is one of the simplest files and it can be switched over to use nolibc without any modifications. Signed-off-by: Benjamin Berg --- arch/um/kernel/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile index b8f4e9281599..4b206a40b611 100644 --- a/arch/um/kernel/Makefile +++ b/arch/um/kernel/Makefile @@ -26,7 +26,7 @@ obj-$(CONFIG_OF) +=3D dtb.o obj-$(CONFIG_EARLY_PRINTK) +=3D early_printk.o obj-$(CONFIG_STACKTRACE) +=3D stacktrace.o =20 -USER_OBJS :=3D config.o +NOLIBC_OBJS :=3D config.o =20 include $(srctree)/arch/um/scripts/Makefile.rules =20 --=20 2.51.0 From nobody Thu Oct 2 00:49:26 2025 Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B10D30C37A; Wed, 24 Sep 2025 14:22:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723729; cv=none; b=QOJtefrkRqJu+GWa48K8N0OtV+9dhu7sAXTqhoPhbXHOYuy7hBZmsXwvXimCVkAQxj7QlojXUj3cGSzjlcQ1q9cepStFYsQa5eWN34fFM+KbCxf7HxODEX3zLvMqkaxfvC2DP4A95H5k78n1UG7VoQkbBAO5sZGUNtHC9e7Ovvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723729; c=relaxed/simple; bh=8cWdpKI/DnvDD347e7jyPxVXAEa3tbXsFCItO8RPDog=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dvbIv4R+zH25fAz1pT2MobRWjcstap6tgEuiLGBghFOvetqy0Uj1BoAQGw6YcvYEde6DyxmmJvqhKldP/evgFU0GRDRxelx0jtuLOpseCGmXbC4Kjm0585/0quyamrTr7PRb6G1hQGPwAXsGXI7YCMvvR+vZPBXSIyjIuQr9hIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=OUMg+eFS; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="OUMg+eFS" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=pzfcxmV9exnO/NrKu+9Abg5ORjXxzI+JoCHdX4YtSlk=; t=1758723727; x=1759933327; b=OUMg+eFSa6xCGjKI1O+SRdLwaJgRFmCowDcymCpKtzhhAKf BKTXd61MhW02SlNUjk0PhWgX3ehKuzu22sXY5MFtsRU2uis97GImJl0iLDAYzGQ7eR2XVSuSiNYU+ LOesJoDcWSYZKXXHensGPY5pTQr7rkh99FkYfW7ceQAarpH3L+Upny8d30+dQPQEW7l5nIhNJfVE5 ictNPImaBkq3l/EAnEdhXZQliqOTBZgI0JfYVQ1YM2YpkjrKmqFqciVZJx57vf4m6m8oOwhzeTy7Y MBk6XuuZExLXvmokxddv5PxH5iG7Z8VpyqS4LcwJXy+wkPrn1l9ViwEtsEJdG3Hg==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1v1QNb-000000090Bz-3jHh; Wed, 24 Sep 2025 16:22:02 +0200 From: Benjamin Berg To: linux-um@lists.infradead.org, Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kselftest@vger.kernel.org, Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Benjamin Berg Subject: [PATCH v3 10/12] tools/nolibc: add uio.h with readv and writev Date: Wed, 24 Sep 2025 16:20:57 +0200 Message-ID: <20250924142059.527768-11-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250924142059.527768-1-benjamin@sipsolutions.net> References: <20250924142059.527768-1-benjamin@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-malware-bazaar: not-scanned From: Benjamin Berg This is generally useful and struct iovec is also needed for other purposes such as ptrace. Signed-off-by: Benjamin Berg Acked-by: Thomas Wei=C3=9Fschuh --- 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 diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 143c2d2c2ba6..9bbbba32dac6 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -62,6 +62,7 @@ all_files :=3D \ sys/time.h \ sys/timerfd.h \ sys/types.h \ + sys/uio.h \ sys/utsname.h \ sys/wait.h \ time.h \ diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index c199ade200c2..b4bc1c9b883d 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -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" diff --git a/tools/include/nolibc/sys/uio.h b/tools/include/nolibc/sys/uio.h new file mode 100644 index 000000000000..7ad42b927d2f --- /dev/null +++ b/tools/include/nolibc/sys/uio.h @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * uio for NOLIBC + * Copyright (C) 2017-2021 Willy Tarreau + * Copyright (C) 2025 Intel Corporation + */ + +/* make sure to include all global symbols */ +#include "../nolibc.h" + +#ifndef _NOLIBC_SYS_UIO_H +#define _NOLIBC_SYS_UIO_H + +#include "../sys.h" +#include + + +/* + * ssize_t readv(int fd, const struct iovec *iovec, int count); + */ +static __attribute__((unused)) +ssize_t sys_readv(int fd, const struct iovec *iovec, int count) +{ + return my_syscall3(__NR_readv, fd, iovec, count); +} + +static __attribute__((unused)) +ssize_t readv(int fd, const struct iovec *iovec, int count) +{ + return __sysret(sys_readv(fd, iovec, count)); +} + +/* + * ssize_t writev(int fd, const struct iovec *iovec, int count); + */ +static __attribute__((unused)) +ssize_t sys_writev(int fd, const struct iovec *iovec, int count) +{ + return my_syscall3(__NR_writev, fd, iovec, count); +} + +static __attribute__((unused)) +ssize_t writev(int fd, const struct iovec *iovec, int count) +{ + return __sysret(sys_writev(fd, iovec, count)); +} + + +#endif /* _NOLIBC_SYS_UIO_H */ diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index a297ee0d6d07..1907128bc3f6 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -1283,6 +1284,10 @@ int run_syscall(int min, int max) int proc; int test; int tmp; + struct iovec iov_one =3D { + .iov_base =3D &tmp, + .iov_len =3D 1, + }; int ret =3D 0; void *p1, *p2; int has_gettid =3D 1; @@ -1395,6 +1400,10 @@ int run_syscall(int min, int max) CASE_TEST(waitpid_child); EXPECT_SYSER(1, waitpid(getpid(), &tmp, WN= OHANG), -1, ECHILD); break; CASE_TEST(write_badf); EXPECT_SYSER(1, write(-1, &tmp, 1), -1, EB= ADF); 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), getp= id()); break; CASE_TEST(syscall_args); EXPECT_SYSER(1, syscall(__NR_statx, 0, NUL= L, 0, 0, NULL), -1, EFAULT); break; CASE_TEST(namespace); EXPECT_SYSZR(euid0 && proc, test_namespace= ()); break; --=20 2.51.0 From nobody Thu Oct 2 00:49:26 2025 Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 300273074A1; Wed, 24 Sep 2025 14:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723730; cv=none; b=XVkuPRWZ5QyMJ2SVDFk5A4SfhIIq8QSLv32/x9+1e8NcGjiBqAJwmHxzAPoABPvwQtwlpp3lO89e6SAVaowkchsJH5wBz8vtmtY4OY1d7+JYlnlcy1e04Z8fPBSXztzJSX/QW6AwqLm5El+nF2nOQCmBEe5t2f165pTIT5coRZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723730; c=relaxed/simple; bh=awqLisS4+otzT1VzhnP+JfaunUlrH6eUNHWKFX7pyDg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t12v8OHAQevQteTx+d+sYcTzljZXRJej39CFIcrugQKlz8H8HuQK+QbTtN3qzx/iAxIyays3BiuqmlK7OfmwMB0eWySLMAspCYKCu8wHqKxd5jglHGSHTs3rItDr0+aK72OsyXhO3/5WQ1J+6cBj+gaaIwPTQm2gDlSZAygjtEc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=XVe7RLfd; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="XVe7RLfd" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=LP9bDhgXxCDJw6Oc9+3jyKgig0nV2Eyo34N0Tx+L9L8=; t=1758723729; x=1759933329; b=XVe7RLfdY3ysDIPpzeINMed1kXnyzyZkgdpcJTBKgHLsAUu SCPpex4xT5q455EMQr+G44kjY9GuCFSVec3o8fFSkMwYPh5Zc+vZMXZr3U+NHpdfE+qxbAS8a1YTm AveUUx3UF5dogHRYaSAyACEM0ihn4xaWSt9Q8p1/dH20T5blRZ3/Br+aQUFdiNiNp1M4UAYR/efMi egruJCcu8HuLlYiZtK80JIq8OLnrQTII4OtFQDItyENHqAWbQn4EcRvD5eBJa1N7OCp61ck6f+wAJ N/Scq7UavMeIX7+9ur1E+bqrKs2//+Oobxz2zVJcz28jqT65+tII2e8GtwNDQtUw==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1v1QNg-000000090Bz-25Cd; Wed, 24 Sep 2025 16:22:04 +0200 From: Benjamin Berg To: linux-um@lists.infradead.org, Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kselftest@vger.kernel.org, Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Benjamin Berg Subject: [PATCH v3 11/12] tools/nolibc: add ptrace support Date: Wed, 24 Sep 2025 16:20:58 +0200 Message-ID: <20250924142059.527768-12-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250924142059.527768-1-benjamin@sipsolutions.net> References: <20250924142059.527768-1-benjamin@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Benjamin Berg Add ptrace support, as it will be useful in UML. Signed-off-by: Benjamin Berg --- 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 diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 9bbbba32dac6..8e0cac3ac522 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -53,6 +53,7 @@ all_files :=3D \ sys/mman.h \ sys/mount.h \ sys/prctl.h \ + sys/ptrace.h \ sys/random.h \ sys/reboot.h \ sys/resource.h \ diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index b4bc1c9b883d..590eef545ca6 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -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" diff --git a/tools/include/nolibc/sys/ptrace.h b/tools/include/nolibc/sys/p= trace.h new file mode 100644 index 000000000000..5d1e52965878 --- /dev/null +++ b/tools/include/nolibc/sys/ptrace.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * ptrace for NOLIBC + * Copyright (C) 2017-2021 Willy Tarreau + * 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 + +/* + * 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)) +ssize_t ptrace(int op, pid_t pid, ...) +{ + ssize_t ret; + va_list args; + + va_start(args, pid); + ret =3D __sysret(sys_ptrace(op, pid, + va_arg(args, void *), + va_arg(args, void *))); + va_end(args); + + return ret; +} + +#endif /* _NOLIBC_SYS_PTRACE_H */ diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 1907128bc3f6..4c1b9ee32b7d 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -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), getp= id()); break; CASE_TEST(syscall_args); EXPECT_SYSER(1, syscall(__NR_statx, 0, NUL= L, 0, 0, NULL), -1, EFAULT); break; CASE_TEST(namespace); EXPECT_SYSZR(euid0 && proc, test_namespace= ()); break; --=20 2.51.0 From nobody Thu Oct 2 00:49:26 2025 Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33F87307AEB; Wed, 24 Sep 2025 14:22:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723731; cv=none; b=O1yemQr1Hrb/mt/TouCyFa0nsUYniNdjR5bwW4rEEfoGL0UDSsOObOZTl5CIrWNgSvF4zh9tjF+dRx7fbU4jn2hMVL0+CJEo8SARNYbJb9ZQVp1aAzxiL49xtISEReoFGS1j0Y2pJMIcwjnIIvXyA9gZ9lNNfURa1eONychgrhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758723731; c=relaxed/simple; bh=JHmhFFy3YycfuHtBvf9yxATgV1mZYvcB4VKEeyw6hqg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N2BQZqVrVaG0lpzQ0ZWvy2Fu0OH5dMPmzSEjch34GkI7jIAdkUtbtpQfY/IYBqZdATpO+OVRHZU6qBkpat9gV4pCYgWgoehRZz5DdCErtBD1kZnfOsB2aA9MDPbFv1qu2dI+dBkv4tsp0mi0LouTCUweOROEOBVDbV5/9C5wrxI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=d2JMJbLx; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="d2JMJbLx" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=sC8Bv+IHsX6wUs//ST+Kb4J52aBiV724ykUwuhZDdgY=; t=1758723730; x=1759933330; b=d2JMJbLxowLhB8kNmUYiA9wxwCXA+bYCgCbdSS43f9/T+t7 hX1CuIOJlOHNkNFikeQ82zFLp0wkakGv02MzT8mEFrNOQb7oXhHom+3Gi99/57fpSA+r1+p051LyA 4USC8jh+HXNJy4v/0lyo7hvjI1LC1C29EDZ1ri2FRVzy7LCbfR/+K1jD55MV6tZjIJXkKiN6Cz44c Vc/Lb0lmXXI+vmHptYmMbBIJGPvvH0hrQhARwEzIdlNhl4M7nPMyWPWlZn+1R1iMobT22u6KPViaS 2ooM7UqRPWpvvynT9kN5oLpxDFkAeAO6f1sJlozo3Efn1Q0dQxHCCArz/btCQIPA==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98.2) (envelope-from ) id 1v1QNi-000000090Bz-1RrK; Wed, 24 Sep 2025 16:22:07 +0200 From: Benjamin Berg To: linux-um@lists.infradead.org, Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kselftest@vger.kernel.org, Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Benjamin Berg Subject: [PATCH v3 12/12] um: switch ptrace FP register access to nolibc Date: Wed, 24 Sep 2025 16:20:59 +0200 Message-ID: <20250924142059.527768-13-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250924142059.527768-1-benjamin@sipsolutions.net> References: <20250924142059.527768-1-benjamin@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Benjamin Berg 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. Signed-off-by: Benjamin Berg --- 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(-) diff --git a/arch/x86/um/os-Linux/Makefile b/arch/x86/um/os-Linux/Makefile index 77a308aaa5ec..d37320430822 100644 --- a/arch/x86/um/os-Linux/Makefile +++ b/arch/x86/um/os-Linux/Makefile @@ -3,10 +3,13 @@ # Licensed under the GPL # =20 -obj-y =3D registers.o mcontext.o +obj-y =3D mcontext.o =20 obj-$(CONFIG_X86_32) +=3D tls.o =20 USER_OBJS :=3D $(obj-y) =20 +obj-y +=3D registers.o +NOLIBC_OBJS :=3D registers.o + include $(srctree)/arch/um/scripts/Makefile.rules diff --git a/arch/x86/um/os-Linux/registers.c b/arch/x86/um/os-Linux/regist= ers.c index eb1cdadc8a61..72c7493f3b89 100644 --- a/arch/x86/um/os-Linux/registers.c +++ b/arch/x86/um/os-Linux/registers.c @@ -7,9 +7,6 @@ #include #include #include -#ifdef __i386__ -#include -#endif #include #include #include @@ -28,9 +25,7 @@ int get_fp_registers(int pid, unsigned long *regs) .iov_len =3D host_fp_size, }; =20 - if (ptrace(PTRACE_GETREGSET, pid, ptrace_regset, &iov) < 0) - return -errno; - return 0; + return sys_ptrace(PTRACE_GETREGSET, pid, (void *)ptrace_regset, &iov); } =20 int put_fp_registers(int pid, unsigned long *regs) @@ -40,9 +35,7 @@ int put_fp_registers(int pid, unsigned long *regs) .iov_len =3D host_fp_size, }; =20 - if (ptrace(PTRACE_SETREGSET, pid, ptrace_regset, &iov) < 0) - return -errno; - return 0; + return sys_ptrace(PTRACE_SETREGSET, pid, (void *)ptrace_regset, &iov); } =20 int arch_init_registers(int pid) @@ -60,9 +53,7 @@ int arch_init_registers(int pid) =20 /* GDB has x86_xsave_length, which uses x86_cpuid_count */ ptrace_regset =3D NT_X86_XSTATE; - ret =3D ptrace(PTRACE_GETREGSET, pid, ptrace_regset, &iov); - if (ret) - ret =3D -errno; + ret =3D sys_ptrace(PTRACE_GETREGSET, pid, (void *)ptrace_regset, &iov); =20 if (ret =3D=3D -ENODEV) { #ifdef CONFIG_X86_32 @@ -71,9 +62,8 @@ int arch_init_registers(int pid) ptrace_regset =3D NT_PRFPREG; #endif iov.iov_len =3D 2 * 1024 * 1024; - ret =3D ptrace(PTRACE_GETREGSET, pid, ptrace_regset, &iov); - if (ret) - ret =3D -errno; + ret =3D sys_ptrace(PTRACE_GETREGSET, pid, + (void *)ptrace_regset, &iov); } =20 munmap(iov.iov_base, 2 * 1024 * 1024); --=20 2.51.0