From ed9c7d168b0ded92e4bfb53acd2f71b61b54e306 Mon Sep 17 00:00:00 2001 From: Vytautas Astrauskas Date: Mon, 6 Apr 2020 14:00:45 -0700 Subject: [PATCH] Report that we do not support foreign thread local statics. --- src/machine.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/machine.rs b/src/machine.rs index 7ed5f1e5539f..2f0aa9157535 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -14,6 +14,7 @@ use rustc_ast::attr; use rustc_data_structures::fx::FxHashMap; use rustc_middle::{ + middle::codegen_fn_attrs::CodegenFnAttrFlags, mir, ty::{ self, @@ -21,7 +22,7 @@ TyCtxt, }, }; -use rustc_span::symbol::{sym, Symbol}; +use rustc_span::{def_id::DefId, symbol::{sym, Symbol}}; use rustc_target::abi::{LayoutOf, Size}; use crate::*; @@ -459,8 +460,14 @@ fn access_local( fn canonical_alloc_id(mem: &Memory<'mir, 'tcx, Self>, id: AllocId) -> AllocId { let tcx = mem.tcx; let alloc = tcx.alloc_map.lock().get(id); + fn is_thread_local<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool { + tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) + } match alloc { Some(GlobalAlloc::Static(def_id)) if tcx.is_foreign_item(def_id) => { + if is_thread_local(*tcx, def_id) { + unimplemented!("Foreign thread local statics are not supported yet."); + } // Figure out if this is an extern static, and if yes, which one. let attrs = tcx.get_attrs(def_id); let link_name = match attr::first_attr_value_str_by_name(&attrs, sym::link_name) { @@ -476,7 +483,7 @@ fn canonical_alloc_id(mem: &Memory<'mir, 'tcx, Self>, id: AllocId) -> AllocId { id } }, - Some(GlobalAlloc::Static(def_id)) if tcx.has_attr(def_id, sym::thread_local) => { + Some(GlobalAlloc::Static(def_id)) if is_thread_local(*tcx, def_id) => { // We have a thread local, so we need to get a unique allocation id for it. mem.extra.tls.get_or_register_allocation(*tcx, id) },