about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Neumann <mneumann@ntecs.de>2016-01-12 20:39:22 +0100
committerMichael Neumann <mneumann@ntecs.de>2016-01-12 20:39:22 +0100
commitd485a511d011aca349c7cda97775392981bf5d5f (patch)
tree716798eea81f00bfa23592fb397c1d92935b53ff
parent7cffc9b1951f5e51ad19bf3b854f7afa8073aadb (diff)
Recognize #[thread_local] on extern static. Fixes #30795.
This will correctly add the thread_local attribute to the external static
variable "errno":

    extern {
         #[thread_local]
         static errno: c_int;
    }

Before this commit, the thread_local attribute is ignored.
-rw-r--r--src/librustc_trans/trans/foreign.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/librustc_trans/trans/foreign.rs b/src/librustc_trans/trans/foreign.rs
index 01fd36867ff..01ce9d51746 100644
--- a/src/librustc_trans/trans/foreign.rs
+++ b/src/librustc_trans/trans/foreign.rs
@@ -40,6 +40,7 @@ use syntax::attr;
 use syntax::codemap::Span;
 use syntax::parse::token::{InternedString, special_idents};
 use syntax::ast;
+use syntax::attr::AttrMetaMethods;
 
 use rustc_front::print::pprust;
 use rustc_front::hir;
@@ -119,8 +120,8 @@ pub fn register_static(ccx: &CrateContext,
     let llty = type_of::type_of(ccx, ty);
 
     let ident = link_name(foreign_item);
-    match attr::first_attr_value_str_by_name(&foreign_item.attrs,
-                                             "linkage") {
+    let c = match attr::first_attr_value_str_by_name(&foreign_item.attrs,
+                                                     "linkage") {
         // If this is a static with a linkage specified, then we need to handle
         // it a little specially. The typesystem prevents things like &T and
         // extern "C" fn() from being non-null, so we can't just declare a
@@ -165,7 +166,16 @@ pub fn register_static(ccx: &CrateContext,
         }
         None => // Generate an external declaration.
             declare::declare_global(ccx, &ident[..], llty),
+    };
+
+    // Handle thread-local external statics.
+    for attr in foreign_item.attrs.iter() {
+        if attr.check_name("thread_local") {
+            llvm::set_thread_local(c, true);
+        }
     }
+
+    return c;
 }
 
 // only use this for foreign function ABIs and glue, use `get_extern_rust_fn` for Rust functions