Report that we do not support foreign thread local statics.

This commit is contained in:
Vytautas Astrauskas
2020-04-06 14:00:45 -07:00
parent 1f33f04fd4
commit ed9c7d168b
+9 -2
View File
@@ -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)
},