Skip to content

Commit 7429420

Browse files
authored
Rollup merge of #146323 - h3fang:issue-146230-fix, r=Amanieu
check before test for hardware capabilites in bits 32~63 of usize This commit tries to fix #146230. `std::arch::is_aarch64_feature_detected` panics on aarch64 ILP32 targets. After some digging, the real problem is https://github.com/rust-lang/rust/blob/91edc3ebccc4daa46c20a93f4709862376da1fdd/library/std_detect/src/detect/os/linux/aarch64.rs#L210-L241 checks bits 32~63 of usize unconditionally on normal aarch64 LP64 target and aarch64 ILP32 target. Here I propose to move these to a block guarded by `#[cfg(target_pointer_width="64")]`. See #146230 for more detailed analysis. r? ```@Amanieu```
2 parents 40520c6 + 4c849c7 commit 7429420

File tree

1 file changed

+44
-33
lines changed

1 file changed

+44
-33
lines changed

library/std_detect/src/detect/os/linux/aarch64.rs

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ struct AtHwcap {
140140
impl From<auxvec::AuxVec> for AtHwcap {
141141
/// Reads AtHwcap from the auxiliary vector.
142142
fn from(auxv: auxvec::AuxVec) -> Self {
143-
AtHwcap {
143+
let mut cap = AtHwcap {
144144
fp: bit::test(auxv.hwcap, 0),
145145
asimd: bit::test(auxv.hwcap, 1),
146146
// evtstrm: bit::test(auxv.hwcap, 2),
@@ -207,39 +207,50 @@ impl From<auxvec::AuxVec> for AtHwcap {
207207
// smef32f32: bit::test(auxv.hwcap2, 29),
208208
smefa64: bit::test(auxv.hwcap2, 30),
209209
wfxt: bit::test(auxv.hwcap2, 31),
210-
// ebf16: bit::test(auxv.hwcap2, 32),
211-
// sveebf16: bit::test(auxv.hwcap2, 33),
212-
cssc: bit::test(auxv.hwcap2, 34),
213-
// rprfm: bit::test(auxv.hwcap2, 35),
214-
sve2p1: bit::test(auxv.hwcap2, 36),
215-
sme2: bit::test(auxv.hwcap2, 37),
216-
sme2p1: bit::test(auxv.hwcap2, 38),
217-
// smei16i32: bit::test(auxv.hwcap2, 39),
218-
// smebi32i32: bit::test(auxv.hwcap2, 40),
219-
smeb16b16: bit::test(auxv.hwcap2, 41),
220-
smef16f16: bit::test(auxv.hwcap2, 42),
221-
mops: bit::test(auxv.hwcap2, 43),
222-
hbc: bit::test(auxv.hwcap2, 44),
223-
sveb16b16: bit::test(auxv.hwcap2, 45),
224-
lrcpc3: bit::test(auxv.hwcap2, 46),
225-
lse128: bit::test(auxv.hwcap2, 47),
226-
fpmr: bit::test(auxv.hwcap2, 48),
227-
lut: bit::test(auxv.hwcap2, 49),
228-
faminmax: bit::test(auxv.hwcap2, 50),
229-
f8cvt: bit::test(auxv.hwcap2, 51),
230-
f8fma: bit::test(auxv.hwcap2, 52),
231-
f8dp4: bit::test(auxv.hwcap2, 53),
232-
f8dp2: bit::test(auxv.hwcap2, 54),
233-
f8e4m3: bit::test(auxv.hwcap2, 55),
234-
f8e5m2: bit::test(auxv.hwcap2, 56),
235-
smelutv2: bit::test(auxv.hwcap2, 57),
236-
smef8f16: bit::test(auxv.hwcap2, 58),
237-
smef8f32: bit::test(auxv.hwcap2, 59),
238-
smesf8fma: bit::test(auxv.hwcap2, 60),
239-
smesf8dp4: bit::test(auxv.hwcap2, 61),
240-
smesf8dp2: bit::test(auxv.hwcap2, 62),
241-
// pauthlr: bit::test(auxv.hwcap2, ??),
210+
..Default::default()
211+
};
212+
213+
// Hardware capabilities from bits 32 to 63 should only
214+
// be tested on LP64 targets with 64 bits `usize`.
215+
// On ILP32 targets like `aarch64-unknown-linux-gnu_ilp32`,
216+
// these hardware capabilities will default to `false`.
217+
// https://github.com/rust-lang/rust/issues/146230
218+
#[cfg(target_pointer_width = "64")]
219+
{
220+
// cap.ebf16: bit::test(auxv.hwcap2, 32);
221+
// cap.sveebf16: bit::test(auxv.hwcap2, 33);
222+
cap.cssc = bit::test(auxv.hwcap2, 34);
223+
// cap.rprfm: bit::test(auxv.hwcap2, 35);
224+
cap.sve2p1 = bit::test(auxv.hwcap2, 36);
225+
cap.sme2 = bit::test(auxv.hwcap2, 37);
226+
cap.sme2p1 = bit::test(auxv.hwcap2, 38);
227+
// cap.smei16i32 = bit::test(auxv.hwcap2, 39);
228+
// cap.smebi32i32 = bit::test(auxv.hwcap2, 40);
229+
cap.smeb16b16 = bit::test(auxv.hwcap2, 41);
230+
cap.smef16f16 = bit::test(auxv.hwcap2, 42);
231+
cap.mops = bit::test(auxv.hwcap2, 43);
232+
cap.hbc = bit::test(auxv.hwcap2, 44);
233+
cap.sveb16b16 = bit::test(auxv.hwcap2, 45);
234+
cap.lrcpc3 = bit::test(auxv.hwcap2, 46);
235+
cap.lse128 = bit::test(auxv.hwcap2, 47);
236+
cap.fpmr = bit::test(auxv.hwcap2, 48);
237+
cap.lut = bit::test(auxv.hwcap2, 49);
238+
cap.faminmax = bit::test(auxv.hwcap2, 50);
239+
cap.f8cvt = bit::test(auxv.hwcap2, 51);
240+
cap.f8fma = bit::test(auxv.hwcap2, 52);
241+
cap.f8dp4 = bit::test(auxv.hwcap2, 53);
242+
cap.f8dp2 = bit::test(auxv.hwcap2, 54);
243+
cap.f8e4m3 = bit::test(auxv.hwcap2, 55);
244+
cap.f8e5m2 = bit::test(auxv.hwcap2, 56);
245+
cap.smelutv2 = bit::test(auxv.hwcap2, 57);
246+
cap.smef8f16 = bit::test(auxv.hwcap2, 58);
247+
cap.smef8f32 = bit::test(auxv.hwcap2, 59);
248+
cap.smesf8fma = bit::test(auxv.hwcap2, 60);
249+
cap.smesf8dp4 = bit::test(auxv.hwcap2, 61);
250+
cap.smesf8dp2 = bit::test(auxv.hwcap2, 62);
251+
// cap.pauthlr = bit::test(auxv.hwcap2, ??);
242252
}
253+
cap
243254
}
244255
}
245256

0 commit comments

Comments
 (0)