1
Fork 0

Preserve public static items across LTO

This commit is contained in:
arcnmx 2015-11-06 04:51:03 -05:00
parent 02d9f29455
commit 892b50ba74
5 changed files with 20 additions and 2 deletions

View file

@ -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)

View file

@ -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) {

View file

@ -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)
}));

View file

@ -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;
}

View file

@ -10,3 +10,6 @@
#[no_mangle]
pub extern fn foo() {}
#[no_mangle]
pub static FOO_STATIC: u8 = 0;