Skip to content

SIGTRAP with custom target #92362

Closed
Closed
@iliakonnov

Description

@iliakonnov

Compiler crashes with SIGTRAP (probably somewhere in LLVM) when building no_std crate that uses custom target specification based on built-in x86_64-unknown-none with -sse2 changed to +sse2.

Simple reproduction:

git clone https://github.com/iliakonnov/rust-crash-sigtrap
cd rust-crash-sigtrap
cargo build
Reproducing without using repo
  1. Start with basic no_std application. For example, see smallest-no-std
  2. Then create target specification:
    rustc +nightly -Z unstable-options --print target-spec-json --target x86_64-unknown-none > x86_64-custom.json
    sed -i 's/"is-builtin": true/"is-builtin": false/' x86_64-custom.json
    sed -i 's/-sse2/+sse2/' x86_64-custom.json
    
  3. Build it!
    cargo build --target x86_64-custom.json -Zbuild-std=core
    

I've expected successful compilation (or any more meaningful error message).

Instead, when compiler_builtins are compiling, following error occurs:

error: could not compile `compiler_builtins`

Caused by:
  process didn't exit successfully: `rustc --crate-name compiler_builtins ~/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.66/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="compiler-builtins"' --cfg 'feature="core"' --cfg 'feature="default"' --cfg 'feature="mem"' --cfg 'feature="rustc-dep-of-std"' -C metadata=87b7f5e35c5dfb1a -C extra-filename=-87b7f5e35c5dfb1a --out-dir ~/minimal/target/x86_64-custom/debug/deps --target ~/minimal/x86_64-custom.json -Z force-unstable-if-unmarked -L dependency=~/minimal/target/x86_64-custom/debug/deps -L dependency=~/minimal/target/debug/deps --extern core=~/minimal/target/x86_64-custom/debug/deps/librustc_std_workspace_core-65e9596df1fda648.rmeta --cap-lints allow --cfg 'feature="unstable"' --cfg 'feature="mem-unaligned"'` \
  (signal: 5, SIGTRAP: trace/breakpoint trap)

Meta

rustc --version --verbose:

rustc 1.59.0-nightly (f8abed9ed 2021-12-26)
binary: rustc
commit-hash: f8abed9ed48bace6be0087bcd44ed534e239b8d8
commit-date: 2021-12-26
host: x86_64-unknown-linux-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0
GDB backtrace
#0  0x00007ffff1bfbf78 in ?? () from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#1  0x00007ffff180c288 in foldCONCAT_VECTORS(llvm::SDLoc const&, llvm::EVT, llvm::ArrayRef<llvm::SDValue>, llvm::SelectionDAG&) [clone .llvm.9555667491127074190] ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#2  0x00007ffff1809525 in llvm::SelectionDAG::getNode(unsigned int, llvm::SDLoc const&, llvm::EVT, llvm::SDValue, llvm::SDValue, llvm::SDNodeFlags) ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#3  0x00007ffff3596b13 in LowerCVTPS2PH(llvm::SDValue, llvm::SelectionDAG&) ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#4  0x00007ffff2521838 in llvm::TargetLowering::LowerOperationWrapper(llvm::SDNode*, llvm::SmallVectorImpl<llvm::SDValue>&, llvm::SelectionDAG&) const ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#5  0x00007ffff2086eca in llvm::DAGTypeLegalizer::SplitVectorOperand(llvm::SDNode*, unsigned int) ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#6  0x00007ffff16f5ea1 in llvm::DAGTypeLegalizer::run() () from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#7  0x00007ffff16f038c in llvm::SelectionDAG::LegalizeTypes() ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#8  0x00007ffff16ee6e0 in llvm::SelectionDAGISel::CodeGenAndEmitDAG() ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#9  0x00007ffff16d0552 in llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#10 0x00007ffff16c9b8d in llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#11 0x00007ffff16c9688 in (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) [clone .llvm.9579652157589533625] ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#12 0x00007ffff1cb94fa in llvm::MachineFunctionPass::runOnFunction(llvm::Function&) ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#13 0x00007ffff1b70447 in llvm::FPPassManager::runOnFunction(llvm::Function&) ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#14 0x00007ffff1b6fd5f in llvm::FPPassManager::runOnModule(llvm::Module&) ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#15 0x00007ffff1fa1fb9 in llvm::legacy::PassManagerImpl::run(llvm::Module&) ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-13-rust-1.59.0-nightly.so
#16 0x00007ffff6653514 in LLVMRustWriteOutputFile () from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-86b6ef79da72f228.so
#17 0x00007ffff6648557 in rustc_codegen_llvm::back::write::write_output_file ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-86b6ef79da72f228.so
#18 0x00007ffff664b3d6 in rustc_codegen_llvm::back::write::codegen ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-86b6ef79da72f228.so
#19 0x00007ffff65e123b in rustc_codegen_ssa::back::write::finish_intra_module_work::<rustc_codegen_llvm::LlvmCodegenBackend> ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-86b6ef79da72f228.so
#20 0x00007ffff65e049b in rustc_codegen_ssa::back::write::execute_work_item::<rustc_codegen_llvm::LlvmCodegenBackend> ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-86b6ef79da72f228.so
#21 0x00007ffff663010f in std::sys_common::backtrace::__rust_begin_short_backtrace::<<rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa::back::write::spawn_work<rustc_codegen_llvm::LlvmCodegenBackend>::{closure#0}, ()>::{closure#0}, ()> ()
   from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-86b6ef79da72f228.so
#22 0x00007ffff663b7e3 in <<std::thread::Builder>::spawn_unchecked<<rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa::back::write::spawn_work<rustc_codegen_llvm::LlvmCodegenBackend>::{closure#0}, ()>::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} () from ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-86b6ef79da72f228.so
#23 0x00007ffff3fa9da3 in alloc::boxed::{impl#44}::call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> ()
    at /rustc/51e8031e14a899477a5e2d78ce461cab31123354/library/alloc/src/boxed.rs:1811
#24 alloc::boxed::{impl#44}::call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> ()
    at /rustc/51e8031e14a899477a5e2d78ce461cab31123354/library/alloc/src/boxed.rs:1811
#25 std::sys::unix::thread::{impl#2}::new::thread_start () at library/std/src/sys/unix/thread.rs:108
#26 0x00007ffff3ea9259 in start_thread () from /usr/lib/libpthread.so.0
#27 0x00007ffff3dc75e3 in clone () from /usr/lib/libc.so.6

@rustbot label +requires-nightly +I-crash

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions