From c776fbf1eb44a90aa613042c60ba48859f4949e4 Mon Sep 17 00:00:00 2001 From: Fang He Date: Mon, 8 Sep 2025 16:35:03 +0800 Subject: [PATCH 1/4] check before test for hardware capabilites in bits 32~63 of usize --- .../std_detect/src/detect/os/linux/aarch64.rs | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/library/std_detect/src/detect/os/linux/aarch64.rs b/library/std_detect/src/detect/os/linux/aarch64.rs index 87a9d6ebb8875..ba5e8f0025683 100644 --- a/library/std_detect/src/detect/os/linux/aarch64.rs +++ b/library/std_detect/src/detect/os/linux/aarch64.rs @@ -140,7 +140,7 @@ struct AtHwcap { impl From for AtHwcap { /// Reads AtHwcap from the auxiliary vector. fn from(auxv: auxvec::AuxVec) -> Self { - AtHwcap { + let mut cap = AtHwcap { fp: bit::test(auxv.hwcap, 0), asimd: bit::test(auxv.hwcap, 1), // evtstrm: bit::test(auxv.hwcap, 2), @@ -207,39 +207,44 @@ impl From for AtHwcap { // smef32f32: bit::test(auxv.hwcap2, 29), smefa64: bit::test(auxv.hwcap2, 30), wfxt: bit::test(auxv.hwcap2, 31), - // ebf16: bit::test(auxv.hwcap2, 32), - // sveebf16: bit::test(auxv.hwcap2, 33), - cssc: bit::test(auxv.hwcap2, 34), - // rprfm: bit::test(auxv.hwcap2, 35), - sve2p1: bit::test(auxv.hwcap2, 36), - sme2: bit::test(auxv.hwcap2, 37), - sme2p1: bit::test(auxv.hwcap2, 38), - // smei16i32: bit::test(auxv.hwcap2, 39), - // smebi32i32: bit::test(auxv.hwcap2, 40), - smeb16b16: bit::test(auxv.hwcap2, 41), - smef16f16: bit::test(auxv.hwcap2, 42), - mops: bit::test(auxv.hwcap2, 43), - hbc: bit::test(auxv.hwcap2, 44), - sveb16b16: bit::test(auxv.hwcap2, 45), - lrcpc3: bit::test(auxv.hwcap2, 46), - lse128: bit::test(auxv.hwcap2, 47), - fpmr: bit::test(auxv.hwcap2, 48), - lut: bit::test(auxv.hwcap2, 49), - faminmax: bit::test(auxv.hwcap2, 50), - f8cvt: bit::test(auxv.hwcap2, 51), - f8fma: bit::test(auxv.hwcap2, 52), - f8dp4: bit::test(auxv.hwcap2, 53), - f8dp2: bit::test(auxv.hwcap2, 54), - f8e4m3: bit::test(auxv.hwcap2, 55), - f8e5m2: bit::test(auxv.hwcap2, 56), - smelutv2: bit::test(auxv.hwcap2, 57), - smef8f16: bit::test(auxv.hwcap2, 58), - smef8f32: bit::test(auxv.hwcap2, 59), - smesf8fma: bit::test(auxv.hwcap2, 60), - smesf8dp4: bit::test(auxv.hwcap2, 61), - smesf8dp2: bit::test(auxv.hwcap2, 62), - // pauthlr: bit::test(auxv.hwcap2, ??), + ..Default::default() + }; + #[cfg(target_pointer_width = "64")] + { + // cap.ebf16: bit::test(auxv.hwcap2, 32); + // cap.sveebf16: bit::test(auxv.hwcap2, 33); + cap.cssc = bit::test(auxv.hwcap2, 34); + // cap.rprfm: bit::test(auxv.hwcap2, 35); + cap.sve2p1 = bit::test(auxv.hwcap2, 36); + cap.sme2 = bit::test(auxv.hwcap2, 37); + cap.sme2p1 = bit::test(auxv.hwcap2, 38); + // cap.smei16i32 = bit::test(auxv.hwcap2, 39); + // cap.smebi32i32 = bit::test(auxv.hwcap2, 40); + cap.smeb16b16 = bit::test(auxv.hwcap2, 41); + cap.smef16f16 = bit::test(auxv.hwcap2, 42); + cap.mops = bit::test(auxv.hwcap2, 43); + cap.hbc = bit::test(auxv.hwcap2, 44); + cap.sveb16b16 = bit::test(auxv.hwcap2, 45); + cap.lrcpc3 = bit::test(auxv.hwcap2, 46); + cap.lse128 = bit::test(auxv.hwcap2, 47); + cap.fpmr = bit::test(auxv.hwcap2, 48); + cap.lut = bit::test(auxv.hwcap2, 49); + cap.faminmax = bit::test(auxv.hwcap2, 50); + cap.f8cvt = bit::test(auxv.hwcap2, 51); + cap.f8fma = bit::test(auxv.hwcap2, 52); + cap.f8dp4 = bit::test(auxv.hwcap2, 53); + cap.f8dp2 = bit::test(auxv.hwcap2, 54); + cap.f8e4m3 = bit::test(auxv.hwcap2, 55); + cap.f8e5m2 = bit::test(auxv.hwcap2, 56); + cap.smelutv2 = bit::test(auxv.hwcap2, 57); + cap.smef8f16 = bit::test(auxv.hwcap2, 58); + cap.smef8f32 = bit::test(auxv.hwcap2, 59); + cap.smesf8fma = bit::test(auxv.hwcap2, 60); + cap.smesf8dp4 = bit::test(auxv.hwcap2, 61); + cap.smesf8dp2 = bit::test(auxv.hwcap2, 62); + // cap.pauthlr = bit::test(auxv.hwcap2, ??); } + cap } } From be284b697fef4c560e040a433fbe2b832ed8426d Mon Sep 17 00:00:00 2001 From: Fang He Date: Mon, 8 Sep 2025 18:39:39 +0800 Subject: [PATCH 2/4] add some comments to clarify the fix --- library/std_detect/src/detect/os/linux/aarch64.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/std_detect/src/detect/os/linux/aarch64.rs b/library/std_detect/src/detect/os/linux/aarch64.rs index ba5e8f0025683..2c36a073b74e8 100644 --- a/library/std_detect/src/detect/os/linux/aarch64.rs +++ b/library/std_detect/src/detect/os/linux/aarch64.rs @@ -209,6 +209,12 @@ impl From for AtHwcap { wfxt: bit::test(auxv.hwcap2, 31), ..Default::default() }; + + // Hardware capabilites from bits 32 to 63 should only + // be tested on LP64 targets with 64 bits `usize`. + // On ILP32 targets like `aarch64-unknown-linux-gun_ilp32`, + // these hardware capabilites will default to `false`. + // https://github.com/rust-lang/rust/issues/146230 #[cfg(target_pointer_width = "64")] { // cap.ebf16: bit::test(auxv.hwcap2, 32); From de359c569b7c3eb630fb44e9078c4bea012eac99 Mon Sep 17 00:00:00 2001 From: Fang He Date: Mon, 8 Sep 2025 18:48:19 +0800 Subject: [PATCH 3/4] fix typos in comment --- library/std_detect/src/detect/os/linux/aarch64.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std_detect/src/detect/os/linux/aarch64.rs b/library/std_detect/src/detect/os/linux/aarch64.rs index 2c36a073b74e8..c53dbf3fd9ba6 100644 --- a/library/std_detect/src/detect/os/linux/aarch64.rs +++ b/library/std_detect/src/detect/os/linux/aarch64.rs @@ -210,10 +210,10 @@ impl From for AtHwcap { ..Default::default() }; - // Hardware capabilites from bits 32 to 63 should only + // Hardware capabilities from bits 32 to 63 should only // be tested on LP64 targets with 64 bits `usize`. // On ILP32 targets like `aarch64-unknown-linux-gun_ilp32`, - // these hardware capabilites will default to `false`. + // these hardware capabilities will default to `false`. // https://github.com/rust-lang/rust/issues/146230 #[cfg(target_pointer_width = "64")] { From 4c849c73a4b49ffe3a96261d95b65df1421befd9 Mon Sep 17 00:00:00 2001 From: Fang He Date: Fri, 12 Sep 2025 08:18:26 +0800 Subject: [PATCH 4/4] fix typo in comment --- library/std_detect/src/detect/os/linux/aarch64.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std_detect/src/detect/os/linux/aarch64.rs b/library/std_detect/src/detect/os/linux/aarch64.rs index c53dbf3fd9ba6..b733b8a9eb236 100644 --- a/library/std_detect/src/detect/os/linux/aarch64.rs +++ b/library/std_detect/src/detect/os/linux/aarch64.rs @@ -212,7 +212,7 @@ impl From for AtHwcap { // Hardware capabilities from bits 32 to 63 should only // be tested on LP64 targets with 64 bits `usize`. - // On ILP32 targets like `aarch64-unknown-linux-gun_ilp32`, + // On ILP32 targets like `aarch64-unknown-linux-gnu_ilp32`, // these hardware capabilities will default to `false`. // https://github.com/rust-lang/rust/issues/146230 #[cfg(target_pointer_width = "64")]