rust-lang/rust

Latest MSYS2 mingw-w64 build failure - undefined reference to `__onexitbegin'

segevfiner opened this issue ยท 4 comments

Yet another build failure caused by newer mingw-w64 from MSYS2

$ ./x.py build --stage 1 src/libtest
   Compiling dtoa v0.4.2
   Compiling libc v0.2.36
   Compiling quote v0.3.15
   Compiling num-traits v0.1.41
   Compiling itoa v0.3.4
   Compiling unicode-xid v0.0.4
   Compiling cfg-if v0.1.2
   Compiling serde v1.0.27
   Compiling getopts v0.2.15
   Compiling lazy_static v0.2.11
   Compiling cc v1.0.4
   Compiling num_cpus v1.8.0
   Compiling synom v0.11.3
   Compiling filetime v0.1.15
   Compiling syn v0.11.11
   Compiling build_helper v0.1.0 (file:///rust/src/build_helper)
   Compiling cmake v0.1.29
   Compiling serde_derive_internals v0.19.0
   Compiling serde_derive v1.0.27
   Compiling serde_json v1.0.9
   Compiling toml v0.4.5
error: linking with `gcc` failed: exit code: 1
  |
  = note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-m64" "rust\\build\\x86_64-pc-windows-gnu\\stage0\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\dllcrt2.o" "rust\\build\\x86_64-pc-windows-gnu\\stage0\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsbegin.o" "-L" "rust\\build\\x86_64-pc-windows-gnu\\stage0\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive0.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive1.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive10.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive11.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive12.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive13.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive14.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive15.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive2.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive3.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive4.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive5.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive6.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive7.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive8.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.serde_derive9.rcgu.o" "-o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.dll" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.crate.metadata.rcgu.o" "rust/build/bootstrap\\debug\\deps\\serde_derive-c7aaf37ae10a4130.crate.allocator.rcgu.o" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "rust/build/bootstrap\\debug\\deps" "-L" "rust\\build\\x86_64-pc-windows-gnu\\stage0\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-L" "rust\\build\\x86_64-pc-windows-gnu\\stage0\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "proc_macro-bcc2434a1b882684" "-Wl,-Bstatic" "rust\\build\\bootstrap\\debug\\deps\\libserde_derive_internals-140c703284f34a9f.rlib" "rust\\build\\bootstrap\\debug\\deps\\libsyn-8dde0c452f8645b6.rlib" "rust\\build\\bootstrap\\debug\\deps\\libquote-583398947b6000c1.rlib" "rust\\build\\bootstrap\\debug\\deps\\libsynom-943bd861c659c6e2.rlib" "rust\\build\\bootstrap\\debug\\deps\\libunicode_xid-543b185aa846767b.rlib" "-L" "rust\\build\\x86_64-pc-windows-gnu\\stage0\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-Wl,-Bdynamic" "-l" "syntax-dbc40f18cf6b2624" "-L" "rust\\build\\x86_64-pc-windows-gnu\\stage0\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc_errors-5b0123adba021764" "-L" "rust\\build\\x86_64-pc-windows-gnu\\stage0\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "term-8caeedeff0eb44f5" "-L" "rust\\build\\x86_64-pc-windows-gnu\\stage0\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc_cratesio_shim-8e669af267f63663" "-L" "rust\\build\\x86_64-pc-windows-gnu\\stage0\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "syntax_pos-445ea2d11e7ccdba" "-L" "rust\\build\\x86_64-pc-windows-gnu\\stage0\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc_data_structures-0f8c40b9dd902cbe" "-L" "rust\\build\\x86_64-pc-windows-gnu\\stage0\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "serialize-793a650545dff7f7" "-L" "rust\\build\\x86_64-pc-windows-gnu\\stage0\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "std-76301403c1b4512d" "-Wl,-Bstatic" "rust\\build\\x86_64-pc-windows-gnu\\stage0\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcompiler_builtins-9642aa5ee0473544.rlib" "-Wl,-Bdynamic" "-l" "kernel32" "-l" "kernel32" "-l" "advapi32" "-l" "advapi32" "-l" "ws2_32" "-l" "userenv" "-l" "shell32" "-shared" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "rust\\build\\x86_64-pc-windows-gnu\\stage0\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsend.o"
  = note: rust\build\x86_64-pc-windows-gnu\stage0\lib\rustlib\x86_64-pc-windows-gnu\lib\dllcrt2.o:crtdll.c:(.rdata$.refptr.__onexitend[.refptr.__onexitend]+0x0): undefined reference to `__onexitend'
          rust\build\x86_64-pc-windows-gnu\stage0\lib\rustlib\x86_64-pc-windows-gnu\lib\dllcrt2.o:crtdll.c:(.rdata$.refptr.__onexitbegin[.refptr.__onexitbegin]+0x0): undefined reference to `__onexitbegin'
          collect2.exe: error: ld returned 1 exit status


error: aborting due to previous error

error: Could not compile `serde_derive`.
warning: build failed, waiting for other jobs to finish...
error: build failed
failed to run: rust/build/x86_64-pc-windows-gnu/stage0/bin/cargo.exe build --manifest-path rust/src/bootstrap/Cargo.toml
Build completed unsuccessfully in 0:00:22

The relevant commit from mingw-w64 is probably mirror/mingw-w64@a0ee49e. I think we are mixing mingw-w64 library versions. Old crt2.o with newer libmsvcrt.a.

Commit 80d6ed2#diff-3e203f016947a52e3f1fad3967027e7e (@alexcrichton) removed the downloading of rust-mingw which is a copy of mingw and libraries that should work with crt2.o, and other such libraries, that are included in rust-std.

Extracting the matching rust-mingw files into the stage0 manually made the build continue. (Not sure if it will finish, it can take a while... ๐Ÿ˜›). EDIT: It finished.

Hm ok, we could try to add that download back in, I sort of forget at this point why it was removed..

I am running Arch Linux, rustc 1.31.0-nightly installed using rustup.
I am using mingw-w64-crt-bin precompiled package from AUR.
I am experiencing the same issue.
To fix this, I tried this and it somehow worked :D

cd /home/farzeen/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/
mv crt2.o crt2.o.bak
cp /usr/x86_64-w64-mingw32/lib/crt2.o ./

I was compiling a Hello World application using gtk-rs.