Skip to content

Commit 892b50b

Browse files
committed
Preserve public static items across LTO
1 parent 02d9f29 commit 892b50b

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

src/librustc/metadata/csearch.rs

+5
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ pub fn is_const_fn(cstore: &cstore::CStore, did: DefId) -> bool {
344344
decoder::is_const_fn(&*cdata, did.index)
345345
}
346346

347+
pub fn is_static(cstore: &cstore::CStore, did: DefId) -> bool {
348+
let cdata = cstore.get_crate_data(did.krate);
349+
decoder::is_static(&*cdata, did.index)
350+
}
351+
347352
pub fn is_impl(cstore: &cstore::CStore, did: DefId) -> bool {
348353
let cdata = cstore.get_crate_data(did.krate);
349354
decoder::is_impl(&*cdata, did.index)

src/librustc/metadata/decoder.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,14 @@ pub fn is_const_fn(cdata: Cmd, id: DefIndex) -> bool {
14251425
}
14261426
}
14271427

1428+
pub fn is_static(cdata: Cmd, id: DefIndex) -> bool {
1429+
let item_doc = cdata.lookup_item(id);
1430+
match item_family(item_doc) {
1431+
ImmStatic | MutStatic => true,
1432+
_ => false,
1433+
}
1434+
}
1435+
14281436
pub fn is_impl(cdata: Cmd, id: DefIndex) -> bool {
14291437
let item_doc = cdata.lookup_item(id);
14301438
match item_family(item_doc) {

src/librustc_trans/trans/base.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2875,7 +2875,8 @@ pub fn trans_crate<'tcx>(tcx: &ty::ctxt<'tcx>,
28752875
sess.cstore.iter_crate_data(|cnum, _| {
28762876
let syms = csearch::get_reachable_ids(&sess.cstore, cnum);
28772877
reachable_symbols.extend(syms.into_iter().filter(|did| {
2878-
csearch::is_extern_fn(&sess.cstore, *did, shared_ccx.tcx())
2878+
csearch::is_extern_fn(&sess.cstore, *did, shared_ccx.tcx()) ||
2879+
csearch::is_static(&sess.cstore, *did)
28792880
}).map(|did| {
28802881
csearch::get_symbol(&sess.cstore, did)
28812882
}));

src/test/run-make/issue-14500/foo.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
// except according to those terms.
1010

1111
extern void foo();
12+
extern char FOO_STATIC;
1213

1314
int main() {
1415
foo();
15-
return 0;
16+
return (int)FOO_STATIC;
1617
}

src/test/run-make/issue-14500/foo.rs

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010

1111
#[no_mangle]
1212
pub extern fn foo() {}
13+
14+
#[no_mangle]
15+
pub static FOO_STATIC: u8 = 0;

0 commit comments

Comments
 (0)