Skip to content

Commit e61ac42

Browse files
committed
Don't use thread local shims for foreign thread locals
1 parent cf3683f commit e61ac42

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

Diff for: compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn exported_symbols_provider_local(
188188
// Export TLS shims
189189
if !tcx.sess.target.dll_tls_export {
190190
symbols.extend(sorted.iter().filter_map(|(&def_id, &info)| {
191-
tcx.is_thread_local_static(def_id).then(|| {
191+
tcx.needs_thread_local_shim(def_id).then(|| {
192192
(
193193
ExportedSymbol::ThreadLocalShim(def_id),
194194
SymbolExportInfo {

Diff for: compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
463463
mir::Rvalue::ThreadLocalRef(def_id) => {
464464
assert!(bx.cx().tcx().is_static(def_id));
465465
let layout = bx.layout_of(bx.cx().tcx().static_ptr_ty(def_id));
466-
let static_ = if !def_id.is_local() && !bx.cx().tcx().sess.target.dll_tls_export {
466+
let static_ = if !def_id.is_local() && bx.cx().tcx().needs_thread_local_shim(def_id)
467+
{
467468
let instance = ty::Instance {
468469
def: ty::InstanceDef::ThreadLocalShim(def_id),
469470
substs: ty::InternalSubsts::empty(),

Diff for: compiler/rustc_middle/src/ty/util.rs

+9
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,15 @@ impl<'tcx> TyCtxt<'tcx> {
599599
self.static_mutability(def_id) == Some(hir::Mutability::Mut)
600600
}
601601

602+
/// Returns `true` if the item pointed to by `def_id` is a thread local which needs a
603+
/// thread local shim generated.
604+
#[inline]
605+
pub fn needs_thread_local_shim(self, def_id: DefId) -> bool {
606+
!self.sess.target.dll_tls_export
607+
&& self.is_thread_local_static(def_id)
608+
&& !self.is_foreign_item(def_id)
609+
}
610+
602611
/// Returns the type a reference to the thread local takes in MIR.
603612
pub fn thread_local_ptr_ty(self, def_id: DefId) -> Ty<'tcx> {
604613
let static_ty = self.type_of(def_id).subst_identity();

Diff for: compiler/rustc_monomorphize/src/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ fn collect_items_rec<'tcx>(
464464
}
465465
}
466466

467-
if !tcx.sess.target.dll_tls_export && tcx.is_thread_local_static(def_id) {
467+
if tcx.needs_thread_local_shim(def_id) {
468468
neighbors.push(respan(
469469
starting_point.span,
470470
MonoItem::Fn(Instance {

0 commit comments

Comments
 (0)