1
Fork 0

add ABI target features *before* -Ctarget-features

This commit is contained in:
Ralf Jung 2024-12-27 22:19:55 +01:00
parent eb527424a5
commit 912b7291d0
4 changed files with 19 additions and 16 deletions

View file

@ -154,12 +154,12 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
// we will silently correct them rather than silently producing wrong code. // we will silently correct them rather than silently producing wrong code.
// (The target sanity check tries to catch this, but we can't know which features are // (The target sanity check tries to catch this, but we can't know which features are
// enabled in GCC by default so we can't be fully sure about that check.) // enabled in GCC by default so we can't be fully sure about that check.)
for feature in abi_enable { // We add these at the beginning of the list so that `-Ctarget-features` can
all_rust_features.push((true, feature)); // still override it... that's unsound, but more compatible with past behavior.
} all_rust_features.splice(
for feature in abi_disable { 0..0,
all_rust_features.push((false, feature)); abi_enable.iter().map(|&f| (true, f)).chain(abi_disable.iter().map(|&f| (false, f))),
} );
// Translate this into GCC features. // Translate this into GCC features.
let feats = all_rust_features let feats = all_rust_features

View file

@ -779,12 +779,12 @@ pub(crate) fn global_llvm_features(
// we will silently correct them rather than silently producing wrong code. // we will silently correct them rather than silently producing wrong code.
// (The target sanity check tries to catch this, but we can't know which features are // (The target sanity check tries to catch this, but we can't know which features are
// enabled in LLVM by default so we can't be fully sure about that check.) // enabled in LLVM by default so we can't be fully sure about that check.)
for feature in abi_enable { // We add these at the beginning of the list so that `-Ctarget-features` can
all_rust_features.push((true, feature)); // still override it... that's unsound, but more compatible with past behavior.
} all_rust_features.splice(
for feature in abi_disable { 0..0,
all_rust_features.push((false, feature)); abi_enable.iter().map(|&f| (true, f)).chain(abi_disable.iter().map(|&f| (false, f))),
} );
// Translate this into LLVM features. // Translate this into LLVM features.
let feats = all_rust_features let feats = all_rust_features

View file

@ -743,6 +743,9 @@ impl Target {
/// the first list contains target features that must be enabled for ABI reasons, /// the first list contains target features that must be enabled for ABI reasons,
/// and the second list contains target feature that must be disabled for ABI reasons. /// and the second list contains target feature that must be disabled for ABI reasons.
/// ///
/// These features are automatically appended to whatever the target spec sats as default
/// features for the target.
///
/// All features enabled/disabled via `-Ctarget-features` and `#[target_features]` are checked /// All features enabled/disabled via `-Ctarget-features` and `#[target_features]` are checked
/// against this. We also check any implied features, based on the information above. If LLVM /// against this. We also check any implied features, based on the information above. If LLVM
/// implicitly enables more implied features than we do, that could bypass this check! /// implicitly enables more implied features than we do, that could bypass this check!

View file

@ -39,8 +39,8 @@ pub unsafe fn banana() -> u32 {
} }
// CHECK: attributes [[APPLEATTRS]] // CHECK: attributes [[APPLEATTRS]]
// COMPAT-SAME: "target-features"="+avx,+avx2,{{.*}}" // COMPAT-SAME: "target-features"="+x87,+sse2,+avx,+avx2,{{.*}}"
// INCOMPAT-SAME: "target-features"="-avx2,-avx,+x87,+sse2,+avx,{{.*}}" // INCOMPAT-SAME: "target-features"="+x87,+sse2,-avx2,-avx,+avx,{{.*}}"
// CHECK: attributes [[BANANAATTRS]] // CHECK: attributes [[BANANAATTRS]]
// COMPAT-SAME: "target-features"="+avx,+avx2,{{.*}}" // COMPAT-SAME: "target-features"="+x87,+sse2,+avx,+avx2,{{.*}}"
// INCOMPAT-SAME: "target-features"="-avx2,-avx,+x87,+sse2" // INCOMPAT-SAME: "target-features"="+x87,+sse2,-avx2,-avx"