From: Alistair Popple <apopple@nvidia.com>
To: Gary Guo <gary@garyguo.net>
Cc: rust-for-linux@vger.kernel.org, "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Asahi Lina" <lina+kernel@asahilina.net>,
"Martin Rodriguez Reboredo" <yakoyoku@gmail.com>
Subject: Re: [PATCH] rust: kbuild: export symbols from the `uapi` crate
Date: Wed, 16 Sep 2026 11:25:13 +1000 [thread overview]
Message-ID: <aqnqBivf3is_1N7x@nvdebian.thelocal> (raw)
In-Reply-To: <DLBLTKG6KVE9.VNWH1D3896J6@garyguo.net>
On 2026-09-10 at 21:36 +1000, Gary Guo <gary@garyguo.net> wrote...
> On Thu Sep 10, 2026 at 3:21 AM BST, Alistair Popple wrote:
> > On 2026-09-10 at 00:25 +1000, Gary Guo <gary@garyguo.net> wrote...
> >> On Wed Sep 9, 2026 at 7:06 AM BST, Alistair Popple wrote:
> >> > 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!
> >>
> >> Hmm, uapi' ideally should just be type exports and produce no code.
> >>
> >> Default implementation should carry `#[inline]` annotation so they're
> >> only codegenned in actual user crate. Rust's `#[derive(Default)]` would always
> >> add that. Can you check if that's bindgen-produced manual Default impl that
> >> somehow misses the attribute?
> >
> > Right, bindgen-produced Default impl do not have that attribute. For example
> > here is the bindgen generated implementation I see:
>
> Perhaps you can open an issue upstream?
For sure - see https://github.com/rust-lang/rust-bindgen/issues/3494
I wasn't quite sure of the justification for why we don't want to just export
these, so please feel free to comment there.
> >
> > impl Default for drm_nova_info_gpu {
> > fn default() -> Self {
> > let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
> > unsafe {
> > ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
> > s.assume_init()
> > }
> > }
> > }
> >
> > Manually adding #[inline] fixes the problem of course. I guess we could add some
> > sed Makefile hackery to manually add it. For example something like the below,
> > not sure if that would be preferred?
>
> Yeah, textual hacks are a bit too fragile (especially that it'll break when
> upstream bindgen adds these annotations). So if you need these impls, I think
> exporting these symbols are fine.
Fun though :) But yes, I agree this is pretty hacky so would rather export the
symbols, at least until bindgen is fixed.
> That said, you can achieve what you need with `drm_nova_info_gpu::zeroed()`
> instead?
We could, but I'd rather fix this here as people are inevitably going to try and
use default::Default() and the linker errors that come from it are pretty obtuse
and difficult to diagnose what the problem really is.
- Alistair
> Best,
> Gary
>
> >
> > ---
> >
> > diff --cc rust/Makefile
> > index da1a7409d984,da1a7409d984..535a3bf181bb
> > --- a/rust/Makefile
> > +++ b/rust/Makefile
> > @@@ -525,13 -525,13 +525,16 @@@ quiet_cmd_bindgen = BINDGEN $
> > $(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \
> > $(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters)
> > $(obj)/bindings/bindings_generated.rs: private bindgen_target_extra = ; \
> > -- sed -Ei 's/pub const RUST_CONST_HELPER_([a-zA-Z0-9_]*)/pub const \1/g' $@
> > ++ sed -Ei 's/pub const RUST_CONST_HELPER_([a-zA-Z0-9_]*)/pub const \1/g; \
> > ++ s/^([[:space:]]*)fn default\(\) -> Self \{/\1#[inline]\n\1fn default() -> Self {/' $@
> > $(obj)/bindings/bindings_generated.rs: $(src)/bindings/bindings_helper.h \
> > $(src)/bindgen_parameters FORCE
> > $(call if_changed_dep,bindgen)
> >
> > $(obj)/uapi/uapi_generated.rs: private bindgen_target_flags = \
> > $(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters)
> > ++$(obj)/uapi/uapi_generated.rs: private bindgen_target_extra = ; \
> > ++ sed -Ei 's/^([[:space:]]*)fn default\(\) -> Self \{/\1#[inline]\n\1fn default() -> Self {/' $@
> > $(obj)/uapi/uapi_generated.rs: $(src)/uapi/uapi_helper.h \
> > $(src)/bindgen_parameters FORCE
> > $(call if_changed_dep,bindgen)
> >
>
next prev parent reply other threads:[~2026-09-16 1:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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
2026-09-16 1:25 ` Alistair Popple [this message]
2026-09-16 7:39 ` Gary Guo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aqnqBivf3is_1N7x@nvdebian.thelocal \
--to=apopple@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=lina+kernel@asahilina.net \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
--cc=yakoyoku@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.