@@ -189,15 +189,21 @@ fn process_builtin_attrs(
189189 match p {
190190 AttributeKind :: Cold ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: COLD ,
191191 AttributeKind :: ExportName { name, .. } => {
192- codegen_fn_attrs. export_name = Some ( * name)
192+ codegen_fn_attrs. symbol_name = Some ( * name)
193193 }
194194 AttributeKind :: Inline ( inline, span) => {
195195 codegen_fn_attrs. inline = * inline;
196196 interesting_spans. inline = Some ( * span) ;
197197 }
198198 AttributeKind :: Naked ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NAKED ,
199199 AttributeKind :: Align { align, .. } => codegen_fn_attrs. alignment = Some ( * align) ,
200- AttributeKind :: LinkName { name, .. } => codegen_fn_attrs. link_name = Some ( * name) ,
200+ AttributeKind :: LinkName { name, .. } => {
201+ // FIXME Remove check for foreign functions once #[link_name] on non-foreign
202+ // functions is a hard error
203+ if tcx. is_foreign_item ( did) {
204+ codegen_fn_attrs. symbol_name = Some ( * name) ;
205+ }
206+ }
201207 AttributeKind :: LinkOrdinal { ordinal, span } => {
202208 codegen_fn_attrs. link_ordinal = Some ( * ordinal) ;
203209 interesting_spans. link_ordinal = Some ( * span) ;
@@ -417,7 +423,7 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code
417423 // * `#[rustc_std_internal_symbol]` mangles the symbol name in a special way
418424 // both for exports and imports through foreign items. This is handled further,
419425 // during symbol mangling logic.
420- } else if codegen_fn_attrs. link_name . is_some ( ) {
426+ } else if codegen_fn_attrs. symbol_name . is_some ( ) {
421427 // * This can be overridden with the `#[link_name]` attribute
422428 } else {
423429 // NOTE: there's one more exception that we cannot apply here. On wasm,
@@ -472,7 +478,7 @@ fn check_result(
472478 }
473479
474480 // error when specifying link_name together with link_ordinal
475- if let Some ( _) = codegen_fn_attrs. link_name
481+ if let Some ( _) = codegen_fn_attrs. symbol_name
476482 && let Some ( _) = codegen_fn_attrs. link_ordinal
477483 {
478484 let msg = "cannot use `#[link_name]` with `#[link_ordinal]`" ;
@@ -523,8 +529,7 @@ fn handle_lang_items(
523529 && let Some ( link_name) = lang_item. link_name ( )
524530 {
525531 codegen_fn_attrs. flags |= CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL ;
526- codegen_fn_attrs. export_name = Some ( link_name) ;
527- codegen_fn_attrs. link_name = Some ( link_name) ;
532+ codegen_fn_attrs. symbol_name = Some ( link_name) ;
528533 }
529534
530535 // error when using no_mangle on a lang item item
0 commit comments