Repository: rust
Issue: Compiling `no_std` for `i686-pc-windows-gnu` ignores `panic=abort`
Labels: A-cross,T-compiler,O-windows-gnu,C-bug,-Zbuild-std,A-panic,O-x86_32

When cross-compiling a `#![no_std]` crate for `i686-pc-windows-gnu` with `panic=abort` it includes unwinding symbols and its dependencies:

```text
Archive member included to satisfy reference by file (symbol)

/usr/lib/gcc/i686-w64-mingw32/13-win32/libgcc_eh.a(unwind-dw2-fde.o)
                              /home/irate-walrus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o (__register_frame_info)
/usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libmsvcrt.a(libmsvcrt_defs01135.o)
                              /usr/lib/gcc/i686-w64-mingw32/13-win32/libgcc_eh.a(unwind-dw2-fde.o) (abort)
/usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libmsvcrt.a(libmsvcrt_defs01177.o)
                              /usr/lib/gcc/i686-w64-mingw32/13-win32/libgcc_eh.a(unwind-dw2-fde.o) (free)
/usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libmsvcrt.a(libmsvcrt_defs01228.o)
                              /usr/lib/gcc/i686-w64-mingw32/13-win32/libgcc_eh.a(unwind-dw2-fde.o) (malloc)
/usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libmsvcrt.a(libmsvcrt_defs01234.o)
                              /usr/lib/gcc/i686-w64-mingw32/13-win32/libgcc_eh.a(unwind-dw2-fde.o) (memcpy)
/usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libmsvcrt.a(libmsvcrt_defs01279.o)
                              /usr/lib/gcc/i686-w64-mingw32/13-win32/libgcc_eh.a(unwind-dw2-fde.o) (strlen)
/usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libmsvcrt.a(libmsvcrt_defh.o)
                              /usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libmsvcrt.a(libmsvcrt_defs01135.o) (_head_lib32_libmsvcrt_def_a)
/usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libmsvcrt.a(libmsvcrt_deft.o)
                              /usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libmsvcrt.a(libmsvcrt_defh.o) (_lib32_libmsvcrt_def_a_iname)
/usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-tlsmcrt.o)
                              /usr/lib/gcc/i686-w64-mingw32/13-win32/libgcc_eh.a(unwind-dw2-fde.o) (_CRT_MT)
/usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libkernel32.a(libkernel32s01416.o)
                              /usr/lib/gcc/i686-w64-mingw32/13-win32/libgcc_eh.a(unwind-dw2-fde.o) (_imp__Sleep@4)
/usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libkernel32.a(libkernel32s00996.o)
                              /usr/lib/gcc/i686-w64-mingw32/13-win32/libgcc_eh.a(unwind-dw2-fde.o) (_imp__LeaveCriticalSection@4)
/usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libkernel32.a(libkernel32s00898.o)
                              /usr/lib/gcc/i686-w64-mingw32/13-win32/libgcc_eh.a(unwind-dw2-fde.o) (_imp__InitializeCriticalSection@4)
/usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libkernel32.a(libkernel32s00321.o)
                              /usr/lib/gcc/i686-w64-mingw32/13-win32/libgcc_eh.a(unwind-dw2-fde.o) (_imp__EnterCriticalSection@4)
/usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libkernel32.a(libkernel32h.o)
                              /usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libkernel32.a(libkernel32s01416.o) (_head_lib32_libkernel32_a)
/usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libkernel32.a(libkernel32t.o)
                              /usr/lib/gcc/i686-w64-mingw32/13-win32/../../../../i686-w64-mingw32/lib/../lib/libkernel32.a(libkernel32h.o) (_lib32_libkernel32_a_iname)
```

As `panic=abort` is specified in the crate's [Cargo.toml](https://github.com/Irate-Walrus/stardust-rs/blob/f85933c11ec40cb9bb78d2a0360fc31831b7a44d/Cargo.toml#L12C1-L12C16) I would expect that these dependencies would not be linked. This would also be consistent with the behavior when compiling for `x86_64-pc-windows-gnu` which does not link these symbols.

I have also attempted the compilation of the crate using the `Z build-std=core,alloc,panic_abort -Z build-std-features=panic_immediate_abort` flags which as not resolved this issue. I also define my own panic-handler and other required symbols in the [main.rs](https://github.com/Irate-Walrus/stardust-rs/blob/f85933c11ec40cb9bb78d2a0360fc31831b7a44d/stardust/src/main.rs#L22-L47). Previous discussion on the rust-lang forum can be found here: https://users.rust-lang.org/t/inclusion-of-lkernel32-and-others-when-compiling-no-std-for-i686-pc-windows-gnu/121551/14.

The project can be found here: https://github.com/Irate-Walrus/stardust-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.84.0-nightly (b8c8287a2 2024-11-03)
binary: rustc
commit-hash: b8c8287a229cd79604aa84c25e1235fc78cd5f2e
commit-date: 2024-11-03
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>

N/A, the project compiles but due to linkage of additional symbols crashes during runtime with an unrelated error.

</p>
</details>