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

SIGTRAP with custom target #92362

Closed
iliakonnov opened this issue Dec 28, 2021 · 5 comments
Closed

SIGTRAP with custom target #92362

iliakonnov opened this issue Dec 28, 2021 · 5 comments
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. requires-nightly This issue requires a nightly compiler in some way.

Comments

@iliakonnov
Copy link

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

@iliakonnov iliakonnov added the C-bug Category: This is a bug. label Dec 28, 2021
@rustbot rustbot added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. requires-nightly This issue requires a nightly compiler in some way. labels Dec 28, 2021
@iliakonnov
Copy link
Author

Addition: disabling soft-float (+soft-float -> -soft-float) fixes this.

@BGR360
Copy link
Contributor

BGR360 commented Dec 29, 2021

@iliakonnov can you confirm that the crash does not occur on the latest stable and/or beta? Trying to figure out if this is a regression or a bug that has always existed.

@iliakonnov
Copy link
Author

iliakonnov commented Dec 29, 2021

@iliakonnov can you confirm that the crash does not occur on the latest stable and/or beta? Trying to figure out if this is a regression or a bug that has always existed.

As far as I know, it is not possible to use -Zbuild-std on non-nightly channels, so I've tried 1.57.0-nightly (5d2a410ff 2021-09-04) which is the first 1.57.0 nightly — got same SIGTRAP.

UPD: Trying rustc 1.56.0-nightly (a0035916e 2021-08-20) which uses LLVM 12.0.1 resulted in

LLVM ERROR: EH registrations only live in functions using WinEH
error: could not compile `core

when compiling core (not compiler_builtins). Looks similiar to #81516

@hkratz
Copy link
Contributor

hkratz commented Dec 29, 2021

Not all feature combinations are supported by LLVM. +soft-float,+sse2 in particular has been known to cause problems. We have issue #89586 for showing a warning for known-bad combinations.

@rustbot label +A-llvm

@rustbot rustbot added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Dec 29, 2021
@iliakonnov
Copy link
Author

Thanks for the comment! I'll close this issue then. Hopefully, it would be helpful for those who will google this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

No branches or pull requests

4 participants