From e3741bee64f5c03ed1cd467e109563d00bdfcdb3 Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Tue, 16 Apr 2024 14:22:31 +0200 Subject: [PATCH] rust: backport fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix issue-21763.rs test failure when vendor is enabled the issue is fixed upstream in 1.79.0 see https://github.com/rust-lang/rust/pull/123652 * fix externally linking some math functions 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: https://github.com/mingw-w64/mingw-w64/commit/a64c1f4b969cff5f9e81c9a760117dc1b92d6ee1 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. * backport fix for windows aarch64 backtrace --- mingw-w64-rust/0015-gcc-subsystem.patch | 10 +++ ...ckport-backtrace-fix-windows-aarch64.patch | 75 +++++++++++++++++++ mingw-w64-rust/PKGBUILD | 32 +++++++- 3 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 mingw-w64-rust/0015-gcc-subsystem.patch create mode 100644 mingw-w64-rust/0016-backport-backtrace-fix-windows-aarch64.patch diff --git a/mingw-w64-rust/0015-gcc-subsystem.patch b/mingw-w64-rust/0015-gcc-subsystem.patch new file mode 100644 index 0000000000000..a6058230dab9d --- /dev/null +++ b/mingw-w64-rust/0015-gcc-subsystem.patch @@ -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", + ]; diff --git a/mingw-w64-rust/0016-backport-backtrace-fix-windows-aarch64.patch b/mingw-w64-rust/0016-backport-backtrace-fix-windows-aarch64.patch new file mode 100644 index 0000000000000..4b079e3a6b8dc --- /dev/null +++ b/mingw-w64-rust/0016-backport-backtrace-fix-windows-aarch64.patch @@ -0,0 +1,75 @@ +--- rustc-1.77.2-src/library/backtrace/src/backtrace/dbghelp.rs.orig 2024-04-19 14:12:20.763735300 -0700 ++++ rustc-1.77.2-src/library/backtrace/src/backtrace/dbghelp.rs 2024-04-19 14:17:14.861312400 -0700 +@@ -127,45 +127,67 @@ + pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) { + use core::ptr; + ++ // Capture the initial context to start walking from. + let mut context = core::mem::zeroed::(); + RtlCaptureContext(&mut context.0); + +- // Call `RtlVirtualUnwind` to find the previous stack frame, walking until we hit ip = 0. +- while context.ip() != 0 { ++ loop { ++ let ip = context.ip(); ++ + let mut base = 0; + +- let fn_entry = RtlLookupFunctionEntry(context.ip(), &mut base, ptr::null_mut()); ++ let fn_entry = RtlLookupFunctionEntry(ip, &mut base, ptr::null_mut()); + if fn_entry.is_null() { ++ // No function entry could be found - this may indicate a corrupt ++ // stack or that a binary was unloaded (amongst other issues). Stop ++ // walking and don't call the callback as we can't be confident in ++ // this frame or the rest of the stack. + break; + } + + let frame = super::Frame { + inner: Frame { + base_address: fn_entry as *mut c_void, +- ip: context.ip() as *mut c_void, ++ ip: ip as *mut c_void, + sp: context.sp() as *mut c_void, + #[cfg(not(target_env = "gnu"))] + inline_context: None, + }, + }; + ++ // We've loaded all the info about the current frame, so now call the ++ // callback. + if !cb(&frame) { ++ // Callback told us to stop, so we're done. + break; + } + ++ // Unwind to the next frame. ++ let previous_ip = ip; ++ let previous_sp = context.sp(); + let mut handler_data = 0usize; + let mut establisher_frame = 0; + + RtlVirtualUnwind( + 0, + base, +- context.ip(), ++ ip, + fn_entry, + &mut context.0, + &mut handler_data as *mut usize as *mut PVOID, + &mut establisher_frame, + ptr::null_mut(), + ); ++ ++ // RtlVirtualUnwind indicates the end of the stack in two different ways: ++ // * On x64, it sets the instruction pointer to 0. ++ // * On ARM64, it leaves the context unchanged (easiest way to check is ++ // to see if the instruction and stack pointers are the same). ++ // If we detect either of these, then unwinding is completed. ++ let ip = context.ip(); ++ if ip == 0 || (ip == previous_ip && context.sp() == previous_sp) { ++ break; ++ } + } + } + diff --git a/mingw-w64-rust/PKGBUILD b/mingw-w64-rust/PKGBUILD index fcce65e864025..e3f5f1e99e303 100644 --- a/mingw-w64-rust/PKGBUILD +++ b/mingw-w64-rust/PKGBUILD @@ -45,22 +45,28 @@ makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-zlib") source=("${rust_dist_server}/${_realname}c-${pkgver}-src.tar.gz"{,.asc} "${embed_manifest_url}" + "https://github.com/rust-lang/rust/commit/f7b2e37f7232540d9f2b2dc6e33597fbb74f4f63.patch" "0001-rustc-llvm-fix-libs.patch" "0005-win32-config.patch" "0007-clang-subsystem.patch" "0008-disable-self-contained.patch" "0011-disable-uac-for-installer.patch" - "0012-vendor-embed-manifest.patch") + "0012-vendor-embed-manifest.patch" + "0015-gcc-subsystem.patch" + "0016-backport-backtrace-fix-windows-aarch64.patch") noextract=(${_realname}c-${pkgver}-src.tar.gz) sha256sums=('ff544823a5cb27f2738128577f1e7e00ee8f4c83f2a348781ae4fc355e91d5a9' 'SKIP' '24ef6d949c0b5b1940c1d6a7aad78d86012152fb8845a1644bc939350d7b75e2' + '05a5bbd1c5ec5fdb66a712a3939b75fae1285309d2ea570d1b14c641927bad8d' '7cb1773c288ffb1c1e751edc49b1890c84bf9c362742bc5225d19d474edb73a0' '7d1c4e49524b835a8eadc961b39f5594b12a522a1e24368999be2c7e85399e4e' '1f668f4aed56060ec74fd53a39da1fbaef69b84de510d955baf349db672a8d15' '7a3b5722ff576b0661f36796f088dee4ce318b5dbc3fdcd65b48972de68a0edf' '761d73328d9695a7a2bd2a10be8225f4a56801fee54cbb51c0841b7f16e2bde6' - '358de2f3e54afbe4aefd401725227becf2468763b7686c5d4fed3b71d1e95ce9') + '358de2f3e54afbe4aefd401725227becf2468763b7686c5d4fed3b71d1e95ce9' + '5e19556f6cfed0485b84c32de1a2a3f8fe330cb73bc16e2596be4aba3bcb3cd5' + '6b383fafc4012624ce3f2e1bbd567d8961ea65c244064d585bf031a78276fe72') validpgpkeys=('108F66205EAEB0AAA8DD5E1C85AB96E6FA1BE5FE' # Rust Language (Tag and Release Signing Key) '474E22316ABF4785A88C6E8EA2C794A986419D8A' # Tom Stellard 'B6C8F98282B944E3B0D5C2530FC3042E345AD05D') # Hans Wennborg @@ -86,6 +92,14 @@ apply_patch_with_msg() { patch -Nbp1 -i "${srcdir}/${_patch}" done } + +apply_patch_with_msg_no_backup() { + for _patch in "$@" + do + msg2 "Applying ${_patch}" + patch -Np1 -i "${srcdir}/${_patch}" + done +} # =========================================== # prepare() { @@ -112,6 +126,20 @@ prepare() { fi apply_patch_with_msg \ 0012-vendor-embed-manifest.patch + + # patch tests + # tidy complains about *.orig files so do not generate backups + apply_patch_with_msg_no_backup \ + f7b2e37f7232540d9f2b2dc6e33597fbb74f4f63.patch + + if [[ $MSYSTEM == MINGW* ]]; then + apply_patch_with_msg \ + 0015-gcc-subsystem.patch + fi + if [[ $MINGW_PACKAGE_PREFIX == *-aarch64 ]]; then + apply_patch_with_msg \ + 0016-backport-backtrace-fix-windows-aarch64.patch + fi } build() {