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

Large number of variables causes stack overflow (SIGSEGV) #122357

Open
coder0xff opened this issue Mar 12, 2024 · 3 comments
Open

Large number of variables causes stack overflow (SIGSEGV) #122357

coder0xff opened this issue Mar 12, 2024 · 3 comments
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) 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. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@coder0xff
Copy link

While building the p384 crate on an experimental platform I encountered a consistent ICE. Initially, the problem seemed to be due to the experimental platform. However, identifying the minimal reproduction revealed that all rustc are likely impacted. Note that the top of the stack is inside LLVM. I wasn't sure whether to report here or in LLVM, but it's clear that the structure that's being passed into LLVM is causing it to recurse too deeply.

This issue is a follow-up to esp-rs#214.

Minimal Reproduction

Directory Structure

.
├── Cargo.toml
└── src
    └── lib.rs

1 directory, 2 files

Contents of: Cargo.toml

[package]
name = "p384"
version = "0.14.0-pre"
edition = "2021"

Contents of: src/lib.rs

pub const fn break_me() {
    let _x0 = 0;
    let _x1 = 0;
    let _x2 = 0;
    let _x3 = 0;
    let _x4 = 0;
    let _x5 = 0;
    let _x6 = 0;
    let _x7 = 0;
    let _x8 = 0;
    let _x9 = 0;
.
.
.
    let _x9990 = 0;
    let _x9991 = 0;
    let _x9992 = 0;
    let _x9993 = 0;
    let _x9994 = 0;
    let _x9995 = 0;
    let _x9996 = 0;
    let _x9997 = 0;
    let _x9998 = 0;
    let _x9999 = 0;
}

pub const BREAK_ME: () = break_me();

Meta

rustc --version --verbose:

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6

Error output

   Compiling p384 v0.14.0-pre (/home/coder0xff/Dropbox/Documents/Projects/Community/src/community/elliptic-curves/p384)
error: rustc interrupted by SIGSEGV, printing backtrace

/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-ef0b2e016afc8182.so(+0x2c31aa6)[0x7eba1ba31aa6]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7eba18a42520]
/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.76.0-stable.so(+0x5e66695)[0x7eba16e66695]
/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.76.0-stable.so(_ZN4llvm16DwarfCompileUnit24constructVariableDIEImplERKNS_11DbgVariableEb+0x3eb)[0x7eba171f60ed]
/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.76.0-stable.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE+0xca5)[0x7eba17163b25]

### cycle encountered after 5 frames with period 6
/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.76.0-stable.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE+0x88d)[0x7eba1716370d]
/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.76.0-stable.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE+0x88d)[0x7eba1716370d]
/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.76.0-stable.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE+0x88d)[0x7eba1716370d]
/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.76.0-stable.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE+0x88d)[0x7eba1716370d]
/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.76.0-stable.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE+0x88d)[0x7eba1716370d]
/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.76.0-stable.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE+0x88d)[0x7eba1716370d]
### recursed 41 times

/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.76.0-stable.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE+0x88d)[0x7eba1716370d]
/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.76.0-stable.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE+0x88d)[0x7eba1716370d]
/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.76.0-stable.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE+0x88d)[0x7eba1716370d]
/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.76.0-stable.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE+0x88d)[0x7eba1716370d]
/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.76.0-stable.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE+0x88d)[0x7eba1716370d]

note: rustc unexpectedly overflowed its stack! this is a bug
note: maximum backtrace depth reached, frames may have been lost
note: we would appreciate a report at https://github.com/rust-lang/rust
note: backtrace dumped due to SIGSEGV! resuming signal
error: could not compile `p384` (lib)

Caused by:
  process didn't exit successfully: `/home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name p384 --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=235 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=0d600d9ffd0ec8ef -C extra-filename=-0d600d9ffd0ec8ef --out-dir /home/coder0xff/Dropbox/Documents/Projects/Community/src/community/elliptic-curves/p384/target/debug/deps -C incremental=/home/coder0xff/Dropbox/Documents/Projects/Community/src/community/elliptic-curves/p384/target/debug/incremental -L dependency=/home/coder0xff/Dropbox/Documents/Projects/Community/src/community/elliptic-curves/p384/target/debug/deps` (signal: 11, SIGSEGV: invalid memory reference)
Backtrace

#0  0x00007ffff0466695 in llvm::X86FrameLowering::getFrameIndexReference(llvm::MachineFunction const&, int, llvm::Register&) const () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
#1  0x00007ffff07f60ed in llvm::DwarfCompileUnit::constructVariableDIEImpl(llvm::DbgVariable const&, bool) () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
#2  0x00007ffff0763b25 in llvm::DwarfCompileUnit::createAndAddScopeChildren(llvm::LexicalScope*, llvm::DIE&) () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
#3  0x00007ffff076370d in llvm::DwarfCompileUnit::createAndAddScopeChildren(llvm::LexicalScope*, llvm::DIE&) () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
#4  0x00007ffff076370d in llvm::DwarfCompileUnit::createAndAddScopeChildren(llvm::LexicalScope*, llvm::DIE&) () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
[repeated many times]
#3018 0x00007ffff076370d in llvm::DwarfCompileUnit::createAndAddScopeChildren(llvm::LexicalScope*, llvm::DIE&) () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
#3019 0x00007ffff076370d in llvm::DwarfCompileUnit::createAndAddScopeChildren(llvm::LexicalScope*, llvm::DIE&) () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
#3020 0x00007ffff076370d in llvm::DwarfCompileUnit::createAndAddScopeChildren(llvm::LexicalScope*, llvm::DIE&) () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
#3021 0x00007ffff0762521 in llvm::DwarfCompileUnit::constructSubprogramScopeDIE(llvm::DISubprogram const*, llvm::LexicalScope*) () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
#3022 0x00007ffff07610e8 in llvm::DwarfDebug::endFunctionImpl(llvm::MachineFunction const*) () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
#3023 0x00007ffff07d313d in llvm::DebugHandlerBase::endFunction(llvm::MachineFunction const*) () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
#3024 0x00007ffff076b5cc in llvm::AsmPrinter::emitFunctionBody() () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
#3025 0x00007ffff0769046 in llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
#3026 0x00007ffff05193ba in llvm::FPPassManager::runOnFunction(llvm::Function&) () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
#3027 0x00007ffff051866f in llvm::FPPassManager::runOnModule(llvm::Module&) () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
#3028 0x00007ffff0720bba in llvm::legacy::PassManagerImpl::run(llvm::Module&) () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-17-rust-1.76.0-stable.so
#3029 0x00007ffff6e16358 in LLVMRustWriteOutputFile () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ef0b2e016afc8182.so
#3030 0x00007ffff6e15f95 in rustc_codegen_llvm::back::write::write_output_file () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ef0b2e016afc8182.so
#3031 0x00007ffff6e13713 in rustc_codegen_llvm::back::write::codegen () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ef0b2e016afc8182.so
#3032 0x00007ffff6e133c2 in rustc_codegen_ssa::back::write::finish_intra_module_work::<rustc_codegen_llvm::LlvmCodegenBackend> () from /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ef0b2e016afc8182.so
#3033 0x00007ffff6eabbf1 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 /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ef0b2e016afc8182.so
#3034 0x00007ffff6eab6c2 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 /home/coder0xff/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ef0b2e016afc8182.so
#3035 0x00007ffff23988e5 in alloc::boxed::{impl#47}::call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> () at library/alloc/src/boxed.rs:2015
#3036 alloc::boxed::{impl#47}::call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> () at library/alloc/src/boxed.rs:2015
#3037 std::sys::unix::thread::{impl#2}::new::thread_start () at library/std/src/sys/unix/thread.rs:108
#3038 0x00007ffff2094ac3 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#3039 0x00007ffff2126850 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

@coder0xff coder0xff 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 12, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 12, 2024
@saethlin
Copy link
Member

We've previously gotten reports of problems compiling this crate:
#121814
#113612
#104021

While yes this is a compiler bug, making the compiler accept this code is likely way harder than adjusting p384 to fit into the compiler's current envelope. If you haven't already reported this to p384, you should consider doing so. I suspect that whatever pattern they're using that causes these problems is also degrading compile time.

If you're stuck because of this problem, you can probably run rustc with a bigger stack, using some combination of ulimit -s or RUST_MIN_STACK. You may also want to configure a Cargo profile override to build this crate specifically debug = 0: https://doc.rust-lang.org/cargo/reference/profiles.html#overrides

@saethlin saethlin added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Mar 12, 2024
@coder0xff
Copy link
Author

Agreed, I'm authoring a PR for p384 as a workaround. Perhaps this issue has value nonetheless due to the minimal reproduction, which appears to be novel amongst the other tickets, even llvm/llvm-project#76920 . Hopefully that makes it easier to address the root problem.

@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 13, 2024
@workingjubilee workingjubilee added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Mar 21, 2024
@workingjubilee
Copy link
Member

workingjubilee commented Mar 21, 2024

It is certainly a reproduction, for certain values of "minimal". Thank you!

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 22, 2024
…ack-workaround-on-overflow, r=TaKO8Ki

Suggest `RUST_MIN_STACK` workaround on overflow

For some Rust crates, like p384, we can't do a whole lot about it even if the stack overflow is reported like in rust-lang#122357 because the problem may be inside LLVM or another codegen backend. We can, however, suggest people set a new `RUST_MIN_STACK` value while handling the SIGSEGV, as that stack-setting will carry forward into the dylib.

As a bonus, this also leads to cleaning up the stack-setting code a bit.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 22, 2024
…ack-workaround-on-overflow, r=TaKO8Ki

Suggest `RUST_MIN_STACK` workaround on overflow

For some Rust crates, like p384, we can't do a whole lot about it even if the stack overflow is reported like in rust-lang#122357 because the problem may be inside LLVM or another codegen backend. We can, however, suggest people set a new `RUST_MIN_STACK` value while handling the SIGSEGV, as that stack-setting will carry forward into the dylib.

As a bonus, this also leads to cleaning up the stack-setting code a bit.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 22, 2024
…ack-workaround-on-overflow, r=TaKO8Ki

Suggest `RUST_MIN_STACK` workaround on overflow

For some Rust crates, like p384, we can't do a whole lot about it even if the stack overflow is reported like in rust-lang#122357 because the problem may be inside LLVM or another codegen backend. We can, however, suggest people set a new `RUST_MIN_STACK` value while handling the SIGSEGV, as that stack-setting will carry forward into the dylib.

As a bonus, this also leads to cleaning up the stack-setting code a bit.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 22, 2024
Rollup merge of rust-lang#122847 - workingjubilee:suggest-rust-min-stack-workaround-on-overflow, r=TaKO8Ki

Suggest `RUST_MIN_STACK` workaround on overflow

For some Rust crates, like p384, we can't do a whole lot about it even if the stack overflow is reported like in rust-lang#122357 because the problem may be inside LLVM or another codegen backend. We can, however, suggest people set a new `RUST_MIN_STACK` value while handling the SIGSEGV, as that stack-setting will carry forward into the dylib.

As a bonus, this also leads to cleaning up the stack-setting code a bit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) 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. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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

5 participants