Description
The MSYS2/MinGW distribution of Rust uses a more recent, unpublished, version of mingw-w64.
Recently the following test started to fail:
---- [ui] tests\ui\issues\issue-2214.rs stdout ----
error: test compilation failed although it shouldn't!
status: exit code: 1
command: PATH="C:\M\mingw-w64-rust\src\MINGW64\build\x86_64-pc-windows-gnu\stage2\bin;C:\M\mingw-w64-rust\src\MINGW64\build\x86_64-pc-windows-gnu\stage0-bootstrap-tools\x86_64-pc-windows-gnu\release\deps;C:\M\mingw-w64-rust\src\MINGW64\build\x86_64-pc-windows-gnu\stage0\bin;C:\msys64\mingw64\bin;C:\msys64\usr\local\bin;C:\msys64\usr\bin;C:\msys64\usr\bin;C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\msys64\usr\bin\site_perl;C:\msys64\usr\bin\vendor_perl;C:\msys64\usr\bin\core_perl" "C:\\M\\mingw-w64-rust\\src\\MINGW64\\build\\x86_64-pc-windows-gnu\\stage2\\bin\\rustc.exe" "C:\\M\\mingw-w64-rust\\src\\rustc-1.77.1-src\\tests\\ui\\issues\\issue-2214.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=C:\\Users\\Philippe\\.cargo" "--sysroot" "C:\\M\\mingw-w64-rust\\src\\MINGW64\\build\\x86_64-pc-windows-gnu\\stage2" "--target=x86_64-pc-windows-gnu" "-O" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "-o" "C:\\M\\mingw-w64-rust\\src\\MINGW64\\build\\x86_64-pc-windows-gnu\\test\\ui\\issues\\issue-2214\\a.exe" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=C:\\M\\mingw-w64-rust\\src\\MINGW64\\build\\x86_64-pc-windows-gnu\\native\\rust-test-helpers" "-L" "C:\\M\\mingw-w64-rust\\src\\MINGW64\\build\\x86_64-pc-windows-gnu\\test\\ui\\issues\\issue-2214\\auxiliary"
stdout: none
--- stderr -------------------------------
error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
|
= note: "x86_64-w64-mingw32-gcc" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-m64" "-Wl,--high-entropy-va" "C:\\M\\mingw-w64-rust\\src\\MINGW64\\build\\x86_64-pc-windows-gnu\\stage2\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsbegin.o" "C:\\msys64\\tmp\\rustcI8gS1G\\symbols.o" "C:\\M\\mingw-w64-rust\\src\\MINGW64\\build\\x86_64-pc-windows-gnu\\test\\ui\\issues\\issue-2214\\a.issue_2214.acb96087d874e44a-cgu.0.rcgu.o" "-L" "C:\\M\\mingw-w64-rust\\src\\MINGW64\\build\\x86_64-pc-windows-gnu\\native\\rust-test-helpers" "-L" "C:\\M\\mingw-w64-rust\\src\\MINGW64\\build\\x86_64-pc-windows-gnu\\test\\ui\\issues\\issue-2214\\auxiliary" "-L" "C:\\M\\mingw-w64-rust\\src\\MINGW64\\build\\x86_64-pc-windows-gnu\\stage2\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-L" "C:\\M\\mingw-w64-rust\\src\\MINGW64\\build\\x86_64-pc-windows-gnu\\stage2\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-Wl,-Bdynamic" "-lstd-52a03da70d492f12" "-Wl,-Bstatic" "C:\\M\\mingw-w64-rust\\src\\MINGW64\\build\\x86_64-pc-windows-gnu\\stage2\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcompiler_builtins-91ce6b54f8d65f85.rlib" "-Wl,-Bdynamic" "-lkernel32" "-ladvapi32" "-lbcrypt" "-lkernel32" "-lntdll" "-luserenv" "-lws2_32" "-lkernel32" "-lws2_32" "-lkernel32" "-lntdll" "-lkernel32" "-lgcc_s" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "-Wl,--nxcompat" "-L" "C:\\M\\mingw-w64-rust\\src\\MINGW64\\build\\x86_64-pc-windows-gnu\\stage2\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-o" "C:\\M\\mingw-w64-rust\\src\\MINGW64\\build\\x86_64-pc-windows-gnu\\test\\ui\\issues\\issue-2214\\a.exe" "-Wl,--gc-sections" "-no-pie" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs" "C:\\M\\mingw-w64-rust\\src\\MINGW64\\build\\x86_64-pc-windows-gnu\\stage2\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsend.o"
= note: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/libmsvcrt.a(lib64_libmsvcrt_common_a-sin.o): in function `sin':
C:/M/B/src/mingw-w64/mingw-w64-crt/math/x86/sin.def.h:64:(.text+0x5f): undefined reference to `__sinl_internal'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/libmsvcrt.a(lib64_libmsvcrt_common_a-log.o): in function `log':
C:/M/B/src/mingw-w64/mingw-w64-crt/math/x86/log.def.h:68:(.text+0x5c): undefined reference to `__logl_internal'
collect2.exe: error: ld returned 1 exit status
= note: 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#rustc-link-lib)
The issue was analyzed by @mati865 here.
The breaking change: mingw-w64/mingw-w64@a64c1f4
The proposed solution worked.
The issue was also reported to mingw-w64 and Martin Storsjö replied:
We have a fair bit of these kinds of circular dependencies between
libmingwex.a and libmsvcr*.a. And we'll probably get more of them, not
less, as we specialize some of our helper routines into different versions
for different CRTs (like this change).So therefore, breakage of this kind is indeed not surprising, when linking
with ld.bfd, if the libs aren't specified repeatedly.When driving linking with GCC and Clang, the linker is already invoked
with multiple "-lmsvcrt -lmingwex [..] -lmsvcrt -lmingwex". There are also
other similar issues that we've had to fix by adding more of these
duplicate linker options, see e.g.
gcc-mirror/gcc@850533a.This is not an issue with lld, because it scans for symbols in all loaded
libraries, not in the strict sequential manner that ld.bfd does.Alternatively, instead of just repeating these linker options over and
over, we could consider to add --start-group --end-group around these
linker options, in GCC, Clang and Rust, which would allow resolving any of
the dependencies in these libraries among themselves. Clang already passes
this, see e.g.
https://github.com/llvm/llvm-project/blob/llvmorg-18.1.4/clang/lib/Driver/ToolChains/MinGW.cpp#L277-L348,
but it only seems to do this when intending to link statically. Perhaps
this should be done unconditionally - this is already done for some
targets, see e.g.
https://github.com/llvm/llvm-project/blob/llvmorg-18.1.4/clang/lib/Driver/ToolChains/NaCl.cpp#L146-L147.// Martin