Skip to contentSkip to conversation

rust: Prefer link_with over link_whole

PATCH In review Zhao Liu 2 participants 3 messages Feb 18, 2025

Subsystems (2)
lore
Share & tools
lore

Zhao Liu

author
#0 lore raw

PATCH 1/1 rust: Prefer link_with over link_whole

The commit fccb744f41c6 ("gdbstub: Try unlinking the unix socket before binding") causes the compilation of rust-qemu-api-integration to fail, because rust-qemu-api-integration uses link_whole which meets the duplicate symbol linker error.

Though it's not the issue of link_whole used by Rust side, there's no need to use link_whole.

Use link_with, which may also bring some benefits, such as faster linking or smaller output files.

---
 rust/hw/char/pl011/meson.build | 2 +-
 rust/hw/timer/hpet/meson.build | 2 +-
 rust/qemu-api/meson.build      | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
rust/hw/char/pl011/meson.build +1 -1
index 547cca5a96f7..4ba9089fcf8e 100644
@@ -18,7 +18,7 @@ _libpl011_rs = static_library(
 )
 
 rust_devices_ss.add(when: 'CONFIG_X_PL011_RUST', if_true: [declare_dependency(
-  link_whole: [_libpl011_rs],
+  link_with: [_libpl011_rs],
   # Putting proc macro crates in `dependencies` is necessary for Meson to find
   # them when compiling the root per-target static rust lib.
   dependencies: [bilge_impl_dep, qemu_api_macros],
rust/hw/timer/hpet/meson.build +1 -1
index c2d7c0532ca4..ce90cc4f021a 100644
@@ -10,7 +10,7 @@ _libhpet_rs = static_library(
 )
 
 rust_devices_ss.add(when: 'CONFIG_X_HPET_RUST', if_true: [declare_dependency(
-  link_whole: [_libhpet_rs],
+  link_with: [_libhpet_rs],
   # Putting proc macro crates in `dependencies` is necessary for Meson to find
   # them when compiling the root per-target static rust lib.
   dependencies: [qemu_api_macros],
rust/qemu-api/meson.build +1 -1
index 2e9c1078b9b2..e825671b694b 100644
@@ -63,7 +63,7 @@ test('rust-qemu-api-integration',
         rust_args: ['--test'],
         install: false,
         dependencies: [qemu_api, qemu_api_macros],
-        link_whole: [rust_qemu_api_objs, libqemuutil]),
+        link_with: [rust_qemu_api_objs, libqemuutil]),
     args: [
         '--test', '--test-threads', '1',
         '--format', 'pretty',
Signature · 1 line
2.34.1
#1 lore raw
Quoted 10 lines · Zhao Liu

The commit fccb744f41c6 ("gdbstub: Try unlinking the unix socket before binding") causes the compilation of rust-qemu-api-integration to fail, because rust-qemu-api-integration uses link_whole which meets the duplicate symbol linker error.

Though it's not the issue of link_whole used by Rust side, there's no need to use link_whole.

Use link_with, which may also bring some benefits, such as faster linking or smaller output files.

link_with, if I remember correctly, drops the constructors. Using it in rust_devices_ss therefore prevents the devices from being registered with QOM.

The real issue is lack of support for "objects" in Meson for Rust executables. A patch to fix that is under review, after which it will be possible to build Rust executables using the same "dependency" objects as C code.

Paolo

Quoted 32 lines

rust_devices_ss.add(when: 'CONFIG_X_PL011_RUST', if_true: [declare_dependency(

rust/hw/char/pl011/meson.build +1 -1
-  link_whole: [_libpl011_rs],
+  link_with: [_libpl011_rs],
    # Putting proc macro crates in `dependencies` is necessary for Meson to find
    # them when compiling the root per-target static rust lib.
    dependencies: [bilge_impl_dep, qemu_api_macros],
rust/hw/timer/hpet/meson.build +1 -1
index c2d7c0532ca4..ce90cc4f021a 100644
@@ -10,7 +10,7 @@ _libhpet_rs = static_library(
  )
 
  rust_devices_ss.add(when: 'CONFIG_X_HPET_RUST', if_true: [declare_dependency(
-  link_whole: [_libhpet_rs],
+  link_with: [_libhpet_rs],
    # Putting proc macro crates in `dependencies` is necessary for Meson to find
    # them when compiling the root per-target static rust lib.
    dependencies: [qemu_api_macros],
rust/qemu-api/meson.build +1 -1
index 2e9c1078b9b2..e825671b694b 100644
@@ -63,7 +63,7 @@ test('rust-qemu-api-integration',
          rust_args: ['--test'],
          install: false,
          dependencies: [qemu_api, qemu_api_macros],
-        link_whole: [rust_qemu_api_objs, libqemuutil]),
+        link_with: [rust_qemu_api_objs, libqemuutil]),
      args: [
          '--test', '--test-threads', '1',
          '--format', 'pretty',
author
#2 lore raw
Quoted 13 lines · Paolo Bonzini

Date: Tue, 18 Feb 2025 09:58:44 +0100
From: Paolo Bonzini <[email protected]>
Subject: Re: [PATCH] rust: Prefer link_with over link_whole

Quoted 8 lines · Zhao Liu

The commit fccb744f41c6 ("gdbstub: Try unlinking the unix socket before binding") causes the compilation of rust-qemu-api-integration to fail, because rust-qemu-api-integration uses link_whole which meets the duplicate symbol linker error.

Though it's not the issue of link_whole used by Rust side, there's no need to use link_whole.

Quoted 6 lines
Quoted 2 lines

Use link_with, which may also bring some benefits, such as faster linking or smaller output files.

link_with, if I remember correctly, drops the constructors. Using it in rust_devices_ss therefore prevents the devices from being registered with QOM.

Interesting, I test with link_with and HPET QOM type can be registered.

I find this is because module_init macro adds #[used] for LOAD_MODULE, which prevents linker dropping QOM type.

Without #[used], both link_with and link_whole will optimize LOAD_MODULE... So here #[used] is the key to getting everything to work properly.

Quoted 4 lines

The real issue is lack of support for "objects" in Meson for Rust executables. A patch to fix that is under review, after which it will be possible to build Rust executables using the same "dependency" objects as C code.

HMM, but with link_with, everything seems to compile fine?

Thanks,
Zhao