From mboxrd@z Thu Jan 1 00:00:00 1970 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 6E4533469EF; Mon, 18 Aug 2025 16:58:15 +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=1755536295; cv=none; b=q8w0k+InnZ5W5gsD7P82Q1trH0Ilz0MScNBRjBszoxgpEmDQkOMFDjPjlfstLWraqfeKXnrNbOayqQCURcG2HQ7lkqh2vTBbcJZKosiybNP6Ow2hKpwiNtEYQdZO+vMt9YrbLBcw+ijrpSfXtWlRpBP0KaDfqR+pQmcyQ/o2pF4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755536295; c=relaxed/simple; bh=pWuSm8OMULuPDaXWOoarB+IRlnekDjxa7jgyfttfV58=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rxtdM/+NDOiH0BepA6AJ1jG/aoymrzcJF9H/jd4WFsDib3Wpzmhdw1VrWwoPEeSO+csHP0MQScve9WCEOIH7KriBvXYmrzJNOtGeYEVRje2GOx/sXOga341/6SE62S6QK5D+3zTmojDrM4DoBhQrNg31xoiOQ3uX40dleVTL2/Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MLe5ivNV; 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="MLe5ivNV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27FBBC4CEEB; Mon, 18 Aug 2025 16:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755536295; bh=pWuSm8OMULuPDaXWOoarB+IRlnekDjxa7jgyfttfV58=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MLe5ivNV87Y7Sb5KhyYweHoF8xwm+lNFj9MTSmwC/CQKvLgzbFgc77mqcU5l0rlmH ZnjjXJa/45adVf4Vfpd9re8nLFmrxNj8ymSApNnnW5QqLikFI1QumrzSygT8sCRn3Y 6b/NWS9N3v10VepyCNJtAwrbVcqVvBCaTS5XIW0p5HXCWSpHIjmQi4OdGOYfx03muY jL1H8tDK99Ojp9mEib0mLPLK6u9MUPUWzV58KAnIpPHvRlQcLh5aiVhwLp5EI8rRY4 mt9MNqQ+D4XnShrx/TANmnhB28gXTljAGkdFR0k6oQnEf4/QV9SZvZTnul+cNEciVE m3nImo51rg0Vg== From: Alexey Gladkov To: Nathan Chancellor , Nicolas Schier , Petr Pavlu , Luis Chamberlain , Sami Tolvanen , Daniel Gomez Cc: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-kbuild@vger.kernel.org, Alexey Gladkov , Miguel Ojeda , Andreas Hindborg , Danilo Krummrich , Alex Gaynor , rust-for-linux@vger.kernel.org Subject: [PATCH v7 6/8] modpost: Add modname to mod_device_table alias Date: Mon, 18 Aug 2025 18:55:00 +0200 Message-ID: <66785b63b47878446a15bcb14a9ef42dc3bda092.1755535876.git.legion@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: Andreas Hindborg Cc: Danilo Krummrich Cc: Alex Gaynor Cc: rust-for-linux@vger.kernel.org Signed-off-by: Alexey Gladkov Acked-by: Danilo Krummrich --- include/linux/module.h | 14 +++++++++++++- rust/kernel/device_id.rs | 8 ++++---- scripts/mod/file2alias.c | 18 ++++++++++++++---- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 3319a5269d286..e31ee29fac6b7 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -244,10 +244,22 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name); /* What your module does. */ #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description) +/* + * Format: __mod_device_table__kmod_____ + * Parts of the string `__kmod_` and `__` are used as delimiters when parsing + * a symbol in file2alias.c + */ +#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) \ -static typeof(name) __mod_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) diff --git a/rust/kernel/device_id.rs b/rust/kernel/device_id.rs index 70d57814ff79b..62c42da12e9de 100644 --- a/rust/kernel/device_id.rs +++ b/rust/kernel/device_id.rs @@ -195,10 +195,10 @@ macro_rules! module_device_table { ($table_type: literal, $module_table_name:ident, $table_name:ident) => { #[rustfmt::skip] #[export_name = - 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_name.raw_ids().size()] = unsafe { ::core::mem::transmute_copy($table_name.raw_ids()) }; diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 00586119a25b7..13021266a18f8 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -1476,8 +1476,8 @@ void handle_moddevtable(struct module *mod, struct elf_info *info, { void *symval; char *zeros = NULL; - const char *type, *name; - size_t typelen; + const char *type, *name, *modname; + size_t typelen, modnamelen; static const char *prefix = "__mod_device_table__"; /* 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) != STT_OBJECT) return; - /* 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 = symname + strlen(prefix); + + modname = strstr(symname, "__kmod_"); + if (!modname) + return; + modname += strlen("__kmod_"); + + type = strstr(modname, "__"); + if (!type) + return; + modnamelen = type - modname; + type += strlen("__"); name = strstr(type, "__"); if (!name) -- 2.50.1