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/attributes.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/attributes.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/attributes.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index e7669470026..3877460fcdb 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -271,6 +271,17 @@ fn stackprotector_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> { Some(sspattr.create_attr(cx.llcx)) } +fn backchain_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> { + if cx.sess().target.arch != "s390x" { + return None; + } + + let requested_features = cx.sess().opts.cg.target_feature.split(','); + let found_positive = requested_features.clone().any(|r| r == "+backchain"); + + if found_positive { Some(llvm::CreateAttrString(cx.llcx, "backchain")) } else { None } +} + pub fn target_cpu_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll Attribute { let target_cpu = llvm_util::target_cpu(cx.tcx.sess); llvm::CreateAttrStringValue(cx.llcx, "target-cpu", target_cpu) @@ -447,6 +458,9 @@ pub fn from_fn_attrs<'ll, 'tcx>( if let Some(align) = codegen_fn_attrs.alignment { llvm::set_alignment(llfn, align); } + if let Some(backchain) = backchain_attr(cx) { + to_add.push(backchain); + } to_add.extend(sanitize_attrs(cx, codegen_fn_attrs.no_sanitize)); to_add.extend(patchable_function_entry_attrs(cx, codegen_fn_attrs.patchable_function_entry)); |
