Skip to content

Commit

Permalink
detect: Remove last use of is_aarch64_feature_detected
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Apr 1, 2023
1 parent a4d656b commit 8418235
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 72 deletions.
39 changes: 24 additions & 15 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@ env:
RUSTFLAGS: -D warnings
RUSTUP_MAX_RETRIES: '10'

aarch64_linux_test_task:
aarch64_linux_gnu_test_task:
env:
TARGET: aarch64-unknown-linux-gnu
matrix:
- name: test ($TARGET)
env:
TARGET: aarch64-unknown-linux-gnu
arm_container:
image: rust:latest
setup_script:
- set -ex
- lscpu
- rustup toolchain add nightly --no-self-update --component rust-src && rustup default nightly
- name: test ($TARGET, glibc 2.17)
env:
TARGET: aarch64-unknown-linux-gnu
arm_container:
# glibc 2.17 is the minimum glibc version that aarch64 support is available: https://sourceware.org/legacy-ml/libc-announce/2012/msg00001.html
image: centos:7
Expand All @@ -34,16 +32,6 @@ aarch64_linux_test_task:
- lscpu
- yum install -y gcc git
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain nightly --component rust-src
- name: test ($TARGET)
env:
TARGET: aarch64-unknown-linux-musl
arm_container:
image: rust:alpine
setup_script:
- set -ex
- apk --no-cache add bash git musl-dev util-linux
- lscpu
- rustup toolchain add nightly --no-self-update --component rust-src && rustup default nightly
test_script:
- |
[ ! -f $HOME/.cargo/env ] || . $HOME/.cargo/env
Expand All @@ -54,6 +42,27 @@ aarch64_linux_test_task:
# FEAT_LSE2 is tested on aarch64 macOS VM.
- RUSTFLAGS="$RUSTFLAGS -C target-feature=+lse" RUSTDOCFLAGS="$RUSTDOCFLAGS -C target-feature=+lse" ./tools/test.sh -vv

aarch64_linux_musl_test_task:
name: test ($TARGET)
env:
TARGET: aarch64-unknown-linux-musl
arm_container:
image: rust:alpine
setup_script:
- set -ex
- apk --no-cache add bash git musl-dev util-linux
- lscpu
- rustup toolchain add nightly --no-self-update --component rust-src && rustup default nightly
test_script:
- set -ex
- ./tools/test.sh -vv
# -crt-static
- RUSTFLAGS="$RUSTFLAGS -C target-feature=-crt-static" RUSTDOCFLAGS="$RUSTDOCFLAGS -C target-feature=-crt-static" ./tools/test.sh -vv
# +lse
# Graviton2 (Neoverse N1) is ARMv8.2-a and doesn't support FEAT_LSE2.
# FEAT_LSE2 is tested on aarch64 macOS VM.
- RUSTFLAGS="$RUSTFLAGS -C target-feature=+lse" RUSTDOCFLAGS="$RUSTDOCFLAGS -C target-feature=+lse" ./tools/test.sh -vv

armel_linux_test_task:
name: test ($TARGET)
env:
Expand Down
1 change: 1 addition & 0 deletions .github/.cspell/organization-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ musleabi
musleabihf
newlibeabihf
nvptx
ohos
openwrt
riscv
softfloat
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ jobs:
if: startsWith(matrix.rust, 'nightly') && !startsWith(matrix.os, 'windows')

- run: tools/test.sh -vv $TARGET $DOCTEST_XCOMPILE $BUILD_STD
# -crt-static
- run: tools/test.sh -vv $TARGET $DOCTEST_XCOMPILE $BUILD_STD
env:
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-feature=-crt-static
RUSTFLAGS: ${{ env.RUSTFLAGS }} -C target-feature=-crt-static
if: contains(matrix.target, '-musl')
# +cmpxchg16b
# macOS is skipped because it is +cmpxchg16b by default
- run: tools/test.sh -vv $TARGET $DOCTEST_XCOMPILE $BUILD_STD
Expand Down
5 changes: 3 additions & 2 deletions src/imp/atomic128/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ Here is the table of targets that support run-time feature detection and the ins
| target_arch | target_os/target_env | instruction/API |
| ----------- | -------------------- | --------------- |
| x86_64 | all (except for sgx) | cpuid |
| aarch64 | linux-gnu/android | getauxval |
| aarch64 | other linux | dlsym(getauxval) (via is_aarch64_feature_detected) |
| aarch64 | linux/android | getauxval |
| aarch64 | freebsd | elf_aux_info |
| aarch64 | macos/openbsd | sysctl |
| aarch64 | windows | IsProcessorFeaturePresent |
| aarch64 | fuchsia | zx_system_get_features |

For targets not included in the above table, run-time detections are disabled and work the same as when `--cfg portable_atomic_no_outline_atomics` is set.

See [detect/aarch64_auxv.rs](detect/aarch64_auxv.rs) module-level comments for more details on Linux/Android/FreeBSD.
36 changes: 29 additions & 7 deletions src/imp/atomic128/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,17 @@

include!("macros.rs");

// On musl with static linking, it seems that getauxval is not always available.
// See detect/aarch64_auxv.rs for more.
#[cfg(not(portable_atomic_no_outline_atomics))]
#[cfg(any(
all(target_os = "linux", target_env = "gnu"),
all(
target_os = "linux",
any(
target_env = "gnu",
all(any(target_env = "musl", target_env = "ohos"), not(target_feature = "crt-static")),
),
),
target_os = "android",
target_os = "freebsd",
))]
Expand All @@ -72,10 +80,6 @@ mod detect;
#[cfg(target_os = "windows")]
#[path = "detect/aarch64_windows.rs"]
mod detect;
#[cfg(not(portable_atomic_no_outline_atomics))]
#[cfg(all(target_os = "linux", not(target_env = "gnu")))]
#[path = "detect/aarch64_std.rs"]
mod detect;

// test only
#[cfg(test)]
Expand Down Expand Up @@ -310,7 +314,16 @@ unsafe fn atomic_compare_exchange(
not(portable_atomic_no_aarch64_target_feature),
not(portable_atomic_no_outline_atomics),
any(
target_os = "linux",
all(
target_os = "linux",
any(
target_env = "gnu",
all(
any(target_env = "musl", target_env = "ohos"),
not(target_feature = "crt-static"),
),
),
),
target_os = "android",
target_os = "freebsd",
target_os = "openbsd",
Expand All @@ -325,7 +338,16 @@ unsafe fn atomic_compare_exchange(
not(portable_atomic_no_aarch64_target_feature),
not(portable_atomic_no_outline_atomics),
any(
target_os = "linux",
all(
target_os = "linux",
any(
target_env = "gnu",
all(
any(target_env = "musl", target_env = "ohos"),
not(target_feature = "crt-static"),
),
),
),
target_os = "android",
target_os = "freebsd",
target_os = "openbsd",
Expand Down
23 changes: 13 additions & 10 deletions src/imp/atomic128/detect/aarch64_auxv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@
//
// - On glibc (*-linux-gnu*), [aarch64 support is available on glibc 2.17+](https://sourceware.org/legacy-ml/libc-announce/2012/msg00001.html)
// and is newer than [glibc 2.16 that added getauxval](https://sourceware.org/legacy-ml/libc-announce/2012/msg00000.html).
// - On musl (*-linux-musl*, *-linux-ohos*), [aarch64 support is available on musl 1.1.7+](https://git.musl-libc.org/cgit/musl/tree/WHATSNEW?h=v1.1.7#n1422)
// and is newer than [musl 1.1.0 that added getauxval](https://git.musl-libc.org/cgit/musl/tree/WHATSNEW?h=v1.1.0#n1197).
// https://github.com/rust-lang/rust/commit/9a04ae4997493e9260352064163285cddc43de3c
// - On bionic (*-android*), [64-bit architecture support is available on Android 5.0+ (API level 21+)](https://android-developers.googleblog.com/2014/10/whats-new-in-android-50-lollipop.html)
// and is newer 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).
//
// On other Linux targets, we cannot assume that getauxval is always available,
// so we use is_aarch64_feature_detected which uses dlsym (+io fallback) instead
// of this module.
// However, on musl with static linking, it seems that getauxval is not always available, independent of version requirements: https://github.com/rust-lang/rust/issues/89626
// (That problem may have been fixed in https://github.com/rust-lang/rust/commit/9a04ae4997493e9260352064163285cddc43de3c,
// but even in the version containing that patch, [there is report](https://github.com/rust-lang/rust/issues/89626#issuecomment-1242636038)
// of the same error.)
//
// - On musl (*-linux-musl*), [aarch64 support is available on musl 1.1.7+](https://git.musl-libc.org/cgit/musl/tree/WHATSNEW?h=v1.1.7#n1422)
// and is newer than [musl 1.1.0 that added getauxval](https://git.musl-libc.org/cgit/musl/tree/WHATSNEW?h=v1.1.0#n1197).
// However, it seems that getauxval is not always available, independent of version requirements: https://github.com/rust-lang/rust/issues/89626
// (That problem may have been fixed in https://github.com/rust-lang/rust/commit/9a04ae4997493e9260352064163285cddc43de3c,
// but even in the version containing that patch, [there is report](https://github.com/rust-lang/rust/issues/89626#issuecomment-1242636038)
// of the same error.)
// - On uClibc-ng (*-linux-uclibc*), they [recently added getauxval](https://repo.or.cz/uclibc-ng.git/commitdiff/d869bb1600942c01a77539128f9ba5b5b55ad647)
// On other Linux targets, we cannot assume that getauxval is always available, so we don't support
// outline-atomics for now.
//
// - On musl with static linking. See the above for more.
// Also, in this case, dlsym(getauxval) always returns null.
// - On uClibc-ng (*-linux-uclibc*, *-l4re-uclibc*), they [recently added getauxval](https://repo.or.cz/uclibc-ng.git/commitdiff/d869bb1600942c01a77539128f9ba5b5b55ad647)
// but have not released it yet (as of 2023-02-09).
// - On Picolibc, [Picolibc 1.4.6 added getauxval stub](https://github.com/picolibc/picolibc#picolibc-version-146).
//
Expand Down
38 changes: 0 additions & 38 deletions src/imp/atomic128/detect/aarch64_std.rs

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions tests/helper/src/gen/sys/aarch64_linux_musl/mod.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions tests/helper/src/gen/sys/mod.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,14 @@ build() {
x_cargo "${args[@]}" "$@"
;;
esac
case "${target}" in
mips*-linux-musl*) ;; # -crt-static by default
*-linux-musl*)
CARGO_TARGET_DIR="${target_dir}/no-crt-static" \
RUSTFLAGS="${target_rustflags} -C target_feature=-crt-static" \
x_cargo "${args[@]}" "$@"
;;
esac
case "${target}" in
x86_64*)
# macOS is skipped because it is +cmpxchg16b by default
Expand Down
Loading

0 comments on commit 8418235

Please sign in to comment.