Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
staticfloat opened this issue Dec 1, 2020 · 28 comments
Assignees
Labels
A-cross Area: Cross compilation A-linkage Area: linking into static, shared libraries and binaries A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows C-bug Category: This is a bug. O-windows Operating system: Windows O-x86_32 Target: x86 processors, 32 bit (like i686-*) P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@staticfloat
Copy link

Summary

When cross-compiling from a Linux distribution that provides SLJL mingw32, linker errors about libunwind symbols are a known issue (#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

staticfloat added a commit to JuliaPackaging/BinaryBuilderBase.jl that referenced this issue Dec 1, 2020
This is required because of a regression in the `Rust` build on
i686-w64-mingw32: rust-lang/rust#79609
staticfloat added a commit to JuliaPackaging/BinaryBuilderBase.jl that referenced this issue Dec 1, 2020
This is required because of a regression in the `Rust` build on
i686-w64-mingw32: rust-lang/rust#79609
giordano pushed a commit to JuliaPackaging/BinaryBuilderBase.jl that referenced this issue Dec 2, 2020
* Roll `Rust` build back to `v1.43`

This is required because of a regression in the `Rust` build on
i686-w64-mingw32: rust-lang/rust#79609

* Bump hardcoded version number
@LunarLambda
Copy link

LunarLambda commented Dec 2, 2020

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
Copy link
Author

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
Copy link
Member

wezm commented Dec 3, 2020

@rustbot modify labels: regression-untriaged

@rustbot rustbot added regression-untriaged Untriaged performance or correctness regression. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 3, 2020
@LeSeulArtichaut LeSeulArtichaut added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed regression-untriaged Untriaged performance or correctness regression. labels Dec 3, 2020
@camelid camelid added A-cross Area: Cross compilation A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows labels Dec 3, 2020
@apiraino
Copy link
Contributor

apiraino commented Dec 9, 2020

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

@apiraino apiraino added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 9, 2020
@rafalh
Copy link

rafalh commented Dec 19, 2020

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

@staticfloat
Copy link
Author

staticfloat commented Jan 13, 2021

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
Copy link

FH0 commented Jan 15, 2021

same problem
1.43 works
lto=true can't solve

my temporary solution

cargo +1.43.0 build --target=i686-pc-windows-gnu

@FH0
Copy link

FH0 commented Jan 18, 2021

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

@wezm
Copy link
Member

wezm commented Apr 7, 2021

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
Copy link
Member

wezm commented Apr 7, 2021

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
Copy link
Contributor

apiraino commented Apr 7, 2021

@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 rustbot added the ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections label Apr 7, 2021
@rustbot
Copy link
Collaborator

rustbot commented Apr 7, 2021

@eggyal
Copy link
Contributor

eggyal commented Apr 8, 2021

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
Copy link
Member

Amanieu commented Apr 8, 2021

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
Copy link

tmatth commented Dec 6, 2021

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
Copy link
Member

Amanieu commented Dec 6, 2021

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

  • Use a toolchain that uses dw2 unwinding instead of sjlj.
  • Use -Z build-std so the standard library is built without unwinding support.
  • 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).

korrat added a commit to korrat/deku that referenced this issue Feb 23, 2022
On some targets, alloc is built with unwinding. Therefore, it requires
libunwind even when compiling with panic=abort. Defining the
_Unwind_Resume symbol fixes this. The actual implementation does not
matter, since it will never be called.

See rust-lang/rust#79609 for more details.
sharksforarms pushed a commit to sharksforarms/deku that referenced this issue Feb 25, 2022
On some targets, alloc is built with unwinding. Therefore, it requires
libunwind even when compiling with panic=abort. Defining the
_Unwind_Resume symbol fixes this. The actual implementation does not
matter, since it will never be called.

See rust-lang/rust#79609 for more details.
vlc-mirrorer pushed a commit to videolan/vlc that referenced this issue Feb 26, 2022
@pachi
Copy link

pachi commented Jun 21, 2022

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
Copy link
Member

pnkfelix commented Dec 2, 2022

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.

vlc-mirrorer pushed a commit to videolan/vlc that referenced this issue Dec 12, 2022
This fixes building with llvm-mingw for i686 (which uses dwarf
for unwinding on i686) after updating to Rust 1.65.0 in
cb4464d.

The problematic patch was needed for fixing build breaks with
mingw toolchains that use SjLj exception handling (which is what
is used in VLC's current CI builds for mingw/i686) - which is
rust-lang/rust#79609.

Rust's stdlib contains references to the _Unwind_Resume symbol
(which is what the symbol is called in dwarf unwinding cases),
but it's not meant to actually be called (since rav1e is built
with "-C panic=abort"). If the mingw toolchain itself uses dwarf
(or SEH) unwinding, then the _Unwind_Resume symbol is provided
from that unwinder. But in the case of SjLj toolchains,
the toolchain only provides a symbol named __Unwind_SjLj_Resume.

The patch provided a dummy _Unwind_Resume symbol as part of the
rav1e build, which fixed the undefined references with SjLj toolchains.

However, since updating to Rust 1.65.0, other object files in
the Rust stdlib seems to pull in more unwinding symbols (there
are undefined references to e.g. _Unwind_GetRegionStart). These
other symbols are named the same both in dwarf, SjLj and SEH
toolchains. In the case of SjLj toolchains, they ended up pulled
in from libunwind/libgcc, but in the case of dwarf or SEH toolchains,
the locally defined _Unwind_Resume caused a conflict with the real
one which ended up included from libunwind/libgcc.

To avoid the issue, provide all referenced symbols as similar stubs;
this makes sure that the build doesn't end up pulling in anything
unwinding related from libunwind/libgcc, either in SjLj or dwarf
toolchains.
@pnkfelix
Copy link
Member

pnkfelix commented Mar 3, 2023

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)

@Noratrieb Noratrieb added O-x86_32 Target: x86 processors, 32 bit (like i686-*) and removed O-x86-all labels Oct 25, 2023
@wesleywiser wesleywiser self-assigned this Oct 27, 2023
kcalbxof added a commit to kcalbxof/noita_entangled_worlds that referenced this issue Nov 30, 2024
kcalbxof added a commit to kcalbxof/noita_entangled_worlds that referenced this issue Nov 30, 2024
kcalbxof added a commit to kcalbxof/noita_entangled_worlds that referenced this issue Nov 30, 2024
@Enselic Enselic added O-windows Operating system: Windows and removed ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections labels Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cross Area: Cross compilation A-linkage Area: linking into static, shared libraries and binaries A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows C-bug Category: This is a bug. O-windows Operating system: Windows O-x86_32 Target: x86 processors, 32 bit (like i686-*) P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests