Re: [PATCH 4/7] gpu: nova-core: export Rust symbols for dependent modules

From: Alexandre Courbot

Date: Thu Apr 30 2026 - 23:30:36 EST


On Fri May 1, 2026 at 12:22 AM JST, Joel Fernandes wrote:
>
> Reviewed-by: Joel Fernandes <joelagnelf@xxxxxxxxxx>
> One comment below:
>
> On 4/30/2026 10:55 AM, Alexandre Courbot wrote:
>> Export `nova-core`'s Rust symbols so that other loadable modules,
>> particularly `nova-drm`, can resolve references to `nova-core` at
>> runtime.
>>
>> This is done by generating declarations and `EXPORT_SYMBOL_GPL()` calls
>> for Rust global text symbols using `nm` and compiling them into the
>> module as `nova_core_exports.o`.
>>
>> This is a workaround until the build system supports Rust cross-crate
>> dependencies natively.
>>
>> Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
>> ---
>> drivers/gpu/nova-core/Makefile | 22 +++++++++++++++++++++-
>> drivers/gpu/nova-core/nova_core_exports.c | 11 +++++++++++
>> 2 files changed, 32 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/nova-core/Makefile b/drivers/gpu/nova-core/Makefile
>> index 1f794baadc86..f9aaf19f2477 100644
>> --- a/drivers/gpu/nova-core/Makefile
>> +++ b/drivers/gpu/nova-core/Makefile
>> @@ -2,4 +2,24 @@
>>
>> obj-$(CONFIG_NOVA_CORE) += nova-core.o
>>
>> -nova-core-y := nova_core.o
>> +nova-core-y := nova_core.o nova_core_exports.o
>> +
>> +# Export Rust symbols so dependent modules can use them at runtime.
>> +#
>> +# This is a workaround until the build system supports Rust cross-module
>> +# dependencies natively.
>> +# Kbuild uses Rust v0 mangling, whose symbols start with "_R".
>> +rust_exports = \
>> + $(NM) -p --defined-only $(1) | \
>> + awk '$$2 == "T" && $$3 ~ /^_R/ { \
>> + printf "extern void %s(void); EXPORT_SYMBOL_GPL(%s);\n", $$3, $$3 \
>> + }'
>
> I am curious (in a fun way) how this (Or Miguel's later approach) will work with
> generics. I don't think we have such use cases but suppose a module has a
> function foo<T> which is expected to be called externally outside the module.
> Suppose the module itself does not call foo internally.
>
> How does the rust compiler know that this function can be called externally if
> it resolves to no callers within the translation unit?
>
> Further, as a result, how does the above extern get emitted then if foo never
> ended up in the object?
>
> Probably Miguel's future infrastructure will address this? If so, probably the
> limitation of the above approach should be called out in the code comments and
> commit message.

Short version: it should Just Work (c). The next patch of the series
generates the metadata of the `nova-core` crate, which contains the MIR
representation of all generic elements. If `nova-drm` needs to
monomorphize some generic code, it will do it from that representation -
thus an export of the symbol is not needed.

IIUC this is how inter-crate generics are handled in Rust, so this is
also the way the kernel is also expected to do.