From nobody Wed Feb 11 11:29:11 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 DD7F5F9C1; Fri, 9 May 2025 16:43: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=1746809023; cv=none; b=SnkkFRw99RuL8PdONRrST4oMt/33l5iwoOTKktpAFmwnRGS+V0o0xfX/ZhJhjUWZxyH7VEy3zIVfFeKSFxN1gfMfcc8K5jEn7qSxe/geE3DarBaW4MTG6PNFXJSYQmugLVa993lsmDpgB0SeXyIPwTvXgWa7eRv0eCFz4rN8h1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746809023; c=relaxed/simple; bh=RYLKPhewo+pQLbsEeVEVyqMLKlwFhIzqJZBOv9JiJWI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bOsaRn05ggmUti/GOsPhchgYlyXyWkRb/s8gD7aVVnal/kJHp2jYpJp07ySKGEZWf5JDqxGnJijM/xqpteZCliq5LzvQeyMtUd+Fu9O2RtpyvQD1hxmcaflGhBismQk78SN764j6oDQAF/tuNZX3mTxnVMihPkC1GqCOly4iKBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GrhYqGKR; 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="GrhYqGKR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07164C4CEED; Fri, 9 May 2025 16:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746809021; bh=RYLKPhewo+pQLbsEeVEVyqMLKlwFhIzqJZBOv9JiJWI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GrhYqGKRdIJw1LR5DmYsay1iOFGTuIp1ZLPFO8h8n0yEtgGZ8ZjmUMt1ptCW7MTsq lPz6ZRaAvENFjG7G6guSuw8GWE8OFKYGUb5j3wzz/lvgNkxrgUqGlg2Ww3gadB9Hqm VZmF8NeO9rE0EM6TGBuXZBdmEKN5bm2yduR/CD9QA9BBcJwSujzVkhbnZvLqqGFXKC CcOFu6Y8eClJzPf14HvyRxQf4uA04n9ReOwc55LFo6E8BPhiayM0Lr7Nfc6I0W1u5B DdKA84or5CioLaJtRE7LOtpl0Cqis9EvO9QwP1pWO3/1lfcFiUgE71CnoBKlvrSWP9 VhoS10hSLPaJA== From: Alexey Gladkov To: Petr Pavlu , Luis Chamberlain , 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 v2 3/6] modpost: Make mod_device_table aliases more unique Date: Fri, 9 May 2025 18:42:34 +0200 Message-ID: <20250509164237.2886508-4-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" In order to avoid symbol conflicts if they appear in the same binary, a more unique alias identifier can be generated. Signed-off-by: Alexey Gladkov Reviewed-by: Petr Pavlu --- include/linux/module.h | 14 ++++++++++++-- scripts/mod/file2alias.c | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index de0da7c7cf03..01fceca47a5b 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -249,10 +249,20 @@ 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(__COUNTER__, \ + __PASTE(__, \ + __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 \ +#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) diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 00586119a25b..dff1799a4c79 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