@@ -189,15 +189,21 @@ fn process_builtin_attrs(
189
189
match p {
190
190
AttributeKind :: Cold ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: COLD ,
191
191
AttributeKind :: ExportName { name, .. } => {
192
- codegen_fn_attrs. export_name = Some ( * name)
192
+ codegen_fn_attrs. symbol_name = Some ( * name)
193
193
}
194
194
AttributeKind :: Inline ( inline, span) => {
195
195
codegen_fn_attrs. inline = * inline;
196
196
interesting_spans. inline = Some ( * span) ;
197
197
}
198
198
AttributeKind :: Naked ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NAKED ,
199
199
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
+ }
201
207
AttributeKind :: LinkOrdinal { ordinal, span } => {
202
208
codegen_fn_attrs. link_ordinal = Some ( * ordinal) ;
203
209
interesting_spans. link_ordinal = Some ( * span) ;
@@ -417,7 +423,7 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code
417
423
// * `#[rustc_std_internal_symbol]` mangles the symbol name in a special way
418
424
// both for exports and imports through foreign items. This is handled further,
419
425
// during symbol mangling logic.
420
- } else if codegen_fn_attrs. link_name . is_some ( ) {
426
+ } else if codegen_fn_attrs. symbol_name . is_some ( ) {
421
427
// * This can be overridden with the `#[link_name]` attribute
422
428
} else {
423
429
// NOTE: there's one more exception that we cannot apply here. On wasm,
@@ -472,7 +478,7 @@ fn check_result(
472
478
}
473
479
474
480
// 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
476
482
&& let Some ( _) = codegen_fn_attrs. link_ordinal
477
483
{
478
484
let msg = "cannot use `#[link_name]` with `#[link_ordinal]`" ;
@@ -523,8 +529,7 @@ fn handle_lang_items(
523
529
&& let Some ( link_name) = lang_item. link_name ( )
524
530
{
525
531
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) ;
528
533
}
529
534
530
535
// error when using no_mangle on a lang item item
0 commit comments