@@ -6,7 +6,6 @@ use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
66use rustc_hir:: attrs:: { AttributeKind , InlineAttr , InstructionSetAttr , UsedBy } ;
77use rustc_hir:: def:: DefKind ;
88use rustc_hir:: def_id:: { DefId , LOCAL_CRATE , LocalDefId } ;
9- use rustc_hir:: weak_lang_items:: WEAK_LANG_ITEMS ;
109use rustc_hir:: { self as hir, Attribute , LangItem , find_attr, lang_items} ;
1110use rustc_middle:: middle:: codegen_fn_attrs:: {
1211 CodegenFnAttrFlags , CodegenFnAttrs , PatchableFunctionEntry ,
@@ -182,15 +181,21 @@ fn process_builtin_attrs(
182181 match p {
183182 AttributeKind :: Cold ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: COLD ,
184183 AttributeKind :: ExportName { name, .. } => {
185- codegen_fn_attrs. export_name = Some ( * name)
184+ codegen_fn_attrs. symbol_name = Some ( * name)
186185 }
187186 AttributeKind :: Inline ( inline, span) => {
188187 codegen_fn_attrs. inline = * inline;
189188 interesting_spans. inline = Some ( * span) ;
190189 }
191190 AttributeKind :: Naked ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NAKED ,
192191 AttributeKind :: Align { align, .. } => codegen_fn_attrs. alignment = Some ( * align) ,
193- AttributeKind :: LinkName { name, .. } => codegen_fn_attrs. link_name = Some ( * name) ,
192+ AttributeKind :: LinkName { name, .. } => {
193+ // FIXME Remove check for foreign functions once #[link_name] on non-foreign
194+ // functions is a hard error
195+ if tcx. is_foreign_item ( did) {
196+ codegen_fn_attrs. symbol_name = Some ( * name) ;
197+ }
198+ }
194199 AttributeKind :: LinkOrdinal { ordinal, span } => {
195200 codegen_fn_attrs. link_ordinal = Some ( * ordinal) ;
196201 interesting_spans. link_ordinal = Some ( * span) ;
@@ -410,7 +415,7 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code
410415 // * `#[rustc_std_internal_symbol]` mangles the symbol name in a special way
411416 // both for exports and imports through foreign items. This is handled further,
412417 // during symbol mangling logic.
413- } else if codegen_fn_attrs. link_name . is_some ( ) {
418+ } else if codegen_fn_attrs. symbol_name . is_some ( ) {
414419 // * This can be overridden with the `#[link_name]` attribute
415420 } else {
416421 // NOTE: there's one more exception that we cannot apply here. On wasm,
@@ -465,7 +470,7 @@ fn check_result(
465470 }
466471
467472 // error when specifying link_name together with link_ordinal
468- if let Some ( _) = codegen_fn_attrs. link_name
473+ if let Some ( _) = codegen_fn_attrs. symbol_name
469474 && let Some ( _) = codegen_fn_attrs. link_ordinal
470475 {
471476 let msg = "cannot use `#[link_name]` with `#[link_ordinal]`" ;
@@ -512,14 +517,11 @@ fn handle_lang_items(
512517 // strippable by the linker.
513518 //
514519 // Additionally weak lang items have predetermined symbol names.
515- if let Some ( lang_item) = lang_item {
516- if WEAK_LANG_ITEMS . contains ( & lang_item) {
517- codegen_fn_attrs. flags |= CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL ;
518- }
519- if let Some ( link_name) = lang_item. link_name ( ) {
520- codegen_fn_attrs. export_name = Some ( link_name) ;
521- codegen_fn_attrs. link_name = Some ( link_name) ;
522- }
520+ if let Some ( lang_item) = lang_item
521+ && let Some ( link_name) = lang_item. link_name ( )
522+ {
523+ codegen_fn_attrs. flags |= CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL ;
524+ codegen_fn_attrs. symbol_name = Some ( link_name) ;
523525 }
524526
525527 // error when using no_mangle on a lang item item
0 commit comments