Repository navigation
build-std panic_immediate_abort undefined reference to panic_cannot_unwind #107016
Copy link
Copy link
Closed
Labels
-Zfixed-x18Unstable option: -Zfixed-x18Unstable option: -Zfixed-x18C-bugCategory: This is a bug.Category: This is a bug.
Description
A Cargo project with:
fn main() {
panic!("foo");
}built with:
cargo +nightly build -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-gnu
results in a linking failure:
error: linking with `cc` failed: exit status: 1
|
= note: LC_ALL="C" PATH="/home/eric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/eric/.cargo/bin:/home/eric/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustcFgLEbF/symbols.o" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/z5-76afd39352411349.1zyytfss6ge6z1c2.rcgu.o" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/z5-76afd39352411349.2cgsr7cusby7dzxg.rcgu.o" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/z5-76afd39352411349.2rjthrgaumg840ve.rcgu.o" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/z5-76afd39352411349.32emvdk76bp91vcu.rcgu.o" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/z5-76afd39352411349.3cj49qdg70f0gyk6.rcgu.o" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/z5-76afd39352411349.3p0mbady7r38kwwe.rcgu.o" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/z5-76afd39352411349.3poyfj1g4stxz92z.rcgu.o" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/z5-76afd39352411349.4yr89ousk3c7d2jy.rcgu.o" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/z5-76afd39352411349.50cbq5av1898h8h6.rcgu.o" "-Wl,--as-needed" "-L" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps" "-L" "/home/eric/Temp/z5/target/debug/deps" "-L" "/home/eric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/libstd-71ebc58fe381d1e2.rlib" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_unwind-3df6cc821977c293.rlib" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/librustc_demangle-666a7821c202eadd.rlib" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/libstd_detect-da0d60497b1c7e5c.rlib" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/libhashbrown-59ad5acb3417a67f.rlib" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/librustc_std_workspace_alloc-afb6c9f84f868152.rlib" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/libunwind-e44bde4753f5d656.rlib" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/libcfg_if-947c10ee011f75a2.rlib" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/liblibc-c433df73698cac4e.rlib" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/liballoc-86b4281adfdfc05f.rlib" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/librustc_std_workspace_core-b0197b2ea51ce186.rlib" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/libcore-d4d5a26fa7790993.rlib" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/libcompiler_builtins-aa52e866272be7f0.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/eric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/z5-76afd39352411349" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
= note: /usr/bin/ld: /home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/liballoc-86b4281adfdfc05f.rlib(alloc-86b4281adfdfc05f.alloc.d0a1cb85-cgu.0.rcgu.o): in function `alloc::raw_vec::RawVec<T,A>::into_box':
/home/eric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/raw_vec.rs:154: undefined reference to `core::panicking::panic_cannot_unwind'
/usr/bin/ld: /home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/liballoc-86b4281adfdfc05f.rlib(alloc-86b4281adfdfc05f.alloc.d0a1cb85-cgu.1.rcgu.o): in function `core::ptr::drop_in_place<alloc::vec::Vec<u8>>':
/home/eric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:490: undefined reference to `core::panicking::panic_cannot_unwind'
/usr/bin/ld: /home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/liballoc-86b4281adfdfc05f.rlib(alloc-86b4281adfdfc05f.alloc.d0a1cb85-cgu.11.rcgu.o): in function `<T as alloc::slice::hack::ConvertVec>::to_vec':
/home/eric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/slice.rs:159: undefined reference to `core::panicking::panic_cannot_unwind'
/usr/bin/ld: /home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/liballoc-86b4281adfdfc05f.rlib(alloc-86b4281adfdfc05f.alloc.d0a1cb85-cgu.2.rcgu.o): in function `alloc::string::String::from_utf8_lossy':
/home/eric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/string.rs:631: undefined reference to `core::panicking::panic_cannot_unwind'
/usr/bin/ld: /home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/liballoc-86b4281adfdfc05f.rlib(alloc-86b4281adfdfc05f.alloc.d0a1cb85-cgu.4.rcgu.o): in function `alloc::vec::Vec<T,A>::into_boxed_slice':
/home/eric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:1103: undefined reference to `core::panicking::panic_cannot_unwind'
/usr/bin/ld: /home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/liballoc-86b4281adfdfc05f.rlib(alloc-86b4281adfdfc05f.alloc.d0a1cb85-cgu.7.rcgu.o):/home/eric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1124: more undefined references to `core::panicking::panic_cannot_unwind' follow
/usr/bin/ld: /home/eric/Temp/z5/target/x86_64-unknown-linux-gnu/debug/deps/z5-76afd39352411349: hidden symbol `_ZN4core9panicking19panic_cannot_unwind17h206df51ed63dec18E' isn't defined
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
= note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the `-l` flag to specify native libraries to link
= note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
This recently started with #104999. cc @saethlin do you have any insight into this?
Meta
rustc --version --verbose:
rustc 1.68.0-nightly (3984bc583 2023-01-17)
binary: rustc
commit-hash: 3984bc5833db8bfb0acc522c9775383e4171f3de
commit-date: 2023-01-17
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6
Metadata
Metadata
Assignees
Labels
-Zfixed-x18Unstable option: -Zfixed-x18Unstable option: -Zfixed-x18C-bugCategory: This is a bug.Category: This is a bug.
Activity
saethlin commentedon Jan 18, 2023
Not particularly. All I can say is this diff makes the example program link fine:
But that doesn't really make any sense to me. There are a lot of other panic lang items which are fine with
#[inline], and I don't understand what is special about this one.Super-Pizza commentedon Jan 21, 2023
Looking inside crate/target/target/debug/deps/libpanic_abort-XXXXXXXXXXXXXXXX.rlib (it's an
archive, usear xo <file>for that), there are a few object files.I looked inside with
objdump -x <object>to find the symbolsAnd in some of them there's a symbol
_ZN4core9panicking15panic_no_unwind17h129a8875f76752ecEthat demangles to
core::panicking::panic_no_unwind::h129a8875f76752echere, which is weirdsaethlin commentedon Jan 21, 2023
But the symbol we want is
core::panicking::panic_cannot_unwind, right?bjorn3 commentedon Jan 21, 2023
There is both
panic_no_unwindandpanic_cannot_unwind. Both are lang items used by codegen backends and the later calls the former with a fixed argument.bjorn3 commentedon Jan 21, 2023
I think the monomorphization collector forgot to consider
panic_cannot_unwindused in some cases. It is handled forTerminatorKind::Abort:rust/compiler/rustc_monomorphize/src/collector.rs
Lines 843 to 851 in 21f6839
double_unwind_guardemitted for calls in cleanup blocks:rust/compiler/rustc_codegen_ssa/src/mir/block.rs
Lines 173 to 186 in 21f6839
tmiasko commentedon Jan 23, 2023
Using -Cpanic=abort works around the issue, and probably something one would like to do this scenario regardless?
saethlin commentedon Jan 23, 2023
🤦 Yes, definitely. This is not the first time I have found odd behavior from mixing unwind with
panic_immediate_abort. I think it would make sense for something somewhere to reject that configuration.tmiasko commentedon Jan 24, 2023
Might be worth retesting when #102906 lands. I think it should address this issue as well.
tmiasko commentedon Mar 9, 2023
#108924 proposes a static assertion that ensures that
panic_immediate_abortis used with-Cpanic=abort.SUPERCILEX commentedon Mar 31, 2023
Can this issue be closed since the PR was merged?
ehuss commentedon Mar 31, 2023
Yea, I think this is effectively solved by #108924. Thanks!
(Although anyone should feel free to reopen if you feel there is more to do here.)