@@ -16,7 +16,7 @@ use rustc_middle::ty::{self, SymbolName, TyCtxt};
16
16
use rustc_middle:: ty:: { GenericArgKind , GenericArgsRef } ;
17
17
use rustc_middle:: util:: Providers ;
18
18
use rustc_session:: config:: { CrateType , OomStrategy } ;
19
- use rustc_target:: spec:: SanitizerSet ;
19
+ use rustc_target:: spec:: { SanitizerSet , TlsModel } ;
20
20
21
21
pub fn threshold ( tcx : TyCtxt < ' _ > ) -> SymbolExportLevel {
22
22
crates_export_threshold ( tcx. crate_types ( ) )
@@ -608,6 +608,25 @@ pub fn linking_symbol_name_for_instance_in_crate<'tcx>(
608
608
format ! ( "{prefix}{undecorated}{suffix}{args_in_bytes}" )
609
609
}
610
610
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
+
611
630
fn wasm_import_module_map ( tcx : TyCtxt < ' _ > , cnum : CrateNum ) -> FxHashMap < DefId , String > {
612
631
// Build up a map from DefId to a `NativeLib` structure, where
613
632
// `NativeLib` internally contains information about
0 commit comments