rust-lang / rust-lang/rust

Compiling `no_std` for `i686-pc-windows-gnu` ignores `panic=abort`

Open
#133,826 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

-Zfixed-x18 A-cross A-panic C-bug O-windows-gnu O-x86_32 T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

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 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. 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

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
Backtrace

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the i686-pc-windows-gnu build in the linked stardust-rs project, using its Cargo.toml and the symbol definitions in stardust/src/main.rs. Compare the resulting linkage with x86_64-pc-windows-gnu and the build-std configuration described in the report; done means panic=abort no longer causes the unwanted unwinding dependencies and symbols.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.