diff options
author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2023-02-03 09:04:12 +0100 |
---|---|---|
committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2023-03-29 08:55:21 +0200 |
commit | 0d89c6a2d44b78d052280d7faecfcb79e6f3d4a1 (patch) | |
tree | f12f0f686444926ccc3cd203daa6d9ad087687d3 /compiler/rustc_codegen_cranelift | |
parent | 51c93553d4344472f2e291b3a4f110f884062a37 (diff) | |
download | rust-0d89c6a2d44b78d052280d7faecfcb79e6f3d4a1.tar.gz |
Support TLS access into dylibs on Windows
Diffstat (limited to 'compiler/rustc_codegen_cranelift')
-rw-r--r-- | compiler/rustc_codegen_cranelift/src/constant.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index 31278f810e9..ebb4de33f99 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/src/constant.rs @@ -54,12 +54,22 @@ pub(crate) fn codegen_tls_ref<'tcx>( def_id: DefId, layout: TyAndLayout<'tcx>, ) -> CValue<'tcx> { - let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false); - let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); - if fx.clif_comments.enabled() { - fx.add_comment(local_data_id, format!("tls {:?}", def_id)); - } - let tls_ptr = fx.bcx.ins().tls_value(fx.pointer_type, local_data_id); + let tls_ptr = if !def_id.is_local() && fx.tcx.needs_thread_local_shim(def_id) { + let instance = ty::Instance { + def: ty::InstanceDef::ThreadLocalShim(def_id), + substs: ty::InternalSubsts::empty(), + }; + let func_ref = fx.get_function_ref(instance); + let call = fx.bcx.ins().call(func_ref, &[]); + fx.bcx.func.dfg.first_result(call) + } else { + let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false); + let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); + if fx.clif_comments.enabled() { + fx.add_comment(local_data_id, format!("tls {:?}", def_id)); + } + fx.bcx.ins().tls_value(fx.pointer_type, local_data_id) + }; CValue::by_val(tls_ptr, layout) } |