Repository: rust
Issue: No backtrace from segfault handler after stack overflow in a proc macro on WSL
Labels: T-compiler,C-bug,A-proc-macros

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
-->

### Code

i have a presumably-extremely-broken proc macro which itself builds successfully but, when used, causes a segfault.

in `lib.rs`:
```Rust
use proc_macro::TokenStream;
use quote::{quote, ToTokens};
use syn::{parse_macro_input, Expr};

#[proc_macro]
pub fn eager(input: TokenStream) -> TokenStream {
    let expr = parse_macro_input!(input as Expr);
    let expanded = expand_macros(expr);
    TokenStream::from(quote! { #expanded })
}

fn expand_macros(expr: Expr) -> Expr {
    match expr {
        Expr::Macro(expr_macro) => {
            let macro_tokens = expr_macro.mac.to_token_stream();
            match syn::parse2::<Expr>(macro_tokens) {
                Ok(parsed_expr) => {
                    expand_macros(parsed_expr)
                }
                Err(_) => {
                    Expr::Verbatim(quote! {})
                }
            }
        }
        _ => expr,
    }
}
```

in `main.rs`:
```Rust
use my_macros::eager;

macro_rules! test_macro {
    ($input:expr) => {
        concat!("test macro applied: ", $input)
    };
}

fn main() {
    let out = eager!(test_macro!("test"));
}
```

tree structure:
```
├── Cargo.lock
├── Cargo.toml
└── src
    ├── lib.rs
    └── tests
        ├── Cargo.lock
        ├── Cargo.toml
        └── src
            └── main.rs
```

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7
```
also happens when running `cargo +nightly build`

### Error output

```
evan@DESKTOP-4LK1HQ6:~/my_macros/src/tests$ cargo build
   Compiling proc-macro2 v1.0.86
   Compiling unicode-ident v1.0.12
   Compiling quote v1.0.37
   Compiling syn v2.0.77
   Compiling my_macros v0.1.0 (/home/evan/my_macros)
   Compiling my_macros_tests v0.1.0 (/home/evan/my_macros/src/tests)
error: could not compile `my_macros_tests` (bin "my_macros_tests")

Caused by:
  process didn't exit successfully: `/home/evan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name my_macros_tests --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=60 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=7c1fe1052e96595b -C extra-filename=-7c1fe1052e96595b --out-dir /home/evan/my_macros/src/tests/target/debug/deps -C incremental=/home/evan/my_macros/src/tests/target/debug/incremental -L dependency=/home/evan/my_macros/src/tests/target/debug/deps --extern my_macros=/home/evan/my_macros/src/tests/target/debug/deps/libmy_macros-c5775cc6c3a5c013.so` (signal: 11, SIGSEGV: invalid memory reference)
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->

</details>