Skip to content

Commit

Permalink
rust: fix externally linking some math functions
Browse files Browse the repository at this point in the history
The tests\ui\issues\issue-2214.rs test fails with undefined reference to `__sinl_internal' and other math functions.

Mateusz Mikuła analyzed the issue and found that the root cause is this change in mingw-w64: mingw-w64/mingw-w64@a64c1f4

The error happens because Rust pulls in lgamma from libmingwex.a, which pulls in sin from libmsvcrt.a, which in turn tries to pull in __sinl_internal from libmingwex.a and fails because of how Rust links MinGW libs.
The proposed fix was to add an extra "-lmingwex" after the second "-lmsvcrt" in https://github.com/rust-lang/rust/blob/aa6a697a1c75b0aa06954136f7641706edadc2be/compiler/rustc_target/src/spec/base/windows_gnu.rs#L30.
  • Loading branch information
filnet committed Apr 16, 2024
1 parent dee35d7 commit 96fa059
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 10 additions & 0 deletions mingw-w64-rust/0015-gcc-subsystem.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- rustc-1.77.2-src/compiler/rustc_target/src/spec/base/windows_gnu.rs.orig 2024-04-13 12:55:59.933083700 +0200
+++ rustc-1.77.2-src/compiler/rustc_target/src/spec/base/windows_gnu.rs 2024-04-13 12:56:15.789241300 +0200
@@ -40,6 +40,7 @@
//
// See https://github.com/rust-lang/rust/pull/47483 for some more details.
"-lmsvcrt",
+ "-lmingwex",
"-luser32",
"-lkernel32",
];
13 changes: 10 additions & 3 deletions mingw-w64-rust/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
$([[ ${CARCH} == i686 ]] || echo "${MINGW_PACKAGE_PREFIX}-rust-docs"))
pkgver=1.77.2
pkgrel=1
pkgrel=2
pkgdesc="Systems programming language focused on safety, speed and concurrency (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
Expand Down Expand Up @@ -53,7 +53,8 @@ source=("${rust_dist_server}/${_realname}c-${pkgver}-src.tar.gz"{,.asc}
"0011-disable-uac-for-installer.patch"
"0012-vendor-embed-manifest.patch"
"0013-backport-compiler-builtins.patch"
"0014-fix-vendored-test.patch")
"0014-fix-vendored-test.patch"
"0015-gcc-subsystem.patch")
noextract=(${_realname}c-${pkgver}-src.tar.gz)
sha256sums=('c61457ef8f596638fddbc7716778b2f6b99ff12513a3b0f13994c3bc521638c3'
'SKIP'
Expand All @@ -66,7 +67,8 @@ sha256sums=('c61457ef8f596638fddbc7716778b2f6b99ff12513a3b0f13994c3bc521638c3'
'761d73328d9695a7a2bd2a10be8225f4a56801fee54cbb51c0841b7f16e2bde6'
'358de2f3e54afbe4aefd401725227becf2468763b7686c5d4fed3b71d1e95ce9'
'56e3433e37ecebe4e5eba1be8debb3e34451be22a00e345ee738bbeb37803092'
'435b69f896f97b45108c92e748ef64edbc21566fe61188b643707aa51522d295')
'435b69f896f97b45108c92e748ef64edbc21566fe61188b643707aa51522d295'
'5e19556f6cfed0485b84c32de1a2a3f8fe330cb73bc16e2596be4aba3bcb3cd5')
validpgpkeys=('108F66205EAEB0AAA8DD5E1C85AB96E6FA1BE5FE' # Rust Language (Tag and Release Signing Key) <rust-key@rust-lang.org>
'474E22316ABF4785A88C6E8EA2C794A986419D8A' # Tom Stellard <tstellar@redhat.com>
'B6C8F98282B944E3B0D5C2530FC3042E345AD05D') # Hans Wennborg <hans@chromium.org>
Expand Down Expand Up @@ -131,6 +133,11 @@ prepare() {
0014-fix-vendored-test.patch
# tidy complains about *.orig files so delete them
rm ${srcdir}/${_realname}c-${pkgver}-src/tests/ui/issues/*.orig

if [[ $MINGW_PACKAGE_PREFIX == mingw-w64-x86_64 ]]; then
apply_patch_with_msg \
0015-gcc-subsystem.patch
fi
}

build() {
Expand Down

0 comments on commit 96fa059

Please sign in to comment.