@@ -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 , 
@@ -156,15 +155,21 @@ fn process_builtin_attrs(
156155            match  p { 
157156                AttributeKind :: Cold ( _)  => codegen_fn_attrs. flags  |= CodegenFnAttrFlags :: COLD , 
158157                AttributeKind :: ExportName  {  name,  .. }  => { 
159-                     codegen_fn_attrs. export_name  = Some ( * name) 
158+                     codegen_fn_attrs. symbol_name  = Some ( * name) 
160159                } 
161160                AttributeKind :: Inline ( inline,  span)  => { 
162161                    codegen_fn_attrs. inline  = * inline; 
163162                    interesting_spans. inline  = Some ( * span) ; 
164163                } 
165164                AttributeKind :: Naked ( _)  => codegen_fn_attrs. flags  |= CodegenFnAttrFlags :: NAKED , 
166165                AttributeKind :: Align  {  align,  .. }  => codegen_fn_attrs. alignment  = Some ( * align) , 
167-                 AttributeKind :: LinkName  {  name,  .. }  => codegen_fn_attrs. link_name  = Some ( * name) , 
166+                 AttributeKind :: LinkName  {  name,  .. }  => { 
167+                     // FIXME Remove check for foreign functions once #[link_name] on non-foreign 
168+                     // functions is a hard error 
169+                     if  tcx. is_foreign_item ( did)  { 
170+                         codegen_fn_attrs. symbol_name  = Some ( * name) ; 
171+                     } 
172+                 } 
168173                AttributeKind :: LinkOrdinal  {  ordinal,  span }  => { 
169174                    codegen_fn_attrs. link_ordinal  = Some ( * ordinal) ; 
170175                    interesting_spans. link_ordinal  = Some ( * span) ; 
@@ -382,7 +387,7 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code
382387            // * `#[rustc_std_internal_symbol]` mangles the symbol name in a special way 
383388            //   both for exports and imports through foreign items. This is handled further, 
384389            //   during symbol mangling logic. 
385-         }  else  if  codegen_fn_attrs. link_name . is_some ( )  { 
390+         }  else  if  codegen_fn_attrs. symbol_name . is_some ( )  { 
386391            // * This can be overridden with the `#[link_name]` attribute 
387392        }  else  { 
388393            // NOTE: there's one more exception that we cannot apply here. On wasm, 
@@ -437,7 +442,7 @@ fn check_result(
437442    } 
438443
439444    // error when specifying link_name together with link_ordinal 
440-     if  let  Some ( _)  = codegen_fn_attrs. link_name 
445+     if  let  Some ( _)  = codegen_fn_attrs. symbol_name 
441446        && let  Some ( _)  = codegen_fn_attrs. link_ordinal 
442447    { 
443448        let  msg = "cannot use `#[link_name]` with `#[link_ordinal]`" ; 
@@ -484,14 +489,11 @@ fn handle_lang_items(
484489    // strippable by the linker. 
485490    // 
486491    // Additionally weak lang items have predetermined symbol names. 
487-     if  let  Some ( lang_item)  = lang_item { 
488-         if  WEAK_LANG_ITEMS . contains ( & lang_item)  { 
489-             codegen_fn_attrs. flags  |= CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL ; 
490-         } 
491-         if  let  Some ( link_name)  = lang_item. link_name ( )  { 
492-             codegen_fn_attrs. export_name  = Some ( link_name) ; 
493-             codegen_fn_attrs. link_name  = Some ( link_name) ; 
494-         } 
492+     if  let  Some ( lang_item)  = lang_item
493+         && let  Some ( link_name)  = lang_item. link_name ( ) 
494+     { 
495+         codegen_fn_attrs. flags  |= CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL ; 
496+         codegen_fn_attrs. symbol_name  = Some ( link_name) ; 
495497    } 
496498
497499    // error when using no_mangle on a lang item item 
0 commit comments