Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH] rust: export zerocopy symbols to modules
@ 2026-07-08 10:37 Alexandre Courbot
  2026-07-08 10:50 ` Miguel Ojeda
  2026-07-08 11:34 ` Gary Guo
  0 siblings, 2 replies; 6+ messages in thread
From: Alexandre Courbot @ 2026-07-08 10:37 UTC (permalink / raw)
  To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Onur Özkan
  Cc: rust-for-linux, linux-kernel, Alexandre Courbot

Non-generic, non-inlined functions of the `zerocopy` crate are only
codegen'd into `zerocopy.o`, with their symbols currently not exported,
making them unavailable to loadable modules.

This can break e.g. nova-core built as a module when
`CONFIG_CC_OPTIMIZE_FOR_SIZE=y`:

    ERROR: modpost: "_RNvMNtCs5wX7wwEUCR9_8zerocopy6layoutNtB2_8SizeInfo24try_to_nonzero_elem_size" [drivers/gpu/nova-core.ko] undefined!
    ERROR: modpost: "_RNvNtCs5wX7wwEUCR9_8zerocopy4util18padding_needed_for" [drivers/gpu/nova-core.ko] undefined!

Fix this by generating and including exports for `zerocopy.o`, similarly
to what is already done for `kernel.o`. All defined symbols (~12 in
total) are exported since the compiler gives no guarantee as to which
functions are codegen'd.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
My `CONFIG_CC_OPTIMIZE_FOR_SIZE=y` config is uncovering the most
interesting bugs. :) This one was revealed after applying [1].

I am not a build system expert at all, so be aware that the patch is
mostly mimicking what I am seeing for the kernel crate and there might
be a better way.

[1] https://lore.kernel.org/20260702120324.40388-4-niyudi.honda@gmail.com
---
 rust/Makefile  | 4 ++++
 rust/exports.c | 1 +
 2 files changed, 5 insertions(+)

diff --git a/rust/Makefile b/rust/Makefile
index a870d1616c71..65170c6d31a4 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_RUST) += core.o compiler_builtins.o ffi.o
 always-$(CONFIG_RUST) += exports_core_generated.h
 
 obj-$(CONFIG_RUST) += zerocopy.o
+always-$(CONFIG_RUST) += exports_zerocopy_generated.h
 
 ifdef CONFIG_RUST_INLINE_HELPERS
 always-$(CONFIG_RUST) += helpers/helpers.bc helpers/helpers_module.bc
@@ -566,6 +567,9 @@ $(obj)/exports_bindings_generated.h: $(obj)/bindings.o FORCE
 $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
 	$(call if_changed,exports)
 
+$(obj)/exports_zerocopy_generated.h: $(obj)/zerocopy.o FORCE
+	$(call if_changed,exports)
+
 quiet_cmd_rustc_procmacrolibrary = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) PL $@
       cmd_rustc_procmacrolibrary = \
 	$(rustc_target_envs) \
diff --git a/rust/exports.c b/rust/exports.c
index 1b52460b0f4e..a9d6be8e8485 100644
--- a/rust/exports.c
+++ b/rust/exports.c
@@ -18,6 +18,7 @@
 #include "exports_core_generated.h"
 #include "exports_bindings_generated.h"
 #include "exports_kernel_generated.h"
+#include "exports_zerocopy_generated.h"
 
 #ifndef CONFIG_RUST_INLINE_HELPERS
 #include "exports_helpers_generated.h"

---
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
change-id: 20260708-zerocopy-export-e6d29c42386c

Best regards,
--  
Alexandre Courbot <acourbot@nvidia.com>


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

end of thread, other threads:[~2026-07-08 16:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08 10:37 [PATCH] rust: export zerocopy symbols to modules Alexandre Courbot
2026-07-08 10:50 ` Miguel Ojeda
2026-07-08 11:34 ` Gary Guo
2026-07-08 11:37   ` Miguel Ojeda
     [not found]     ` <CAPvrYMF3L0x5PBJk2TnSPyi0Lci2H0vGBu6QS_Rm4XFQtTV6mw@mail.gmail.com>
2026-07-08 16:23       ` Miguel Ojeda
2026-07-08 11:51   ` Gary Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox