@@ -12,6 +12,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
12
12
use rustc_data_structures:: profiling:: { get_resident_set_size, print_time_passes_entry} ;
13
13
use rustc_data_structures:: sync:: { IntoDynSyncSend , par_map} ;
14
14
use rustc_data_structures:: unord:: UnordMap ;
15
+ use rustc_hir:: Target ;
15
16
use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
16
17
use rustc_hir:: lang_items:: LangItem ;
17
18
use rustc_metadata:: EncodedMetadata ;
@@ -967,21 +968,35 @@ impl CrateInfo {
967
968
// by the compiler, but that's ok because all this stuff is unstable anyway.
968
969
let target = & tcx. sess . target ;
969
970
if !are_upstream_rust_objects_already_included ( tcx. sess ) {
970
- let missing_weak_lang_items: FxIndexSet < Symbol > = info
971
+ let add_prefix = match ( target. is_like_windows , target. arch . as_ref ( ) ) {
972
+ ( true , "x86" ) => |name : String , _: SymbolExportKind | format ! ( "_{name}" ) ,
973
+ ( true , "arm64ec" ) => {
974
+ // Only functions are decorated for arm64ec.
975
+ |name : String , export_kind : SymbolExportKind | match export_kind {
976
+ SymbolExportKind :: Text => format ! ( "#{name}" ) ,
977
+ _ => name,
978
+ }
979
+ }
980
+ _ => |name : String , _: SymbolExportKind | name,
981
+ } ;
982
+ let missing_weak_lang_items: FxIndexSet < ( Symbol , SymbolExportKind ) > = info
971
983
. used_crates
972
984
. iter ( )
973
985
. flat_map ( |& cnum| tcx. missing_lang_items ( cnum) )
974
986
. filter ( |l| l. is_weak ( ) )
975
987
. filter_map ( |& l| {
976
988
let name = l. link_name ( ) ?;
977
- lang_items:: required ( tcx, l) . then_some ( name)
989
+ let export_kind = match l. target ( ) {
990
+ Target :: Fn => SymbolExportKind :: Text ,
991
+ Target :: Static => SymbolExportKind :: Data ,
992
+ _ => bug ! (
993
+ "Don't know what the export kind is for lang item of kind {:?}" ,
994
+ l. target( )
995
+ ) ,
996
+ } ;
997
+ lang_items:: required ( tcx, l) . then_some ( ( name, export_kind) )
978
998
} )
979
999
. collect ( ) ;
980
- let prefix = match ( target. is_like_windows , target. arch . as_ref ( ) ) {
981
- ( true , "x86" ) => "_" ,
982
- ( true , "arm64ec" ) => "#" ,
983
- _ => "" ,
984
- } ;
985
1000
986
1001
// This loop only adds new items to values of the hash map, so the order in which we
987
1002
// iterate over the values is not important.
@@ -994,10 +1009,13 @@ impl CrateInfo {
994
1009
. for_each ( |( _, linked_symbols) | {
995
1010
let mut symbols = missing_weak_lang_items
996
1011
. iter ( )
997
- . map ( |item| {
1012
+ . map ( |( item, export_kind ) | {
998
1013
(
999
- format ! ( "{prefix}{}" , mangle_internal_symbol( tcx, item. as_str( ) ) ) ,
1000
- SymbolExportKind :: Text ,
1014
+ add_prefix (
1015
+ mangle_internal_symbol ( tcx, item. as_str ( ) ) ,
1016
+ * export_kind,
1017
+ ) ,
1018
+ * export_kind,
1001
1019
)
1002
1020
} )
1003
1021
. collect :: < Vec < _ > > ( ) ;
@@ -1012,12 +1030,12 @@ impl CrateInfo {
1012
1030
// errors.
1013
1031
linked_symbols. extend ( ALLOCATOR_METHODS . iter ( ) . map ( |method| {
1014
1032
(
1015
- format ! (
1016
- "{prefix}{}" ,
1033
+ add_prefix (
1017
1034
mangle_internal_symbol (
1018
1035
tcx,
1019
- global_fn_name( method. name) . as_str( )
1020
- )
1036
+ global_fn_name ( method. name ) . as_str ( ) ,
1037
+ ) ,
1038
+ SymbolExportKind :: Text ,
1021
1039
) ,
1022
1040
SymbolExportKind :: Text ,
1023
1041
)
0 commit comments