Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/librustc_trans/trans/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/test/auxiliary/thread-local-extern-static.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[thread_local]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests will need license header blocks, and I would expect at least that each test would require #![feature(thread_local)], although I suspect the one below may not require it (could you make sure?)

pub static FOO: u32 = 3;
10 changes: 10 additions & 0 deletions src/test/run-pass/thread-local-extern-static.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extern crate thread_local_extern_static;

extern {
#[thread_local]
static FOO: u32;
}

fn main() {
assert_eq!(FOO, 3);
}