From nobody Wed Feb 11 11:30:35 2026 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 730CB25DCEE; Sat, 26 Apr 2025 16:18:49 +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=1745684329; cv=none; b=kDTV6IvbIxlv05T3dIvOr0t5U9Y2NMefU61LB7Jqjz5gsiuRvkW+FWSGTiaSv0meYOsjptt61ilL6oS4yxbDpA9J2rSL7MMNhenV1R6uBSx9gK5+stw1j+vyUAtzPf7KxADVHzr//bRiYH/gD4izNR9kenl2Y/AO99R+eEeunsU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745684329; c=relaxed/simple; bh=E60k28ZKt8yIe3zf+g3OEkU9hsKiFagyaN8gRcYtEdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dU+RzLK6tXY8GmWa7lkOeZVuer3T5/gWDNqoBtBd40M3s752VFpKEwp42UejdN7ntMJtvVO1oaLWbRyTFxaE/MF6UdWiZ7y85t9CZ2RK8ZFJWSrxyEJpPhnN01QEYV8SRyMHifXPcI+zO/VgasizD1VMOa1n78q40433PgT2jPo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tSE/TyNc; 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="tSE/TyNc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E19AC4CEE9; Sat, 26 Apr 2025 16:18:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745684328; bh=E60k28ZKt8yIe3zf+g3OEkU9hsKiFagyaN8gRcYtEdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tSE/TyNcKQ4PqC2ohm7KICFT/iX06ysRKhcGnc6+AAsS5CrO34hODfFXMEGvPRuqo uaLgC1OfR2ChuflezG9VsMr5L6bVkZTGVwUWSgAYuny7hFUeI+yzes/G9OjN4Z3nw5 WYuZ3fR2eA9vDaU2cNtetyX40Nld08ajgwB0WyS3GXea9rfVMsH6MfegYrhiFG0wUA Y/EfARvaM3j90hrMkwm/8OLQfEhZJtN16TlbkyNcL2rPPfFSasVfmtB/6hzdE+yhU/ +/ZvinTg0iwQGunfAwgEomJe/4RE6SIzm/LZWeW4S/bnnhp55PiorYydJcb2S0JdST J9FgLSby44DLA== From: Alexey Gladkov To: Luis Chamberlain , Petr Pavlu , Sami Tolvanen , Daniel Gomez , Masahiro Yamada , Nathan Chancellor , Nicolas Schier Cc: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-kbuild@vger.kernel.org, Alexey Gladkov Subject: [PATCH v1 5/7] modpost: Create modalias for builtin modules Date: Sat, 26 Apr 2025 18:16:36 +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" 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: Alexey Gladkov --- include/linux/module.h | 4 ---- scripts/mod/file2alias.c | 13 ++++++++++++- scripts/mod/modpost.c | 21 ++++++++++++++++++--- scripts/mod/modpost.h | 7 ++++++- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 7250b4a527ec..6225793ddcd4 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -257,14 +257,10 @@ extern void cleanup_module(void); __PASTE(type, \ __PASTE(__, name))))))) =20 -#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)))) -#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/mod/file2alias.c b/scripts/mod/file2alias.c index dff1799a4c79..0fa3f031b904 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -1471,7 +1471,8 @@ static const struct devtable devtable[] =3D { /* Create MODULE_ALIAS() statements. * At this time, we cannot write the actual output C source yet, * so we write into the mod->dev_table_buf buffer. */ -void handle_moddevtable(struct module *mod, struct elf_info *info, +void handle_moddevtable(struct list_head *modules, + struct module *mod, struct elf_info *info, Elf_Sym *sym, const char *symname) { void *symval; @@ -1509,6 +1510,16 @@ void handle_moddevtable(struct module *mod, struct e= lf_info *info, typelen =3D name - type; name +=3D strlen("__"); =20 + if (mod->is_vmlinux) { + struct module *builtin_mod; + + builtin_mod =3D new_module(modname, modnamelen); + builtin_mod->is_vmlinux =3D mod->is_vmlinux; + builtin_mod->dump_file =3D MODULE_BUILTIN_FNAME; + + mod =3D builtin_mod; + } + /* Handle all-NULL symbols allocated into .bss */ if (info->sechdrs[get_secindex(info, sym)].sh_type & SHT_NOBITS) { zeros =3D calloc(1, sym->st_size); diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index be89921d60b6..10e1987fc0e3 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -183,7 +183,7 @@ static struct module *find_module(const char *filename,= const char *modname) return NULL; } =20 -static struct module *new_module(const char *name, size_t namelen) +struct module *new_module(const char *name, size_t namelen) { struct module *mod; =20 @@ -1610,7 +1610,7 @@ static void read_symbols(const char *modname) symname =3D remove_dot(info.strtab + sym->st_name); =20 handle_symbol(mod, &info, sym, symname); - handle_moddevtable(mod, &info, sym, symname); + handle_moddevtable(&modules, mod, &info, sym, symname); } =20 check_sec_ref(mod, &info); @@ -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); + + list_for_each_entry(mod, &modules, list) { + if (!mod->is_vmlinux || !mod->dump_file || + strcmp(mod->dump_file, MODULE_BUILTIN_FNAME)) + continue; + list_for_each_entry_safe(alias, next, &mod->aliases, node) { + buf_printf(&buf, "MODULE_ALIAS_MODNAME(\"%s\", \"%s\");\n", + mod->name, alias->str); + list_del(&alias->node); + 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..85e48f7dd837 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -199,6 +199,10 @@ static inline bool is_valid_name(struct elf_info *elf,= Elf_Sym *sym) return !is_mapping_symbol(name); } =20 +#define MODULE_BUILTIN_FNAME "(builtin)" + +struct module *new_module(const char *name, size_t namelen); + /* symsearch.c */ void symsearch_init(struct elf_info *elf); void symsearch_finish(struct elf_info *elf); @@ -207,7 +211,8 @@ Elf_Sym *symsearch_find_nearest(struct elf_info *elf, E= lf_Addr addr, Elf_Addr min_distance); =20 /* file2alias.c */ -void handle_moddevtable(struct module *mod, struct elf_info *info, +void handle_moddevtable(struct list_head *modules, + struct module *mod, struct elf_info *info, Elf_Sym *sym, const char *symname); =20 /* sumversion.c */ --=20 2.49.0