Skip to content

ICE: -Crpath without -o #119571

Closed
Closed
@JakobDegen

Description

@JakobDegen

I tried this:

touch empty.rs && rustc +nightly empty.rs --crate-type dylib -Crpath

I expected to see this happen: Anything but an ICE

Instead, this happened:

thread 'rustc' panicked at compiler/rustc_codegen_ssa/src/back/rpath.rs:88:43:
called `Result::unwrap()` on an `Err` value: Error { kind: InvalidInput, message: "cannot make an empty path absolute" }

The unwraps in this function all look a bit suspicious tbh:

fn get_rpath_relative_to_output(config: &mut RPathConfig<'_>, lib: &Path) -> OsString {
// Mac doesn't appear to support $ORIGIN
let prefix = if config.is_like_osx { "@loader_path" } else { "$ORIGIN" };
// Strip filenames
let lib = lib.parent().unwrap();
let output = config.out_filename.parent().unwrap();
let lib = try_canonicalize(lib).unwrap();
let output = try_canonicalize(output).unwrap();
let relative = path_relative_from(&lib, &output)
.unwrap_or_else(|| panic!("couldn't create relative path from {output:?} to {lib:?}"));
let mut rpath = OsString::from(prefix);
rpath.push("/");
rpath.push(relative);
rpath
}

Meta

rustc --version --verbose:

rustc 1.77.0-nightly (e51e98dde 2023-12-31)
binary: rustc
commit-hash: e51e98dde6a60637b6a71b8105245b629ac3fe77
commit-date: 2023-12-31
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6
Backtrace

thread 'rustc' panicked at compiler/rustc_codegen_ssa/src/back/rpath.rs:88:43:
called `Result::unwrap()` on an `Err` value: Error { kind: InvalidInput, message: "cannot make an empty path absolute" }
stack backtrace:
   0:     0x7f944f610946 - std::backtrace_rs::backtrace::libunwind::trace::h44f4ca7c442c0986
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f944f610946 - std::backtrace_rs::backtrace::trace_unsynchronized::h8e72beef8f98799e
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f944f610946 - std::sys_common::backtrace::_print_fmt::had1f7322c7191a83
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f944f610946 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc02075f68ac68e83
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f944f663060 - core::fmt::rt::Argument::fmt::h4fb797bf569c9381
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/core/src/fmt/rt.rs:142:9
   5:     0x7f944f663060 - core::fmt::write::h6f1ea15fe9368d17
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f944f60436f - std::io::Write::write_fmt::haaa4143b58137630
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/io/mod.rs:1810:15
   7:     0x7f944f610724 - std::sys_common::backtrace::_print::h16f1f390d8dff6aa
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f944f610724 - std::sys_common::backtrace::print::h7a4cfc718891723c
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f944f6134b7 - std::panicking::default_hook::{{closure}}::h66f09592313f4ce8
  10:     0x7f944f613219 - std::panicking::default_hook::he45e0a376ce42f7d
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/panicking.rs:292:9
  11:     0x7f944c36605c - std[59bbd359e4a0812d]::panicking::update_hook::<alloc[9e8bbef5278c9f16]::boxed::Box<rustc_driver_impl[f5f02e8ab7f89dcf]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f944f613c06 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h0ebdda5c503ff158
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/alloc/src/boxed.rs:2029:9
  13:     0x7f944f613c06 - std::panicking::rust_panic_with_hook::h4f38919015b1c60f
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/panicking.rs:783:13
  14:     0x7f944f613952 - std::panicking::begin_panic_handler::{{closure}}::h6e933e94ded3024f
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/panicking.rs:657:13
  15:     0x7f944f610e46 - std::sys_common::backtrace::__rust_end_short_backtrace::h4efef00f0bd07d56
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f944f6136b0 - rust_begin_unwind
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/panicking.rs:645:5
  17:     0x7f944f65f765 - core::panicking::panic_fmt::h3f2350d70561f7cb
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/core/src/panicking.rs:72:14
  18:     0x7f944f65fe63 - core::result::unwrap_failed::hc28f4ee1a6255957
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/core/src/result.rs:1649:5
  19:     0x7f944c2acd1b - rustc_codegen_ssa[dae9f9943a1cfee7]::back::rpath::get_rpath_flags
  20:     0x7f944e5c5d9a - rustc_codegen_ssa[dae9f9943a1cfee7]::back::link::linker_with_args
  21:     0x7f944e534f0a - rustc_codegen_ssa[dae9f9943a1cfee7]::back::link::link_natively
  22:     0x7f944e1ec237 - rustc_codegen_ssa[dae9f9943a1cfee7]::back::link::link_binary
  23:     0x7f944e1eb6ea - <rustc_codegen_llvm[8394d916703c6365]::LlvmCodegenBackend as rustc_codegen_ssa[dae9f9943a1cfee7]::traits::backend::CodegenBackend>::link
  24:     0x7f944df585a1 - <rustc_interface[8dea96efab884454]::queries::Linker>::link
  25:     0x7f944e62d70a - rustc_interface[8dea96efab884454]::interface::run_compiler::<core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>, rustc_driver_impl[f5f02e8ab7f89dcf]::run_compiler::{closure#0}>::{closure#0}
  26:     0x7f944e5b7306 - std[59bbd359e4a0812d]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[8dea96efab884454]::util::run_in_thread_with_globals<rustc_interface[8dea96efab884454]::util::run_in_thread_pool_with_globals<rustc_interface[8dea96efab884454]::interface::run_compiler<core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>, rustc_driver_impl[f5f02e8ab7f89dcf]::run_compiler::{closure#0}>::{closure#0}, core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>>::{closure#0}, core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>>
  27:     0x7f944e5b7133 - <<std[59bbd359e4a0812d]::thread::Builder>::spawn_unchecked_<rustc_interface[8dea96efab884454]::util::run_in_thread_with_globals<rustc_interface[8dea96efab884454]::util::run_in_thread_pool_with_globals<rustc_interface[8dea96efab884454]::interface::run_compiler<core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>, rustc_driver_impl[f5f02e8ab7f89dcf]::run_compiler::{closure#0}>::{closure#0}, core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>>::{closure#0}, core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>>::{closure#1} as core[f50a4b4ddb6878bb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  28:     0x7f944f61db35 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hfced58be344e2c05
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/alloc/src/boxed.rs:2015:9
  29:     0x7f944f61db35 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7842a7154462ae57
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/alloc/src/boxed.rs:2015:9
  30:     0x7f944f61db35 - std::sys::unix::thread::Thread::new::thread_start::ha365c5d9b9d0ac99
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/sys/unix/thread.rs:108:17
  31:     0x7f94494aa9eb - <unknown>
  32:     0x7f944952e7cc - <unknown>
  33:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please attach the file at `/tmp/rusttest/tmp/rustc-ice-2024-01-04T07_26_52-1064517.txt` to your bug report

note: compiler flags: --crate-type dylib -C rpath

query stack during panic:
end of query stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-CLIArea: Command-line interface (CLI) to the compilerA-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions