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

Rust windows toolchain has broken libraries #499

Open
staticfloat opened this issue Nov 17, 2019 · 3 comments
Open

Rust windows toolchain has broken libraries #499

staticfloat opened this issue Nov 17, 2019 · 3 comments

Comments

@staticfloat
Copy link
Member

This seems to be an upstream problem, but there also seems to be a workaround:

With $target = i686-w64-mingw32:

# rustc -o ${prefix}/bin/hello_world${exeext} -g /usr/share/testsuite/rust/hello_world/hello_world.rs
...
[00:15:41]   = note: /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/crt2.o:crtexe.c:(.text+0x75): undefined reference to `__onexitend'
[00:15:41]           /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/crt2.o:crtexe.c:(.text+0x7a): undefined reference to `__onexitbegin'
[00:15:41]           /opt/i686-w64-mingw32/bin/../lib/gcc/i686-w64-mingw32/4.8.5/../../../../i686-w64-mingw32/bin/ld: /opt/x86_64-linux-gnu/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/crt2.o: bad reloc address 0x0 in section `.CRT$XCAA'
[00:15:41]           collect2: error: ld returned 1 exit status

X-ref: rust-lang/rust#32859 (comment)

@giordano
Copy link
Member

giordano commented Jan 27, 2022

The above issue is gone, but now we have (again for i686-w64-mingw32):

sandbox:${WORKSPACE} # mkdir -p ${bindir}
sandbox:${WORKSPACE} # rustc -o ${bindir}/hello_world${exeext} -g /usr/share/testsuite/rust/hello_world/hello_world.rs
 WARN rustc_codegen_ssa::back::link Linker does not support -no-pie command line option. Retrying without.
error: linking with `i686-w64-mingw32-gcc` failed: exit status: 1
  |
  = note: "i686-w64-mingw32-gcc" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-Wl,--large-address-aware" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o" "/workspace/destdir/bin/hello_world.hello_world.f26c5fe2-cgu.0.rcgu.o" "/workspace/destdir/bin/hello_world.hello_world.f26c5fe2-cgu.1.rcgu.o" "/workspace/destdir/bin/hello_world.hello_world.f26c5fe2-cgu.2.rcgu.o" "/workspace/destdir/bin/hello_world.hello_world.f26c5fe2-cgu.3.rcgu.o" "/workspace/destdir/bin/hello_world.hello_world.f26c5fe2-cgu.4.rcgu.o" "/workspace/destdir/bin/hello_world.hello_world.f26c5fe2-cgu.5.rcgu.o" "/workspace/destdir/bin/hello_world.hello_world.f26c5fe2-cgu.6.rcgu.o" "/workspace/destdir/bin/hello_world.hello_world.f26c5fe2-cgu.7.rcgu.o" "/workspace/destdir/bin/hello_world.2vww31saalyanugl.rcgu.o" "-L" "/opt/x86_64-linux-musl/toolchains/1.57.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.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libstd-3566ebb723257252.rlib" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libpanic_abort-9f279b9941a87043.rlib" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libobject-a568171fb90f4868.rlib" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libmemchr-8bebec6c9064cd12.rlib" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libaddr2line-3e23d9be6db03a84.rlib" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libgimli-9e986033c2483920.rlib" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libstd_detect-50f69ef8f2cb05e1.rlib" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/librustc_demangle-048e5b2eebdc4235.rlib" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libhashbrown-3a8b7c7477fe25f8.rlib" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/librustc_std_workspace_alloc-d7d97010a0a1c998.rlib" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libunwind-5065a97eae0b8509.rlib" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libcfg_if-290774ef6aa5cd40.rlib" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/liblibc-4f6e03f208e0d53b.rlib" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/liballoc-166e042e6cd01510.rlib" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/librustc_std_workspace_core-9b8d5d7d829afd65.rlib" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libcore-376497abbd8b512b.rlib" "-Wl,--end-group" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libcompiler_builtins-730befa83ea003e3.rlib" "-Wl,-Bdynamic" "-lkernel32" "-lws2_32" "-lbcrypt" "-ladvapi32" "-luserenv" "-lkernel32" "-lgcc_eh" "-l:libpthread.a" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "-Wl,--nxcompat" "-L" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib" "-o" "/workspace/destdir/bin/hello_world.exe" "-Wl,--gc-sections" "-nodefaultlibs" "/opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o"
  = note: /opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libstd-3566ebb723257252.rlib(std-3566ebb723257252.std.5f2a8faf-cgu.0.rcgu.o): In function `ZN5alloc11collections5btree3mem7replace17h18298a3a0fe7eecdE':
          /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\alloc\src\collections\btree/mem.rs:35: undefined reference to `_Unwind_Resume'
          /opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libstd-3566ebb723257252.rlib(std-3566ebb723257252.std.5f2a8faf-cgu.0.rcgu.o): In function `ZN64_$LT$std..backtrace..BytesOrWide$u20$as$u20$core..fmt..Debug$GT$3fmt17h64e5e6ce2fa98deaE':
          /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src/backtrace.rs:247: undefined reference to `_Unwind_Resume'
          /opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libstd-3566ebb723257252.rlib(std-3566ebb723257252.std.5f2a8faf-cgu.0.rcgu.o): In function `ZN4core3ops8function6FnOnce9call_once17h21e9840e4b0f898dE':
          /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\core\src\ops/function.rs:227: undefined reference to `_Unwind_Resume'
          /opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libstd-3566ebb723257252.rlib(std-3566ebb723257252.std.5f2a8faf-cgu.0.rcgu.o): In function `ZN3std9backtrace7Capture7resolve17h6f0e2e010e4b7c54E':
          /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src/backtrace.rs:485: undefined reference to `_Unwind_Resume'
          /opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libstd-3566ebb723257252.rlib(std-3566ebb723257252.std.5f2a8faf-cgu.0.rcgu.o): In function `ZN4core3ops8function6FnOnce9call_once17hf9f1e4e2bb527f08E':
          /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\core\src\ops/function.rs:227: undefined reference to `_Unwind_Resume'
          /opt/x86_64-linux-musl/toolchains/1.57.0-x86_64-unknown-linux-musl/lib/rustlib/i686-pc-windows-gnu/lib/libstd-3566ebb723257252.rlib(std-3566ebb723257252.std.5f2a8faf-cgu.0.rcgu.o):/rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\core\src\ptr/mod.rs:188: more undefined references to `_Unwind_Resume' follow
          collect2: error: ld returned 1 exit status
          
  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: aborting due to previous error

Good news is that only 32-bit Windows has problems, all other platforms are in a much better shape now.

@johnnychen94
Copy link

It looks like default MinGW toolchain isn't so compatible with rust

Ubuntu mingw packages for i686 uses sjlj exceptions, but rust target
i686-pc-windows-gnu uses dwarf exceptions. So we build mingw packages
that are compatible with rust.

From https://github.com/malbarbo/cross/blob/16a64e7028d90a3fdf285cfd642cdde9443c0645/docker/mingw.sh#L7-L9

Ref: cross-rs/cross#469

@giordano
Copy link
Member

That's well known, 4 years ago we should have probably linked rust-lang/rust#79609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants