All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rust: exports: emit ___EXPORT_SYMBOL without C declarations
@ 2026-10-19 15:12 Giuliano Procida
  2026-10-19 23:36 ` Sami Tolvanen
  2026-10-20 19:22 ` Miguel Ojeda
  0 siblings, 2 replies; 11+ messages in thread
From: Giuliano Procida @ 2026-10-19 15:12 UTC (permalink / raw)
  To: Miguel Ojeda; +Cc: rust-for-linux, Alice Ryhl, Sami Tolvanen, Giuliano Procida

Previously, `EXPORT_SYMBOL_RUST_GPL(sym)` declared `extern int sym;` so
that it could invoke `EXPORT_SYMBOL_GPL(sym)`, which required `sym` to
be a declared C identifier for `typeof(sym)`, `__ADDRESSABLE(sym)`, and
(when `CONFIG_GENDWARFKSYMS` is enabled) `__GENDWARFKSYMS_EXPORT(sym)`.

This resulted in the compiler emiting DWARF debug information in
`rust/exports.o` describing every exported Rust symbol—functions and
data alike, as a C `int` variable.

Although `rust/Makefile` sets `skip_gendwarfksyms = 1` on `exports.o`,
the bogus `int` DWARF entries were still present in `vmlinux`, where
they conflicted with the true DWARF types emitted by `rustc` and
confused DWARF consumers such as debuggers and ABI analysis tools.

This change defines `EXPORT_SYMBOL_RUST_GPL(sym)` using
`___EXPORT_SYMBOL` directly:

	asm(__stringify(___EXPORT_SYMBOL(sym, "GPL", "")))

matching the `__ASSEMBLY__` path in `include/linux/export.h`.

Omitting the C-level wrappers from `__EXPORT_SYMBOL` is safe because:
- `__GENDWARFKSYMS_EXPORT(sym)` is unneeded because `gendwarfksyms` runs
  directly on the defining Rust and helper object files and is already
  disabled for `rust/exports.o`.
- `extern int sym;`, `extern typeof(sym) sym;`, and `__ADDRESSABLE(sym)`
  have no effect in `rust/exports.c`: the symbols are already emitted in
  separate translation units (scraped via `nm --defined-only`), the fake
  `extern int` declaration never produced kCFI function type IDs, and
  `___EXPORT_SYMBOL` already emits a `.quad`/`.long` reference to `sym`
  in `.export_symbol` that satisfies both ELF linking and LTO module-asm
  symbol resolution.
- `DEFAULT_SYMBOL_NAMESPACE`, `__DISABLE_EXPORTS`, `__PKVM_HYP__`, and
  `__GENKSYMS__` are not used by `rust/exports.c`.

Signed-off-by: Giuliano Procida <gprocida@google.com>
---
 rust/exports.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/rust/exports.c b/rust/exports.c
index 1b52460b0f4e..7d094d0dea1c 100644
--- a/rust/exports.c
+++ b/rust/exports.c
@@ -1,19 +1,20 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * A hack to export Rust symbols for loadable modules without having to redo
- * the entire `include/linux/export.h` logic in Rust.
+ * Export Rust symbols for loadable modules using similar logic to that in
+ * `include/linux/export.h`.
  *
  * This requires Rust's new/future `v0` mangling scheme because the default one
  * ("legacy") uses invalid characters for C identifiers (thus we cannot use the
  * `EXPORT_SYMBOL_*` macros).
  *
  * All symbols are exported as GPL-only to guarantee no GPL-only feature is
- * accidentally exposed.
+ * accidentally exposed. There is no support for symbol namespaces.
  */
 
 #include <linux/export.h>
 
-#define EXPORT_SYMBOL_RUST_GPL(sym) extern int sym; EXPORT_SYMBOL_GPL(sym)
+#define EXPORT_SYMBOL_RUST_GPL(sym)				\
+	asm(__stringify(___EXPORT_SYMBOL(sym, "GPL", "")))
 
 #include "exports_core_generated.h"
 #include "exports_bindings_generated.h"
-- 
2.56.0.212.g129ede20d9-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-10-22 13:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-19 15:12 [PATCH] rust: exports: emit ___EXPORT_SYMBOL without C declarations Giuliano Procida
2026-10-19 23:36 ` Sami Tolvanen
2026-10-20 19:22 ` Miguel Ojeda
2026-10-21  9:27   ` Petr Pavlu
2026-10-21  9:44     ` Miguel Ojeda
2026-10-21 14:21   ` Giuliano Procida
2026-10-22 12:42     ` Miguel Ojeda
2026-10-22 13:46       ` [PATCH v2 0/2] clean up EXPORT_SYMBOL_RUST_GPL Giuliano Procida
2026-10-22 13:46       ` [PATCH v2 1/2] rust: move EXPORT_SYMBOL_RUST_GPL to include/linux/export.h Giuliano Procida
2026-10-22 13:55         ` sashiko-bot
2026-10-22 13:46       ` [PATCH v2 2/2] rust: exports: emit ___EXPORT_SYMBOL without C declarations Giuliano Procida

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.