diff options
| author | liushuyu <liushuyu011@gmail.com> | 2024-07-10 11:57:36 +0800 |
|---|---|---|
| committer | liushuyu <liushuyu011@gmail.com> | 2024-07-17 07:56:00 +0800 |
| commit | 01e6e60bf363e5ac056717f7bec8703a7b941c8b (patch) | |
| tree | dc20e2598ee243524948c5507219905e5ee48d0a /compiler/rustc_codegen_llvm/src/llvm_util.rs | |
| parent | 366bc8691b53fb40994c6ea86f4e4091000bd16a (diff) | |
| download | rust-01e6e60bf363e5ac056717f7bec8703a7b941c8b.tar.gz rust-01e6e60bf363e5ac056717f7bec8703a7b941c8b.zip | |
rustc_codegen_llvm: properly passing backchain attribute to LLVM ...
... this is a special attribute that was made to be a target-feature in LLVM 18+, but in all previous versions, this "feature" is a naked attribute. We will have to handle this situation differently than all other target-features.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/llvm_util.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/llvm_util.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 98dc8ac86d2..4d56d1d3b1a 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -14,7 +14,7 @@ use rustc_session::config::{PrintKind, PrintRequest}; use rustc_session::Session; use rustc_span::symbol::Symbol; use rustc_target::spec::{MergeFunctions, PanicStrategy}; -use rustc_target::target_features::RUSTC_SPECIFIC_FEATURES; +use rustc_target::target_features::{RUSTC_SPECIAL_FEATURES, RUSTC_SPECIFIC_FEATURES}; use std::ffi::{c_char, c_void, CStr, CString}; use std::fmt::Write; @@ -321,6 +321,10 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> { } }) .filter(|feature| { + // skip checking special features, as LLVM may not understands them + if RUSTC_SPECIAL_FEATURES.contains(feature) { + return true; + } // check that all features in a given smallvec are enabled for llvm_feature in to_llvm_features(sess, feature) { let cstr = SmallCStr::new(llvm_feature); @@ -546,6 +550,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str // -Ctarget-features let supported_features = sess.target.supported_target_features(); + let (llvm_major, _, _) = get_version(); let mut featsmap = FxHashMap::default(); let feats = sess .opts @@ -604,6 +609,13 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str if RUSTC_SPECIFIC_FEATURES.contains(&feature) { return None; } + + // if the target-feature is "backchain" and LLVM version is greater than 18 + // then we also need to add "+backchain" to the target-features attribute. + // otherwise, we will only add the naked `backchain` attribute to the attribute-group. + if feature == "backchain" && llvm_major < 18 { + return None; + } // ... otherwise though we run through `to_llvm_features` when // passing requests down to LLVM. This means that all in-language // features also work on the command line instead of having two |
