@@ -16,7 +16,7 @@ use rustc_middle::ty::{self, SymbolName, TyCtxt};
1616use rustc_middle:: ty:: { GenericArgKind , GenericArgsRef } ;
1717use rustc_middle:: util:: Providers ;
1818use rustc_session:: config:: { CrateType , OomStrategy } ;
19- use rustc_target:: spec:: SanitizerSet ;
19+ use rustc_target:: spec:: { SanitizerSet , TlsModel } ;
2020
2121pub fn threshold ( tcx : TyCtxt < ' _ > ) -> SymbolExportLevel {
2222 crates_export_threshold ( tcx. crate_types ( ) )
@@ -608,6 +608,25 @@ pub fn linking_symbol_name_for_instance_in_crate<'tcx>(
608608 format ! ( "{prefix}{undecorated}{suffix}{args_in_bytes}" )
609609}
610610
611+ pub fn exporting_symbol_name_for_instance_in_crate < ' tcx > (
612+ tcx : TyCtxt < ' tcx > ,
613+ symbol : ExportedSymbol < ' tcx > ,
614+ cnum : CrateNum ,
615+ ) -> String {
616+ let undecorated = symbol_name_for_instance_in_crate ( tcx, symbol, cnum) ;
617+
618+ if matches ! ( tcx. sess. tls_model( ) , TlsModel :: EmulatedTls )
619+ && let ExportedSymbol :: NonGeneric ( def_id) = symbol
620+ && tcx. is_thread_local_static ( def_id)
621+ {
622+ // When using emutls, LLVM will add the `__emutls_v.` prefix to thread local symbols,
623+ // and exported symbol name need to match this.
624+ format ! ( "__emutls_v.{undecorated}" )
625+ } else {
626+ undecorated
627+ }
628+ }
629+
611630fn wasm_import_module_map ( tcx : TyCtxt < ' _ > , cnum : CrateNum ) -> FxHashMap < DefId , String > {
612631 // Build up a map from DefId to a `NativeLib` structure, where
613632 // `NativeLib` internally contains information about
0 commit comments