@@ -12,6 +12,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
1212use rustc_data_structures:: profiling:: { get_resident_set_size, print_time_passes_entry} ;
1313use rustc_data_structures:: sync:: { IntoDynSyncSend , par_map} ;
1414use rustc_data_structures:: unord:: UnordMap ;
15+ use rustc_hir:: Target ;
1516use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
1617use rustc_hir:: lang_items:: LangItem ;
1718use rustc_metadata:: EncodedMetadata ;
@@ -967,21 +968,35 @@ impl CrateInfo {
967968 // by the compiler, but that's ok because all this stuff is unstable anyway.
968969 let target = & tcx. sess . target ;
969970 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
971983 . used_crates
972984 . iter ( )
973985 . flat_map ( |& cnum| tcx. missing_lang_items ( cnum) )
974986 . filter ( |l| l. is_weak ( ) )
975987 . filter_map ( |& l| {
976988 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) )
978998 } )
979999 . collect ( ) ;
980- let prefix = match ( target. is_like_windows , target. arch . as_ref ( ) ) {
981- ( true , "x86" ) => "_" ,
982- ( true , "arm64ec" ) => "#" ,
983- _ => "" ,
984- } ;
9851000
9861001 // This loop only adds new items to values of the hash map, so the order in which we
9871002 // iterate over the values is not important.
@@ -994,10 +1009,13 @@ impl CrateInfo {
9941009 . for_each ( |( _, linked_symbols) | {
9951010 let mut symbols = missing_weak_lang_items
9961011 . iter ( )
997- . map ( |item| {
1012+ . map ( |( item, export_kind ) | {
9981013 (
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,
10011019 )
10021020 } )
10031021 . collect :: < Vec < _ > > ( ) ;
@@ -1012,12 +1030,12 @@ impl CrateInfo {
10121030 // errors.
10131031 linked_symbols. extend ( ALLOCATOR_METHODS . iter ( ) . map ( |method| {
10141032 (
1015- format ! (
1016- "{prefix}{}" ,
1033+ add_prefix (
10171034 mangle_internal_symbol (
10181035 tcx,
1019- global_fn_name( method. name) . as_str( )
1020- )
1036+ global_fn_name ( method. name ) . as_str ( ) ,
1037+ ) ,
1038+ SymbolExportKind :: Text ,
10211039 ) ,
10221040 SymbolExportKind :: Text ,
10231041 )
0 commit comments