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: Support run-time detection on aarch64 OpenBSD #1374

Merged
merged 3 commits into from
Jan 26, 2023

Conversation

taiki-e
Copy link
Member

@taiki-e taiki-e commented Jan 25, 2023

OpenBSD doesn't trap the mrs instruction, but exposes the system registers through sysctl.
openbsd/src@d335af9

So, we can support run-time detection using the register parsing code in os/aarch64.rs (currently used on aarch64 FreeBSD) and sysctl. (See also go's patch that does the same thing as this patch: golang/go@cd54ef1. See also OpenBSD libcrypto patch: openbsd/src@be689f1.)

Tested on aarch64 OpenBSD VM 7.2-current/7.2-stable/7.1-stable.
The following screenshot is from a test on 7.2-current:

openbsd7 2-current

On 7.2-stable/7.1-stable, the features referring to ID_AA64PFR0_EL1 returns false because the patch that supports ID_AA64PFR0_EL1 (openbsd/src@c7654cd) is not included:

openbsd7 1-stable

@rustbot
Copy link
Collaborator

rustbot commented Jan 25, 2023

r? @Amanieu

(rustbot has picked a reviewer for you, use r? to override)

@@ -56,6 +56,12 @@ cfg_if! {
mod aarch64;
#[path = "os/freebsd/mod.rs"]
mod os;
} else if #[cfg(all(target_os = "openbsd", target_arch = "aarch64", feature = "libc"))] {
#[allow(dead_code)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this?

Copy link
Member Author

Choose a reason for hiding this comment

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

That module has code that calls the mrs instruction, but it is not used on OpenBSD.

Added a comment mentioning it.

Copy link
Contributor

@lu-zero lu-zero left a comment

Choose a reason for hiding this comment

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

It looks fine to me.

bors bot added a commit to taiki-e/portable-atomic that referenced this pull request Jan 26, 2023
64: detect: Support run-time detection of FEAT_LSE on aarch64 OpenBSD r=taiki-e a=taiki-e

As of nightly-2023-01-23, is_aarch64_feature_detected doesn't support run-time detection of FEAT_LSE on OpenBSD.

This patch also supports run-time detection of FEAT_LSE on aarch64 FreeBSD without "std" feature.

This patch also adds preliminary support for run-time detection of FEAT_LSE2 and FEAT_LSE128. This is currently only used in tests but will be used in the library in the future.

~~As well as #63, I will send a patch to stdarch later.~~ Filed rust-lang/stdarch#1374.

Co-authored-by: Taiki Endo <[email protected]>
@Amanieu Amanieu merged commit 3a96d41 into rust-lang:master Jan 26, 2023
@taiki-e taiki-e deleted the std-detect-aarch64-bsd branch January 27, 2023 01:24
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.

4 participants