Skip to content

Commit e366108

Browse files
committed
mark naked functions as InstantiatedMode::GloballyShared
this makes sure that the function prototype is defined correctly, and we don't see LLVM complaining about a global value with invalid linkage
1 parent aa11613 commit e366108

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -643,14 +643,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
643643
}
644644
}
645645

646-
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
647-
// naked functions are generated using an extern function and global assembly. To
648-
// make sure that these can be linked together by LLVM, the linkage should be external,
649-
// unless the user explicitly configured something else (in which case any linker errors
650-
// they encounter are their responsibility).
651-
codegen_fn_attrs.linkage = codegen_fn_attrs.linkage.or(Some(Linkage::External));
652-
}
653-
654646
// Weak lang items have the same semantics as "std internal" symbols in the
655647
// sense that they're preserved through all our LTO passes and only
656648
// strippable by the linker.

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::dep_graph::{DepNode, WorkProduct, WorkProductId};
2+
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
23
use crate::ty::{GenericArgs, Instance, InstanceKind, SymbolName, TyCtxt};
34
use rustc_attr::InlineAttr;
45
use rustc_data_structures::base_n::BaseNString;
@@ -118,7 +119,9 @@ impl<'tcx> MonoItem<'tcx> {
118119
let entry_def_id = tcx.entry_fn(()).map(|(id, _)| id);
119120
// If this function isn't inlined or otherwise has an extern
120121
// indicator, then we'll be creating a globally shared version.
121-
if tcx.codegen_fn_attrs(instance.def_id()).contains_extern_indicator()
122+
let codegen_fn_attrs = tcx.codegen_fn_attrs(instance.def_id());
123+
if codegen_fn_attrs.contains_extern_indicator()
124+
|| codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED)
122125
|| !instance.def.generates_cgu_internal_copy(tcx)
123126
|| Some(instance.def_id()) == entry_def_id
124127
{

0 commit comments

Comments
 (0)