Skip to content

Commit e2b6512

Browse files
taiki-eAmanieu
authored andcommitted
std_detect: Always avoid dlsym on *-linux-{musl,ohos}* targets
1 parent 2f430c5 commit e2b6512

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

ci/build-std-detect.sh

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ set -ex
1010
cd "$(dirname "$0")"/..
1111

1212
targets=(
13+
# Linux
14+
aarch64-unknown-linux-musl
15+
armv5te-unknown-linux-musleabi
16+
aarch64-unknown-linux-ohos
17+
armv7-unknown-linux-ohos
18+
1319
# Android
1420
aarch64-linux-android
1521
arm-linux-androideabi

crates/std_detect/README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ run-time feature detection. When this feature is disabled, `std_detect` assumes
3030
that [`getauxval`] is linked to the binary. If that is not the case the behavior
3131
is undefined.
3232

33-
Note: This feature is ignored on `*-linux-gnu*` and `*-android*` targets
33+
Note: This feature is ignored on `*-linux-{gnu,musl,ohos}*` and `*-android*` targets
3434
because we can safely assume `getauxval` is linked to the binary.
3535
* `*-linux-gnu*` targets ([since Rust 1.64](https://blog.rust-lang.org/2022/08/01/Increasing-glibc-kernel-requirements.html))
36-
have glibc requirements higher than [glibc 2.16 that added `getauxval`](https://sourceware.org/legacy-ml/libc-announce/2012/msg00000.html).
36+
have glibc requirements higher than [glibc 2.16 that added `getauxval`](https://sourceware.org/legacy-ml/libc-announce/2012/msg00000.html).
37+
* `*-linux-musl*` targets ([at least since Rust 1.15](https://github.com/rust-lang/rust/blob/1.15.0/src/ci/docker/x86_64-musl/build-musl.sh#L15))
38+
use musl newer than [musl 1.1.0 that added `getauxval`](https://git.musl-libc.org/cgit/musl/tree/WHATSNEW?h=v1.1.0#n1197)
39+
* `*-linux-ohos*` targets use a [fork of musl 1.2](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/native-lib/musl.md)
3740
* `*-android*` targets ([since Rust 1.68](https://blog.rust-lang.org/2023/01/09/android-ndk-update-r25.html))
38-
have the minimum supported API level higher than [Android 4.3 (API level 18) that added `getauxval`](https://github.com/aosp-mirror/platform_bionic/blob/d3ebc2f7c49a9893b114124d4a6b315f3a328764/libc/include/sys/auxv.h#L49).
41+
have the minimum supported API level higher than [Android 4.3 (API level 18) that added `getauxval`](https://github.com/aosp-mirror/platform_bionic/blob/d3ebc2f7c49a9893b114124d4a6b315f3a328764/libc/include/sys/auxv.h#L49).
3942

4043
* `std_detect_file_io` (enabled by default, requires `std`): Enable to perform run-time feature
4144
detection using file APIs (e.g. `/proc/cpuinfo`, etc.) if other more performant

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

+22-8
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ pub(crate) struct AuxVec {
5858
/// feature detection on some platforms.
5959
///
6060
/// Note: The `std_detect_dlsym_getauxval` cargo feature is ignored on
61-
/// `*-linux-gnu*` and `*-android*` targets because we can safely assume `getauxval`
61+
/// `*-linux-{gnu,musl,ohos}*` and `*-android*` targets because we can safely assume `getauxval`
6262
/// is linked to the binary.
6363
/// - `*-linux-gnu*` targets ([since Rust 1.64](https://blog.rust-lang.org/2022/08/01/Increasing-glibc-kernel-requirements.html))
6464
/// have glibc requirements higher than [glibc 2.16 that added `getauxval`](https://sourceware.org/legacy-ml/libc-announce/2012/msg00000.html).
65+
/// - `*-linux-musl*` targets ([at least since Rust 1.15](https://github.com/rust-lang/rust/blob/1.15.0/src/ci/docker/x86_64-musl/build-musl.sh#L15))
66+
/// use musl newer than [musl 1.1.0 that added `getauxval`](https://git.musl-libc.org/cgit/musl/tree/WHATSNEW?h=v1.1.0#n1197)
67+
/// - `*-linux-ohos*` targets use a [fork of musl 1.2](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/native-lib/musl.md)
6568
/// - `*-android*` targets ([since Rust 1.68](https://blog.rust-lang.org/2023/01/09/android-ndk-update-r25.html))
6669
/// have the minimum supported API level higher than [Android 4.3 (API level 18) that added `getauxval`](https://github.com/aosp-mirror/platform_bionic/blob/d3ebc2f7c49a9893b114124d4a6b315f3a328764/libc/include/sys/auxv.h#L49).
6770
///
@@ -73,7 +76,10 @@ pub(crate) struct AuxVec {
7376
pub(crate) fn auxv() -> Result<AuxVec, ()> {
7477
#[cfg(all(
7578
feature = "std_detect_dlsym_getauxval",
76-
not(all(target_os = "linux", target_env = "gnu")),
79+
not(all(
80+
target_os = "linux",
81+
any(target_env = "gnu", target_env = "musl", target_env = "ohos"),
82+
)),
7783
// TODO: libc crate currently doesn't provide getauxval on 32-bit Android.
7884
not(all(target_os = "android", target_pointer_width = "64")),
7985
))]
@@ -120,12 +126,15 @@ pub(crate) fn auxv() -> Result<AuxVec, ()> {
120126
}
121127
}
122128

123-
#[cfg(any(
124-
not(feature = "std_detect_dlsym_getauxval"),
125-
all(target_os = "linux", target_env = "gnu"),
129+
#[cfg(not(all(
130+
feature = "std_detect_dlsym_getauxval",
131+
not(all(
132+
target_os = "linux",
133+
any(target_env = "gnu", target_env = "musl", target_env = "ohos"),
134+
)),
126135
// TODO: libc crate currently doesn't provide getauxval on 32-bit Android.
127-
all(target_os = "android", target_pointer_width = "64"),
128-
))]
136+
not(all(target_os = "android", target_pointer_width = "64")),
137+
)))]
129138
{
130139
// Targets with only AT_HWCAP:
131140
#[cfg(any(
@@ -184,7 +193,12 @@ pub(crate) fn auxv() -> Result<AuxVec, ()> {
184193
test,
185194
all(
186195
feature = "std_detect_dlsym_getauxval",
187-
not(all(target_os = "linux", target_env = "gnu"))
196+
not(all(
197+
target_os = "linux",
198+
any(target_env = "gnu", target_env = "musl", target_env = "ohos"),
199+
)),
200+
// TODO: libc crate currently doesn't provide getauxval on 32-bit Android.
201+
not(all(target_os = "android", target_pointer_width = "64")),
188202
)
189203
))]
190204
fn getauxval(key: usize) -> Result<usize, ()> {

0 commit comments

Comments
 (0)