@@ -6,7 +6,6 @@ use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
6
6
use rustc_hir:: attrs:: { AttributeKind , InlineAttr , InstructionSetAttr , UsedBy } ;
7
7
use rustc_hir:: def:: DefKind ;
8
8
use rustc_hir:: def_id:: { DefId , LOCAL_CRATE , LocalDefId } ;
9
- use rustc_hir:: weak_lang_items:: WEAK_LANG_ITEMS ;
10
9
use rustc_hir:: { self as hir, Attribute , LangItem , find_attr, lang_items} ;
11
10
use rustc_middle:: middle:: codegen_fn_attrs:: {
12
11
CodegenFnAttrFlags , CodegenFnAttrs , PatchableFunctionEntry ,
@@ -156,15 +155,21 @@ fn process_builtin_attrs(
156
155
match p {
157
156
AttributeKind :: Cold ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: COLD ,
158
157
AttributeKind :: ExportName { name, .. } => {
159
- codegen_fn_attrs. export_name = Some ( * name)
158
+ codegen_fn_attrs. symbol_name = Some ( * name)
160
159
}
161
160
AttributeKind :: Inline ( inline, span) => {
162
161
codegen_fn_attrs. inline = * inline;
163
162
interesting_spans. inline = Some ( * span) ;
164
163
}
165
164
AttributeKind :: Naked ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NAKED ,
166
165
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
+ }
168
173
AttributeKind :: LinkOrdinal { ordinal, span } => {
169
174
codegen_fn_attrs. link_ordinal = Some ( * ordinal) ;
170
175
interesting_spans. link_ordinal = Some ( * span) ;
@@ -382,7 +387,7 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code
382
387
// * `#[rustc_std_internal_symbol]` mangles the symbol name in a special way
383
388
// both for exports and imports through foreign items. This is handled further,
384
389
// during symbol mangling logic.
385
- } else if codegen_fn_attrs. link_name . is_some ( ) {
390
+ } else if codegen_fn_attrs. symbol_name . is_some ( ) {
386
391
// * This can be overridden with the `#[link_name]` attribute
387
392
} else {
388
393
// NOTE: there's one more exception that we cannot apply here. On wasm,
@@ -437,7 +442,7 @@ fn check_result(
437
442
}
438
443
439
444
// 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
441
446
&& let Some ( _) = codegen_fn_attrs. link_ordinal
442
447
{
443
448
let msg = "cannot use `#[link_name]` with `#[link_ordinal]`" ;
@@ -484,14 +489,11 @@ fn handle_lang_items(
484
489
// strippable by the linker.
485
490
//
486
491
// 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) ;
495
497
}
496
498
497
499
// error when using no_mangle on a lang item item
0 commit comments