Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH] rust: kbuild: export symbols from the `uapi` crate
@ 2026-09-09  6:06 Alistair Popple
  2026-09-09 14:25 ` Gary Guo
  0 siblings, 1 reply; 5+ messages in thread
From: Alistair Popple @ 2026-09-09  6:06 UTC (permalink / raw)
  To: rust-for-linux
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, Asahi Lina,
	Martin Rodriguez Reboredo, Alistair Popple

Symbols from the `bindings` crate and the C helpers are exported so
that loadable modules can link against code the compiler chose not to
instantiate in the module itself. The `uapi` crate has the same problem
but nothing from it is exported.

In practice this goes unnoticed because the only functions in `uapi`
are the trivial `Default` implementations generated by `bindgen`,
which rustc inlines across crates. With CONFIG_RUST_DEBUG_ASSERTIONS=y
however, the `Default` implementation for structs can grow past the
automatic cross-crate inlining threshold. The module then references the
copy in `uapi.o`, which is not exported, and the build fails:

  ERROR: modpost: drivers/gpu/nova-drm.ko: symbol '_RNvXsH_Csk9v2ZIpWbWt_4uapiNtB5_17drm_nova_info_gpuNtNtCsfr3MPOfBGpN_4core7default7Default7default' undefined!

Fix this by exporting the `uapi` symbols in the same way as `bindings`.

Fixes: 4e1746656839 ("rust: uapi: Add UAPI crate")
Signed-off-by: Alistair Popple <apopple@nvidia.com>
Assisted-by: LLM
---
 rust/Makefile  | 7 ++++++-
 rust/exports.c | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/rust/Makefile b/rust/Makefile
index da1a7409d984..083992a5c1c9 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -27,6 +27,7 @@ always-$(CONFIG_RUST) += exports_bindings_generated.h exports_kernel_generated.h
 
 always-$(CONFIG_RUST) += uapi/uapi_generated.rs
 obj-$(CONFIG_RUST) += uapi.o
+always-$(CONFIG_RUST) += exports_uapi_generated.h
 
 ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW
 obj-$(CONFIG_RUST) += build_error.o
@@ -575,7 +576,8 @@ $(obj)/exports_core_generated.h: $(obj)/core.o FORCE
 # in the crate where they are defined. Other helpers, called from non-inline
 # functions, may not be exported, in principle. However, in general, the Rust
 # compiler does not guarantee codegen will be performed for a non-inline
-# function either. Therefore, we export all symbols from helpers and bindings.
+# function either. Therefore, we export all symbols from helpers, bindings and
+# uapi.
 # In the future, this may be revisited to reduce the number of exports after
 # the compiler is informed about the places codegen is required.
 $(obj)/exports_helpers_generated.h: $(obj)/helpers/helpers.o FORCE
@@ -587,6 +589,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_uapi_generated.h: $(obj)/uapi.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..434f0b73151f 100644
--- a/rust/exports.c
+++ b/rust/exports.c
@@ -17,6 +17,7 @@
 
 #include "exports_core_generated.h"
 #include "exports_bindings_generated.h"
+#include "exports_uapi_generated.h"
 #include "exports_kernel_generated.h"
 
 #ifndef CONFIG_RUST_INLINE_HELPERS

base-commit: b705c185105762676aa6ec16cf976101df87cc35
-- 
2.54.0


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

end of thread, other threads:[~2026-09-10 11:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-09  6:06 [PATCH] rust: kbuild: export symbols from the `uapi` crate Alistair Popple
2026-09-09 14:25 ` Gary Guo
2026-09-10  2:21   ` Alistair Popple
2026-09-10  9:20     ` Alice Ryhl
2026-09-10 11:36     ` Gary Guo

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