Skip to content

Preserve public static items across LTO #29656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ pub fn is_const_fn(cstore: &cstore::CStore, did: DefId) -> bool {
decoder::is_const_fn(&*cdata, did.index)
}

pub fn is_static(cstore: &cstore::CStore, did: DefId) -> bool {
let cdata = cstore.get_crate_data(did.krate);
decoder::is_static(&*cdata, did.index)
}

pub fn is_impl(cstore: &cstore::CStore, did: DefId) -> bool {
let cdata = cstore.get_crate_data(did.krate);
decoder::is_impl(&*cdata, did.index)
Expand Down
8 changes: 8 additions & 0 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,14 @@ pub fn is_const_fn(cdata: Cmd, id: DefIndex) -> bool {
}
}

pub fn is_static(cdata: Cmd, id: DefIndex) -> bool {
let item_doc = cdata.lookup_item(id);
match item_family(item_doc) {
ImmStatic | MutStatic => true,
_ => false,
}
}

pub fn is_impl(cdata: Cmd, id: DefIndex) -> bool {
let item_doc = cdata.lookup_item(id);
match item_family(item_doc) {
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_trans/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2875,7 +2875,8 @@ pub fn trans_crate<'tcx>(tcx: &ty::ctxt<'tcx>,
sess.cstore.iter_crate_data(|cnum, _| {
let syms = csearch::get_reachable_ids(&sess.cstore, cnum);
reachable_symbols.extend(syms.into_iter().filter(|did| {
csearch::is_extern_fn(&sess.cstore, *did, shared_ccx.tcx())
csearch::is_extern_fn(&sess.cstore, *did, shared_ccx.tcx()) ||
csearch::is_static(&sess.cstore, *did)
}).map(|did| {
csearch::get_symbol(&sess.cstore, did)
}));
Expand Down
3 changes: 2 additions & 1 deletion src/test/run-make/issue-14500/foo.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
// except according to those terms.

extern void foo();
extern char FOO_STATIC;

int main() {
foo();
return 0;
return (int)FOO_STATIC;
}
3 changes: 3 additions & 0 deletions src/test/run-make/issue-14500/foo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@

#[no_mangle]
pub extern fn foo() {}

#[no_mangle]
pub static FOO_STATIC: u8 = 0;