ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.11k stars 2.49k forks source link

Migration to `0.12.0` from `0.11.0` causes linker errors #19846

Closed gh0st-work closed 1 month ago

gh0st-work commented 5 months ago

Zig Version

0.12.0 (x86_64-unknown-linux-gnu)

Steps to Reproduce and Observed Behavior

Basically I have Rust -> C -> Zig interop, that is built via bash script:

#!/bin/bash

set -xeo pipefail
args="$@"
rust_re=deps/rust/re
rust_target=x86_64-unknown-linux-gnu
cwd=$(pwd)

cd $rust_re
rustup +nightly component add rust-src
cargo +nightly build --release -Zbuild-std-features=panic_immediate_abort --target $rust_target 
cd $cwd
zig test -lc -L$rust_re/target/$rust_target/release -lre -I$rust_re $args

-Zbuild-std-features=panic_immediate_abort flag on rustc/cargo means do not unwind on panic, just abort
On version 0.11.0 it compiles and runs successfully. On version 0.12.0 it spits:

error: ld.lld: undefined symbol: _Unwind_GetLanguageSpecificData
    note: referenced by re.83d2ecc66557743f-cgu.0
    note:               re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o:(rust_eh_personality) in archive deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a
error: ld.lld: undefined symbol: _Unwind_GetIPInfo
    note: referenced by re.83d2ecc66557743f-cgu.0
    note:               re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o:(rust_eh_personality) in archive deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a
error: ld.lld: undefined symbol: _Unwind_GetRegionStart
    note: referenced by re.83d2ecc66557743f-cgu.0
    note:               re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o:(rust_eh_personality) in archive deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a
error: ld.lld: undefined symbol: _Unwind_SetGR
    note: referenced by re.83d2ecc66557743f-cgu.0
    note:               re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o:(rust_eh_personality) in archive deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a
error: ld.lld: undefined symbol: _Unwind_SetIP
    note: referenced by re.83d2ecc66557743f-cgu.0
    note:               re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o:(rust_eh_personality) in archive deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a
error: ld.lld: undefined symbol: _Unwind_GetTextRelBase
    note: referenced by re.83d2ecc66557743f-cgu.0
    note:               re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o:(core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h1d3236e86af3e08f) in archive deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a
    note: referenced by re.83d2ecc66557743f-cgu.0
    note:               re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o:(std::sys::personality::gcc::find_eh_action::_$u7b$$u7b$closure$u7d$$u7d$::hd66d48a07a90d596) in archive deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a
error: ld.lld: undefined symbol: _Unwind_GetDataRelBase
    note: referenced by re.83d2ecc66557743f-cgu.0
    note:               re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o:(core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::heebf990fdc5fbf40) in archive deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a
    note: referenced by re.83d2ecc66557743f-cgu.0
    note:               re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o:(std::sys::personality::gcc::find_eh_action::_$u7b$$u7b$closure$u7d$$u7d$::hdb3326233ad0e396) in archive deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a

And with -fno-lld:

error: undefined symbol: _Unwind_GetLanguageSpecificData
    note: referenced by deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a(re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o):.text.rust_eh_personality
error: undefined symbol: _Unwind_GetRegionStart
    note: referenced by deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a(re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o):.text.rust_eh_personality
error: undefined symbol: _Unwind_GetDataRelBase
    note: referenced by deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a(re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o):.text._ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17heebf990fdc5fbf40E
    note: referenced by deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a(re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o):.text._ZN3std3sys11personality3gcc14find_eh_action28_$u7b$$u7b$closure$u7d$$u7d$17hdb3326233ad0e396E
error: undefined symbol: _Unwind_SetIP
    note: referenced by deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a(re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o):.text.rust_eh_personality
error: undefined symbol: _Unwind_GetIPInfo
    note: referenced by deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a(re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o):.text.rust_eh_personality
error: undefined symbol: _Unwind_SetGR
    note: referenced by deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a(re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o):.text.rust_eh_personality
error: undefined symbol: _Unwind_GetTextRelBase
    note: referenced by deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a(re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o):.text._ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h1d3236e86af3e08fE
    note: referenced by deps/rust/re/target/x86_64-unknown-linux-gnu/release/libre.a(re-6b1d223c8d8288a5.re.83d2ecc66557743f-cgu.0.rcgu.o):.text._ZN3std3sys11personality3gcc14find_eh_action28_$u7b$$u7b$closure$u7d$$u7d$17hd66d48a07a90d596E

I can compile it linking with libunwind or c++, but it will be great to known what is the issue, why it suddenly stopped working. Last time it worked because it was a fluke and you somehow just changed the internals?

Expected Behavior

Compile / know what's changed

kassane commented 5 months ago

Maybe missing, -lunwind (EH ABI) or try replacing -lc to -lc++. Also, for zig triple-target arch-linux-gnu, remove unknown

gh0st-work commented 5 months ago

Maybe missing, -lunwind (EH ABI) or try replacing -lc to -lc++. Also, for zig triple-target arch-linux-gnu, remove unknown

I can compile it linking with libunwind or c++, but it will be great to known what is the issue, why it suddenly stopped working.

Also, most likely need to change the label from bug to question