rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.47k stars 12.73k forks source link

ICE compiling liballoc with -Z randomize-layout in effect #90476

Open chorman0773 opened 3 years ago

chorman0773 commented 3 years ago

Code

fn main(){} // Should occur with any code as it happens in the standard library

Occurs while compiling alloc using -Z build-std while -Z randomize-layout is in effect.

Meta

rustc --version --verbose:

rustc 1.58.0-nightly (c390d69a6 2021-10-28)
binary: rustc
commit-hash: c390d69a615f095208ac94841f3310268521b2ee
commit-date: 2021-10-28
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

Error output

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `8`,
 right: `0`', /rustc/c390d69a615f095208ac94841f3310268521b2ee/compiler/rustc_codegen_ssa/src/base.rs:212:17
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c390d69a615f095208ac94841f3310268521b2ee/library/std/src/panicking.rs:495:5
   1: core::panicking::panic_fmt
             at /rustc/c390d69a615f095208ac94841f3310268521b2ee/library/core/src/panicking.rs:106:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed::<u64, u64>
   4: rustc_codegen_ssa::base::unsize_ptr::<rustc_codegen_llvm::builder::Builder>
   5: <rustc_codegen_ssa::mir::FunctionCx<rustc_codegen_llvm::builder::Builder>>::codegen_rvalue_operand
   6: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::Builder>
   7: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
   8: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::symbol::Symbol, rustc_codegen_ssa::ModuleCodegen<rustc_codegen_llvm::ModuleLlvm>>
   9: rustc_codegen_llvm::base::compile_codegen_unit
  10: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
  11: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  12: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  13: <rustc_interface::passes::QueryContext>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_errors::ErrorReported>>
  14: <rustc_interface::queries::Queries>::ongoing_codegen
  15: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  16: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}>
  17: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

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.58.0-nightly (c390d69a6 2021-10-28) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z force-unstable-if-unmarked -Z randomize-layout -C embed-bitcode=no -C debuginfo=2 --crate-type lib

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

query stack during panic:
end of query stack
error: could not compile `alloc`

CC: @Kixiron

Kixiron commented 3 years ago

Yep, this is a more general issue (aside from the apparent fact that alloc relies on something unspecified, but that's not my area) since layout calculation (and therefore randomization) happens after whenever transmute size comparisons happen. which is what I'd assume would be the intended checker of this. Since nothing after layout calculation gets the randomized info, it just hits codegen where an assertion catches it.

Enselic commented 1 year ago

Triage: I can't reproduce this. Am I doing some silly mistake perhaps?

$ RUSTFLAGS=-Zrandomize-layout cargo +nightly-2021-10-29 build -Z build-std --target x86_64-unknown-linux-gnu
[...]
   Compiling repro v0.1.0 (/home/martin/src/bin)
    Finished dev [unoptimized + debuginfo] target(s) in 12.05s
$ git ls-files | xargs bat
───────┬─────────────────────────────────────────────────────────────────────────────────────────
       │ File: .gitignore
───────┼─────────────────────────────────────────────────────────────────────────────────────────
   1   │ /target
───────┴─────────────────────────────────────────────────────────────────────────────────────────
───────┬─────────────────────────────────────────────────────────────────────────────────────────
       │ File: Cargo.lock
───────┼─────────────────────────────────────────────────────────────────────────────────────────
   1   │ # This file is automatically @generated by Cargo.
   2   │ # It is not intended for manual editing.
   3   │ version = 3
   4   │
   5   │ [[package]]
   6   │ name = "repro"
   7   │ version = "0.1.0"
───────┴─────────────────────────────────────────────────────────────────────────────────────────
───────┬─────────────────────────────────────────────────────────────────────────────────────────
       │ File: Cargo.toml
───────┼─────────────────────────────────────────────────────────────────────────────────────────
   1   │ [package]
   2   │ name = "repro"
   3   │ version = "0.1.0"
   4   │ edition = "2021"
───────┴─────────────────────────────────────────────────────────────────────────────────────────
───────┬─────────────────────────────────────────────────────────────────────────────────────────
       │ File: src/main.rs
───────┼─────────────────────────────────────────────────────────────────────────────────────────
   1   │ fn main(){} // Should occur with any code as it happens in the standard library
───────┴─────────────────────────────────────────────────────────────────────────────────────────