c2rust
c2rust copied to clipboard
linker error with `mold`
I get a linker error when trying to build c2rust using mold. I've configured the mold linker as my default because it is much faster.
> LLVM_CONFIG_PATH=llvm-config-19 cargo build --release
...
= note: mold: fatal: failed to load plugin : /usr/bin/mold: undefined symbol: onload
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Mold is configured like so
# .cargo/config.toml
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"]
and is the latest version
> mold --version
mold 2.34.1 (de65f6bd75b93eeb9f3775fc136ee79683ff35f1; compatible with GNU ld)
When I comment out the rustflags line there (i.e. the default linker is picked) the build does succeed. When I explicitly pick ld.lld from the llvm that I'm using that also works (you still need the linker = "clang" bit of config for this):
LLVM_CONFIG_PATH=llvm-config-19 RUSTFLAGS="-C link-arg=-fuse-ld=/usr/bin/ld.lld-19" cargo build --release
Not a huge problem, and maybe even a limitation in mold, but it does add a bit of friction and might indicate an issue somewhere in the c2rust build pipeline?
That's odd, I use mold, too.
A particular version? And there isn't some sneaky .cargo/config.toml overriding it? (any rustflags anywhere will override that global toml config I believe)
I have this in my ~/.cargo/config.toml:
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/home/kkysen/.linuxbrew/bin/mold"]
with these versions:
❯ ~/.linuxbrew/bin/mold --version
mold 2.34.1 (compatible with GNU ld)
❯ llvm-config --version
19.1.4
❯ strings target/debug/c2rust | rg mold
mold 2.34.1 (compatible with GNU ld)
❯ strings target/release/c2rust | rg mold
mold 2.34.1 (compatible with GNU ld)
So I'm not sure what's different.