Skip to content

Commit

Permalink
rust: backport fixes
Browse files Browse the repository at this point in the history
* fix issue-21763.rs test failure when vendor is enabled

the issue is fixed upstream in 1.79.0
see rust-lang/rust#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: 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.

* backport fix for windows aarch64 backtrace
  • Loading branch information
filnet authored and jeremyd2019 committed Jun 3, 2024
1 parent a24d524 commit a98ad3a
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 2 deletions.
75 changes: 75 additions & 0 deletions mingw-w64-rust/0016-backport-backtrace-fix-windows-aarch64.patch
Original file line number Diff line number Diff line change
@@ -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::<MyContext>();
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;
+ }
}
}

32 changes: 30 additions & 2 deletions mingw-w64-rust/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,32 @@ source=("${rust_dist_server}/${_realname}c-${pkgver}-src.tar.gz"{,.asc}
"${embed_manifest_url}"
"https://github.com/rust-lang/compiler-builtins/commit/d8ab794ed61e2c7c0750f57332a680d5aa8db48c.patch"
"https://github.com/rust-lang/compiler-builtins/commit/3f47913bc6414bab4254d49f9f6e7238fecace69.patch"
"https://github.com/rust-lang/rust/commit/f7b2e37f7232540d9f2b2dc6e33597fbb74f4f63.patch"
"https://github.com/rust-lang/rust/commit/eac0b3a1d1b8d1db8fa95c50e118de5b9471e5af.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"
"0013-backport-compiler-builtins.patch")
"0013-backport-compiler-builtins.patch"
"0016-backport-backtrace-fix-windows-aarch64.patch")
noextract=(${_realname}c-${pkgver}-src.tar.gz)
sha256sums=('ff544823a5cb27f2738128577f1e7e00ee8f4c83f2a348781ae4fc355e91d5a9'
'SKIP'
'24ef6d949c0b5b1940c1d6a7aad78d86012152fb8845a1644bc939350d7b75e2'
'0426bc2a82f56ddabc0646100891bc61b9a57f4b7aec9f45aff40d7ba081db4f'
'b888615732b1c9b0d4e8459cc9bd7ffb8afbf13bab840c2d345dc1492a63c9c3'
'05a5bbd1c5ec5fdb66a712a3939b75fae1285309d2ea570d1b14c641927bad8d'
'd9a1ac6343c3d5428691701aba2489858cca069510da319ceca9c7bf7ed0ca0d'
'7cb1773c288ffb1c1e751edc49b1890c84bf9c362742bc5225d19d474edb73a0'
'7d1c4e49524b835a8eadc961b39f5594b12a522a1e24368999be2c7e85399e4e'
'46b63be79e4f2d5da2b183ed963429bce22966227bf24a73b158d23875841b11'
'7a3b5722ff576b0661f36796f088dee4ce318b5dbc3fdcd65b48972de68a0edf'
'761d73328d9695a7a2bd2a10be8225f4a56801fee54cbb51c0841b7f16e2bde6'
'23fc45f4e718770375be1c5196f035075de16d25e8f895100a3d1d2492995f86'
'465cb553e9dbaf176ad7b2e9bf7ebd8e481551cf2e8bbb8ba41c80acb28b3ed1')
'465cb553e9dbaf176ad7b2e9bf7ebd8e481551cf2e8bbb8ba41c80acb28b3ed1'
'6b383fafc4012624ce3f2e1bbd567d8961ea65c244064d585bf031a78276fe72')
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 All @@ -92,6 +98,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() {
Expand Down Expand Up @@ -127,6 +141,20 @@ prepare() {
# still needs to patch .cargo-checksums.json
apply_patch_with_msg \
0013-backport-compiler-builtins.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 \
eac0b3a1d1b8d1db8fa95c50e118de5b9471e5af.patch
fi
if [[ $MINGW_PACKAGE_PREFIX == *-aarch64 ]]; then
apply_patch_with_msg \
0016-backport-backtrace-fix-windows-aarch64.patch
fi
}

build() {
Expand Down

0 comments on commit a98ad3a

Please sign in to comment.