Re: [PATCH] rust: export zerocopy symbols to modules
From: Gary Guo
Date: Wed Jul 08 2026 - 07:39:15 EST
On Wed Jul 8, 2026 at 11:37 AM BST, Alexandre Courbot wrote:
> 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!
It looks to me that this should be done by fixing zerocopy.
Both these functions should be marked as `#[inline]`. I would expect zerocopy.o
to be having no .text.
Instead of exporting this, I would vouch for going to another extreme --
completely leave zerocopy.o unlinked, so we catch cases where code is actually
generated.
Best,
Gary
>
> 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(+)