Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1c2d264

Browse files
authored
Rollup merge of #146144 - heiher:entry-func-features, r=petrochenkov
compiler: Apply target features to the entry function Fixes #146143
2 parents 7e189a0 + 923b892 commit 1c2d264

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

‎compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,19 @@ pub(crate) fn tune_cpu_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribu
296296
.map(|tune_cpu| llvm::CreateAttrStringValue(cx.llcx, "tune-cpu", tune_cpu))
297297
}
298298

299+
/// Get the `target-features` LLVM attribute.
300+
pub(crate) fn target_features_attr<'ll>(
301+
cx: &CodegenCx<'ll, '_>,
302+
function_features: Vec<String>,
303+
) -> Option<&'ll Attribute> {
304+
let global_features = cx.tcx.global_backend_features(()).iter().map(String::as_str);
305+
let function_features = function_features.iter().map(String::as_str);
306+
let target_features =
307+
global_features.chain(function_features).intersperse(",").collect::<String>();
308+
(!target_features.is_empty())
309+
.then(|| llvm::CreateAttrStringValue(cx.llcx, "target-features", &target_features))
310+
}
311+
299312
/// Get the `NonLazyBind` LLVM attribute,
300313
/// if the codegen options allow skipping the PLT.
301314
pub(crate) fn non_lazy_bind_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
@@ -523,14 +536,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
523536
}
524537
}
525538

526-
let global_features = cx.tcx.global_backend_features(()).iter().map(|s| s.as_str());
527-
let function_features = function_features.iter().map(|s| s.as_str());
528-
let target_features: String =
529-
global_features.chain(function_features).intersperse(",").collect();
530-
531-
if !target_features.is_empty() {
532-
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "target-features", &target_features));
533-
}
539+
to_add.extend(target_features_attr(cx, function_features));
534540

535541
attributes::apply_to_llfn(llfn, Function, &to_add);
536542
}

‎compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,15 +853,21 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
853853
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function> {
854854
let entry_name = self.sess().target.entry_name.as_ref();
855855
if self.get_declared_value(entry_name).is_none() {
856-
Some(self.declare_entry_fn(
856+
let llfn = self.declare_entry_fn(
857857
entry_name,
858858
llvm::CallConv::from_conv(
859859
self.sess().target.entry_abi,
860860
self.sess().target.arch.borrow(),
861861
),
862862
llvm::UnnamedAddr::Global,
863863
fn_type,
864-
))
864+
);
865+
attributes::apply_to_llfn(
866+
llfn,
867+
llvm::AttributePlace::Function,
868+
attributes::target_features_attr(self, vec![]).as_slice(),
869+
);
870+
Some(llfn)
865871
} else {
866872
// If the symbol already exists, it is an error: for example, the user wrote
867873
// #[no_mangle] extern "C" fn main(..) {..}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /