Skip to content

Commit 774d95f

Browse files
a4lgtaiki-e
andcommitted
RISC-V: Use target_arch for RV(32|64) detection
As Taiki Endo pointed out, there's a problem if we continue using `target_pointer_width` values to detect an architecture because: * There are separate `target_arch`s already and * There is an experimental ABI (not ratified though): RV64ILP32. cf. <https://lpc.events/event/17/contributions/1475/attachments/1186/2442/rv64ilp32_%20Run%20ILP32%20on%20RV64%20ISA.pdf> Co-Authored-By: Taiki Endo <[email protected]>
1 parent 896b671 commit 774d95f

File tree

1 file changed

+6
-4
lines changed
  • crates/std_detect/src/detect/os/linux

1 file changed

+6
-4
lines changed

crates/std_detect/src/detect/os/linux/riscv.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ pub(crate) fn detect_features() -> cache::Initializer {
3030

3131
// Handle base ISA.
3232
let has_i = bit::test(auxv.hwcap, (b'i' - b'a').into());
33-
// If future RV128I is supported, implement with `enable_feature` here
34-
#[cfg(target_pointer_width = "64")]
33+
// If future RV128I is supported, implement with `enable_feature` here.
34+
// Note that we should use `target_arch` instead of `target_pointer_width`
35+
// to avoid misdetection caused by experimental ABIs such as RV64ILP32.
36+
#[cfg(target_arch = "riscv64")]
3537
enable_feature(Feature::rv64i, has_i);
36-
#[cfg(target_pointer_width = "32")]
38+
#[cfg(target_arch = "riscv32")]
3739
enable_feature(Feature::rv32i, has_i);
3840
// FIXME: e is not exposed in any of asm/hwcap.h, uapi/asm/hwcap.h, uapi/asm/hwprobe.h
39-
#[cfg(target_pointer_width = "32")]
41+
#[cfg(target_arch = "riscv32")]
4042
enable_feature(Feature::rv32e, bit::test(auxv.hwcap, (b'e' - b'a').into()));
4143

4244
// FIXME: Auxvec does not show supervisor feature support, but this mode may be useful

0 commit comments

Comments
 (0)