Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std_detect: Always avoid dlsym on *-linux-{musl,ohos}* targets #1746

Merged
merged 2 commits into from
Mar 26, 2025

Conversation

taiki-e
Copy link
Member

@taiki-e taiki-e commented Mar 18, 2025

Similar to #1375 (for *-linux-gnu*) and #1406 (for *-android*), but for -linux-{musl,ohos}*:

On musl with static linking, there is a known problem that getauxval is not always available, independent of version requirements: rust-lang/rust#89626
However, this seems to be due to the fact that compiler-builtins is built before libc (which is a dependency of std) links musl. So IIUC the std and its dependent can use getauxval without this problem (std_detect is a part of std). Actually std uses it since Rust 1.78: rust-lang/rust@9da004e


After this PR, remaining linux/android targets that use dlsym are:

@rustbot
Copy link
Collaborator

rustbot commented Mar 18, 2025

r? @Amanieu

rustbot has assigned @Amanieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

not(all(
target_os = "linux",
any(target_env = "gnu", target_env = "musl", target_env = "ohos"),
)),
// TODO: libc crate currently doesn't provide getauxval on 32-bit Android.
not(all(target_os = "android", target_pointer_width = "64")),
))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of duplication in this function which makes it hard to review. I think this is a good opportunity to move the choice of whether to use libc::getauxval or look it up dynamically into the local getauxval function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 2960b07.

I actually found a difference between the two blocks...

// Targets with only AT_HWCAP:
#[cfg(any(
target_arch = "riscv32",
target_arch = "riscv64",
target_arch = "mips",
target_arch = "mips64"
))]

// Targets with only AT_HWCAP:
#[cfg(any(
target_arch = "riscv32",
target_arch = "riscv64",
target_arch = "mips",
target_arch = "mips64",
target_arch = "loongarch64",
))]

@taiki-e taiki-e force-pushed the std-detect-getauxval branch 2 times, most recently from 148859f to d0173d3 Compare March 25, 2025 15:17
@taiki-e taiki-e force-pushed the std-detect-getauxval branch from d0173d3 to 2960b07 Compare March 25, 2025 15:49
@Amanieu Amanieu added this pull request to the merge queue Mar 26, 2025
Merged via the queue into rust-lang:master with commit d7e425a Mar 26, 2025
60 checks passed
@taiki-e taiki-e deleted the std-detect-getauxval branch March 26, 2025 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants