rust: exports: emit ___EXPORT_SYMBOL without C declarations
Subsystems (4)
PATCH 1/1 rust: exports: emit ___EXPORT_SYMBOL without C declarations
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.
--- rust/exports.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
rust/exports.c +5 -4
@@ -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"
Signature · 1 line
2.56.0.212.g129ede20d9-goog
Quoted 36 lines · Giuliano Procida
Previously,
EXPORT_SYMBOL_RUST_GPL(sym)declaredextern int sym;so that it could invokeEXPORT_SYMBOL_GPL(sym), which requiredsymto be a declared C identifier fortypeof(sym),__ADDRESSABLE(sym), and (whenCONFIG_GENDWARFKSYMSis enabled)__GENDWARFKSYMS_EXPORT(sym).This resulted in the compiler emiting DWARF debug information in
rust/exports.odescribing every exported Rust symbol—functions and data alike, as a Cintvariable.Although
rust/Makefilesetsskip_gendwarfksyms = 1onexports.o, the bogusintDWARF entries were still present invmlinux, where they conflicted with the true DWARF types emitted byrustcand confused DWARF consumers such as debuggers and ABI analysis tools.This change defines
EXPORT_SYMBOL_RUST_GPL(sym)using___EXPORT_SYMBOLdirectly:asm(__stringify(___EXPORT_SYMBOL(sym, "GPL", "")))matching the
__ASSEMBLY__path ininclude/linux/export.h.Omitting the C-level wrappers from
__EXPORT_SYMBOLis safe because:
-__GENDWARFKSYMS_EXPORT(sym)is unneeded becausegendwarfksymsruns directly on the defining Rust and helper object files and is already disabled forrust/exports.o.
-extern int sym;,extern typeof(sym) sym;, and__ADDRESSABLE(sym)have no effect inrust/exports.c: the symbols are already emitted in separate translation units (scraped vianm --defined-only), the fakeextern intdeclaration never produced kCFI function type IDs, and___EXPORT_SYMBOLalready emits a.quad/.longreference tosymin.export_symbolthat satisfies both ELF linking and LTO module-asm symbol resolution.
-DEFAULT_SYMBOL_NAMESPACE,__DISABLE_EXPORTS,__PKVM_HYP__, and__GENKSYMS__are not used byrust/exports.c.
Quoted 1 line
Signed-off-by Giuliano Procida <[email protected]>
Sami
Quoted 7 lines · Giuliano Procida
This change defines
EXPORT_SYMBOL_RUST_GPL(sym)using___EXPORT_SYMBOLdirectly:asm(__stringify(___EXPORT_SYMBOL(sym, "GPL", "")))matching the
__ASSEMBLY__path ininclude/linux/export.h.
Hmm... It says it matches the __ASSEMBLY__ path, but it matches the #else path, no?
Cc'ing the RUST entry and modules too.
In addition, I wonder if we should avoid hardcoding the particular form of that asm(... and instead expose it from the C header. That way we avoid repetition and getting it out-of-sync -- that was part of the original reasoning.
By the way, I am right that you noticed this via GCC builds?
(Nit: please write the commit message in the imperative form:
https://docs.kernel.org/process/submitting-patches.html#describe-your-changes)
Thanks!
Cheers,
Miguel
Quoted 12 lines · Miguel Ojeda
Quoted 7 lines · Giuliano Procida
This change defines
EXPORT_SYMBOL_RUST_GPL(sym)using___EXPORT_SYMBOLdirectly:asm(__stringify(___EXPORT_SYMBOL(sym, "GPL", "")))matching the
__ASSEMBLY__path ininclude/linux/export.h.Hmm... It says it matches the
__ASSEMBLY__path, but it matches the#elsepath, no?
Quoted 6 lines
Cc'ing the
RUSTentry and modules too.In addition, I wonder if we should avoid hardcoding the particular form of that
asm(...and instead expose it from the C header. That way we avoid repetition and getting it out-of-sync -- that was part of the original reasoning.
It should be also ok to move EXPORT_SYMBOL_RUST_GPL() directly into include/linux/export.h.
-- Petr
Quoted 3 lines · Petr Pavlu
It should be also ok to move
EXPORT_SYMBOL_RUST_GPL()directly intoinclude/linux/export.h.
Yeah, that sounds great to me. Probably with a small comment added, and removing the one in Nova too (which this patch should do anyway -- it is going away, but still).
Cheers,
Miguel
Hi.
Quoted 6 lines · Miguel Ojeda
Quoted 4 lines · Giuliano Procida
This change defines
EXPORT_SYMBOL_RUST_GPL(sym)using___EXPORT_SYMBOLdirectly:
Quoted 6 lines
Quoted 3 lines
asm(__stringify(___EXPORT_SYMBOL(sym, "GPL", "")))matching the
__ASSEMBLY__path ininclude/linux/export.h.Hmm... It says it matches the
__ASSEMBLY__path, but it matches the#elsepath, no?
The description was AI generated, but it is accurate. Both paths use the triple-underscore three-argument macro alone.
...
#elif defined(__ASSEMBLY__)
#define __EXPORT_SYMBOL(sym, license, ns) \
___EXPORT_SYMBOL(sym, license, ns)
#else
...
Quoted 6 lines
Cc'ing the
RUSTentry and modules too.In addition, I wonder if we should avoid hardcoding the particular form of that
asm(...and instead expose it from the C header. That way we avoid repetition and getting it out-of-sync -- that was part of the original reasoning.
I wondered the same thing, but that would introduce yet another intermediate macro.
Quoted 1 line
By the way, I am right that you noticed this via GCC builds?
No, Android kernels have been built with Clang for years.
We post-process DWARF information with STG for ABI purposes and noticed this interesting side effect there.
Quoted 2 lines
(Nit: please write the commit message in the imperative form:
https://docs.kernel.org/process/submitting-patches.html#describe-your-changes)
I will do so in the next version.
Quoted 4 lines
Thanks!
Cheers,
Miguel
Quoted 3 lines · Giuliano Procida
The description was AI generated, but it is accurate. Both paths use the triple-underscore three-argument macro alone.
Yeah, I understand that not having the extern and so on is what the AI wants to emphasize here, instead of the asm(... wrapping of the #else side, but it sounds confusing to me, i.e. it introduces the change as if matching the assembly path was important for some reason in particular.
Quoted 2 lines
I wondered the same thing, but that would introduce yet another intermediate macro.
We are introducing a macro either way -- in fact we have to introduce it twice if we don't do it centrally.
I guess you mean avoiding the duplication in the C header, but that duplication already exists in this version. So if no new intermediate macro is preferred, then at least the duplication would be more local and thus more obvious when they both need to be updated.
Quoted 4 lines
No, Android kernels have been built with Clang for years.
We post-process DWARF information with STG for ABI purposes and noticed this interesting side effect there.
Ah, nevermind, I checked the DWARF emitted by Clang, but without gendwarfksyms, my bad (I am aware of Android using Clang, of course; it is why it sounded strange and wanted to double-check if it was related to GCC somehow).
Thanks!
Cheers,
Miguel
v2 cover clean up EXPORT_SYMBOL_RUST_GPL
The two separate patches now move EXPORT_SYMBOL_RUST_GPL definitions into linux/export.h and prevent the emission of bogus type information for Rust symbols.
Giuliano Procida (2):
rust: move EXPORT_SYMBOL_RUST_GPL to include/linux/export.h
rust: exports: emit ___EXPORT_SYMBOL without C declarations
drivers/gpu/Makefile | 4 ++-- drivers/gpu/nova-core/nova_core_exports.c | 2 -- include/linux/export.h | 14 ++++++++++++++ rust/exports.c | 12 +----------- 4 files changed, 17 insertions(+), 15 deletions(-)
Signature · 1 line
2.56.0.218.g1ec904b173-goog
v3 cover clean up EXPORT_SYMBOL_RUST_GPL
Move EXPORT_SYMBOL_RUST_GPL definitions into linux/export.h and prevent the emission of bogus type information for Rust symbols.
Addressing Sashiko review comments, the first commit now ensures the moves do not trigger warnings from scripts/misc-check about missing symbol exports.
Giuliano Procida (2):
rust: move EXPORT_SYMBOL_RUST_GPL to include/linux/export.h
rust: exports: emit ___EXPORT_SYMBOL without C declarations
drivers/gpu/Makefile | 4 ++-- drivers/gpu/nova-core/nova_core_exports.c | 5 ++--- include/linux/export.h | 14 ++++++++++++++ rust/exports.c | 12 +----------- scripts/misc-check | 4 ++-- 5 files changed, 21 insertions(+), 18 deletions(-)
Signature · 1 line
2.56.0.385.gac671c819a-goog
PATCH v3 1/2 rust: move EXPORT_SYMBOL_RUST_GPL to include/linux/export.h
In reply to Giuliano ProcidaMove identical definitions of EXPORT_SYMBOL_RUST_GPL to include/linux/export.h from:
- rust/exports.c
- drivers/gpu/nova-core/nova_core_exports.c
Both files already include <linux/export.h>.
Update scripts/misc-check to recognize EXPORT_SYMBOL_RUST_GPL() and reference it in nova_core_exports.c's header comment so W=2 builds do not warn about an unused <linux/export.h> include.
--- drivers/gpu/nova-core/nova_core_exports.c | 5 ++--- include/linux/export.h | 13 +++++++++++++ rust/exports.c | 12 +----------- scripts/misc-check | 4 ++-- 4 files changed, 18 insertions(+), 16 deletions(-)
drivers/gpu/nova-core/nova_core_exports.c +2 -3
@@ -2,7 +2,8 @@// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. /* -* Exports Rust symbols from the `nova_core` crate for use by dependent modules. +* Exports Rust symbols from the `nova_core` crate for use by dependent modules +* via `EXPORT_SYMBOL_RUST_GPL()`. * * This is a workaround until the build system supports Rust cross-module * dependencies natively.
@@ -10,6 +11,4 @@#include <linux/export.h> -#define EXPORT_SYMBOL_RUST_GPL (sym) extern int sym; EXPORT_SYMBOL_GPL(sym) -#include "exports_nova_core_generated.h"
include/linux/export.h +13 -0
@@ -93,4 +93,17 @@#define EXPORT_SYMBOL_FOR_MODULES (sym, mods) __EXPORT_SYMBOL(sym, "GPL", "module:" mods) +/* +* A hack to export Rust symbols for loadable modules without having to redo +* the entire `EXPORT_SYMBOL_GPL` logic in Rust. +* +* 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. +*/ +#define EXPORT_SYMBOL_RUST_GPL (sym) extern int sym; EXPORT_SYMBOL_GPL(sym) +#endif /* _LINUX_EXPORT_H */
rust/exports.c +1 -11
@@ -1,20 +1,10 @@// 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. -* -* 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. +* Export symbols from the `rust/` crates and C helpers for loadable modules. */ #include <linux/export.h> -#define EXPORT_SYMBOL_RUST_GPL (sym) extern int sym; EXPORT_SYMBOL_GPL(sym) -#include "exports_core_generated.h" #include "exports_bindings_generated.h" #include "exports_kernel_generated.h"
scripts/misc-check +2 -2
@@ -45,7 +45,7 @@ check_tracked_ignored_files () { # does not automatically fix it. check_missing_include_linux_export_h () { - git -C "${srctree:-.}" grep --files-with-matches -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' \ + git -C "${srctree:-.}" grep --files-with-matches -E 'EXPORT_SYMBOL((_RUST)?(_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' \ -- '*.[ch]' :^tools/ :^include/linux/export.h | xargs -r git -C "${srctree:-.}" grep --files-without-match '#include[[:space:]]*<linux/export\.h>' | xargs -r printf "%s: warning: EXPORT_SYMBOL() is used, but #include <linux/export.h> is missing\n" >&2
@@ -58,7 +58,7 @@ check_unnecessary_include_linux_export_h () { git -C "${srctree:-.}" grep --files-with-matches '#include[[:space:]]*<linux/export\.h>' \ -- '*.[c]' :^tools/ | - xargs -r git -C "${srctree:-.}" grep --files-without-match -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' | + xargs -r git -C "${srctree:-.}" grep --files-without-match -E 'EXPORT_SYMBOL((_RUST)?(_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' | xargs -r printf "%s: warning: EXPORT_SYMBOL() is not used, but #include <linux/export.h> is present\n" >&2 }
Signature · 1 line
2.56.0.385.gac671c819a-goog
Re: [PATCH v3 1/2] rust: move EXPORT_SYMBOL_RUST_GPL to include/linux/export.h
Quoted 14 lines · Giuliano Procida
scripts/misc-check +1
-1@@ -45,7 +45,7 @@ check_tracked_ignored_files () { # does not automatically fix it. check_missing_include_linux_export_h () { - git -C "${srctree:-.}" grep --files-with-matches -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' \ + git -C "${srctree:-.}" grep --files-with-matches -E 'EXPORT_SYMBOL((_RUST)?(_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' \ -- '*.[ch]' :^tools/ :^include/linux/export.h | xargs -r git -C "${srctree:-.}" grep --files-without-match '#include[[:space:]]*<linux/export\.h>' | xargs -r printf "%s: warning: EXPORT_SYMBOL() is used, but #include <linux/export.h> is missing\n" >&2
scripts/misc-check check_unnecessary_include_linux_export_h () { · line 64
Quoted 8 lines
scripts/misc-check +1
-1@@ -58,7 +58,7 @@ check_unnecessary_include_linux_export_h () { git -C "${srctree:-.}" grep --files-with-matches '#include[[:space:]]*<linux/export\.h>' \ -- '*.[c]' :^tools/ | - xargs -r git -C "${srctree:-.}" grep --files-without-match -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' | + xargs -r git -C "${srctree:-.}" grep --files-without-match -E 'EXPORT_SYMBOL((_RUST)?(_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' | xargs -r printf "%s: warning: EXPORT_SYMBOL() is not used, but #include <linux/export.h> is present\n" >&2 }
This is minor, but the updated pattern matches non-existent EXPORT_SYMBOL() variants. To preserve the current strict matching, it should instead be changed to:
EXPORT_SYMBOL((_NS)?(_GPL)?|_FOR_MODULES|_RUST_GPL)\(.*\)
Alternatively, I think the pattern could be made more permissive in general, something like:
EXPORT_SYMBOL(_[A-Z_]+)?\(.*\)
This has the advantage of not requiring changes when a variant of EXPORT_SYMBOL() is added/removed and shouldn't sacrifice any of the desired functionality.
-- Petr
Re: [PATCH v3 1/2] rust: move EXPORT_SYMBOL_RUST_GPL to include/linux/export.h
Quoted 29 lines · Petr Pavlu
Quoted 14 lines · Giuliano Procida
scripts/misc-check +1
-1@@ -45,7 +45,7 @@ check_tracked_ignored_files () { # does not automatically fix it. check_missing_include_linux_export_h () { - git -C "${srctree:-.}" grep --files-with-matches -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' \ + git -C "${srctree:-.}" grep --files-with-matches -E 'EXPORT_SYMBOL((_RUST)?(_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' \ -- '*.[ch]' :^tools/ :^include/linux/export.h | xargs -r git -C "${srctree:-.}" grep --files-without-match '#include[[:space:]]*<linux/export\.h>' | xargs -r printf "%s: warning: EXPORT_SYMBOL() is used, but #include <linux/export.h> is missing\n" >&2scripts/misc-check check_unnecessary_include_linux_export_h () { · line 64
Quoted 8 lines
scripts/misc-check +1
-1@@ -58,7 +58,7 @@ check_unnecessary_include_linux_export_h () { git -C "${srctree:-.}" grep --files-with-matches '#include[[:space:]]*<linux/export\.h>' \ -- '*.[c]' :^tools/ | - xargs -r git -C "${srctree:-.}" grep --files-without-match -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' | + xargs -r git -C "${srctree:-.}" grep --files-without-match -E 'EXPORT_SYMBOL((_RUST)?(_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' | xargs -r printf "%s: warning: EXPORT_SYMBOL() is not used, but #include <linux/export.h> is present\n" >&2 }This is minor, but the updated pattern matches non-existent
EXPORT_SYMBOL()variants. To preserve the current strict matching, it should instead be changed to:
Quoted 1 line
EXPORT_SYMBOL((_NS)?(_GPL)?|_FOR_MODULES|_RUST_GPL)\(.*\)
I'll take this suggestion which was also my initial thought.
My second thought was that if Linux were ever going to allow non-GPL or namespaced
Rust symbols, the syntax I came up with would be the best future-proofing.
Quoted 8 lines
Alternatively, I think the pattern could be made more permissive in general, something like:
EXPORT_SYMBOL(_[A-Z_]+)?\(.*\)
This has the advantage of not requiring changes when a variant of
EXPORT_SYMBOL()is added/removed and shouldn't sacrifice any of the desired functionality.
AI analysis: Using a permissive regex in check_missing_include_linux_export_h introduces 81 to 84 false-positive warnings across the kernel.
Things like: EXPORT_SYMBOL_IF_KUNIT, EXPORT_SYMBOL_ACPI_LIB.
Quoted 1 line
-- Petr
v4 cover clean up EXPORT_SYMBOL_RUST_GPL
Move EXPORT_SYMBOL_RUST_GPL definitions into linux/export.h and prevent the emission of bogus type information for Rust symbols.
Addressing review comments, the first commit now ensures the moves do not trigger warnings from scripts/misc-check about missing symbol exports by extending regexes to match EXPORT_SYMBOL_RUST_GPL as well.
Giuliano Procida (2):
rust: move EXPORT_SYMBOL_RUST_GPL to include/linux/export.h
rust: exports: emit ___EXPORT_SYMBOL without C declarations
drivers/gpu/Makefile | 4 ++-- drivers/gpu/nova-core/nova_core_exports.c | 5 ++--- include/linux/export.h | 14 ++++++++++++++ rust/exports.c | 12 +----------- scripts/misc-check | 4 ++-- 5 files changed, 21 insertions(+), 18 deletions(-)
Signature · 1 line
2.56.0.385.gac671c819a-goog
Re: [PATCH v4 0/2] clean up EXPORT_SYMBOL_RUST_GPL
Hi Giuliano,
Quoted 11 lines · Giuliano Procida
Move
EXPORT_SYMBOL_RUST_GPLdefinitions intolinux/export.hand prevent the emission of bogus type information for Rust symbols.Addressing review comments, the first commit now ensures the moves do not trigger warnings from
scripts/misc-checkabout missing symbol exports by extending regexes to matchEXPORT_SYMBOL_RUST_GPLas well.Giuliano Procida (2):
rust: moveEXPORT_SYMBOL_RUST_GPLtoinclude/linux/export.h
rust: exports: emit___EXPORT_SYMBOLwithout C declarations
Quoted 6 lines
drivers/gpu/Makefile | 4 ++-- drivers/gpu/nova-core/nova_core_exports.c | 5 ++--- include/linux/export.h | 14 ++++++++++++++ rust/exports.c | 12 +----------- scripts/misc-check | 4 ++-- 5 files changed, 21 insertions(+), 18 deletions(-)
For the series:
As a side note, starting a new thread for each version would make it easier to navigate the patches in email clients and lore:
https://docs.kernel.org/process/submitting-patches.html#explicit-in-reply-to-headers
Sami
Re: [PATCH v4 0/2] clean up EXPORT_SYMBOL_RUST_GPL
In reply to Giuliano ProcidaQuoted 11 lines · Giuliano Procida
Move
EXPORT_SYMBOL_RUST_GPLdefinitions intolinux/export.hand prevent the emission of bogus type information for Rust symbols.Addressing review comments, the first commit now ensures the moves do not trigger warnings from
scripts/misc-checkabout missing symbol exports by extending regexes to matchEXPORT_SYMBOL_RUST_GPLas well.Giuliano Procida (2):
rust: moveEXPORT_SYMBOL_RUST_GPLtoinclude/linux/export.h
rust: exports: emit___EXPORT_SYMBOLwithout C declarations
Quoted 6 lines
drivers/gpu/Makefile | 4 ++-- drivers/gpu/nova-core/nova_core_exports.c | 5 ++--- include/linux/export.h | 14 ++++++++++++++ rust/exports.c | 12 +----------- scripts/misc-check | 4 ++-- 5 files changed, 21 insertions(+), 18 deletions(-)
Looks ok to me.
Signature · 2 lines
Thanks, Petr
Gary Guo
reviewerRe: [PATCH v4 0/2] clean up EXPORT_SYMBOL_RUST_GPL
In reply to Giuliano ProcidaQuoted 11 lines · Giuliano Procida
Move
EXPORT_SYMBOL_RUST_GPLdefinitions intolinux/export.hand prevent the emission of bogus type information for Rust symbols.Addressing review comments, the first commit now ensures the moves do not trigger warnings from
scripts/misc-checkabout missing symbol exports by extending regexes to matchEXPORT_SYMBOL_RUST_GPLas well.Giuliano Procida (2):
rust: moveEXPORT_SYMBOL_RUST_GPLtoinclude/linux/export.h
rust: exports: emit___EXPORT_SYMBOLwithout C declarations
Quoted 6 lines
drivers/gpu/Makefile | 4 ++-- drivers/gpu/nova-core/nova_core_exports.c | 5 ++--- include/linux/export.h | 14 ++++++++++++++ rust/exports.c | 12 +----------- scripts/misc-check | 4 ++-- 5 files changed, 21 insertions(+), 18 deletions(-)
How about just getting rid of EXPORT_SYMBOL_RUST_GPL completely? The only reason that it exists is because EXPORT_SYMBOL_GPL in C expects the symbol to exist.
We can simply change change rust/exports.c to rust/exports.S and get rid of EXPORT_SYMBOL_RUST_GPL completely (plus saving a C compiler invoocation):
Something like this:
rust/Makefile +1 -1
@@ -571,7 +571,7 @@ rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__(p quiet_cmd_exports = EXPORTS $@ cmd_exports = \ - $(call rust_exports,$<,"EXPORT_SYMBOL_RUST_GPL(%s);\n") > $@ + $(call rust_exports,$<,"EXPORT_SYMBOL_GPL(%s);\n") > $@ $(obj)/exports_core_generated.h: $(obj)/core.o FORCE $(call if_changed,exports)
rust/exports.S renamed from rust/exports.c +1 -3
@@ -13,8 +13,6 @@ #include <linux/export.h> -#define EXPORT_SYMBOL_RUST_GPL(sym) extern int sym; EXPORT_SYMBOL_GPL(sym) - #include "exports_core_generated.h" #include "exports_bindings_generated.h" #include "exports_kernel_generated.h"
@@ -25,5 +23,5 @@ // For modules using `rust/build_error.rs`. #ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW -EXPORT_SYMBOL_RUST_GPL(rust_build_error); +EXPORT_SYMBOL_GPL(rust_build_error); #endif
Re: [PATCH v4 0/2] clean up EXPORT_SYMBOL_RUST_GPL
Quoted 20 lines · Gary Guo
Quoted 11 lines · Giuliano Procida
Move
EXPORT_SYMBOL_RUST_GPLdefinitions intolinux/export.hand prevent the emission of bogus type information for Rust symbols.Addressing review comments, the first commit now ensures the moves do not trigger warnings from
scripts/misc-checkabout missing symbol exports by extending regexes to matchEXPORT_SYMBOL_RUST_GPLas well.Giuliano Procida (2):
rust: moveEXPORT_SYMBOL_RUST_GPLtoinclude/linux/export.h
rust: exports: emit___EXPORT_SYMBOLwithout C declarationsQuoted 6 lines
drivers/gpu/Makefile | 4 ++-- drivers/gpu/nova-core/nova_core_exports.c | 5 ++--- include/linux/export.h | 14 ++++++++++++++ rust/exports.c | 12 +----------- scripts/misc-check | 4 ++-- 5 files changed, 21 insertions(+), 18 deletions(-)
Quoted 2 lines
How about just getting rid of
EXPORT_SYMBOL_RUST_GPLcompletely? The only reason that it exists is becauseEXPORT_SYMBOL_GPLin C expects the symbol to exist.
At some point there may a desire to limit which Rust symbols get exported on a granular level like for C. But that's out of scope here.
Quoted 36 lines
We can simply change change
rust/exports.ctorust/exports.Sand get rid ofEXPORT_SYMBOL_RUST_GPLcompletely (plus saving a C compiler invoocation):Something like this:
rust/Makefile +1
-1@@ -571,7 +571,7 @@ rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__(p quiet_cmd_exports = EXPORTS $@ cmd_exports = \ - $(call rust_exports,$<,"EXPORT_SYMBOL_RUST_GPL(%s);\n") > $@ + $(call rust_exports,$<,"EXPORT_SYMBOL_GPL(%s);\n") > $@ $(obj)/exports_core_generated.h: $(obj)/core.o FORCE $(call if_changed,exports)rust/exports.S renamed from rust/exports.c +0
-2@@ -13,8 +13,6 @@ #include <linux/export.h> -#define EXPORT_SYMBOL_RUST_GPL(sym) extern int sym; EXPORT_SYMBOL_GPL(sym) - #include "exports_core_generated.h" #include "exports_bindings_generated.h" #include "exports_kernel_generated.h"
rust/exports.S line 27
Quoted 6 lines
rust/exports.S renamed from rust/exports.c +1
-1@@ -25,5 +23,5 @@ // For modules using `rust/build_error.rs`. #ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW -EXPORT_SYMBOL_RUST_GPL(rust_build_error); +EXPORT_SYMBOL_GPL(rust_build_error); #endif
This doesn't cover drivers/gpu/nova-core/nova_core_exports.c though.
Gary Guo
reviewerRe: [PATCH v4 0/2] clean up EXPORT_SYMBOL_RUST_GPL
Quoted 63 lines · Giuliano Procida
Quoted 20 lines · Gary Guo
Quoted 11 lines · Giuliano Procida
Move
EXPORT_SYMBOL_RUST_GPLdefinitions intolinux/export.hand prevent the emission of bogus type information for Rust symbols.Addressing review comments, the first commit now ensures the moves do not trigger warnings from
scripts/misc-checkabout missing symbol exports by extending regexes to matchEXPORT_SYMBOL_RUST_GPLas well.Giuliano Procida (2):
rust: moveEXPORT_SYMBOL_RUST_GPLtoinclude/linux/export.h
rust: exports: emit___EXPORT_SYMBOLwithout C declarationsQuoted 6 lines
drivers/gpu/Makefile | 4 ++-- drivers/gpu/nova-core/nova_core_exports.c | 5 ++--- include/linux/export.h | 14 ++++++++++++++ rust/exports.c | 12 +----------- scripts/misc-check | 4 ++-- 5 files changed, 21 insertions(+), 18 deletions(-)Quoted 2 lines
How about just getting rid of
EXPORT_SYMBOL_RUST_GPLcompletely? The only reason that it exists is becauseEXPORT_SYMBOL_GPLin C expects the symbol to exist.At some point there may a desire to limit which Rust symbols get exported on a granular level like for C. But that's out of scope here.
Quoted 36 lines
We can simply change change
rust/exports.ctorust/exports.Sand get rid ofEXPORT_SYMBOL_RUST_GPLcompletely (plus saving a C compiler invoocation):Something like this:
rust/Makefile +1
-1@@ -571,7 +571,7 @@ rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__(p quiet_cmd_exports = EXPORTS $@ cmd_exports = \ - $(call rust_exports,$<,"EXPORT_SYMBOL_RUST_GPL(%s);\n") > $@ + $(call rust_exports,$<,"EXPORT_SYMBOL_GPL(%s);\n") > $@ $(obj)/exports_core_generated.h: $(obj)/core.o FORCE $(call if_changed,exports)rust/exports.S renamed from rust/exports.c +0
-2@@ -13,8 +13,6 @@ #include <linux/export.h> -#define EXPORT_SYMBOL_RUST_GPL(sym) extern int sym; EXPORT_SYMBOL_GPL(sym) - #include "exports_core_generated.h" #include "exports_bindings_generated.h" #include "exports_kernel_generated.h"@@ -25,5 +23,5 @@
Quoted 8 lines
rust/exports.S line 27
Quoted 6 lines
rust/exports.S renamed from rust/exports.c +1
-1// For modules using `rust/build_error.rs`. #ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW -EXPORT_SYMBOL_RUST_GPL(rust_build_error); +EXPORT_SYMBOL_GPL(rust_build_error); #endifThis doesn't cover
drivers/gpu/nova-core/nova_core_exports.cthough.
The same can be done to that file.
Best,
Gary
PATCH v4 1/2 rust: move EXPORT_SYMBOL_RUST_GPL to include/linux/export.h
In reply to Giuliano ProcidaMove identical definitions of EXPORT_SYMBOL_RUST_GPL to include/linux/export.h from:
- rust/exports.c
- drivers/gpu/nova-core/nova_core_exports.c
Both files already include <linux/export.h>.
Update scripts/misc-check to recognize EXPORT_SYMBOL_RUST_GPL() and reference it in nova_core_exports.c's header comment so W=2 builds do not warn about an unused <linux/export.h> include.
--- drivers/gpu/nova-core/nova_core_exports.c | 5 ++--- include/linux/export.h | 13 +++++++++++++ rust/exports.c | 12 +----------- scripts/misc-check | 4 ++-- 4 files changed, 18 insertions(+), 16 deletions(-)
drivers/gpu/nova-core/nova_core_exports.c +2 -3
@@ -2,7 +2,8 @@// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. /* -* Exports Rust symbols from the `nova_core` crate for use by dependent modules. +* Exports Rust symbols from the `nova_core` crate for use by dependent modules +* via `EXPORT_SYMBOL_RUST_GPL()`. * * This is a workaround until the build system supports Rust cross-module * dependencies natively.
@@ -10,6 +11,4 @@#include <linux/export.h> -#define EXPORT_SYMBOL_RUST_GPL (sym) extern int sym; EXPORT_SYMBOL_GPL(sym) -#include "exports_nova_core_generated.h"
include/linux/export.h +13 -0
@@ -93,4 +93,17 @@#define EXPORT_SYMBOL_FOR_MODULES (sym, mods) __EXPORT_SYMBOL(sym, "GPL", "module:" mods) +/* +* A hack to export Rust symbols for loadable modules without having to redo +* the entire `EXPORT_SYMBOL_GPL` logic in Rust. +* +* 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. +*/ +#define EXPORT_SYMBOL_RUST_GPL (sym) extern int sym; EXPORT_SYMBOL_GPL(sym) +#endif /* _LINUX_EXPORT_H */
rust/exports.c +1 -11
@@ -1,20 +1,10 @@// 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. -* -* 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. +* Export symbols from the `rust/` crates and C helpers for loadable modules. */ #include <linux/export.h> -#define EXPORT_SYMBOL_RUST_GPL (sym) extern int sym; EXPORT_SYMBOL_GPL(sym) -#include "exports_core_generated.h" #include "exports_bindings_generated.h" #include "exports_kernel_generated.h"
scripts/misc-check +2 -2
@@ -45,7 +45,7 @@ check_tracked_ignored_files () { # does not automatically fix it. check_missing_include_linux_export_h () { - git -C "${srctree:-.}" grep --files-with-matches -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' \ + git -C "${srctree:-.}" grep --files-with-matches -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_FOR_MODULES|_RUST_GPL)\(.*\)' \ -- '*.[ch]' :^tools/ :^include/linux/export.h | xargs -r git -C "${srctree:-.}" grep --files-without-match '#include[[:space:]]*<linux/export\.h>' | xargs -r printf "%s: warning: EXPORT_SYMBOL() is used, but #include <linux/export.h> is missing\n" >&2
@@ -58,7 +58,7 @@ check_unnecessary_include_linux_export_h () { git -C "${srctree:-.}" grep --files-with-matches '#include[[:space:]]*<linux/export\.h>' \ -- '*.[c]' :^tools/ | - xargs -r git -C "${srctree:-.}" grep --files-without-match -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' | + xargs -r git -C "${srctree:-.}" grep --files-without-match -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_FOR_MODULES|_RUST_GPL)\(.*\)' | xargs -r printf "%s: warning: EXPORT_SYMBOL() is not used, but #include <linux/export.h> is present\n" >&2 }
Signature · 1 line
2.56.0.385.gac671c819a-goog
PATCH v4 2/2 rust: exports: emit ___EXPORT_SYMBOL without C declarations
In reply to Giuliano ProcidaDefine EXPORT_SYMBOL_RUST_GPL(sym) using ___EXPORT_SYMBOL directly:
asm(__stringify(___EXPORT_SYMBOL(sym, "GPL", "")))
matching the __ASSEMBLY__ path.
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 emitting DWARF debug information in rust/exports.o and drivers/gpu/nova-core/nova_core_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 and drivers/gpu/Makefile runs gendwarfksyms on nova_core.o rather than nova_core_exports.o, the bogus int DWARF entries were still present in vmlinux and nova-core.ko, where they conflicted with the true DWARF types emitted by rustc and confused DWARF consumers such as debuggers and ABI analysis tools.
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 rather than on rust/exports.o or nova_core_exports.o.
- extern int sym;, extern typeof(sym) sym;, and __ADDRESSABLE(sym) have no effect in rust/exports.c or nova_core_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, and __GENKSYMS__ are not used by rust/exports.c or nova_core_exports.c.
--- drivers/gpu/Makefile | 4 ++-- include/linux/export.h | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/Makefile +2 -2
@@ -47,8 +47,8 @@ $(obj)/nova-core/nova_core_exports.o: $(obj)/nova-core/exports_nova_core_generat CFLAGS_nova-core/nova_core_exports.o := -I $(objtree)/$(obj)/nova-core ifdef CONFIG_MODVERSIONS -# The C export shim declares Rust symbols as `extern int`, so reuse its export -# list but generate symbol CRCs from the Rust object instead of the shim's DWARF. +# The C export shim has no DWARF type info for Rust symbols, so reuse +# its export list but generate symbol CRCs from the Rust object. $(obj)/nova-core/nova_core_exports.o: private cmd_gensymtypes_c = \ $(call getexportsymbols,\1) | \ $(objtree)/scripts/gendwarfksyms/gendwarfksyms \
include/linux/export.h +5 -4
@@ -94,16 +94,17 @@#define EXPORT_SYMBOL_FOR_MODULES (sym, mods) __EXPORT_SYMBOL(sym, "GPL", "module:" mods)/* -* A hack to export Rust symbols for loadable modules without having to redo -* the entire `EXPORT_SYMBOL_GPL` logic in Rust. +* Export Rust symbols for loadable modules without having to redo the entire +* `EXPORT_SYMBOL_GPL` logic in Rust. * * 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. */ -#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", "")))#endif /* _LINUX_EXPORT_H */
Signature · 1 line
2.56.0.385.gac671c819a-goog
PATCH v3 2/2 rust: exports: emit ___EXPORT_SYMBOL without C declarations
In reply to Giuliano ProcidaDefine EXPORT_SYMBOL_RUST_GPL(sym) using ___EXPORT_SYMBOL directly:
asm(__stringify(___EXPORT_SYMBOL(sym, "GPL", "")))
matching the __ASSEMBLY__ path.
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 emitting DWARF debug information in rust/exports.o and drivers/gpu/nova-core/nova_core_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 and drivers/gpu/Makefile runs gendwarfksyms on nova_core.o rather than nova_core_exports.o, the bogus int DWARF entries were still present in vmlinux and nova-core.ko, where they conflicted with the true DWARF types emitted by rustc and confused DWARF consumers such as debuggers and ABI analysis tools.
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 rather than on rust/exports.o or nova_core_exports.o.
- extern int sym;, extern typeof(sym) sym;, and __ADDRESSABLE(sym) have no effect in rust/exports.c or nova_core_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, and __GENKSYMS__ are not used by rust/exports.c or nova_core_exports.c.
--- drivers/gpu/Makefile | 4 ++-- include/linux/export.h | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/Makefile +2 -2
@@ -47,8 +47,8 @@ $(obj)/nova-core/nova_core_exports.o: $(obj)/nova-core/exports_nova_core_generat CFLAGS_nova-core/nova_core_exports.o := -I $(objtree)/$(obj)/nova-core ifdef CONFIG_MODVERSIONS -# The C export shim declares Rust symbols as `extern int`, so reuse its export -# list but generate symbol CRCs from the Rust object instead of the shim's DWARF. +# The C export shim has no DWARF type info for Rust symbols, so reuse +# its export list but generate symbol CRCs from the Rust object. $(obj)/nova-core/nova_core_exports.o: private cmd_gensymtypes_c = \ $(call getexportsymbols,\1) | \ $(objtree)/scripts/gendwarfksyms/gendwarfksyms \
include/linux/export.h +5 -4
@@ -94,16 +94,17 @@#define EXPORT_SYMBOL_FOR_MODULES (sym, mods) __EXPORT_SYMBOL(sym, "GPL", "module:" mods)/* -* A hack to export Rust symbols for loadable modules without having to redo -* the entire `EXPORT_SYMBOL_GPL` logic in Rust. +* Export Rust symbols for loadable modules without having to redo the entire +* `EXPORT_SYMBOL_GPL` logic in Rust. * * 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. */ -#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", "")))#endif /* _LINUX_EXPORT_H */
Signature · 1 line
2.56.0.385.gac671c819a-goog
PATCH v2 1/2 rust: move EXPORT_SYMBOL_RUST_GPL to include/linux/export.h
In reply to Miguel OjedaMove identical definitions of EXPORT_SYMBOL_RUST_GPL to include/linux/export.h from:
- rust/exports.c
- drivers/gpu/nova-core/nova_core_exports.c
Both files already include <linux/export.h>.
--- drivers/gpu/nova-core/nova_core_exports.c | 2 -- include/linux/export.h | 13 +++++++++++++ rust/exports.c | 12 +----------- 3 files changed, 14 insertions(+), 13 deletions(-)
drivers/gpu/nova-core/nova_core_exports.c +0 -2
@@ -10,6 +10,4 @@#include <linux/export.h> -#define EXPORT_SYMBOL_RUST_GPL (sym) extern int sym; EXPORT_SYMBOL_GPL(sym) -#include "exports_nova_core_generated.h"
include/linux/export.h +13 -0
@@ -93,4 +93,17 @@#define EXPORT_SYMBOL_FOR_MODULES (sym, mods) __EXPORT_SYMBOL(sym, "GPL", "module:" mods) +/* +* A hack to export Rust symbols for loadable modules without having to redo +* the entire `EXPORT_SYMBOL_GPL` logic in Rust. +* +* 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. +*/ +#define EXPORT_SYMBOL_RUST_GPL (sym) extern int sym; EXPORT_SYMBOL_GPL(sym) +#endif /* _LINUX_EXPORT_H */
rust/exports.c +1 -11
@@ -1,20 +1,10 @@// 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. -* -* 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. +* Export symbols from the `rust/` crates and C helpers for loadable modules. */ #include <linux/export.h> -#define EXPORT_SYMBOL_RUST_GPL (sym) extern int sym; EXPORT_SYMBOL_GPL(sym) -#include "exports_core_generated.h" #include "exports_bindings_generated.h" #include "exports_kernel_generated.h"
Signature · 1 line
2.56.0.218.g1ec904b173-goog
[email protected]
AI reviewRe: [PATCH v2 1/2] rust: move EXPORT_SYMBOL_RUST_GPL to include/linux/export.h
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] rust: missing scripts/misc-check update for EXPORT_SYMBOL_RUST_GPL() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] rust: missing scripts/misc-check update for EXPORT_SYMBOL_RUST_GPL() --
commit 9207c761154db27eab7d2644afb940dea51e432c
Author: Giuliano Procida <[email protected]>
rust: move EXPORT_SYMBOL_RUST_GPL to include/linux/export.h
This commit moves the duplicate definitions of EXPORT_SYMBOL_RUST_GPL from rust/exports.c and drivers/gpu/nova-core/nova_core_exports.c into include/linux/export.h.
Quoted 49 lines
drivers/gpu/nova-core/nova_core_exports.c +0
-2@@ -10,6 +10,4 @@#include <linux/export.h> -#define EXPORT_SYMBOL_RUST_GPL (sym) extern int sym; EXPORT_SYMBOL_GPL(sym) -#include "exports_nova_core_generated.h" include/linux/export.h +13
-0@@ -93,4 +93,17 @@#define EXPORT_SYMBOL_FOR_MODULES (sym, mods) __EXPORT_SYMBOL(sym, "GPL", "module:" mods) +/* +* A hack to export Rust symbols for loadable modules without having to redo +* the entire `EXPORT_SYMBOL_GPL` logic in Rust. +* +* 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. +*/ +#define EXPORT_SYMBOL_RUST_GPL (sym) extern int sym; EXPORT_SYMBOL_GPL(sym) +#endif /* _LINUX_EXPORT_H */ rust/exports.c +0
-9@@ -1,20 +1,10 @@// 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. -* -* 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.
rust/exports.c line 10
Quoted 10 lines
rust/exports.c +1
-2+* Export symbols from the `rust/` crates and C helpers for loadable modules. */ #include <linux/export.h> -#define EXPORT_SYMBOL_RUST_GPL (sym) extern int sym; EXPORT_SYMBOL_GPL(sym) -#include "exports_core_generated.h" #include "exports_bindings_generated.h" #include "exports_kernel_generated.h"
[Severity: Low]
Does moving EXPORT_SYMBOL_RUST_GPL into include/linux/export.h cause scripts/misc-check to emit false-positive warnings during W=2 builds?
In scripts/misc-check, check_missing_include_linux_export_h() and check_unnecessary_include_linux_export_h() match export macros against tracked files using:
scripts/misc-check:check_unnecessary_include_linux_export_h() {
git -C "${srctree:-.}" grep --files-with-matches '#include[[:space:]]*<linux/export\.h>' \
-- '*.[c]' :^tools/ |
xargs -r git -C "${srctree:-.}" grep --files-without-match -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_FOR_MODULES)\(.*\)' |
xargs -r printf "%s: warning: EXPORT_SYMBOL() is not used, but #include <linux/export.h> is present\n" >&2
}Previously, the local macro definition in both rust/exports.c and drivers/gpu/nova-core/nova_core_exports.c contained EXPORT_SYMBOL_GPL(sym), which satisfied that regular expression.
With the macro definition moved to include/linux/export.h, rust/exports.c only contains EXPORT_SYMBOL_RUST_GPL(rust_build_error), and drivers/gpu/nova-core/nova_core_exports.c only includes exports_nova_core_generated.h without any direct EXPORT_SYMBOL* calls in the tracked .c file. As a result, running make W=2 warns on both files:
drivers/gpu/nova-core/nova_core_exports.c: warning: EXPORT_SYMBOL() is not used, but #include <linux/export.h> is present rust/exports.c: warning: EXPORT_SYMBOL() is not used, but #include <linux/export.h> is present
Should scripts/misc-check also be updated to recognize EXPORT_SYMBOL_RUST_GPL() and handle C export files that only invoke it via generated headers?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v2 2/2 rust: exports: emit ___EXPORT_SYMBOL without C declarations
In reply to Miguel OjedaDefine EXPORT_SYMBOL_RUST_GPL(sym) using ___EXPORT_SYMBOL directly:
asm(__stringify(___EXPORT_SYMBOL(sym, "GPL", "")))
matching the __ASSEMBLY__ path.
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 emitting DWARF debug information in rust/exports.o and drivers/gpu/nova-core/nova_core_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 and drivers/gpu/Makefile runs gendwarfksyms on nova_core.o rather than nova_core_exports.o, the bogus int DWARF entries were still present in vmlinux and nova-core.ko, where they conflicted with the true DWARF types emitted by rustc and confused DWARF consumers such as debuggers and ABI analysis tools.
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 rather than on rust/exports.o or nova_core_exports.o.
- extern int sym;, extern typeof(sym) sym;, and __ADDRESSABLE(sym) have no effect in rust/exports.c or nova_core_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, and __GENKSYMS__ are not used by rust/exports.c or nova_core_exports.c.
--- drivers/gpu/Makefile | 4 ++-- include/linux/export.h | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/Makefile +2 -2
@@ -47,8 +47,8 @@ $(obj)/nova-core/nova_core_exports.o: $(obj)/nova-core/exports_nova_core_generat CFLAGS_nova-core/nova_core_exports.o := -I $(objtree)/$(obj)/nova-core ifdef CONFIG_MODVERSIONS -# The C export shim declares Rust symbols as `extern int`, so reuse its export -# list but generate symbol CRCs from the Rust object instead of the shim's DWARF. +# The C export shim has no DWARF type info for Rust symbols, so reuse +# its export list but generate symbol CRCs from the Rust object. $(obj)/nova-core/nova_core_exports.o: private cmd_gensymtypes_c = \ $(call getexportsymbols,\1) | \ $(objtree)/scripts/gendwarfksyms/gendwarfksyms \
include/linux/export.h +5 -4
@@ -94,16 +94,17 @@#define EXPORT_SYMBOL_FOR_MODULES (sym, mods) __EXPORT_SYMBOL(sym, "GPL", "module:" mods)/* -* A hack to export Rust symbols for loadable modules without having to redo -* the entire `EXPORT_SYMBOL_GPL` logic in Rust. +* Export Rust symbols for loadable modules without having to redo the entire +* `EXPORT_SYMBOL_GPL` logic in Rust. * * 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. */ -#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", "")))#endif /* _LINUX_EXPORT_H */
Signature · 1 line
2.56.0.218.g1ec904b173-goog