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

ICE when linking no_std lib to a no_std binary #82823

Closed
mikegedelman opened this issue Mar 6, 2021 · 2 comments
Closed

ICE when linking no_std lib to a no_std binary #82823

mikegedelman opened this issue Mar 6, 2021 · 2 comments
Labels
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.

Comments

@mikegedelman
Copy link

Code

Have a #![no_std] lib crate and then another #![no_std] binary crate, attempt to link them together.

// foo/no_std_lib/lib.rs
#![no_std]
#![feature(lang_items)]

#[lang = "start"]
fn lang_start() {}

#[panic_handler]
fn panic(_: &::core::panic::PanicInfo) -> ! {loop {}}


// foo/app/main.rs
#![no_std]

extern crate no_std_lib;

fn main() {}


// foo/app/Cargo.toml
[dependencies]
"no_std_lib" = { path = "../no_std_lib" }


// foo/Cargo.toml
...
[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

Changing app from a binary to a library (so linking two libraries) doesn't cause the error.

Full repo for repro: https://github.com/mikegedelman/rust-no-std-ice

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (caca2121f 2021-03-05)
binary: rustc
commit-hash: caca2121ffe4cb47d8ea2d9469c493995f57e0b5
commit-date: 2021-03-05
host: x86_64-apple-darwin
release: 1.52.0-nightly
LLVM version: 12.0.0

Error output

-> % cargo build
   Compiling no_std_lib v0.0.1 (/Users/mgedelman/projects/break_rust/no_std_lib)
   Compiling app v0.0.1 (/Users/mgedelman/projects/break_rust/app)
error: internal compiler error: compiler/rustc_metadata/src/rmeta/decoder.rs:1153:17: get_optimized_mir: missing MIR for `DefId(4:14 ~ no_std_lib[cfa6]::lang_start)`

thread 'rustc' panicked at 'Box<Any>', /rustc/caca2121ffe4cb47d8ea2d9469c493995f57e0b5/library/std/src/panic.rs:59:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: 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: rustc 1.52.0-nightly (caca2121f 2021-03-05) running on x86_64-apple-darwin

note: compiler flags: -C panic=abort -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
#0 [optimized_mir] optimizing MIR for `no_std_lib::lang_start`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to previous error

error: could not compile `app`
Backtrace

thread 'rustc' panicked at 'Box<Any>', /rustc/caca2121ffe4cb47d8ea2d9469c493995f57e0b5/library/std/src/panic.rs:59:5
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt::{{closure}}
   6: rustc_middle::ty::context::tls::with_opt
   7: rustc_middle::util::bug::opt_span_bug_fmt
   8: rustc_middle::util::bug::bug_fmt
   9: rustc_metadata::rmeta::decoder::<impl rustc_metadata::creader::CrateMetadataRef>::get_optimized_mir::{{closure}}
  10: rustc_metadata::rmeta::decoder::<impl rustc_metadata::creader::CrateMetadataRef>::get_optimized_mir
  11: rustc_metadata::rmeta::decoder::cstore_impl::provide_extern::optimized_mir
  12: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  13: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  14: rustc_data_structures::stack::ensure_sufficient_stack
  15: rustc_query_system::query::plumbing::force_query_with_job
  16: rustc_query_system::query::plumbing::get_query_impl
  17: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::optimized_mir
  18: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::instance_mir
  19: rustc_mir::monomorphize::collector::collect_neighbours
  20: rustc_mir::monomorphize::collector::collect_items_rec
  21: rustc_session::utils::<impl rustc_session::session::Session>::time
  22: rustc_mir::monomorphize::collector::collect_crate_mono_items
  23: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  24: rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::collect_and_partition_mono_items>::compute
  25: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  26: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  27: rustc_data_structures::stack::ensure_sufficient_stack
  28: rustc_query_system::query::plumbing::force_query_with_job
  29: rustc_query_system::query::plumbing::get_query_impl
  30: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::collect_and_partition_mono_items
  31: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  32: rustc_interface::passes::QueryContext::enter
  33: rustc_interface::queries::Queries::ongoing_codegen
  34: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  35: rustc_span::with_source_map
  36: rustc_interface::interface::create_compiler_and_run
  37: rustc_span::with_session_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: 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: rustc 1.52.0-nightly (caca2121f 2021-03-05) running on x86_64-apple-darwin

note: compiler flags: -C panic=abort -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
#0 [optimized_mir] optimizing MIR for `no_std_lib::lang_start`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

@mikegedelman mikegedelman 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 Mar 6, 2021
@mikegedelman
Copy link
Author

Agh, I thought I had searched well enough, went to double check - nope.

@mikegedelman
Copy link
Author

Duplicate of #79559

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

No branches or pull requests

1 participant