Open staticfloat opened 3 years ago
Having a similar problem at the moment.
Not sure if this is an acceptable solution for you, but using rust-embedded/cross to build for i686-pc-windows-gnu
works.
(Although I had some issues with installing it through cargo. Instead, clone it, run the docker image building script for the i686-pc-windows-gnu
image, then cargo install --path .
.)
Not sure if this is an acceptable solution for you, but using rust-embedded/cross to build for i686-pc-windows-gnu works.
For me it's not because our entire ecosystem is based on mingw32 using SJLJ, rather than dwarf2, and I don't believe you can mix those two within a single process (e.g. loading those rust-built libraries within a C++ process that uses a different exception style).
@rustbot modify labels: regression-untriaged
Assigning P-high
as discussed as part of the Prioritization Working Group procedure and removing I-prioritize
.
Adding lto = true
in Cargo.toml
is a workaround for me.
I just tested this, and using LTO on Rust 1.48.0 (or 1.49.0) does not solve these errors for me.
Here is example output while compiling Librsvg
v2.50.2
:
note: ccache /opt/i686-w64-mingw32/bin/i686-w64-mingw32-gcc -D_GLIBCXX_USE_CXX11_ABI=0 -frandom-seed=0xbfedf747 -march=pentium4 -mtune=generic -fno-use-linker-plugin -Wl,--nxcompat -Wl,--large-address-aware /opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o -L /opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib /workspace/srcdir/librsvg-2.50.2/target/i686-pc-windows-gnu/release/deps/librsvg_tests-e64ad8d0778e
4238.librsvg_tests.deth3xsk-cgu.2.rcgu.o -o /workspace/srcdir/librsvg-2.50.2/target/i686-pc-windows-gnu/release/deps/librsvg_tests-e64ad8d0778e4238.exe -Wl,--gc-sections -nodefaultlibs -L /workspace/srcdir/librsvg-2.50.2/target/i686-pc-windows-gnu/release/deps -L /works
pace/srcdir/librsvg-2.50.2/target/release/deps -L /opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib -Wl,--start-group -Wl,--end-group -Wl,-Bstatic /opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib
/rustlib/i686-pc-windows-gnu/lib/libcompiler_builtins-c634db1b8ae16db1.rlib -Wl,-Bdynamic -ladvapi32 -lws2_32 -luserenv -lgcc_eh -l:libpthread.a -lmsvcrt -lmingwex -lmingw32 -lgcc -lmsvcrt -luser32 -lkernel32 /opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux
-musl/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o
/workspace/srcdir/librsvg-2.50.2/target/i686-pc-windows-gnu/release/deps/librsvg_tests-e64ad8d0778e4238.librsvg_tests.deth3xsk-cgu.2.rcgu.o: In function `ZN5alloc3fmt6format17h2fa488a24f5e28c3E':
/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\alloc\src\fmt.rs:579: undefined reference to `_Unwind_Resume'
/workspace/srcdir/librsvg-2.50.2/target/i686-pc-windows-gnu/release/deps/librsvg_tests-e64ad8d0778e4238.librsvg_tests.deth3xsk-cgu.2.rcgu.o: In function `ZN5alloc6string6String15from_utf8_lossy17h684f42102552feddE':
/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\alloc\src\string.rs:567: undefined reference to `_Unwind_Resume'
/workspace/srcdir/librsvg-2.50.2/target/i686-pc-windows-gnu/release/deps/librsvg_tests-e64ad8d0778e4238.librsvg_tests.deth3xsk-cgu.2.rcgu.o:/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\alloc\src\string.rs:567: undefined reference to `_Un
wind_Resume'
/workspace/srcdir/librsvg-2.50.2/target/i686-pc-windows-gnu/release/deps/librsvg_tests-e64ad8d0778e4238.librsvg_tests.deth3xsk-cgu.2.rcgu.o:/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\alloc\src\string.rs:567: undefined reference to `_Un
wind_Resume'
/workspace/srcdir/librsvg-2.50.2/target/i686-pc-windows-gnu/release/deps/librsvg_tests-e64ad8d0778e4238.librsvg_tests.deth3xsk-cgu.2.rcgu.o:/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\alloc\src\string.rs:567: undefined reference to `_Un
wind_RaiseException'
/workspace/srcdir/librsvg-2.50.2/target/i686-pc-windows-gnu/release/deps/librsvg_tests-e64ad8d0778e4238.librsvg_tests.deth3xsk-cgu.2.rcgu.o:/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\alloc\src\string.rs:567: undefined reference to `_Un
wind_Resume'
/workspace/srcdir/librsvg-2.50.2/target/i686-pc-windows-gnu/release/deps/librsvg_tests-e64ad8d0778e4238.librsvg_tests.deth3xsk-cgu.2.rcgu.o:/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\alloc\src\string.rs:567: undefined reference to `_Un
wind_Resume'
/workspace/srcdir/librsvg-2.50.2/target/i686-pc-windows-gnu/release/deps/librsvg_tests-e64ad8d0778e4238.librsvg_tests.deth3xsk-cgu.2.rcgu.o:/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\alloc\src\string.rs:567: undefined reference to `_Un
wind_Resume'
/workspace/srcdir/librsvg-2.50.2/target/i686-pc-windows-gnu/release/deps/librsvg_tests-e64ad8d0778e4238.librsvg_tests.deth3xsk-cgu.2.rcgu.o:/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\alloc\src\string.rs:567: undefined reference to `_Un
wind_Resume'
/workspace/srcdir/librsvg-2.50.2/target/i686-pc-windows-gnu/release/deps/librsvg_tests-e64ad8d0778e4238.librsvg_tests.deth3xsk-cgu.2.rcgu.o:/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\alloc\src\string.rs:567: undefined reference to `_Un
wind_Resume'
/workspace/srcdir/librsvg-2.50.2/target/i686-pc-windows-gnu/release/deps/librsvg_tests-e64ad8d0778e4238.librsvg_tests.deth3xsk-cgu.2.rcgu.o:/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\alloc\src\string.rs:567: more undefined references t
o `_Unwind_Resume' follow
collect2: error: ld returned 1 exit status
Perhaps this works for simpler packages, but for more complex things, it doesn't appear to properly eliminate the dependency on libunwind
.
same problem 1.43 works lto=true can't solve
my temporary solution
cargo +1.43.0 build --target=i686-pc-windows-gnu
Debug can't compile, while release can.
cargo build --target=i686-pc-windows-gnu --release
Hi all, this issue has remained open for a number of releases now and is preventing us from using Rust > 1.43.0 in Prince. What would be the best way to help find a solution? I'm not sure I am in position to find and fix the issue myself (due to my lack of experience working on the compiler) but I could try to bisect changes to work out what change introduced the issue, or something like that if it will help.
In case it's helpful here's a Dockerfile
that can be used to reproduce the issue (without messing with your local system):
FROM rust:1.51-slim-buster
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc-mingw-w64-i686
RUN rustup target add i686-pc-windows-gnu
RUN echo "fn main() {\nprintln!(\"Hello, Windows!\");\n}" > hello_world.rs && \
rustc --target=i686-pc-windows-gnu -C panic=abort -o hello_world.exe hello_world.rs
Build that image with: docker build -t mingw-i686-rust .
It fails as-is but succeeds with <= 1.43.0.
@wezm thanks for the latest comment with a way to reproduce the issue
@rustbot ping icebreakers-cleanup-crew
is this something that can be nailed to some past changes?
Hey Cleanup Crew ICE-breakers! This bug has been identified as a good "Cleanup ICE-breaking candidate". In case it's useful, here are some instructions for tackling these sorts of bugs. Maybe take a look? Thanks! <3
cc @AminArria @camelid @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @henryboisdequin @imtsuki @JamesPatrickGill @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @shekohex @sinato @smmalis37 @steffahn @Stupremee @tamuhey @turboladen @woshilapin @yerke
I think you should start bisection with https://github.com/rust-lang/rust/pull/67502, my gut says this PR changed it.
Using the following Dockerfile
, I was able to pinpoint it to between nightly-2020-03-14
and nightly-2020-03-15
.
FROM rust:1.51-slim-buster
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc-mingw-w64-i686 binutils-mingw-w64-i686 pkg-config libssl-dev
RUN echo "fn main() {\nprintln!(\"Hello, Windows!\");\n}" > hello_world.rs
RUN echo "rustup target add i686-pc-windows-gnu\nrustc --target=i686-pc-windows-gnu -C panic=abort -C linker=/usr/bin/i686-w64-mingw32-gcc -o hello_world.exe hello_world.rs" > hello_world.sh
RUN chmod +x hello_world.sh
RUN cat hello_world.rs
RUN cat hello_world.sh
RUN rustup default nightly-2020-03-14 # Change this to 15 to fail
RUN ./hello_world.sh
#67502 was merged on 21 Jan, modulo timezones. So that likely isn't the cause. See https://github.com/rust-lang/rust/issues/79609#issuecomment-814914868
I concur with @hameerabbasi. I adapted the Dockerfile
to run a bisection (specifically testing for failures due to libunwind
being absent during linking, rather than anything else):
FROM rust:1.51-slim-buster
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc-mingw-w64-i686 openssl libssl-dev pkg-config
RUN rustup target add i686-pc-windows-gnu
RUN cargo install cargo-bisect-rustc
RUN mkdir /home/issue-79609
WORKDIR /home/issue-79609
RUN echo "fn main() {\nprintln!(\"Hello, Windows!\");\n}" > hello_world.rs
RUN echo '#!/bin/bash\nrustc --target=i686-pc-windows-gnu -C panic=abort hello_world.rs |& grep "undefined reference to \`_Unwind_Resume'\''"\n[ $? -eq 1 ]' > build.sh && chmod u+x build.sh
ENTRYPOINT ["cargo", "bisect-rustc", "--target", "i686-pc-windows-gnu", "--script", "./build.sh"]
Bisecting over calendar 2020 identified nightly-2020-03-15
as the first with the regression. Obviously CI artefacts from back then are no longer available (to me, at least) for easy bisection of the individual commits.
fetching (via local git) commits from 1572c433eed495d0ade41511ae106b180e02851d to 7cdbc87a49b0b705a41a004a6d486b0952521ae7 opening existing repository at "rust.git" refreshing repository looking up first commit looking up second commit checking that commits are by bors and thus have ci artifacts... finding bors merge commits found 7 bors merge commits in the specified range commit[0] 2020-03-13UTC: Auto merge of #69986 - JohnTitor:rollup-h0809mf, r=JohnTitor commit[1] 2020-03-13UTC: Auto merge of #67502 - Mark-Simulacrum:opt-catch, r=Mark-Simulacrum commit[2] 2020-03-14UTC: Auto merge of #69716 - jonas-schievink:generator-size, r=tmandry commit[3] 2020-03-14UTC: Auto merge of #69744 - ecstatic-morse:fix-enum-discr-effect-test, r=oli-obk commit[4] 2020-03-14UTC: Auto merge of #69923 - matthiaskrgr:submodule_upd, r=Dylan-DPC commit[5] 2020-03-14UTC: Auto merge of #69076 - cjgillot:split_trait, r=matthewjasper commit[6] 2020-03-14UTC: Auto merge of #69999 - RalfJung:miri-unwind, r=oli-obk ERROR: no commits between 1572c433eed495d0ade41511ae106b180e02851d and 7cdbc87a49b0b705a41a004a6d486b0952521ae7 within last 167 days
Actually, #67502 is amongst those so @mati865's suspicion was probably right.
The issue here seems to be that std
is compiled with unwinding and therefore has several references to _Unwind_Resume
. One way to avoid this would be to use -Z build-std
which recompiles std
without unwinding support.
The issue here seems to be that
std
is compiled with unwinding and therefore has several references to_Unwind_Resume
. One way to avoid this would be to use-Z build-std
which recompilesstd
without unwinding support.
Since unwinding is unavailable on that target, I guess this is actually a CI issue because the distributed std
is being built incorrectly?
@eggyal unwinding is perfectly fine on that target if you have proper C toolchain. MSYS2 provides Dwarf-2 enabled 32-bit from the beginning I think, Fedora and Arch Linux provide that toolchain since last year and recently Debian (and therefore Unbuntu) has also switched: https://salsa.debian.org/mingw-w64-team/gcc-mingw-w64/-/commit/8da432fefb792fbe2f9fec2f15278d02e86e6281
Okay, thanks @mati865. So the fix is in gcc-mingw-w64-i686 v24, Debian packages of which are currently available on bullseye and sid (but not buster, which the Dockerfile
s in this issue have been using).
I confirmed that basing the Docker image on Debian bullseye (FROM rust:1.51-slim-bullseye
) does successfully build the binary. However, bullseye is the Debian testing release, which "does not get security updates in a timely manner". It would be ideal if it worked on the stable release (buster
) but at least that option is available.
To be fair this issue was specifically about SLJL mingw32 whereas the "fix" in v24 drops SLJL for Dwarf2; I should have called it a "workaround" instead, sitting alongside @Amanieu's alternative suggestion of using -Z build-std
(which is of course only available when using a nightly toolchain).
As a workaround you could just define your own _Unwind_Resume
function with #[no_mangle]
so libunwind doesn't get pulled in. The contents don't matter since it won't even get called.
In case it's helpful here's a
Dockerfile
that can be used to reproduce the issue (without messing with your local system):FROM rust:1.51-slim-buster RUN apt-get update && \ apt-get install -y --no-install-recommends gcc-mingw-w64-i686 RUN rustup target add i686-pc-windows-gnu RUN echo "fn main() {\nprintln!(\"Hello, Windows!\");\n}" > hello_world.rs && \ rustc --target=i686-pc-windows-gnu -C panic=abort -o hello_world.exe hello_world.rs
Build that image with:
docker build -t mingw-i686-rust .
It fails as-is but succeeds with <= 1.43.0.
Bumping as this is still reproducible with the latest stable:
FROM rust:1.57-slim-buster
but fixed with:
FROM rust:1.57-slim-bullseye
I don't think this issue can be fixed. The only solutions are:
-Z build-std
so the standard library is built without unwinding support._Unwind_Resume
symbol to satisfy the linker (it's never going to be called with -C panic=abort
so the implementation doesn't matter).I don't think this issue can be fixed. The only solutions are:
- Define your own
_Unwind_Resume
symbol to satisfy the linker (it's never going to be called with-C panic=abort
so the implementation doesn't matter).
I'm trying to cross compile to i686-pc-windows-gnu from Linux (Ubuntu 20.04) using rust 1.61.
Following the preceding advise, I'm adding this to my main binary:
#[no_mangle]
pub extern "C" fn _Unwind_Resume() {}
And it is indeed working. Thanks!
Visiting for P-high review.
From the discussion here, it seems like finding a seamless solution to this problem is either hard or impossible.
the right long-term solution may involve some form of -Z build-std
but any solution here is probably going to require post-processing of the linker-failure (including its stack trace), pattern matching for the "undefined reference to `_Unwind_Resume'" and then giving guidance as to what workarounds the user can use in response.
I may have aimed a bit too high in my ideas in my previous comment from 2022-12-02.
A much easier answer is to add an entry for i686-pc-windows-gnu to https://doc.rust-lang.org/rustc/platform-support.html , document this there, and point this issue at those docs (so that people googling about this will end up there eventually)
Summary
When cross-compiling from a Linux distribution that provides SLJL mingw32, linker errors about
libunwind
symbols are a known issue (https://github.com/rust-lang/rust/issues/12859). The generally-accepted workaround is to disable exception handling (via-C panic=abort
) which should disable the need to collect backtraces and eliminate the linker errors. This works on a 1.43.0 toolchain, but is broken on 1.44.0-1.48.0Example of error
Here's an example of the error, running within the
BinaryBuilder.jl
cross-compilation environment.Testing with multiple versions
I use the following script to install new versions of
rustc
:Version it worked on
This works on Rust 1.43.0.
Version with regression
This does not work on Rust 1.44.0-1.48.0