-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compiler_rt duplicate symbol when statically linking #5320
Comments
What crate were you trying to cross compile? |
This looks similar to what I see when cross compiling a rust crate from In the zig wrapper, if I use Looks like it is calling
|
|
I've also just encountered this. The rust musl target must be including musl libc now. But I'm not sure how to control that. I just created a hello world and set zig cc as the linker (but I'm using the correct triple). The rust-std crate and zig both appear to be providing key functions from musl and so the result is duplicate symbols: Here is one example:
|
I just looked at the actual command rustc generates for the link step, and it does specify |
I don't think it's as simple as just a missing flag - AFAIK LLD by default behaves as if My gut tells me that the best lasting solution would be to have Zig's shipped musl-libc export symbols with weak linkage. However, that would imply modifying the musl-libc implementation in C which might not be the best idea given that the plan is to implement our libc in Zig anyhow (then we are free to select linkage scope as we please btw). Whatever the decision moving forward with this is however, I don't think this is a contributor friendly issue. |
This doesn't seem to be an issue with Zig itself. See below for the 'solution'.
[target.x86_64-unknown-linux-musl]
linker = "/home/mizu/src/bin/zigcc"
[target.aarch64-unknown-linux-musl]
linker = "/home/mizu/src/bin/zigcc"
#!/bin/sh
zig cc -target aarch64-linux-musl $@ Trying to build: mizu@arch ~/s/tmp (master)> cargo build -v -j8 --target --release --target aarch64-unknown-linux-musl
Compiling tmp v0.1.0 (/home/mizu/src/tmp)
Running `rustc --crate-name tmp --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -C embed-bitcode=no -C metadata=2a52e9ef211a284c -C extra-filename=-2a52e9ef211a284c --out-dir /home/mizu/src/tmp/target/aarch64-unknown-linux-musl/release/deps --target aarch64-unknown-linux-musl -C linker=/home/mizu/src/bin/zigcc -L dependency=/home/mizu/src/tmp/target/aarch64-unknown-linux-musl/release/deps -L dependency=/home/mizu/src/tmp/target/release/deps`
error: linking with `/home/mizu/src/bin/zigcc` failed: exit status: 1
|
= note: "/home/mizu/src/bin/zigcc" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crt1.o" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crti.o" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crtbegin.o" "/home/mizu/src/tmp/target/aarch64-unknown-linux-musl/release/deps/tmp-2a52e9ef211a284c.tmp.6928ceeb-cgu.0.rcgu.o" "/home/mizu/src/tmp/target/aarch64-unknown-linux-musl/release/deps/tmp-2a52e9ef211a284c.tmp.6928ceeb-cgu.1.rcgu.o" "/home/mizu/src/tmp/target/aarch64-unknown-linux-musl/release/deps/tmp-2a52e9ef211a284c.tmp.6928ceeb-cgu.2.rcgu.o" "/home/mizu/src/tmp/target/aarch64-unknown-linux-musl/release/deps/tmp-2a52e9ef211a284c.tmp.6928ceeb-cgu.3.rcgu.o" "/home/mizu/src/tmp/target/aarch64-unknown-linux-musl/release/deps/tmp-2a52e9ef211a284c.4ucp8ulk07m9gm2r.rcgu.o" "-Wl,--as-needed" "-L" "/home/mizu/src/tmp/target/aarch64-unknown-linux-musl/release/deps" "-L" "/home/mizu/src/tmp/target/release/deps" "-L" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/libstd-bdbf6aa170ce7026.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/libpanic_unwind-5be1c53da60b5881.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/libminiz_oxide-1959fbdf206646e4.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/libadler-a47f5830822f9c02.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/libobject-cd98f396222b4d7e.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/libaddr2line-d38f6341d62392ad.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/libgimli-a61cab30ff0219ae.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/libstd_detect-9f17ab861ecf115c.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/librustc_demangle-352911c204e74fa0.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/libhashbrown-9aa532a01c969bdd.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/librustc_std_workspace_alloc-26d9b724dec55e94.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/libunwind-d8b041d6a66897d1.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/libcfg_if-06496de8cf6164c5.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-a4a4ce071f33e013.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/liballoc-ef91896e3c9fecd3.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/librustc_std_workspace_core-c0638f1a74e9729c.rlib" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/libcore-9451ddfb08bf3e9a.rlib" "-Wl,--end-group" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/libcompiler_builtins-deb7323b0a537dc8.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-nostartfiles" "-L" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib" "-L" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained" "-o" "/home/mizu/src/tmp/target/aarch64-unknown-linux-musl/release/deps/tmp-2a52e9ef211a284c" "-Wl,--gc-sections" "-static" "-no-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crtend.o" "/home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crtn.o"
= note: warning: unsupported linker arg: --as-needed
warning: unsupported linker arg: -Bstatic
warning: unsupported linker arg: -Bdynamic
warning: unsupported linker arg: -znoexecstack
warning: unsupported linker arg: -zrelro
warning: unsupported linker arg: -znow
ld.lld: error: duplicate symbol: _start
>>> defined at crt1.c
>>> /home/mizu/.cache/zig/o/f6cd4be2bc5abdf530e2d00f59810213/crt1.o:(.text+0x0)
>>> defined at crt1.c
>>> /home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crt1.o:(.text+0x0)
ld.lld: error: duplicate symbol: _start_c
>>> defined at crt1.c
>>> /home/mizu/.cache/zig/o/f6cd4be2bc5abdf530e2d00f59810213/crt1.o:(_start_c)
>>> defined at crt1.c
>>> /home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crt1.o:(.text._start_c+0x0)
ld.lld: error: duplicate symbol: _init
>>> defined at /home/mizu/.cache/zig/o/15297845b4426c92f203a9bd9c2fabb7/crti.o:(.init+0x0)
>>> defined at /home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crti.o:(.init+0x0)
ld.lld: error: duplicate symbol: _fini
>>> defined at /home/mizu/.cache/zig/o/15297845b4426c92f203a9bd9c2fabb7/crti.o:(.fini+0x0)
>>> defined at /home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crti.o:(.fini+0x0)
ld.lld: error: duplicate symbol: __init_tp
>>> defined at __init_tls.c
>>> __init_tls.lo:(__init_tp) in archive /home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-a4a4ce071f33e013.rlib
>>> defined at __init_tls.c
>>> /home/mizu/.cache/zig/o/b2b8d5340238cc9049a2acf66d725b20/__init_tls.o:(.text.__init_tp+0x0) in archive /home/mizu/.cache/zig/o/ba2fec6018ac82e4bb0fec9898caac2f/libc.a
ld.lld: error: duplicate symbol: __copy_tls
>>> defined at __init_tls.c
>>> __init_tls.lo:(__copy_tls) in archive /home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-a4a4ce071f33e013.rlib
>>> defined at __init_tls.c
>>> /home/mizu/.cache/zig/o/b2b8d5340238cc9049a2acf66d725b20/__init_tls.o:(.text.__copy_tls+0x0) in archive /home/mizu/.cache/zig/o/ba2fec6018ac82e4bb0fec9898caac2f/libc.a
ld.lld: error: duplicate symbol: __progname
>>> defined at libc.c
>>> libc.lo:(__progname) in archive /home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-a4a4ce071f33e013.rlib
>>> defined at libc.c
>>> /home/mizu/.cache/zig/o/10d9697181e072b2c49780417398bd92/libc.o:(.bss.__progname+0x0) in archive /home/mizu/.cache/zig/o/ba2fec6018ac82e4bb0fec9898caac2f/libc.a
ld.lld: error: duplicate symbol: __progname_full
>>> defined at libc.c
>>> libc.lo:(__progname_full) in archive /home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-a4a4ce071f33e013.rlib
>>> defined at libc.c
>>> /home/mizu/.cache/zig/o/10d9697181e072b2c49780417398bd92/libc.o:(.bss.__progname_full+0x0) in archive /home/mizu/.cache/zig/o/ba2fec6018ac82e4bb0fec9898caac2f/libc.a
ld.lld: error: duplicate symbol: __get_handler_set
>>> defined at sigaction.c
>>> sigaction.lo:(__get_handler_set) in archive /home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-a4a4ce071f33e013.rlib
>>> defined at sigaction.c
>>> /home/mizu/.cache/zig/o/49cee9df8f412a767e3a9c38d8455fb6/sigaction.o:(.text.__get_handler_set+0x0) in archive /home/mizu/.cache/zig/o/ba2fec6018ac82e4bb0fec9898caac2f/libc.a
ld.lld: error: duplicate symbol: __libc_sigaction
>>> defined at sigaction.c
>>> sigaction.lo:(__libc_sigaction) in archive /home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-a4a4ce071f33e013.rlib
>>> defined at sigaction.c
>>> /home/mizu/.cache/zig/o/49cee9df8f412a767e3a9c38d8455fb6/sigaction.o:(.text.__libc_sigaction+0x0) in archive /home/mizu/.cache/zig/o/ba2fec6018ac82e4bb0fec9898caac2f/libc.a
ld.lld: error: duplicate symbol: __sigaction
>>> defined at sigaction.c
>>> sigaction.lo:(__sigaction) in archive /home/mizu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-a4a4ce071f33e013.rlib
>>> defined at sigaction.c
>>> /home/mizu/.cache/zig/o/49cee9df8f412a767e3a9c38d8455fb6/sigaction.o:(.text.__sigaction+0x0) in archive /home/mizu/.cache/zig/o/ba2fec6018ac82e4bb0fec9898caac2f/libc.a
error: could not compile `tmp` due to previous error
Caused by:
process didn't exit successfully: `rustc --crate-name tmp --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -C embed-bitcode=no -C metadata=2a52e9ef211a284c -C extra-filename=-2a52e9ef211a284c --out-dir /home/mizu/src/tmp/target/aarch64-unknown-linux-musl/release/deps --target aarch64-unknown-linux-musl -C linker=/home/mizu/src/bin/zigcc -L dependency=/home/mizu/src/tmp/target/aarch64-unknown-linux-musl/release/deps -L dependency=/home/mizu/src/tmp/target/release/deps` (exit status: 1) Thanks to the insights given by @kubkon , I solved the issue by manually removing Rust's libc from the linker args. If you read carefully it tells you the location Rust's libc (amongst other things) around where it says Building for real this time: # < copy the build command from where it starts "/home/mizu/src/bin/zigcc" "/home/mizu/.rustup/ ....etc.. >
# < paste to build.sh >
sd '("[^"]*(liblibc|crt1\.o|crti\.o)[^"]*")' ' ' build.sh # naive attempt to remove unwanted libs (double check with the error messages!)
sh build.sh I'm using It's more of a workaround since I have to manually copy the build invocation command from the terminal after my entire program fails to build (because that's when Rust spits out the linker args. Rust doesn't seem to allow you to play around with them). It builds fine now and the executable ( |
I'm trying to cross compile Wasmer (Rust) c-api into musl and I'm getting the same error when using the generated Wasmer musl lib... any tip on how to make it work in an automated fashion @kubkon ? |
Currently experiencing the same issue. Zig does not seem to support -fallow-multiple-definition, and -fno-compiler-rt does not seem to do anything. Any suggestion how to fix or workaround this issue? |
You could expose the respective lld options in the build system and linker code. |
Doing this for now, but I'll want to research how to properly fix these issues in zig later: |
For anyone with issue, I use this new_array=()
for value in "$@"
do
[[ $value != *self-contained/*crt* ]] && new_array+=($value)
done
zig cc -target x86_64-linux-musl "${new_array[@]}" Tested with zig 0.11.0-dev.1501+885d69689, and rust 1.67.1 Reference: https://github.com/rust-cross/cargo-zigbuild/pull/12/files |
Hi.
I'm trying to cross compile a crate in Rust using Zig (
0.6.0+e79d7e0de
) as a C compiler but I keep getting the error below.I'm on WSL Ubuntu 18.04 trying to cross compile to
aarch64-linux-musl
.Any thoughts?
The text was updated successfully, but these errors were encountered: