From nobody Thu Oct 9 01:16:06 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A57A9DDC1; Sat, 21 Jun 2025 13:57:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750514258; cv=none; b=ZeYPJN/vXoA7EeICfH039kOqnRVSW1BdAx8EsW+JMsxOa/SSpj3AxuJZWgI5VTMtzMF6m0aXsbr01TMNaCVl0378niMNyHwjSjAsGWYUAvZ7B7/eVG7yhfuW9G+L7QRIWt/Ph8MY3xRW6bfBy8jgvcUYbAofHkh6ldiG3IP05o4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750514258; c=relaxed/simple; bh=SV2yBb7mPZ1Z1JgQ1i1j3we1Iejdg6pRIK1Z7mGfVw0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hu2pCzA1KhrvD/Zu586yECLzvfXWVM2qGyb41a3wPA7wN9Ln5KO/iXPNvv85Lj9cGiiBEl46oGsmkZlyxXwxY6kcShahUfnhLv5pmlJw24ttDAyz3tbTLKXGdYCpv8YGcF2Jk/yuUGg3KiA+3obRUNCokN1UfVib5d7kfXWhvZ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Pe1Ttxxq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Pe1Ttxxq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F009C4CEF1; Sat, 21 Jun 2025 13:57:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750514258; bh=SV2yBb7mPZ1Z1JgQ1i1j3we1Iejdg6pRIK1Z7mGfVw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pe1TtxxqDXAXltnMjYAAJPHpXLJ5a/Ku568lPJeZzwqM85bzVh/k58miB6EUy1iSs xR1bpM4IptIBxrzU1ZA6n0VauDleF6bx2aaNSnpaijtTyFV7C5ewAHeMuLqJ/b+kLU FwRhQn9xWpvYUUGF7nVFZzbQ/CO1IWCe4ONDatUMyzmcRXz5xKDPl1JFIOEHV8A98i GWkQGvKs7tOAyoMe0nxczGsfZ8TeOHVJuB8CbEq/b55KgjnGBkuQsBA3q3RWb8lDMV rjyka1rol65130hFu9ONZ5qici2LPV5AqgnQfcPApyxTlK0ImHSbJW3AqjW4DlesMB XnCWnTZa8BrTg== From: Alexey Gladkov To: Masahiro Yamada , Petr Pavlu , Luis Chamberlain , Sami Tolvanen , Daniel Gomez , Nathan Chancellor , Nicolas Schier Cc: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-scsi@vger.kernel.org, Herbert Xu , "David S. Miller" Subject: [PATCH v4 1/7] module: remove meaningless 'name' parameter from __MODULE_INFO() Date: Sat, 21 Jun 2025 15:57:13 +0200 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: 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: Masahiro Yamada The symbol names in the .modinfo section are never used and already randomized by the __UNIQUE_ID() macro. Therefore, the second parameter of __MODULE_INFO() is meaningless and can be removed to simplify the code. With this change, the symbol names in the .modinfo section will be prefixed with __UNIQUE_ID_modinfo, making it clearer that they originate from MODULE_INFO(). [Before] $ objcopy -j .modinfo vmlinux.o modinfo.o $ nm -n modinfo.o | head -n10 0000000000000000 r __UNIQUE_ID_license560 0000000000000011 r __UNIQUE_ID_file559 0000000000000030 r __UNIQUE_ID_description558 0000000000000074 r __UNIQUE_ID_license580 000000000000008e r __UNIQUE_ID_file579 00000000000000bd r __UNIQUE_ID_description578 00000000000000e6 r __UNIQUE_ID_license581 00000000000000ff r __UNIQUE_ID_file580 0000000000000134 r __UNIQUE_ID_description579 0000000000000179 r __UNIQUE_ID_uncore_no_discover578 [After] $ objcopy -j .modinfo vmlinux.o modinfo.o $ nm -n modinfo.o | head -n10 0000000000000000 r __UNIQUE_ID_modinfo560 0000000000000011 r __UNIQUE_ID_modinfo559 0000000000000030 r __UNIQUE_ID_modinfo558 0000000000000074 r __UNIQUE_ID_modinfo580 000000000000008e r __UNIQUE_ID_modinfo579 00000000000000bd r __UNIQUE_ID_modinfo578 00000000000000e6 r __UNIQUE_ID_modinfo581 00000000000000ff r __UNIQUE_ID_modinfo580 0000000000000134 r __UNIQUE_ID_modinfo579 0000000000000179 r __UNIQUE_ID_modinfo578 Cc: Herbert Xu Cc: "David S. Miller" Signed-off-by: Masahiro Yamada --- include/crypto/algapi.h | 4 ++-- include/linux/module.h | 3 --- include/linux/moduleparam.h | 9 +++++---- include/net/tcp.h | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 188eface0a11..fc4574940636 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h @@ -43,8 +43,8 @@ * alias. */ #define MODULE_ALIAS_CRYPTO(name) \ - __MODULE_INFO(alias, alias_userspace, name); \ - __MODULE_INFO(alias, alias_crypto, "crypto-" name) + MODULE_INFO(alias, name); \ + MODULE_INFO(alias, "crypto-" name) =20 struct crypto_aead; struct crypto_instance; diff --git a/include/linux/module.h b/include/linux/module.h index 8050f77c3b64..24fe6b865e9c 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -164,9 +164,6 @@ extern void cleanup_module(void); =20 struct module_kobject *lookup_or_create_module_kobject(const char *name); =20 -/* Generic info of form tag =3D "info" */ -#define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info) - /* For userspace: you can also call me... */ #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias) =20 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h index bfb85fd13e1f..00166f747e27 100644 --- a/include/linux/moduleparam.h +++ b/include/linux/moduleparam.h @@ -20,18 +20,19 @@ /* Chosen so that structs with an unsigned long line up. */ #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long)) =20 -#define __MODULE_INFO(tag, name, info) \ - static const char __UNIQUE_ID(name)[] \ +/* Generic info of form tag =3D "info" */ +#define MODULE_INFO(tag, info) \ + static const char __UNIQUE_ID(modinfo)[] \ __used __section(".modinfo") __aligned(1) \ =3D __MODULE_INFO_PREFIX __stringify(tag) "=3D" info =20 #define __MODULE_PARM_TYPE(name, _type) \ - __MODULE_INFO(parmtype, name##type, #name ":" _type) + MODULE_INFO(parmtype, #name ":" _type) =20 /* One for each parameter, describing how to use it. Some files do multiple of these per line, so can't just use MODULE_INFO. */ #define MODULE_PARM_DESC(_parm, desc) \ - __MODULE_INFO(parm, _parm, #_parm ":" desc) + MODULE_INFO(parm, #_parm ":" desc) =20 struct kernel_param; =20 diff --git a/include/net/tcp.h b/include/net/tcp.h index 5078ad868fee..9b39ef630c92 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -2662,8 +2662,8 @@ void tcp_update_ulp(struct sock *sk, struct proto *p, void (*write_space)(struct sock *sk)); =20 #define MODULE_ALIAS_TCP_ULP(name) \ - __MODULE_INFO(alias, alias_userspace, name); \ - __MODULE_INFO(alias, alias_tcp_ulp, "tcp-ulp-" name) + MODULE_INFO(alias, name); \ + MODULE_INFO(alias, "tcp-ulp-" name) =20 #ifdef CONFIG_NET_SOCK_MSG struct sk_msg; --=20 2.49.0 From nobody Thu Oct 9 01:16:06 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 80C494120B; Sat, 21 Jun 2025 13:57:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750514263; cv=none; b=rh+mX+2db6Ag3ia68Mu7eJtXGkZVLc8KMHCI8JH1PZNZhJjz2OleOCweuKF0S+CEYOd+PcU1E7fUEhCV3+VrC133HFchAq1sGgHml+8WbmDMb7AwzKiFu6t4VSBCDHBE3/j4XqdHVxRQ+SXWaXy/VE/WXxMOjWhV7sMONMY0ju0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750514263; c=relaxed/simple; bh=V0Ki0PP0IWixyV5REiz3OtpIGehZ28ZeA9xGhY+yj9g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qKCOTGEP5SKmXZZbSkRy7UnFvwHDe8TNBFpEMjpDtgKEStKdPQBY6p8KGrJDtTHNthjk1O+4DGIGWPrz3aysZBiKVAwoV1/mkz35+kNblyveATjHoOnZwaxDieCH9etTwKW9HP7skyvwOcLu+ZjgNbj2OdRGYOiSxWRHiBVE6sQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TqHKOrvb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TqHKOrvb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2B3CC4CEE7; Sat, 21 Jun 2025 13:57:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750514261; bh=V0Ki0PP0IWixyV5REiz3OtpIGehZ28ZeA9xGhY+yj9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TqHKOrvb1SeLhY7Ku5BBEl4wunCBDIKYpJ+lBhp3EsfuXqPPpmZPh2y8/k/zp9jJR wHLNwve6vXHwT2NGY/QbMZkequLpSHH5Rx8GfLO+ezH1yEisj/wq78WH/CnHRv6TM+ mjRRA1uoUAY8zj3s//vCFmnAvmk6ZvEyRSiFf5GZ06vd3sp7STUnakDa32hFhh6C0S wZiTYgOT0GGDWLIY7vL4z4+QSiwtXg/GCJCTK6mQ2vv0reGzNrFsWqaSxzJ0fgrc0q mVamolz3u0EB6QKGUwhrLMdlW58gvnZ7OPISl/ojHutpfgbFaSWkRs7jymChfZykW5 dqO6IDu6nTZkw== From: Alexey Gladkov To: Masahiro Yamada , Petr Pavlu , Luis Chamberlain , Sami Tolvanen , Daniel Gomez , Nathan Chancellor , Nicolas Schier Cc: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH v4 2/7] kbuild: always create intermediate vmlinux.unstripped Date: Sat, 21 Jun 2025 15:57:14 +0200 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: 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: Masahiro Yamada Generate the intermediate vmlinux.unstripped regardless of CONFIG_ARCH_VMLINUX_NEEDS_RELOCS. If CONFIG_ARCH_VMLINUX_NEEDS_RELOCS is unset, vmlinux.unstripped and vmlinux are identiacal. This simplifies the build rule, and allows to strip more sections by adding them to remove-section-y. Signed-off-by: Masahiro Yamada --- scripts/Makefile.vmlinux | 45 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index b64862dc6f08..4f2d4c3fb737 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -9,20 +9,6 @@ include $(srctree)/scripts/Makefile.lib =20 targets :=3D =20 -ifdef CONFIG_ARCH_VMLINUX_NEEDS_RELOCS -vmlinux-final :=3D vmlinux.unstripped - -quiet_cmd_strip_relocs =3D RSTRIP $@ - cmd_strip_relocs =3D $(OBJCOPY) --remove-section=3D'.rel*' --remove-= section=3D!'.rel*.dyn' $< $@ - -vmlinux: $(vmlinux-final) FORCE - $(call if_changed,strip_relocs) - -targets +=3D vmlinux -else -vmlinux-final :=3D vmlinux -endif - %.o: %.c FORCE $(call if_changed_rule,cc_o_c) =20 @@ -61,19 +47,19 @@ targets +=3D .builtin-dtbs-list =20 ifdef CONFIG_GENERIC_BUILTIN_DTB targets +=3D .builtin-dtbs.S .builtin-dtbs.o -$(vmlinux-final): .builtin-dtbs.o +vmlinux.unstripped: .builtin-dtbs.o endif =20 -# vmlinux +# vmlinux.unstripped # ------------------------------------------------------------------------= --- =20 ifdef CONFIG_MODULES targets +=3D .vmlinux.export.o -$(vmlinux-final): .vmlinux.export.o +vmlinux.unstripped: .vmlinux.export.o endif =20 ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX -$(vmlinux-final): arch/$(SRCARCH)/tools/vmlinux.arch.o +vmlinux.unstripped: arch/$(SRCARCH)/tools/vmlinux.arch.o =20 arch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE $(Q)$(MAKE) $(build)=3Darch/$(SRCARCH)/tools $@ @@ -86,17 +72,30 @@ cmd_link_vmlinux =3D \ $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) =20 -targets +=3D $(vmlinux-final) -$(vmlinux-final): scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE +targets +=3D vmlinux.unstripped +vmlinux.unstripped: scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE +$(call if_changed_dep,link_vmlinux) ifdef CONFIG_DEBUG_INFO_BTF -$(vmlinux-final): $(RESOLVE_BTFIDS) +vmlinux.unstripped: $(RESOLVE_BTFIDS) endif =20 ifdef CONFIG_BUILDTIME_TABLE_SORT -$(vmlinux-final): scripts/sorttable +vmlinux.unstripped: scripts/sorttable endif =20 +# vmlinux +# ------------------------------------------------------------------------= --- + +remove-section-y :=3D +remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) +=3D '.rel*' + +quiet_cmd_strip_relocs =3D OBJCOPY $@ + cmd_strip_relocs =3D $(OBJCOPY) $(addprefix --remove-section=3D,$(re= move-section-y)) $< $@ + +targets +=3D vmlinux +vmlinux: vmlinux.unstripped FORCE + $(call if_changed,strip_relocs) + # modules.builtin.ranges # ------------------------------------------------------------------------= --- ifdef CONFIG_BUILTIN_MODULE_RANGES @@ -110,7 +109,7 @@ modules.builtin.ranges: $(srctree)/scripts/generate_bui= ltin_ranges.awk \ modules.builtin vmlinux.map vmlinux.o.map FORCE $(call if_changed,modules_builtin_ranges) =20 -vmlinux.map: $(vmlinux-final) +vmlinux.map: vmlinux.unstripped @: =20 endif --=20 2.49.0 From nobody Thu Oct 9 01:16:06 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7F34F20D4E1; Sat, 21 Jun 2025 13:57:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750514264; cv=none; b=N9KkSi5QZeiJLU5/1FwDNDksdISWMIuNaIpJ2te+6gN8qVQLGbaOGykjet1Z3A/QAr6cflVDEhbOxiOWsDyVGngs7mtTMXWj5gIPkaKamdyLiXiQzaz4dhp5SRttcFN1VIibLzherhrT5pbExjjfKj019ZF/wkuDoTHWeUDR98c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750514264; c=relaxed/simple; bh=KUafdHVAFlR3dIvZDr3EeiL7KupPBGcv8xjCd5EYL7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tOWJW22wQ4sBHJBONiowiO3Wa23rr6aT5bFDqa1Hdm7iIteONFchX8b2Oiylh8t35zKsgEDRHr+qR4UQH6+u9owXdTs7AO6tZ3BduoqGf2uifbaAD0y7o9tk+7VWfGkmWY3mt0lmI4ND2gRggbhOltudQ2j5CqOpOq3uEdDFv54= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OCq25/PR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OCq25/PR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BBB5C4AF09; Sat, 21 Jun 2025 13:57:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750514263; bh=KUafdHVAFlR3dIvZDr3EeiL7KupPBGcv8xjCd5EYL7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OCq25/PRcRZlK95RHWzkqXJ+EKEB60MZvwjTeO0MIIgDESs8xKXCzaaTDzm7dc+ue dypbzqRKPCfBLp5llR7ewrAyMYvIK4yoU/Ni/buCo8Cx1jijlgZWd1LGGEph6ppjeX dibVTqeKCUQp0Au7duiUeklV9PcR3JQ44jQuNZf2L4MfkiVc1YiIN0tux9GtvQ9Pnm 8Jhm3BgMxnzaPr1JwPG6+UFvgV3VuAyel2OD2pUGt6wOUaxWaecdrvMNhRtvgQ15Uh 0ZAlG6hNxIud1mOI1Mj+yuCLbH9AXdlweYfXQhh0bSBsKJHP2pbCCIGYeLprr+4NOe TVcDU0VvJjivg== From: Alexey Gladkov To: Masahiro Yamada , Petr Pavlu , Luis Chamberlain , Sami Tolvanen , Daniel Gomez , Nathan Chancellor , Nicolas Schier Cc: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH v4 3/7] kbuild: keep .modinfo section in vmlinux.unstripped Date: Sat, 21 Jun 2025 15:57:15 +0200 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: 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: Masahiro Yamada Keep the .modinfo section during linking, but strip it from the final vmlinux. Adjust scripts/mksysmap to exclude modinfo symbols from kallsyms. This change will allow the next commit to extract the .modinfo section from the vmlinux.unstripped intermediate. Signed-off-by: Masahiro Yamada --- include/asm-generic/vmlinux.lds.h | 2 +- scripts/Makefile.vmlinux | 2 +- scripts/mksysmap | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinu= x.lds.h index fa5f19b8d53a..1791665006f9 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -831,6 +831,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELL= ER_CLANG) =20 /* Required sections not related to debugging. */ #define ELF_DETAILS \ + .modinfo : { *(.modinfo) } \ .comment 0 : { *(.comment) } \ .symtab 0 : { *(.symtab) } \ .strtab 0 : { *(.strtab) } \ @@ -1044,7 +1045,6 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPE= LLER_CLANG) *(.discard.*) \ *(.export_symbol) \ *(.no_trim_symbol) \ - *(.modinfo) \ /* ld.bfd warns about .gnu.version* even when not emitted */ \ *(.gnu.version*) \ =20 diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index 4f2d4c3fb737..e2ceeb9e168d 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -86,7 +86,7 @@ endif # vmlinux # ------------------------------------------------------------------------= --- =20 -remove-section-y :=3D +remove-section-y :=3D .modinfo remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) +=3D '.rel*' =20 quiet_cmd_strip_relocs =3D OBJCOPY $@ diff --git a/scripts/mksysmap b/scripts/mksysmap index 3accbdb269ac..a607a0059d11 100755 --- a/scripts/mksysmap +++ b/scripts/mksysmap @@ -79,6 +79,9 @@ / _SDA_BASE_$/d / _SDA2_BASE_$/d =20 +# MODULE_INFO() +/ __UNIQUE_ID_modinfo[0-9]*$/d + # ------------------------------------------------------------------------= --- # Ignored patterns # (symbols that contain the pattern are ignored) --=20 2.49.0 From nobody Thu Oct 9 01:16:06 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9D5C420D4E1; Sat, 21 Jun 2025 13:57:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750514267; cv=none; b=R7pPQxzy2XxP1t0hpmBh70AKHyJ/E6627RIuXUuKNFpfq87wsKBvDMkGDOA3sdZDUg83KDcVtrMrqiGP6er/rAu0M/MXtlZTjVDvWTCp8Z93HaJeqDYXYqm5qyuzrrWWlDh0KuT3QTdaU53mmZ4T3PEWYRH2F2bU0lJhtHqKDtg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750514267; c=relaxed/simple; bh=QcOgqocEZGX7M/SEIk2LBmtO7Cxt9ewPmhV9uu+zKeo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JhSmfs/QGC+EUaBAkQJRzsyJQhhYHSaP14z9fAmi/pPLxXXgVHja13muW1ErU93yueJ1etBAxSbrkxuUIl0PQ9bUU2bkR4hH7OV2e6txjlLsEwclGdoR7MLZpRgD/IIYDAKJwlRy8v9B6gybCawXNINlwVNbTLWSEQS5WfcwFNs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PHgATPsr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PHgATPsr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 657D7C4CEED; Sat, 21 Jun 2025 13:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750514267; bh=QcOgqocEZGX7M/SEIk2LBmtO7Cxt9ewPmhV9uu+zKeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PHgATPsrwCG/JM5poSek8+RUoOLPPenjrnN6sw9ZEThNHG53reF0KHz35aRYLb32P S+m/GkNMaXoM8xT0nSfSajjVLgmHkyzIZpfJ6a2+ZwuccLUixyYxduiFlYJyjaEaHq irzP2OHP0/+SRtuSW/YY//LI2dgA0pTN6T9hQSbma7qAn0uy7h1QOj8kX3yJgZuJE3 74gZGkq0jVvzRXCO45KRhF2ZMwVjrEY7x0fZcjBVA8MrdDGsZLjTNC11aBjFVFSD8s Lc86Npa/wAsANJ57XvGd7lqA8ey4NX9EW38By5mf3+gLndeSKX/rsukHo5HZzbL04H BPsaXrwEAc58w== From: Alexey Gladkov To: Masahiro Yamada , Petr Pavlu , Luis Chamberlain , Sami Tolvanen , Daniel Gomez , Nathan Chancellor , Nicolas Schier Cc: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-scsi@vger.kernel.org, Alexey Gladkov Subject: [PATCH v4 4/7] kbuild: extract modules.builtin.modinfo from vmlinux.unstripped Date: Sat, 21 Jun 2025 15:57:16 +0200 Message-ID: <38c1e5cd57158ff433c00e71a437dbab4c0285a8.1750511018.git.legion@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: 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: Masahiro Yamada Currently, we assume all the data for modules.builtin.modinfo are available in vmlinux.o. This makes it impossible for modpost, which is invoked after vmlinux.o, to add additional module info. This commit moves the modules.builtin.modinfo rule after modpost. Signed-off-by: Masahiro Yamada Signed-off-by: Alexey Gladkov --- scripts/Makefile.vmlinux | 26 ++++++++++++++++++++++++++ scripts/Makefile.vmlinux_o | 26 +------------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index e2ceeb9e168d..fdab5aa90215 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -96,6 +96,32 @@ targets +=3D vmlinux vmlinux: vmlinux.unstripped FORCE $(call if_changed,strip_relocs) =20 +# modules.builtin.modinfo +# ------------------------------------------------------------------------= --- + +OBJCOPYFLAGS_modules.builtin.modinfo :=3D -j .modinfo -O binary + +targets +=3D modules.builtin.modinfo +modules.builtin.modinfo: vmlinux.unstripped FORCE + $(call if_changed,objcopy) + +# modules.builtin +# ------------------------------------------------------------------------= --- + +__default: modules.builtin + +# The second line aids cases where multiple modules share the same object. + +quiet_cmd_modules_builtin =3D GEN $@ + cmd_modules_builtin =3D \ + tr '\0' '\n' < $< | \ + sed -n 's/^[[:alnum:]:_]*\.file=3D//p' | \ + tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@ + +targets +=3D modules.builtin +modules.builtin: modules.builtin.modinfo FORCE + $(call if_changed,modules_builtin) + # modules.builtin.ranges # ------------------------------------------------------------------------= --- ifdef CONFIG_BUILTIN_MODULE_RANGES diff --git a/scripts/Makefile.vmlinux_o b/scripts/Makefile.vmlinux_o index b024ffb3e201..23c8751285d7 100644 --- a/scripts/Makefile.vmlinux_o +++ b/scripts/Makefile.vmlinux_o @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only =20 PHONY :=3D __default -__default: vmlinux.o modules.builtin.modinfo modules.builtin +__default: vmlinux.o =20 include include/config/auto.conf include $(srctree)/scripts/Kbuild.include @@ -73,30 +73,6 @@ vmlinux.o: $(initcalls-lds) vmlinux.a $(KBUILD_VMLINUX_L= IBS) FORCE =20 targets +=3D vmlinux.o =20 -# modules.builtin.modinfo -# ------------------------------------------------------------------------= --- - -OBJCOPYFLAGS_modules.builtin.modinfo :=3D -j .modinfo -O binary - -targets +=3D modules.builtin.modinfo -modules.builtin.modinfo: vmlinux.o FORCE - $(call if_changed,objcopy) - -# modules.builtin -# ------------------------------------------------------------------------= --- - -# The second line aids cases where multiple modules share the same object. - -quiet_cmd_modules_builtin =3D GEN $@ - cmd_modules_builtin =3D \ - tr '\0' '\n' < $< | \ - sed -n 's/^[[:alnum:]:_]*\.file=3D//p' | \ - tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@ - -targets +=3D modules.builtin -modules.builtin: modules.builtin.modinfo FORCE - $(call if_changed,modules_builtin) - # Add FORCE to the prerequisites of a target to force it to be always rebu= ilt. # ------------------------------------------------------------------------= --- =20 --=20 2.49.0 From nobody Thu Oct 9 01:16:06 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2771872629; Sat, 21 Jun 2025 13:57:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750514271; cv=none; b=un24a+YmXYrI4cQw7GXUPrjZ/MmDCGIUbNFdhO43Bla+H4yQ0sW26VKYBD+h3WpyjthZW1pjEX9T2OvLF0PqpBtybJDhE8mt+e6YVRgjPsjVILwFc3qxZB0pG2GrSKUJvEqgC8lhWwnV0VHkijhekzVdm59yJckU92MFzWvCPEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750514271; c=relaxed/simple; bh=cXATu5WHYSddNew6hPBjs/f3aIkMJ3j64KCP2miazbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qx05LO84E8r+BoOTcuB8sBVpEEtXrFLD179gKtOOsvW3ZYxX0GjYew7gY3FBIQi1nFhfWRV+DJJoxdb93FY8IftZCBiL/8bouzjj85mOGJ8sHcV2XuvWR4UTDkTsmnJlqHk1gcR1i/GtdjADMUkU5Kbk6iw+VQHUKtH9DumCS2A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f+8yleFK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="f+8yleFK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92E3EC4CEE7; Sat, 21 Jun 2025 13:57:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750514270; bh=cXATu5WHYSddNew6hPBjs/f3aIkMJ3j64KCP2miazbo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f+8yleFKIaGU88WKWjhroLJO29zQe1UJsd7OK4BWcOQ76RyyB2WvJWx6HJ/D6b4CA zt0W7OHPa7lAAxEUqSqlWd205M2n3y+hsyZxybjvGp1+6SzZDl8pB+kA1cjDdRrhDG D5K2mIgrzr3u/1oQU+5RWJ4E6DOtcgZ83LDdcVAuLlM5kE4/suIAw6GDGDkm4Nn1We p+/96D0zAdMqc0jsjsfBYNJdirLRhpDe3fZKBRxx8e5nas4QZLrfghDrhHb0/nVdyu CP/jfx12iQQ/dWLNc7a5Y8Nbq5qJxyJfIVdmy7ztXwtuAzA9ufS+RDR9yG77QUzKdH 9CbbNhzXftjYw== From: Alexey Gladkov To: Masahiro Yamada , Petr Pavlu , Luis Chamberlain , Sami Tolvanen , Daniel Gomez , Nathan Chancellor , Nicolas Schier Cc: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-scsi@vger.kernel.org, Alexey Gladkov , Khalid Aziz , "Martin K. Petersen" , James Bottomley Subject: [PATCH v4 5/7] scsi: Always define blogic_pci_tbl structure Date: Sat, 21 Jun 2025 15:57:17 +0200 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: 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" The blogic_pci_tbl structure is used by the MODULE_DEVICE_TABLE macro. There is no longer a need to protect it with the MODULE condition, since this no longer causes the compiler to warn about an unused variable. Cc: Khalid Aziz Cc: "Martin K. Petersen" Suggested-by: James Bottomley Signed-off-by: Alexey Gladkov --- drivers/scsi/BusLogic.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c index 1f100270cd38..08e12a3d6703 100644 --- a/drivers/scsi/BusLogic.c +++ b/drivers/scsi/BusLogic.c @@ -3715,7 +3715,6 @@ static void __exit blogic_exit(void) =20 __setup("BusLogic=3D", blogic_setup); =20 -#ifdef MODULE /*static const struct pci_device_id blogic_pci_tbl[] =3D { { PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, @@ -3731,7 +3730,6 @@ static const struct pci_device_id blogic_pci_tbl[] = =3D { {PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT)}, {0, }, }; -#endif MODULE_DEVICE_TABLE(pci, blogic_pci_tbl); =20 module_init(blogic_init); --=20 2.49.0 From nobody Thu Oct 9 01:16:06 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4C98C221540; Sat, 21 Jun 2025 13:57:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750514274; cv=none; b=Yz9oQLJb5qXEzulRLC7cXZlBZHWu/VvjolkNNj089tbm7sDnekHTc9oBFmOxtPE1oiNcjFudcyyhKUe2McCEGqiy+ZEWt7N0i4e/pUioS0DGOBWZgCEwquTPyMYun6s7Pz2xWFOGy45+CXcUuNCKERv/c1SB4RuRQAcSQ9LfbSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750514274; c=relaxed/simple; bh=AuegPmeYvpA3eTfQDAnxQdGpla+4yg+qXxtOidi62CQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IeNKVAEPok2yhJnID4AfTe5IMgqMl53SETdEURnMGeXLAH0+lmoDdZFXrwy1qAcG8gH/wQY/B7qftMXT+bD+1RjsjQaT3vurtt+Cqhe+dl5dkBxZr3l4Mmrsuw2oPFdau6reSn0PMrI4JpC6wLUkudHqtpGq2/cgPl7+HlP+9eM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Nrrb5O7N; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Nrrb5O7N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F926C4CEEF; Sat, 21 Jun 2025 13:57:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750514274; bh=AuegPmeYvpA3eTfQDAnxQdGpla+4yg+qXxtOidi62CQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nrrb5O7N9VjsXmw5z9X2sNO0f4k++mtYq9sJYt10ibLmkHyJeufaYAOvOnAwi2OIc YoNHp/tNz+PJqH0uSMt3xdrSByt6wSAAoGvKAZtvea8yUUrq9fiOxA0uIdLxhZARcP kMMGsP4dYI8TEjTQbehQ2kMARDnmdOhtQgczXV+u0RJM4yOTKQfHZ/I3ABn10rnaPV uXE7dG6f+Bmeva01H5cfNG6+CvXF/AubXVDmnDHvJuP4RHtTPB1vdAnXKQBL2/wK8U Y0i5pz0fSNIQIZ16cDqD9WmJR/iHIyxYtqymEf+EmJPvvzupKIzqFG99xJTJCBGYt6 mCkeck4udQivw== From: Alexey Gladkov To: Masahiro Yamada , Petr Pavlu , Luis Chamberlain , Sami Tolvanen , Daniel Gomez , Nathan Chancellor , Nicolas Schier Cc: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-scsi@vger.kernel.org, Alexey Gladkov , Miguel Ojeda , Alex Gaynor Subject: [PATCH v4 6/7] modpost: Add modname to mod_device_table alias Date: Sat, 21 Jun 2025 15:57:18 +0200 Message-ID: <6e2f70b07a710e761eb68d089d96cee7b27bb2d5.1750511018.git.legion@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: 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" At this point, if a symbol is compiled as part of the kernel, information about which module the symbol belongs to is lost. To save this it is possible to add the module name to the alias name. It's not very pretty, but it's possible for now. Cc: Miguel Ojeda Cc: Alex Gaynor =20 Signed-off-by: Alexey Gladkov --- include/linux/module.h | 14 +++++++++++--- rust/kernel/device_id.rs | 8 ++++---- scripts/mod/file2alias.c | 18 ++++++++++++++---- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 24fe6b865e9c..e0f826fab2ac 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -243,11 +243,19 @@ struct module_kobject *lookup_or_create_module_kobjec= t(const char *name); /* What your module does. */ #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _descrip= tion) =20 +/* Format: __mod_device_table__kmod_____ */ +#define __mod_device_table(type, name) \ + __PASTE(__mod_device_table__, \ + __PASTE(__KBUILD_MODNAME, \ + __PASTE(__, \ + __PASTE(type, \ + __PASTE(__, name))))) + #ifdef MODULE /* Creates an alias so file2alias.c can find device table. */ -#define MODULE_DEVICE_TABLE(type, name) \ -extern typeof(name) __mod_device_table__##type##__##name \ - __attribute__ ((unused, alias(__stringify(name)))) +#define MODULE_DEVICE_TABLE(type, name) \ +static typeof(name) __mod_device_table(type, name) \ + __attribute__ ((used, alias(__stringify(name)))) #else /* !MODULE */ #define MODULE_DEVICE_TABLE(type, name) #endif diff --git a/rust/kernel/device_id.rs b/rust/kernel/device_id.rs index 0a4eb56d98f2..365d8f544844 100644 --- a/rust/kernel/device_id.rs +++ b/rust/kernel/device_id.rs @@ -154,10 +154,10 @@ macro_rules! module_device_table { ($table_type: literal, $module_table_name:ident, $table_name:ident) = =3D> { #[rustfmt::skip] #[export_name =3D - concat!("__mod_device_table__", $table_type, - "__", module_path!(), - "_", line!(), - "_", stringify!($table_name)) + concat!("__mod_device_table__", line!(), + "__kmod_", module_path!(), + "__", $table_type, + "__", stringify!($table_name)) ] static $module_table_name: [::core::mem::MaybeUninit; $table_n= ame.raw_ids().size()] =3D unsafe { ::core::mem::transmute_copy($table_name.raw_ids()) }; diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 00586119a25b..13021266a18f 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -1476,8 +1476,8 @@ void handle_moddevtable(struct module *mod, struct el= f_info *info, { void *symval; char *zeros =3D NULL; - const char *type, *name; - size_t typelen; + const char *type, *name, *modname; + size_t typelen, modnamelen; static const char *prefix =3D "__mod_device_table__"; =20 /* We're looking for a section relative symbol */ @@ -1488,10 +1488,20 @@ void handle_moddevtable(struct module *mod, struct = elf_info *info, if (ELF_ST_TYPE(sym->st_info) !=3D STT_OBJECT) return; =20 - /* All our symbols are of form __mod_device_table____. */ + /* All our symbols are of form __mod_device_table__kmod___= __. */ if (!strstarts(symname, prefix)) return; - type =3D symname + strlen(prefix); + + modname =3D strstr(symname, "__kmod_"); + if (!modname) + return; + modname +=3D strlen("__kmod_"); + + type =3D strstr(modname, "__"); + if (!type) + return; + modnamelen =3D type - modname; + type +=3D strlen("__"); =20 name =3D strstr(type, "__"); if (!name) --=20 2.49.0 From nobody Thu Oct 9 01:16:06 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 49B76221FA4; Sat, 21 Jun 2025 13:57:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750514277; cv=none; b=WYrp0KbTXKWBMomr8i98rzDm8hG19rjnfe29j9Yp4nSHWRAUOn0IrfPe+QxXhJFQimeY/NXSSsQmjL21o6B7dMR8D0YklS47QmaMAXL1GtuNkaqMKouJGaF4PiOliUSn6+2gl522T7ycTCyV96t1XviHOkeD0HAnM3hBPWQbJGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750514277; c=relaxed/simple; bh=nEVwenXZZz5nM7DkAj/oakR9uk7yJuktxc9Q++SALQI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VzwfyfygNW/MUJrdAvlqZl/21HUzu20S6gLisfLLxgy3bQ6pProLawUHkVs6/heJQLBRIIE2NKPP4Ak6uhsWp+i1puwWLjAAgMVqI1TRWEePLkddYqTyeXm4KKXBX5Heso249Ek+GUGryLpT0Dy2UQt66xbn92Ii5wApRNbAdzw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QQAmjQmS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QQAmjQmS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97DA7C4CEE7; Sat, 21 Jun 2025 13:57:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750514277; bh=nEVwenXZZz5nM7DkAj/oakR9uk7yJuktxc9Q++SALQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QQAmjQmSnGNaSRJWHBTNWcBSGB0eex/eBbsr/t3VEr//g5kgG81MHjaNEp4mWrD3x wkq3ozdRubVpozvitVwkRaCMhEub3MwaFF6EdOM3uv2vPKShW2wZobF0Ntp8jjM0mY Kz7jyViiU0EXr7Y4dd0qCMSj/EaKjJoTbNbH+gvlxMu/5saB6qEq3mJP5T3rsqcIxH RRuhpyGsLiJm7Yj06iAVfoksO9N+K0gsC3uNLOBDokdNc0NBwREKfFgc5W8Lv/VBBR LG6YcjYvAtkX1vMPX1z0o1BXrw4Xd1J3D9SDhh6Z7lH38zTzDy8cdEU4TaKAcLG8px eIe4d6VMI66Jg== From: Alexey Gladkov To: Masahiro Yamada , Petr Pavlu , Luis Chamberlain , Sami Tolvanen , Daniel Gomez , Nathan Chancellor , Nicolas Schier Cc: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-scsi@vger.kernel.org, Alexey Gladkov Subject: [PATCH v4 7/7] modpost: Create modalias for builtin modules Date: Sat, 21 Jun 2025 15:57:19 +0200 Message-ID: <321947106ec997b5a2a9c93ec2229cb2f9eb377c.1750511018.git.legion@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: 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" For some modules, modalias is generated using the modpost utility and the section is added to the module file. When a module is added inside vmlinux, modpost does not generate modalias for such modules and the information is lost. As a result kmod (which uses modules.builtin.modinfo in userspace) cannot determine that modalias is handled by a builtin kernel module. $ cat /sys/devices/pci0000:00/0000:00:14.0/modalias pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30 $ modinfo xhci_pci name: xhci_pci filename: (builtin) license: GPL file: drivers/usb/host/xhci-pci description: xHCI PCI Host Controller Driver Missing modalias "pci:v*d*sv*sd*bc0Csc03i30*" which will be generated by modpost if the module is built separately. To fix this it is necessary to generate the same modalias for vmlinux as for the individual modules. Fortunately '.vmlinux.export.o' is already generated from which '.modinfo' can be extracted in the same way as for vmlinux.o. Signed-off-by: Masahiro Yamada Signed-off-by: Alexey Gladkov --- include/linux/module.h | 4 ---- scripts/Makefile.vmlinux | 5 ++++- scripts/mksysmap | 3 +++ scripts/mod/file2alias.c | 16 ++++++++++++++++ scripts/mod/modpost.c | 17 ++++++++++++++++- scripts/mod/modpost.h | 2 ++ 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index e0f826fab2ac..3aeee5d0a77c 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -251,14 +251,10 @@ struct module_kobject *lookup_or_create_module_kobjec= t(const char *name); __PASTE(type, \ __PASTE(__, name))))) =20 -#ifdef MODULE /* Creates an alias so file2alias.c can find device table. */ #define MODULE_DEVICE_TABLE(type, name) \ static typeof(name) __mod_device_table(type, name) \ __attribute__ ((used, alias(__stringify(name)))) -#else /* !MODULE */ -#define MODULE_DEVICE_TABLE(type, name) -#endif =20 /* Version of form [:][-]. * Or for CVS/RCS ID version, everything but the number is stripped. diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index fdab5aa90215..fcc188d26ead 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -89,8 +89,11 @@ endif remove-section-y :=3D .modinfo remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) +=3D '.rel*' =20 +remove-symbols :=3D -w --strip-symbol=3D'__mod_device_table__*' + quiet_cmd_strip_relocs =3D OBJCOPY $@ - cmd_strip_relocs =3D $(OBJCOPY) $(addprefix --remove-section=3D,$(re= move-section-y)) $< $@ + cmd_strip_relocs =3D $(OBJCOPY) $(addprefix --remove-section=3D,$(re= move-section-y)) \ + $(remove-symbols) $< $@ =20 targets +=3D vmlinux vmlinux: vmlinux.unstripped FORCE diff --git a/scripts/mksysmap b/scripts/mksysmap index a607a0059d11..c4531eacde20 100755 --- a/scripts/mksysmap +++ b/scripts/mksysmap @@ -59,6 +59,9 @@ # EXPORT_SYMBOL (namespace) / __kstrtabns_/d =20 +# MODULE_DEVICE_TABLE (symbol name) +/ __mod_device_table__/d + # ------------------------------------------------------------------------= --- # Ignored suffixes # (do not forget '$' after each pattern) diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 13021266a18f..7da9735e7ab3 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -1527,5 +1527,21 @@ void handle_moddevtable(struct module *mod, struct e= lf_info *info, } } =20 + if (mod->is_vmlinux) { + struct module_alias *alias; + + /* + * If this is vmlinux, record the name of the builtin module. + * Traverse the linked list in the reverse order, and set the + * builtin_modname unless it has already been set in the + * previous call. + */ + list_for_each_entry_reverse(alias, &mod->aliases, node) { + if (alias->builtin_modname) + break; + alias->builtin_modname =3D xstrndup(modname, modnamelen); + } + } + free(zeros); } diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index be89921d60b6..67668b159444 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -2021,11 +2021,26 @@ static void write_if_changed(struct buffer *b, cons= t char *fname) static void write_vmlinux_export_c_file(struct module *mod) { struct buffer buf =3D { }; + struct module_alias *alias, *next; =20 buf_printf(&buf, - "#include \n"); + "#include \n" + "#include \n"); =20 add_exported_symbols(&buf, mod); + + buf_printf(&buf, + "#undef __MODULE_INFO_PREFIX\n" + "#define __MODULE_INFO_PREFIX\n"); + + list_for_each_entry_safe(alias, next, &mod->aliases, node) { + buf_printf(&buf, "MODULE_INFO(%s.alias, \"%s\");\n", + alias->builtin_modname, alias->str); + list_del(&alias->node); + free(alias->builtin_modname); + free(alias); + } + write_if_changed(&buf, ".vmlinux.export.c"); free(buf.p); } diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index 9133e4c3803f..2aecb8f25c87 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -99,10 +99,12 @@ buf_write(struct buffer *buf, const char *s, int len); * struct module_alias - auto-generated MODULE_ALIAS() * * @node: linked to module::aliases + * @modname: name of the builtin module (only for vmlinux) * @str: a string for MODULE_ALIAS() */ struct module_alias { struct list_head node; + char *builtin_modname; char str[]; }; =20 --=20 2.49.0