Skip to content

Stack overflow in thread local's drop rendered as a segmentation fault. #109785

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
jswrenn opened this issue Mar 30, 2023 · 2 comments
Closed

Stack overflow in thread local's drop rendered as a segmentation fault. #109785

jswrenn opened this issue Mar 30, 2023 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jswrenn
Copy link
Member

jswrenn commented Mar 30, 2023

Code

pub fn main() {
    struct RecursiveDrop;

    impl Drop for RecursiveDrop {
        fn drop(&mut self) {
            let _ = RecursiveDrop;
        }
    }

    thread_local!(static LOCAL: RecursiveDrop = const { RecursiveDrop });

    LOCAL.with(|_| {});
}

Current output

Segmentation fault (core dumped)

Desired output

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Aborted (core dumped)

Rationale and extra context

This should encounter a guard page and produce the expected diagnostic, but it does not.

rustc --version --verbose:

rustc 1.70.0-nightly (44f518058 2023-03-20)
binary: rustc
commit-hash: 44f5180584404d18058cbbf224c55255db4fdcbb
commit-date: 2023-03-20
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7
@jswrenn jswrenn added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 30, 2023
@cuviper
Copy link
Member

cuviper commented Mar 31, 2023

Encountering a guard page is a SIGSEGV, as that handler shows, but the tricky question is whether that code correctly identifies it as such, especially with kernel-managed stack growth on the main thread. Can you run this in GDB and see a backtrace? It would also help to have info registers and info proc mappings.

@workingjubilee
Copy link
Member

Technically #111272 is a duplicate of this issue but that one managed to have much more data and discussion in it so I am closing this one instead.

@workingjubilee workingjubilee closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants