Repository: rust
Issue: rust 1.77.1 fails to build on aarch64-unknown-netbsd with stack exhaustion
Labels: P-low,T-compiler,regression-from-stable-to-stable,O-netbsd,C-bug,O-AArch64,S-needs-repro

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I tried building rust 1.77.1 using the internal LLVM on an emulated aarch64 system, as part of an effort of putting a new rust version through its testing cycle to keep it working on our various NetBSD platforms.

I expected to see this happen: The build should complete

Instead, this happened: The build of 1.77.1 fails with stack exhaustion.  As a contrast, 1.76.0 succeeds on this same host.

### 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`:
```
<version>
```

As this is in the middle of the build, it's a little unclear which version of rustc is running on this point, though indications are that it's 1.77.1 in one of the bootstrap stages.  Also, trying to get the bootstrap compiler to run from the CLI is also proving challenging:

```
arm64: {7} /usr/pkgsrc/wip/rust177/work/rustc-1.77.1-src/build/bootstrap/debug/rustc --version
rustc shim: FATAL: RUSTC_STAGE was not set
rustc shim: NOTE: use `x.py build -vvv` to see all environment variables set by bootstrap
arm64: {8} env LD_LIBRARY_PATH=work/rustc-1.77.1-src/build/aarch64-unknown-netbsd/stage1/lib/ tcsh
arm64: {1} /usr/pkgsrc/wip/rust177/work/rustc-1.77.1-src/build/bootstrap/debug/rustc --version
rustc shim: FATAL: RUSTC_STAGE was not set
rustc shim: NOTE: use `x.py build -vvv` to see all environment variables set by bootstrap
arm64: {2} env RUSTC_STAGE=1 /usr/pkgsrc/wip/rust177/work/rustc-1.77.1-src/build/bootstrap/debug/rustc --version
thread 'main' panicked at src/bin/rustc.rs:57:48:
RUSTC_SYSROOT was not set
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
arm64: {3} exit

```

I hestitate doing `x.py build -vvv`, both because it iself probably requies own settings / environment variables, and for fear that will turn into a multi-hour endevour.

The build log ends with:

```
   Compiling gsgdt v0.1.2
     Running `/usr/pkgsrc/wip/rust177/work/rustc-1.77.1-src/build/bootstrap/debug/rustc /usr/pkgsrc/wip/rust177/work/rustc-1.77.1-src/build/bootstrap/debug/rustc --crate-name gsgdt --edition=2018 /usr/pkgsrc/wip/rust177/work/rustc-1.77.1-src/vendor/gsgdt/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -Zunstable-options --check-cfg 'cfg()' -C metadata=4c45b577cc1da5ed -C extra-filename=-4c45b577cc1da5ed --out-dir /usr/pkgsrc/wip/rust177/work/rustc-1.77.1-src/build/aarch64-unknown-netbsd/stage1-rustc/aarch64-unknown-netbsd/release/deps --target aarch64-unknown-netbsd -L dependency=/usr/pkgsrc/wip/rust177/work/rustc-1.77.1-src/build/aarch64-unknown-netbsd/stage1-rustc/aarch64-unknown-netbsd/release/deps -L dependency=/usr/pkgsrc/wip/rust177/work/rustc-1.77.1-src/build/aarch64-unknown-netbsd/stage1-rustc/release/deps --extern serde=/usr/pkgsrc/wip/rust177/work/rustc-1.77.1-src/build/aarch64-unknown-netbsd/stage1-rustc/aarch64-unknown-netbsd/release/deps/libserde-a7ca7ee3064e8334.rmeta --cap-lints allow --cfg=windows_raw_dylib -Csymbol-mangling-version=v0 -Zunstable-options '--check-cfg=cfg(bootstrap)' '--check-cfg=cfg(parallel_compiler)' '--check-cfg=cfg(no_btreemap_remove_entry)' '--check-cfg=cfg(crossbeam_loom)' '--check-cfg=cfg(span_locations)' '--check-cfg=cfg(rustix_use_libc)' '--check-cfg=cfg(emulate_second_only_system)' '--check-cfg=cfg(windows_raw_dylib)' -Zmacro-backtrace -Clink-args=-Wl,-z,origin -Clink-args=-Wl,-rpath,/usr/pkg/lib -Zunstable-options -Csplit-debuginfo=off -Zunstable-options '-Wrustc::internal' -Cprefer-dynamic -Z binary-dep-depinfo`

thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
rustc exited with signal: 6 (SIGABRT) (core dumped)
```

Unfortunately, gdb decided not to play ball with this one:

```
arm64: {3} gdb /usr/pkgsrc/wip/rust177/work/rustc-1.77.1-src/build/bootstrap/debug/rustc work/rustc-1.77.1-src/rustc.core
GNU gdb (GDB) 8.3
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "aarch64--netbsd".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
BFD: warning: /usr/pkgsrc/wip/rust177/work/rustc-1.77.1-src/build/bootstrap/debug/rustc: unsupported GNU_PROPERTY_TYPE (5) type: 0xc0000000
Reading symbols from /usr/pkgsrc/wip/rust177/work/rustc-1.77.1-src/build/bootstrap/debug/rustc...
[New process 2]
[New process 1]
Core was generated by `rustc'.
Program terminated with signal SIGABRT, Aborted.
#0  0x0000fb48f375a32c in ?? ()
[Current thread is 1 (process 2)]
warning: Unsupported auto-load script at offset 0 in section .debug_gdb_scripts
of file /usr/pkgsrc/wip/rust177/work/rustc-1.77.1-src/build/bootstrap/debug/rustc.
Use `info auto-load python-scripts [REGEXP]' to list them.
(gdb) i reg
x0             0x0                 0
x1             0x0                 0
x2             0x1                 1
x3             0x0                 0
x4             0x10                16
x5             0xffffffffffffffc0  -64
x6             0xfb48f21fff80      276290718400384
x7             0x7f7f7f7f7f7f7f7f  9187201950435737471
x8             0x0                 0
x9             0x1003              4099
x10            0xc                 12
x11            0x1                 1
x12            0x3ed23c8801c       4317042475036
x13            0x3ed23c88035       4317042475061
x14            0x3f                63
x15            0xfb48f2200d70      276290718403952
x16            0xfb48f37c5d50      276290741230928
x17            0xfb48f375a328      276290740790056
x18            0xfb48ec23e431      276290617992241
x19            0xfb48f31bab10      276290734893840
x20            0xfb48f31babd0      276290734894032
x21            0xfb48f22011f0      276290718405104
x22            0xfb48f319e010      276290734776336
x23            0xfb48f319e028      276290734776360
--Type <RET> for more, q to quit, c to continue without paging--
x24            0x1                 1
x25            0x0                 0
x26            0xfb48f2200648      276290718402120
x27            0x5                 5
x28            0xfb48f31bac50      276290734894160
x29            0xfb48f22005e0      276290718402016
x30            0xfb48f3759ff4      276290740789236
sp             0xfb48f31bab00      0xfb48f31bab00
pc             0xfb48f375a32c      0xfb48f375a32c
cpsr           0x80000000          [ EL=0 N ]
fpsr           0x0                 0
fpcr           0x10                16
(gdb) x/i 0xfb48f375a32c
=> 0xfb48f375a32c:        Cannot access memory at address 0xfb48f375a32c
(gdb) 
```