[PATCH] rust: export zerocopy symbols to modules
From: Alexandre Courbot
Date: Wed Jul 08 2026 - 06:42:49 EST
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@xxxxxxxxxx>
---
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@xxxxxxxxx
---
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@xxxxxxxxxx>