- 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) {
- Some(name) => name,
- None => tcx.item_name(def_id),
- };
- // Check if we know this one.
- if let Some(canonical_id) = mem.extra.extern_statics.get(&link_name) {
- trace!("canonical_alloc_id: {:?} ({}) -> {:?}", id, link_name, canonical_id);
- *canonical_id
- } else {
- // Return original id; `Memory::get_static_alloc` will throw an error.
- id
- }
- },
- 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)
- },
+ // Figure out if this is an extern static, and if yes, which one.
+ let def_id = match tcx.alloc_map.lock().get(id) {
+ Some(GlobalAlloc::Static(def_id)) if tcx.is_foreign_item(def_id) => def_id,