@@ -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 ,
@@ -182,15 +181,21 @@ fn process_builtin_attrs(
182
181
match p {
183
182
AttributeKind :: Cold ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: COLD ,
184
183
AttributeKind :: ExportName { name, .. } => {
185
- codegen_fn_attrs. export_name = Some ( * name)
184
+ codegen_fn_attrs. symbol_name = Some ( * name)
186
185
}
187
186
AttributeKind :: Inline ( inline, span) => {
188
187
codegen_fn_attrs. inline = * inline;
189
188
interesting_spans. inline = Some ( * span) ;
190
189
}
191
190
AttributeKind :: Naked ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NAKED ,
192
191
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
+ }
194
199
AttributeKind :: LinkOrdinal { ordinal, span } => {
195
200
codegen_fn_attrs. link_ordinal = Some ( * ordinal) ;
196
201
interesting_spans. link_ordinal = Some ( * span) ;
@@ -410,7 +415,7 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code
410
415
// * `#[rustc_std_internal_symbol]` mangles the symbol name in a special way
411
416
// both for exports and imports through foreign items. This is handled further,
412
417
// during symbol mangling logic.
413
- } else if codegen_fn_attrs. link_name . is_some ( ) {
418
+ } else if codegen_fn_attrs. symbol_name . is_some ( ) {
414
419
// * This can be overridden with the `#[link_name]` attribute
415
420
} else {
416
421
// NOTE: there's one more exception that we cannot apply here. On wasm,
@@ -465,7 +470,7 @@ fn check_result(
465
470
}
466
471
467
472
// 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
469
474
&& let Some ( _) = codegen_fn_attrs. link_ordinal
470
475
{
471
476
let msg = "cannot use `#[link_name]` with `#[link_ordinal]`" ;
@@ -512,14 +517,11 @@ fn handle_lang_items(
512
517
// strippable by the linker.
513
518
//
514
519
// 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) ;
523
525
}
524
526
525
527
// error when using no_mangle on a lang item item
0 commit comments