Skip to content

Commit e3538c3

Browse files
committed
rust: backport fixes
* 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
1 parent e377811 commit e3538c3

File tree

2 files changed

+105
-2
lines changed

2 files changed

+105
-2
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
--- rustc-1.77.2-src/library/backtrace/src/backtrace/dbghelp.rs.orig 2024-04-19 14:12:20.763735300 -0700
2+
+++ rustc-1.77.2-src/library/backtrace/src/backtrace/dbghelp.rs 2024-04-19 14:17:14.861312400 -0700
3+
@@ -127,45 +127,67 @@
4+
pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
5+
use core::ptr;
6+
7+
+ // Capture the initial context to start walking from.
8+
let mut context = core::mem::zeroed::<MyContext>();
9+
RtlCaptureContext(&mut context.0);
10+
11+
- // Call `RtlVirtualUnwind` to find the previous stack frame, walking until we hit ip = 0.
12+
- while context.ip() != 0 {
13+
+ loop {
14+
+ let ip = context.ip();
15+
+
16+
let mut base = 0;
17+
18+
- let fn_entry = RtlLookupFunctionEntry(context.ip(), &mut base, ptr::null_mut());
19+
+ let fn_entry = RtlLookupFunctionEntry(ip, &mut base, ptr::null_mut());
20+
if fn_entry.is_null() {
21+
+ // No function entry could be found - this may indicate a corrupt
22+
+ // stack or that a binary was unloaded (amongst other issues). Stop
23+
+ // walking and don't call the callback as we can't be confident in
24+
+ // this frame or the rest of the stack.
25+
break;
26+
}
27+
28+
let frame = super::Frame {
29+
inner: Frame {
30+
base_address: fn_entry as *mut c_void,
31+
- ip: context.ip() as *mut c_void,
32+
+ ip: ip as *mut c_void,
33+
sp: context.sp() as *mut c_void,
34+
#[cfg(not(target_env = "gnu"))]
35+
inline_context: None,
36+
},
37+
};
38+
39+
+ // We've loaded all the info about the current frame, so now call the
40+
+ // callback.
41+
if !cb(&frame) {
42+
+ // Callback told us to stop, so we're done.
43+
break;
44+
}
45+
46+
+ // Unwind to the next frame.
47+
+ let previous_ip = ip;
48+
+ let previous_sp = context.sp();
49+
let mut handler_data = 0usize;
50+
let mut establisher_frame = 0;
51+
52+
RtlVirtualUnwind(
53+
0,
54+
base,
55+
- context.ip(),
56+
+ ip,
57+
fn_entry,
58+
&mut context.0,
59+
&mut handler_data as *mut usize as *mut PVOID,
60+
&mut establisher_frame,
61+
ptr::null_mut(),
62+
);
63+
+
64+
+ // RtlVirtualUnwind indicates the end of the stack in two different ways:
65+
+ // * On x64, it sets the instruction pointer to 0.
66+
+ // * On ARM64, it leaves the context unchanged (easiest way to check is
67+
+ // to see if the instruction and stack pointers are the same).
68+
+ // If we detect either of these, then unwinding is completed.
69+
+ let ip = context.ip();
70+
+ if ip == 0 || (ip == previous_ip && context.sp() == previous_sp) {
71+
+ break;
72+
+ }
73+
}
74+
}
75+

mingw-w64-rust/PKGBUILD

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,32 @@ source=("${rust_dist_server}/${_realname}c-${pkgver}-src.tar.gz"{,.asc}
4747
"${embed_manifest_url}"
4848
"https://github.com/rust-lang/compiler-builtins/commit/d8ab794ed61e2c7c0750f57332a680d5aa8db48c.patch"
4949
"https://github.com/rust-lang/compiler-builtins/commit/3f47913bc6414bab4254d49f9f6e7238fecace69.patch"
50+
"https://github.com/rust-lang/rust/commit/f7b2e37f7232540d9f2b2dc6e33597fbb74f4f63.patch"
51+
"https://github.com/rust-lang/rust/commit/eac0b3a1d1b8d1db8fa95c50e118de5b9471e5af.patch"
5052
"0001-rustc-llvm-fix-libs.patch"
5153
"0005-win32-config.patch"
5254
"0007-clang-subsystem.patch"
5355
"0008-disable-self-contained.patch"
5456
"0011-disable-uac-for-installer.patch"
5557
"0012-vendor-embed-manifest.patch"
56-
"0013-backport-compiler-builtins.patch")
58+
"0013-backport-compiler-builtins.patch"
59+
"0016-backport-backtrace-fix-windows-aarch64.patch")
5760
noextract=(${_realname}c-${pkgver}-src.tar.gz)
5861
sha256sums=('ff544823a5cb27f2738128577f1e7e00ee8f4c83f2a348781ae4fc355e91d5a9'
5962
'SKIP'
6063
'24ef6d949c0b5b1940c1d6a7aad78d86012152fb8845a1644bc939350d7b75e2'
6164
'0426bc2a82f56ddabc0646100891bc61b9a57f4b7aec9f45aff40d7ba081db4f'
6265
'b888615732b1c9b0d4e8459cc9bd7ffb8afbf13bab840c2d345dc1492a63c9c3'
66+
'05a5bbd1c5ec5fdb66a712a3939b75fae1285309d2ea570d1b14c641927bad8d'
67+
'd9a1ac6343c3d5428691701aba2489858cca069510da319ceca9c7bf7ed0ca0d'
6368
'7cb1773c288ffb1c1e751edc49b1890c84bf9c362742bc5225d19d474edb73a0'
6469
'7d1c4e49524b835a8eadc961b39f5594b12a522a1e24368999be2c7e85399e4e'
6570
'46b63be79e4f2d5da2b183ed963429bce22966227bf24a73b158d23875841b11'
6671
'7a3b5722ff576b0661f36796f088dee4ce318b5dbc3fdcd65b48972de68a0edf'
6772
'761d73328d9695a7a2bd2a10be8225f4a56801fee54cbb51c0841b7f16e2bde6'
6873
'23fc45f4e718770375be1c5196f035075de16d25e8f895100a3d1d2492995f86'
69-
'465cb553e9dbaf176ad7b2e9bf7ebd8e481551cf2e8bbb8ba41c80acb28b3ed1')
74+
'465cb553e9dbaf176ad7b2e9bf7ebd8e481551cf2e8bbb8ba41c80acb28b3ed1'
75+
'6b383fafc4012624ce3f2e1bbd567d8961ea65c244064d585bf031a78276fe72')
7076
validpgpkeys=('108F66205EAEB0AAA8DD5E1C85AB96E6FA1BE5FE' # Rust Language (Tag and Release Signing Key) <[email protected]>
7177
'474E22316ABF4785A88C6E8EA2C794A986419D8A' # Tom Stellard <[email protected]>
7278
'B6C8F98282B944E3B0D5C2530FC3042E345AD05D') # Hans Wennborg <[email protected]>
@@ -92,6 +98,14 @@ apply_patch_with_msg() {
9298
patch -Nbp1 -i "${srcdir}/${_patch}"
9399
done
94100
}
101+
102+
apply_patch_with_msg_no_backup() {
103+
for _patch in "$@"
104+
do
105+
msg2 "Applying ${_patch}"
106+
patch -Np1 -i "${srcdir}/${_patch}"
107+
done
108+
}
95109
# =========================================== #
96110

97111
prepare() {
@@ -127,6 +141,20 @@ prepare() {
127141
# still needs to patch .cargo-checksums.json
128142
apply_patch_with_msg \
129143
0013-backport-compiler-builtins.patch
144+
145+
# patch tests
146+
# tidy complains about *.orig files so do not generate backups
147+
apply_patch_with_msg_no_backup \
148+
f7b2e37f7232540d9f2b2dc6e33597fbb74f4f63.patch
149+
150+
if [[ $MSYSTEM == MINGW* ]]; then
151+
apply_patch_with_msg \
152+
eac0b3a1d1b8d1db8fa95c50e118de5b9471e5af.patch
153+
fi
154+
if [[ $MINGW_PACKAGE_PREFIX == *-aarch64 ]]; then
155+
apply_patch_with_msg \
156+
0016-backport-backtrace-fix-windows-aarch64.patch
157+
fi
130158
}
131159

132160
build() {

0 commit comments

Comments
 (0)