diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 701bacb9..76e03e2f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -252,12 +252,11 @@ jobs: RUSTFLAGS: ${{ env.RUSTFLAGS }} -C target-feature=-sse2 RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-feature=-sse2 if: startsWith(matrix.target, 'i686') - # x86 x87 + # x86 -x87 - run: tools/test.sh -vv --tests $TARGET $BUILD_STD $RELEASE env: - # i586 is -C target-feature=+x87 by default, but cfg(target_feature = "x87") doesn't work. - RUSTFLAGS: ${{ env.RUSTFLAGS }} --cfg target_feature="x87" - RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} --cfg target_feature="x87" + RUSTFLAGS: ${{ env.RUSTFLAGS }} -C target-feature=+soft-float,-x87,-mmx + RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-feature=+soft-float,-x87,-mmx if: startsWith(matrix.target, 'i586') # aarch64 +lse - run: tools/test.sh -vv --tests $TARGET $BUILD_STD $RELEASE diff --git a/build.rs b/build.rs index 11d7bee2..e25b171a 100644 --- a/build.rs +++ b/build.rs @@ -41,7 +41,7 @@ fn main() { // TODO: handle multi-line target_feature_fallback // grep -E 'target_feature_fallback\("' build.rs | sed -E 's/^.*target_feature_fallback\(//; s/",.*$/"/' | LC_ALL=C sort -u | tr '\n' ',' println!( - r#"cargo:rustc-check-cfg=cfg(atomic_maybe_uninit_target_feature,values("a","cmpxchg16b","fast-serialization","lse","lse128","lse2","mclass","partword-atomics","quadword-atomics","rcpc","rcpc3","v5te","v6","v7","v8","v8m"))"# + r#"cargo:rustc-check-cfg=cfg(atomic_maybe_uninit_target_feature,values("a","cmpxchg16b","fast-serialization","lse","lse128","lse2","mclass","partword-atomics","quadword-atomics","rcpc","rcpc3","v5te","v6","v7","v8","v8m","x87"))"# ); } @@ -108,6 +108,15 @@ fn main() { || target_os == "watchos" || target_os == "visionos"; match target_arch { + "x86" => { + // i586 is -C target-feature=+x87 by default, but cfg(target_feature = "x87") doesn't work. + // And core assumes x87 is always available. + // https://github.com/rust-lang/rust/blob/1.80.0/library/core/src/num/dec2flt/fpu.rs#L6 + // https://github.com/rust-lang/rust/blob/1.80.0/compiler/rustc_target/src/spec/targets/i686_unknown_uefi.rs#L24 + // However, custom bare metal targets tend to disable x87 and do not use floats. + let has_x87 = target_os != "none"; + target_feature_fallback("x87", has_x87); + } "x86_64" => { // cmpxchg16b_target_feature stabilized in Rust 1.69. if needs_target_feature_fallback(&version, Some(69)) { diff --git a/src/arch/x86.rs b/src/arch/x86.rs index f1d187b7..8b52df86 100644 --- a/src/arch/x86.rs +++ b/src/arch/x86.rs @@ -248,9 +248,7 @@ macro_rules! atomic64 { core::mem::transmute::<_, [MaybeUninit; 2]>(out)[0] } #[cfg(not(target_feature = "sse"))] - // It seems core assumes x87 target_feature is always available? - // https://github.com/rust-lang/rust/blob/1.80.0/library/core/src/num/dec2flt/fpu.rs#L6 - #[cfg(target_feature = "x87")] + #[cfg(any(target_feature = "x87", atomic_maybe_uninit_target_feature = "x87"))] // SAFETY: the caller must uphold the safety contract. // // Refs: @@ -279,7 +277,7 @@ macro_rules! atomic64 { out } #[cfg(not(target_feature = "sse"))] - #[cfg(not(target_feature = "x87"))] + #[cfg(not(any(target_feature = "x87", atomic_maybe_uninit_target_feature = "x87")))] // SAFETY: the caller must uphold the safety contract. // // Refs: https://www.felixcloutier.com/x86/cmpxchg8b:cmpxchg16b @@ -348,9 +346,7 @@ macro_rules! atomic64 { } } #[cfg(not(target_feature = "sse"))] - // It seems core assumes x87 target_feature is always available? - // https://github.com/rust-lang/rust/blob/1.80.0/library/core/src/num/dec2flt/fpu.rs#L6 - #[cfg(target_feature = "x87")] + #[cfg(any(target_feature = "x87", atomic_maybe_uninit_target_feature = "x87"))] // SAFETY: the caller must uphold the safety contract. // // Refs: @@ -402,7 +398,7 @@ macro_rules! atomic64 { } } #[cfg(not(target_feature = "sse"))] - #[cfg(not(target_feature = "x87"))] + #[cfg(not(any(target_feature = "x87", atomic_maybe_uninit_target_feature = "x87")))] // SAFETY: the caller must uphold the safety contract. // // Refs: https://www.felixcloutier.com/x86/cmpxchg8b:cmpxchg16b diff --git a/tools/build.sh b/tools/build.sh index c110a83b..65b2c363 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -240,9 +240,8 @@ build() { x_cargo "${args[@]}" "$@" ;; i586*) - # i586 is -C target-feature=+x87 by default, but cfg(target_feature = "x87") doesn't work. - CARGO_TARGET_DIR="${target_dir}/x87" \ - RUSTFLAGS="${target_rustflags} --cfg target_feature=\"x87\"" \ + CARGO_TARGET_DIR="${target_dir}/no-x87" \ + RUSTFLAGS="${target_rustflags} -C target-feature=-x87" \ x_cargo "${args[@]}" "$@" ;; aarch64* | arm64*)