Skip to content

Commit 6c9d750

Browse files
committed
Add cranelift support
1 parent e61ac42 commit 6c9d750

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

Diff for: compiler/rustc_codegen_cranelift/src/constant.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,22 @@ pub(crate) fn codegen_tls_ref<'tcx>(
5454
def_id: DefId,
5555
layout: TyAndLayout<'tcx>,
5656
) -> 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+
};
6373
CValue::by_val(tls_ptr, layout)
6474
}
6575

0 commit comments

Comments
 (0)