rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.32k stars 12.58k forks source link

Passing `-C panic=abort` still attempts to link in `libunwind` when targeting `i686-pc-windows-gnu` on `v1.44+` #79609

Open staticfloat opened 3 years ago

staticfloat commented 3 years ago

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

Example of error

Here's an example of the error, running within the BinaryBuilder.jl cross-compilation environment.

# cat hello_world.rs 
fn main() {
    println!("Hello, World!");
}
# /opt/x86_64-linux-musl/bin/rustc --target=i686-pc-windows-gnu -C panic=abort -o /tmp/testsuite/i686-w64-mingw32/rust/hello_world/hello_world.exe hello_world.rs
error: linking with `i686-w64-mingw32-gcc` failed: exit code: 1
  |
  = note: "i686-w64-mingw32-gcc" "-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" "/tmp/testsuite/i686-w64-mingw32/rust/hello_world/hello_world.hello_world.7rcbfp3g-cgu.0.rcgu.o" "/tmp/testsuite/i686-w64-mingw32/rust/hello_world/hello_world.hello_world.7rcbfp3g-cgu.1.rcgu.o" "/tmp/testsuite/i686-w64-mingw32/rust/hello_world/hello_world.hello_world.7rcbfp3g-cgu.2.rcgu.o" "/tmp/testsuite/i686-w64-mingw32/rust/hello_world/hello_world.hello_world.7rcbfp3g-cgu.3.rcgu.o" "/tmp/testsuite/i686-w64-mingw32/rust/hello_world/hello_world.hello_world.7rcbfp3g-cgu.4.rcgu.o" "/tmp/testsuite/i686-w64-mingw32/rust/hello_world/hello_world.hello_world.7rcbfp3g-cgu.5.rcgu.o" "/tmp/testsuite/i686-w64-mingw32/rust/hello_world/hello_world.hello_world.7rcbfp3g-cgu.6.rcgu.o" "/tmp/testsuite/i686-w64-mingw32/rust/hello_world/hello_world.hello_world.7rcbfp3g-cgu.7.rcgu.o" "-o" "/tmp/testsuite/i686-w64-mingw32/rust/hello_world/hello_world.exe" "/tmp/testsuite/i686-w64-mingw32/rust/hello_world/hello_world.1oeskw8cnf06rbmk.rcgu.o" "-Wl,--gc-sections" "-nodefaultlibs" "-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,-Bstatic" "/opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libstd-fe449066d03836b9.rlib" "/opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libpanic_abort-905e0827b1faa99b.rlib" "/opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libobject-b5919c53897ea4e7.rlib" "/opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libaddr2line-09e1099705854178.rlib" "/opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libgimli-a13132083f96cf01.rlib" "/opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/librustc_demangle-1a2a881500c3aa11.rlib" "/opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libhashbrown-12335b7735858229.rlib" "/opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/librustc_std_workspace_alloc-03e236d940d65c13.rlib" "/opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libunwind-67ee36f8c83e0d23.rlib" "/opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libcfg_if-551dfddd5bf52674.rlib" "/opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/liblibc-119051673c0a64ec.rlib" "/opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/liballoc-e4d213396c740246.rlib" "/opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/librustc_std_workspace_core-09a82c5ce50e9376.rlib" "/opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libcore-e59a5606ba4e2b3b.rlib" "-Wl,--end-group" "/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"
  = note: /opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libstd-fe449066d03836b9.rlib(std-fe449066d03836b9.std.3uongtsb-cgu.0.rcgu.o): In function `ZN64_$LT$std..backtrace..BytesOrWide$u20$as$u20$core..fmt..Debug$GT$3fmt17h42ce8df8b153bc33E':
          /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src/backtrace.rs:231: undefined reference to `_Unwind_Resume'
          /opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libstd-fe449066d03836b9.rlib(std-fe449066d03836b9.std.3uongtsb-cgu.0.rcgu.o): In function `ZN4core3ops8function6FnOnce9call_once17h47abe59cb2be30c1E':
          /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\core\src\ops/function.rs:227: undefined reference to `_Unwind_Resume'
          /opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libstd-fe449066d03836b9.rlib(std-fe449066d03836b9.std.3uongtsb-cgu.0.rcgu.o): In function `ZN4core3ops8function6FnOnce9call_once17h48798ced7406d4f4E':
          /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\io/stdio.rs:563: undefined reference to `_Unwind_Resume'
          /opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libstd-fe449066d03836b9.rlib(std-fe449066d03836b9.std.3uongtsb-cgu.0.rcgu.o): In function `ZN4core3ops8function6FnOnce9call_once17h0a2adbee20aeb7b2E':
          /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\core\src\ops/function.rs:227: undefined reference to `_Unwind_Resume'
          /opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libstd-fe449066d03836b9.rlib(std-fe449066d03836b9.std.3uongtsb-cgu.0.rcgu.o): In function `ZN71_$LT$alloc..vec..IntoIter$LT$T$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17h9354c90820e79e8dE':
          /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\alloc\src/vec.rs:3069: undefined reference to `_Unwind_Resume'
          /opt/x86_64-linux-musl/toolchains/1.48.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libstd-fe449066d03836b9.rlib(std-fe449066d03836b9.std.3uongtsb-cgu.0.rcgu.o):/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\core\src\ptr/mod.rs:175: more undefined references to `_Unwind_Resume' follow
          collect2: error: ld returned 1 exit status

error: aborting due to previous error

Testing with multiple versions

I use the following script to install new versions of rustc:

#!/bin/bash
# Usage: change_win32_toolchain.sh [version]

TOOLCHAIN_VER=${1:-1.48.0}
rustup toolchain add ${TOOLCHAIN_VER}
rustup target add --toolchain ${TOOLCHAIN_VER} i686-pc-windows-gnu

# Copy crt2.o in to rust, see https://github.com/rust-lang/rust/issues/32859#issuecomment-573423629
cp /opt/i686-w64-mingw32/i686-w64-mingw32/sys-root/lib/crt2.o /opt/x86_64-linux-musl/toolchains/${TOOLCHAIN_VER}-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/crt2.o

# Set this new toolchain as the default for all invocations of `rustc`
export RUSTUP_TOOLCHAIN=${TOOLCHAIN_VER}-x86_64-unknown-linux-musl

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

LunarLambda commented 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 ..)

staticfloat commented 3 years ago

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

wezm commented 3 years ago

@rustbot modify labels: regression-untriaged

apiraino commented 3 years ago

Assigning P-high as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

rafalh commented 3 years ago

Adding lto = true in Cargo.toml is a workaround for me.

staticfloat commented 3 years ago

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.

FH0 commented 3 years ago

same problem 1.43 works lto=true can't solve

my temporary solution

cargo +1.43.0 build --target=i686-pc-windows-gnu
FH0 commented 3 years ago

Debug can't compile, while release can. cargo build --target=i686-pc-windows-gnu --release

wezm commented 3 years ago

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.

wezm commented 3 years ago

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.

apiraino commented 3 years ago

@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?

rustbot commented 3 years ago

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

mati865 commented 3 years ago

I think you should start bisection with https://github.com/rust-lang/rust/pull/67502, my gut says this PR changed it.

hameerabbasi commented 3 years ago

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

eggyal commented 3 years ago

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
eggyal commented 3 years ago

Actually, #67502 is amongst those so @mati865's suspicion was probably right.

Amanieu commented 3 years ago

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.

eggyal commented 3 years ago

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.

Since unwinding is unavailable on that target, I guess this is actually a CI issue because the distributed std is being built incorrectly?

mati865 commented 3 years ago

@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

eggyal commented 3 years ago

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 Dockerfiles in this issue have been using).

wezm commented 3 years ago

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.

eggyal commented 3 years ago

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

Amanieu commented 3 years ago

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.

tmatth commented 2 years ago

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
Amanieu commented 2 years ago

I don't think this issue can be fixed. The only solutions are:

pachi commented 2 years ago

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!

pnkfelix commented 1 year ago

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.

pnkfelix commented 1 year ago

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)