[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <73cb9332-3e5a-493a-8ae1-227a2ea58eb3@lunn.ch>
Date: Sat, 18 Nov 2023 00:18:10 +0100
From: Andrew Lunn <andrew@...n.ch>
To: Benno Lossin <benno.lossin@...ton.me>
Cc: Boqun Feng <boqun.feng@...il.com>,
FUJITA Tomonori <fujita.tomonori@...il.com>, netdev@...r.kernel.org,
rust-for-linux@...r.kernel.org, tmgross@...ch.edu,
miguel.ojeda.sandonis@...il.com, wedsonaf@...il.com
Subject: Re: [PATCH net-next v7 2/5] rust: net::phy add module_phy_driver
macro
On Fri, Nov 17, 2023 at 11:01:58PM +0000, Benno Lossin wrote:
> On 11/17/23 23:54, Andrew Lunn wrote:
> > Each kernel module should be in its own symbol name space. The only
> > symbols which are visible outside of the module are those exported
> > using EXPORT_SYMBOL_GPL() or EXPORT_SYMBOL(). A PHY driver does not
> > export anything, in general.
> >
> > Being built in also does not change this.
> >
> > Neither drivers/net/phy/ax88796b_rust.o nor
> > rust/doctests_kernel_generated.o should have exported this symbol.
> >
> > I've no idea how this actually works, i guess there are multiple
> > passes through the linker? Maybe once to resolve symbols across object
> > files within a module. Normal global symbols are then made local,
> > leaving only those exported with EXPORT_SYMBOL_GPL() or
> > EXPORT_SYMBOL()? A second pass through linker then links all the
> > exported symbols thorough the kernel?
>
> I brought this issue up in [1], but I was a bit confused by your last
> reply there, as I have no idea how the `EXPORT_SYMBOL` macros work.
>
> IIRC on the Rust side all public items are automatically GPL exported.
So that sounds wrong to me. But as i said, i don't know how this
actually works.
In kernel C code, you effectively have three levels of symbol
visibility.
Anything static is not visible outside of the .o file.
Anything global within a module is visible across multiple compilation
units within that module, but not visible outside of the module.
Symbols marked with EXPORT_SYMBOL_GPL() or EXPORT_SYMBOL() are visible
through the entire kernel.
Device drivers generally don't have any EXPORT_SYMBOL* symbols. They
do however need to import symbols which are EXPORT_SYMBOL*. Core
code, like phylib, has lots of EXPORT_SYMBOL*. You can also have
modules which are just libraries, and they use EXPORT_SYMBOL*. Other
modules will be linked to them.
> But `#[no_mangle]` is probably a special case, since in userspace it
> is usually used to do interop with C (and therefore the symbol is always
> exported with the name not mangled).
So you might need this for symbols which are EXPORT_SYMBOL*,
especially if they are going to be used by C code. If only other Rust
modules are going to use them, and the mangled name is predictable, i
suppose you could use the mangled name.
Andrew
Powered by blists - more mailing lists