@@ -54,12 +54,22 @@ pub(crate) fn codegen_tls_ref<'tcx>(
54
54
def_id : DefId ,
55
55
layout : TyAndLayout < ' tcx > ,
56
56
) -> CValue < ' tcx > {
57
- let data_id = data_id_for_static ( fx. tcx , fx. module , def_id, false ) ;
58
- let local_data_id = fx. module . declare_data_in_func ( data_id, & mut fx. bcx . func ) ;
59
- if fx. clif_comments . enabled ( ) {
60
- fx. add_comment ( local_data_id, format ! ( "tls {:?}" , def_id) ) ;
61
- }
62
- let tls_ptr = fx. bcx . ins ( ) . tls_value ( fx. pointer_type , local_data_id) ;
57
+ let tls_ptr = if !def_id. is_local ( ) && fx. tcx . needs_thread_local_shim ( def_id) {
58
+ let instance = ty:: Instance {
59
+ def : ty:: InstanceDef :: ThreadLocalShim ( def_id) ,
60
+ substs : ty:: InternalSubsts :: empty ( ) ,
61
+ } ;
62
+ let func_ref = fx. get_function_ref ( instance) ;
63
+ let call = fx. bcx . ins ( ) . call ( func_ref, & [ ] ) ;
64
+ fx. bcx . func . dfg . first_result ( call)
65
+ } else {
66
+ let data_id = data_id_for_static ( fx. tcx , fx. module , def_id, false ) ;
67
+ let local_data_id = fx. module . declare_data_in_func ( data_id, & mut fx. bcx . func ) ;
68
+ if fx. clif_comments . enabled ( ) {
69
+ fx. add_comment ( local_data_id, format ! ( "tls {:?}" , def_id) ) ;
70
+ }
71
+ fx. bcx . ins ( ) . tls_value ( fx. pointer_type , local_data_id)
72
+ } ;
63
73
CValue :: by_val ( tls_ptr, layout)
64
74
}
65
75
0 commit comments