diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
commit | ef24de24a82fe681581cc130f342363c47c0969a (patch) | |
tree | 0d494f7e1a38b95c92426f58fe6eaa877303a86c /library/stdarch/crates/std_detect | |
parent | Releasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip |
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/stdarch/crates/std_detect')
-rw-r--r-- | library/stdarch/crates/std_detect/Cargo.toml | 1 | ||||
-rw-r--r-- | library/stdarch/crates/std_detect/src/detect/os/linux/auxvec.rs | 59 | ||||
-rw-r--r-- | library/stdarch/crates/std_detect/src/detect/os/x86.rs | 6 |
3 files changed, 12 insertions, 54 deletions
diff --git a/library/stdarch/crates/std_detect/Cargo.toml b/library/stdarch/crates/std_detect/Cargo.toml index 589a3900a..12d4a658c 100644 --- a/library/stdarch/crates/std_detect/Cargo.toml +++ b/library/stdarch/crates/std_detect/Cargo.toml @@ -30,7 +30,6 @@ compiler_builtins = { version = "0.1.2", optional = true } alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-alloc" } [dev-dependencies] -auxv = "0.3.3" cupid = "0.6.0" [features] diff --git a/library/stdarch/crates/std_detect/src/detect/os/linux/auxvec.rs b/library/stdarch/crates/std_detect/src/detect/os/linux/auxvec.rs index 8bc0b30c3..ee46aa1ac 100644 --- a/library/stdarch/crates/std_detect/src/detect/os/linux/auxvec.rs +++ b/library/stdarch/crates/std_detect/src/detect/os/linux/auxvec.rs @@ -19,6 +19,7 @@ pub(crate) const AT_HWCAP2: usize = 26; /// If an entry cannot be read all the bits in the bitfield are set to zero. /// This should be interpreted as all the features being disabled. #[derive(Debug, Copy, Clone)] +#[cfg_attr(test, derive(PartialEq))] pub(crate) struct AuxVec { pub hwcap: usize, #[cfg(any( @@ -174,9 +175,12 @@ pub(crate) fn auxv() -> Result<AuxVec, ()> { /// Tries to read the `key` from the auxiliary vector by calling the /// dynamically-linked `getauxval` function. If the function is not linked, /// this function return `Err`. -#[cfg(all( - feature = "std_detect_dlsym_getauxval", - not(all(target_os = "linux", target_env = "gnu")) +#[cfg(any( + test, + all( + feature = "std_detect_dlsym_getauxval", + not(all(target_os = "linux", target_env = "gnu")) + ) ))] fn getauxval(key: usize) -> Result<usize, ()> { use libc; @@ -262,35 +266,8 @@ fn auxv_from_buf(buf: &[usize]) -> Result<AuxVec, ()> { #[cfg(test)] mod tests { - extern crate auxv as auxv_crate; use super::*; - // Reads the Auxiliary Vector key from /proc/self/auxv - // using the auxv crate. - #[cfg(feature = "std_detect_file_io")] - fn auxv_crate_getprocfs(key: usize) -> Option<usize> { - use self::auxv_crate::procfs::search_procfs_auxv; - use self::auxv_crate::AuxvType; - let k = key as AuxvType; - match search_procfs_auxv(&[k]) { - Ok(v) => Some(v[&k] as usize), - Err(_) => None, - } - } - - // Reads the Auxiliary Vector key from getauxval() - // using the auxv crate. - #[cfg(not(any(target_arch = "mips", target_arch = "mips64")))] - fn auxv_crate_getauxval(key: usize) -> Option<usize> { - use self::auxv_crate::getauxval::Getauxval; - use self::auxv_crate::AuxvType; - let q = auxv_crate::getauxval::NativeGetauxval {}; - match q.getauxval(key as AuxvType) { - Ok(v) => Some(v as usize), - Err(_) => None, - } - } - // FIXME: on mips/mips64 getauxval returns 0, and /proc/self/auxv // does not always contain the AT_HWCAP key under qemu. #[cfg(any( @@ -301,7 +278,7 @@ mod tests { #[test] fn auxv_crate() { let v = auxv(); - if let Some(hwcap) = auxv_crate_getauxval(AT_HWCAP) { + if let Ok(hwcap) = getauxval(AT_HWCAP) { let rt_hwcap = v.expect("failed to find hwcap key").hwcap; assert_eq!(rt_hwcap, hwcap); } @@ -314,7 +291,7 @@ mod tests { target_arch = "powerpc64" ))] { - if let Some(hwcap2) = auxv_crate_getauxval(AT_HWCAP2) { + if let Ok(hwcap2) = getauxval(AT_HWCAP2) { let rt_hwcap2 = v.expect("failed to find hwcap2 key").hwcap2; assert_eq!(rt_hwcap2, hwcap2); } @@ -391,22 +368,8 @@ mod tests { #[test] #[cfg(feature = "std_detect_file_io")] fn auxv_crate_procfs() { - let v = auxv(); - if let Some(hwcap) = auxv_crate_getprocfs(AT_HWCAP) { - assert_eq!(v.unwrap().hwcap, hwcap); - } - - // Targets with AT_HWCAP and AT_HWCAP2: - #[cfg(any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "powerpc", - target_arch = "powerpc64" - ))] - { - if let Some(hwcap2) = auxv_crate_getprocfs(AT_HWCAP2) { - assert_eq!(v.unwrap().hwcap2, hwcap2); - } + if let Ok(procfs_auxv) = auxv_from_file("/proc/self/auxv") { + assert_eq!(auxv().unwrap(), procfs_auxv); } } } diff --git a/library/stdarch/crates/std_detect/src/detect/os/x86.rs b/library/stdarch/crates/std_detect/src/detect/os/x86.rs index d8afc1aca..d8dd84db4 100644 --- a/library/stdarch/crates/std_detect/src/detect/os/x86.rs +++ b/library/stdarch/crates/std_detect/src/detect/os/x86.rs @@ -49,11 +49,7 @@ pub(crate) fn detect_features() -> cache::Initializer { ecx, edx, } = __cpuid(0); - let vendor_id: [[u8; 4]; 3] = [ - mem::transmute(ebx), - mem::transmute(edx), - mem::transmute(ecx), - ]; + let vendor_id: [[u8; 4]; 3] = [ebx.to_ne_bytes(), edx.to_ne_bytes(), ecx.to_ne_bytes()]; let vendor_id: [u8; 12] = mem::transmute(vendor_id); (max_basic_leaf, vendor_id) }; |