Skip to content
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

Nightly rustc panic when compiling a simple no_std program #125545

Closed
limuy2022 opened this issue May 25, 2024 · 4 comments · Fixed by #127694
Closed

Nightly rustc panic when compiling a simple no_std program #125545

limuy2022 opened this issue May 25, 2024 · 4 comments · Fixed by #127694
Labels
A-cranelift Things relevant to the [future] cranelift backend C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-bare-metal Target: Rust without an operating system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@limuy2022
Copy link

Code

min.zip

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (36153f1a4 2024-05-24)
binary: rustc
commit-hash: 36153f1a4e3162f0a143c7b3e468ecb3beb0008e
commit-date: 2024-05-24
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

Error output

thread 'rustc' panicked at src/driver/aot.rs:302:89:
called `Result::unwrap()` on an `Err` value: Backend(binary format is unknown

Backtrace

Stack backtrace:
   0: <anyhow::Error>::msg::<&str>
   1: rustc_codegen_cranelift::driver::aot::make_module
   2: rustc_codegen_cranelift::driver::aot::module_codegen::{closure#0}
   3: rustc_codegen_cranelift::driver::aot::module_codegen
   4: <rustc_middle::dep_graph::DepsType as rustc_query_system::dep_graph::Deps>::with_deps::<<rustc_query_system::dep_graph::graph::DepGraphData<rustc_middle::dep_graph::DepsType>>::with_task<rustc_middle::ty::context::TyCtxt, (rustc_codegen_cranelift::config::BackendConfig, alloc::sync::Arc<rustc_codegen_cranelift::global_asm::GlobalAsmConfig>, rustc_span::symbol::Symbol, rustc_codegen_cranelift::concurrency_limiter::ConcurrencyLimiterToken), rustc_codegen_cranelift::driver::aot::OngoingModuleCodegen>::{closure#0}::{closure#0}, rustc_codegen_cranelift::driver::aot::OngoingModuleCodegen>
   5: rustc_codegen_cranelift::driver::aot::run_aot::{closure#3}::{closure#0}
   6: <core::iter::adapters::filter_map::FilterMap<alloc::vec::into_iter::IntoIter<(usize, &rustc_middle::mir::mono::CodegenUnit)>, rustc_data_structures::sync::parallel::enabled::par_map<(usize, &rustc_middle::mir::mono::CodegenUnit), alloc::vec::Vec<(usize, &rustc_middle::mir::mono::CodegenUnit)>, rustc_codegen_cranelift::driver::aot::OngoingModuleCodegen, alloc::vec::Vec<rustc_codegen_cranelift::driver::aot::OngoingModuleCodegen>, rustc_codegen_cranelift::driver::aot::run_aot::{closure#3}::{closure#0}>::{closure#0}::{closure#1}> as core::iter::traits::iterator::Iterator>::next
   7: rustc_codegen_cranelift::driver::aot::run_aot
   8: <rustc_codegen_cranelift::CraneliftCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
   9: rustc_interface::passes::start_codegen
  10: <rustc_interface::queries::Queries>::codegen_and_build_linker
  11: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
  12: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
  13: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#2} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  14: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library/alloc/src/boxed.rs:2063:9
  15: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library/alloc/src/boxed.rs:2063:9
  16: std::sys::pal::unix::thread::Thread::new::thread_start
             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library/std/src/sys/pal/unix/thread.rs:108:17
  17: <unknown>
  18: <unknown>)
stack backtrace:
   0: rust_begin_unwind
             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_fmt
             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/36153f1a4e3162f0a143c7b3e468ecb3beb0008e/library/core/src/result.rs:1658:5
   3: rustc_codegen_cranelift::driver::aot::make_module
   4: rustc_codegen_cranelift::driver::aot::module_codegen::{closure#0}
   5: rustc_codegen_cranelift::driver::aot::module_codegen
   6: <rustc_middle::dep_graph::DepsType as rustc_query_system::dep_graph::Deps>::with_deps::<<rustc_query_system::dep_graph::graph::DepGraphData<rustc_middle::dep_graph::DepsType>>::with_task<rustc_middle::ty::context::TyCtxt, (rustc_codegen_cranelift::config::BackendConfig, alloc::sync::Arc<rustc_codegen_cranelift::global_asm::GlobalAsmConfig>, rustc_span::symbol::Symbol, rustc_codegen_cranelift::concurrency_limiter::ConcurrencyLimiterToken), rustc_codegen_cranelift::driver::aot::OngoingModuleCodegen>::{closure#0}::{closure#0}, rustc_codegen_cranelift::driver::aot::OngoingModuleCodegen>
   7: rustc_codegen_cranelift::driver::aot::run_aot::{closure#3}::{closure#0}
   8: <core::iter::adapters::filter_map::FilterMap<alloc::vec::into_iter::IntoIter<(usize, &rustc_middle::mir::mono::CodegenUnit)>, rustc_data_structures::sync::parallel::enabled::par_map<(usize, &rustc_middle::mir::mono::CodegenUnit), alloc::vec::Vec<(usize, &rustc_middle::mir::mono::CodegenUnit)>, rustc_codegen_cranelift::driver::aot::OngoingModuleCodegen, alloc::vec::Vec<rustc_codegen_cranelift::driver::aot::OngoingModuleCodegen>, rustc_codegen_cranelift::driver::aot::run_aot::{closure#3}::{closure#0}>::{closure#0}::{closure#1}> as core::iter::traits::iterator::Iterator>::next
   9: rustc_codegen_cranelift::driver::aot::run_aot
  10: <rustc_codegen_cranelift::CraneliftCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  11: rustc_interface::passes::start_codegen
  12: <rustc_interface::queries::Queries>::codegen_and_build_linker
  13: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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 make sure that you have updated to the latest nightly

note: please attach the file at `/home/limuy/桌面/EmperorOS/rustc-ice-2024-05-25T12_29_13-33604.txt` to your bug report

note: compiler flags: --crate-type lib -C embed-bitcode=no -Z codegen-backend=cranelift -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack

@limuy2022 limuy2022 added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 25, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 25, 2024
@lqd
Copy link
Member

lqd commented May 25, 2024

Looks like cg_clif cc @bjorn3

@bjorn3 bjorn3 added the A-cranelift Things relevant to the [future] cranelift backend label May 25, 2024
@bjorn3
Copy link
Member

bjorn3 commented May 25, 2024

You are compiling for riscv64gc-unknown-none-elf. It looks like the target_lexicon crate doesn't know that the binary format for that target is ELF and instead returns that the binary format is unknown. This then results in cranelift-object returning an error that it doesn't know how to create object files for this binary format and in turn cg_clif panics as it didn't expect an error. @sunfishcode should target-lexicon return ELF as object file for all -none targets? That is already the default when the OS is not recognized and I don't think we have any targets with an object file format other than ELF except for the wasm, windows, apple, ibm and vxworks targets all of which aren't matched by the -none case anyway.

@bjorn3 bjorn3 added O-bare-metal Target: Rust without an operating system and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 25, 2024
@bjorn3
Copy link
Member

bjorn3 commented Jul 8, 2024

bytecodealliance/target-lexicon#108 should fix this. Waiting on a new release of target-lexicon and cg_clif updating to it though.

@sunfishcode
Copy link
Member

I've now released target-lexicon 0.12.15 with bytecodealliance/target-lexicon#108 which changes the default binary format to ELF, following the code in LLVM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cranelift Things relevant to the [future] cranelift backend C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-bare-metal Target: Rust without an operating system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants