Skip to content

Commit d485a51

Browse files
committed
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.
1 parent 7cffc9b commit d485a51

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/librustc_trans/trans/foreign.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use syntax::attr;
4040
use syntax::codemap::Span;
4141
use syntax::parse::token::{InternedString, special_idents};
4242
use syntax::ast;
43+
use syntax::attr::AttrMetaMethods;
4344

4445
use rustc_front::print::pprust;
4546
use rustc_front::hir;
@@ -119,8 +120,8 @@ pub fn register_static(ccx: &CrateContext,
119120
let llty = type_of::type_of(ccx, ty);
120121

121122
let ident = link_name(foreign_item);
122-
match attr::first_attr_value_str_by_name(&foreign_item.attrs,
123-
"linkage") {
123+
let c = match attr::first_attr_value_str_by_name(&foreign_item.attrs,
124+
"linkage") {
124125
// If this is a static with a linkage specified, then we need to handle
125126
// it a little specially. The typesystem prevents things like &T and
126127
// extern "C" fn() from being non-null, so we can't just declare a
@@ -165,7 +166,16 @@ pub fn register_static(ccx: &CrateContext,
165166
}
166167
None => // Generate an external declaration.
167168
declare::declare_global(ccx, &ident[..], llty),
169+
};
170+
171+
// Handle thread-local external statics.
172+
for attr in foreign_item.attrs.iter() {
173+
if attr.check_name("thread_local") {
174+
llvm::set_thread_local(c, true);
175+
}
168176
}
177+
178+
return c;
169179
}
170180

171181
// only use this for foreign function ABIs and glue, use `get_extern_rust_fn` for Rust functions

0 commit comments

Comments
 (0)