Re: [PATCH net-next v7 2/5] rust: net::phy add module_phy_driver macro

FUJITA Tomonori
2023-11-19T09:44:42Z

On Fri, 17 Nov 2023 14:21:38 -0800
Boqun Feng <boqun.feng@gmail.com> wrote:

> When run the following kunit command:
>
> ./tools/testing/kunit/kunit.py run --make_options LLVM=1 --arch x86_64 \
> --kconfig_add CONFIG_RUST=y \
> --kconfig_add CONFIG_RUST_PHYLIB_ABSTRACTIONS=y \
> --kconfig_add CONFIG_PHYLIB=y \
> --kconfig_add CONFIG_NETDEVICES=y \
> --kconfig_add CONFIG_NET=y \
> --kconfig_add CONFIG_AX88796B_RUST_PHY=y \
> --kconfig_add CONFIG_AX88796B_PHY=y
>
> I got the following errors:
>
> ERROR:root:ld.lld: error: duplicate symbol: __rust_asix_phy_init
> >>> defined at doctests_kernel_generated.5ed8fd29a53cf22f-cgu.0
> >>> rust/doctests_kernel_generated.o:(__rust_asix_phy_init) in archive vmlinux.a
> >>> defined at ax88796b_rust.37fb93aefca595fa-cgu.0
> >>> drivers/net/phy/ax88796b_rust.o:(.text+0x160) in archive vmlinux.a
>
> ld.lld: error: duplicate symbol: __rust_asix_phy_exit
> >>> defined at doctests_kernel_generated.5ed8fd29a53cf22f-cgu.0
> >>> rust/doctests_kernel_generated.o:(__rust_asix_phy_exit) in archive vmlinux.a
> >>> defined at ax88796b_rust.37fb93aefca595fa-cgu.0
> >>> drivers/net/phy/ax88796b_rust.o:(.text+0x1E0) in archive vmlinux.a
>
> ld.lld: error: duplicate symbol: __mod_mdio__phydev_device_table
> >>> defined at doctests_kernel_generated.5ed8fd29a53cf22f-cgu.0
> >>> rust/doctests_kernel_generated.o:(__mod_mdio__phydev_device_table) in archive vmlinux.a
> >>> defined at ax88796b_rust.37fb93aefca595fa-cgu.0
> >>> drivers/net/phy/ax88796b_rust.o:(.rodata+0x58) in archive vmlinux.a
>
> Because kunit will use the above doc test to generate test, and since
> CONFIG_AX88796B_RUST_PHY is also selected, the `module_phy_driver!` has
> been called twice, and causes duplicate symbols.
>
> For "rust_asix_phy_*" symbols, it's easy to fix: just rename the usage
> in the example.

Surely, done.

> But for __mod_mdio__phydev_device_table, it's hard-coded
> in `module_phy_driver!`, I don't have a quick fix right now. Also, does
> it mean `module_phy_driver!` is only supposed to be "called" once for
> the entire kernel?

As I wrote in another mail, I fixed this.