Inclusion of `-lkernel32`and others when compiling `libcompiler_builtins` for `i686-pc-windows-gnu`
Irate-Walrus opened this issue · 3 comments
When cross-compiling for i686-pc-windows-gnu libcompiler_builtins-461ff43f4f8a3a70.rlib is linked with the following flags "-lgcc_eh" "-l:libpthread.a" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmingwex" "-luser32" "-lkernel32". This appears to be linked whether or not compiler_builtins appears in the crate's Cargo.toml. I believe this linking is resulting in the following error: undefined reference to 'stmain'.
The crate is #![no_std] and defines its own _entry and main (stmain) functions, both -nostdlib and -nostartfiles are being passed to the linker. It can be found here: https://github.com/Irate-Walrus/stardust-rs
Following is the error output:
error: linking with `i686-w64-mingw32-gcc` failed: exit status: 1
|
= note: LC_ALL="C" PATH="/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/user/go/bin:/home/user/.cargo/bin:/home/user/.local/scripts:/home/user/.local/bin:/home/user/go/bin:/home/user/.cargo/bin:/home/user/.local/scripts:/home/user/.local/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/user/.dotnet/tools" VSLANG="1033" "i686-w64-mingw32-gcc" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-Wl,--large-address-aware" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o" "/tmp/rustcExzT5y/symbols.o" "/home/user/Source/stardust-rs/target/i686-pc-windows-gnu/release/deps/stardust-0cbc72f4e9364613.stardust.d04ac4ac0cdcadb1-cgu.0.rcgu.o" "-Wl,-Bstatic" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libcompiler_builtins-461ff43f4f8a3a70.rlib" "-Wl,-Bdynamic" "-lgcc_eh" "-l:libpthread.a" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmingwex" "-luser32" "-lkernel32" "-Wl,--nxcompat" "-o" "/home/user/Source/stardust-rs/target/i686-pc-windows-gnu/release/deps/stardust-0cbc72f4e9364613.exe" "-Wl,--gc-sections" "-no-pie" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs" "-Wl,--verbose" "-fpack-struct=8" "-falign-jumps=1" "-w" "-Wl,-s,--no-seh,--enable-stdcall-fixup" "-Wl,--subsystem,console" "-Wl,-T./stardust/scripts/windows.ld" "-nostdlib" "-nostartfiles" "-static" "-fno-ident" "-Wl,--gc-sections,--build-id=none" "-falign-labels=1" "-Wall" "-fno-asynchronous-unwind-tables" "-Wl,-e_start" "-Wl,-Map=/home/user/Source/stardust-rs/target/i686-pc-windows-gnu/release/build/stardust-5660e9920ec42a40/out/stardust.map" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-1gnu/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o"
= note: /usr/bin/i686-w64-mingw32-ld: /home/user/Source/stardust-rs/target/i686-pc-windows-gnu/release/deps/stardust-0cbc72f4e9364613.stardust.d04ac4ac0cdcadb1-cgu.0.rcgu.o:stardust.d04ac4ac0cdcadb1-cgu.0:(.text.prologue+0xa): undefined reference to `stmain'
This is just my hypothesis, but I'm looking for advice on how to proceed either by linking libcompiler_builtins without these additional dependencies or ensuring it is not linked at all. At least if I remove it completely I'll be able to tell whether the linking error is related to the undesired dependencies being included. You help is much appreciated 😄
Rustc unconditionally passes it for all mingw targets independent of compiler-builtins: https://github.com/rust-lang/rust/blob/5afd5ad29c014de69bea61d028a1ce832ed75a75/compiler/rustc_target/src/spec/base/windows_gnu.rs#L42
Thanks for the quick response, much appreciated! This is going to be a pain. How would you recommend I proceed here? I could probably raise an issue on rust to grab more context and/or patch rustc myself to stop this. Feel free to close this issue :)
Closing this now, as no further comments have been made and issue is not within compiler-builtins.