Skip to content

Commit 41caec4

Browse files
taiki-eAmanieu
authored andcommitted
std_detect: Always avoid dlsym on *-android* targets
1 parent 5c6dc52 commit 41caec4

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

crates/std_detect/README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@ 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*` targets, since all `*-linux-gnu*` targets ([since Rust 1.64](https://blog.rust-lang.org/2022/08/01/Increasing-glibc-kernel-requirements.html)) have glibc requirements higher than [glibc 2.16 that added `getauxval`](https://sourceware.org/legacy-ml/libc-announce/2012/msg00000.html), and we can safely assume [`getauxval`] is linked to the binary.
33+
Note: This feature is ignored on `*-linux-gnu*` and `*-android*` targets
34+
because we can safely assume `getauxval` is linked to the binary.
35+
* `*-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).
37+
* `*-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).
3439

3540
* `std_detect_file_io` (enabled by default, requires `std`): Enable to perform run-time feature
3641
detection using file APIs (e.g. `/proc/cpuinfo`, etc.) if other more performant
3742
methods fail. This feature requires `libstd` as a dependency, preventing the
3843
crate from working on applications in which `std` is not available.
3944

40-
[`getauxval`]: http://man7.org/linux/man-pages/man3/getauxval.3.html
45+
[`getauxval`]: https://man7.org/linux/man-pages/man3/getauxval.3.html
4146

4247
# Platform support
4348

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ pub(crate) struct AuxVec {
5454
/// error, cpuinfo still can (and will) be used to try to perform run-time
5555
/// feature detection on some platforms.
5656
///
57-
/// Note: The `std_detect_dlsym_getauxval` cargo feature is ignored on `*-linux-gnu*` targets,
58-
/// since [all `*-linux-gnu*` targets ([since Rust 1.64](https://blog.rust-lang.org/2022/08/01/Increasing-glibc-kernel-requirements.html))
59-
/// have glibc requirements higher than [glibc 2.16 that added `getauxval`](https://sourceware.org/legacy-ml/libc-announce/2012/msg00000.html),
60-
/// and we can safely assume [`getauxval`] is linked to the binary.
57+
/// Note: The `std_detect_dlsym_getauxval` cargo feature is ignored on
58+
/// `*-linux-gnu*` and `*-android*` targets because we can safely assume `getauxval`
59+
/// is linked to the binary.
60+
/// - `*-linux-gnu*` targets ([since Rust 1.64](https://blog.rust-lang.org/2022/08/01/Increasing-glibc-kernel-requirements.html))
61+
/// have glibc requirements higher than [glibc 2.16 that added `getauxval`](https://sourceware.org/legacy-ml/libc-announce/2012/msg00000.html).
62+
/// - `*-android*` targets ([since Rust 1.68](https://blog.rust-lang.org/2023/01/09/android-ndk-update-r25.html))
63+
/// 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).
6164
///
6265
/// For more information about when `getauxval` is available check the great
6366
/// [`auxv` crate documentation][auxv_docs].
@@ -67,7 +70,8 @@ pub(crate) struct AuxVec {
6770
pub(crate) fn auxv() -> Result<AuxVec, ()> {
6871
#[cfg(all(
6972
feature = "std_detect_dlsym_getauxval",
70-
not(all(target_os = "linux", target_env = "gnu"))
73+
not(all(target_os = "linux", target_env = "gnu")),
74+
not(target_os = "android"),
7175
))]
7276
{
7377
// Try to call a dynamically-linked getauxval function.
@@ -111,7 +115,8 @@ pub(crate) fn auxv() -> Result<AuxVec, ()> {
111115

112116
#[cfg(any(
113117
not(feature = "std_detect_dlsym_getauxval"),
114-
all(target_os = "linux", target_env = "gnu")
118+
all(target_os = "linux", target_env = "gnu"),
119+
target_os = "android",
115120
))]
116121
{
117122
// Targets with only AT_HWCAP:

0 commit comments

Comments
 (0)