Skip to content

Commit 5099b8c

Browse files
michaelwoeristeralexcrichton
authored andcommitted
debuginfo: Don't create debuginfo for statics inlined from other crates.
Fixes issue #13213, that is linker errors when the inlined static has been optimized out of the exporting crate.
1 parent c26d254 commit 5099b8c

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

src/librustc/middle/trans/debuginfo.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,13 @@ pub fn create_global_var_metadata(cx: &CrateContext,
293293
return;
294294
}
295295

296+
// Don't create debuginfo for globals inlined from other crates. The other crate should already
297+
// contain debuginfo for it. More importantly, the global might not even exist in un-inlined
298+
// form anywhere which would lead to a linker errors.
299+
if cx.external_srcs.borrow().contains_key(&node_id) {
300+
return;
301+
}
302+
296303
let var_item = cx.tcx.map.get(node_id);
297304

298305
let (ident, span) = match var_item {

src/test/auxiliary/issue13213aux.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type = "lib"]
12+
// compile-flags:-g
13+
14+
pub use private::P;
15+
16+
pub struct S {
17+
p: P,
18+
}
19+
20+
mod private {
21+
pub struct P {
22+
p: i32,
23+
}
24+
pub static THREE: P = P { p: 3 };
25+
}
26+
27+
pub static A: S = S { p: private::THREE };

src/test/debug-info/issue13213.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-android: FIXME(#10381)
12+
13+
// aux-build:issue13213aux.rs
14+
extern crate issue13213aux;
15+
16+
// compile-flags:-g
17+
18+
// This tests make sure that we get no linker error when using a completely inlined static. Some
19+
// statics that are marked with AvailableExternallyLinkage in the importing crate, may actually not
20+
// be available because they have been optimized out from the exporting crate.
21+
fn main() {
22+
let b: issue13213aux::S = issue13213aux::A;
23+
zzz();
24+
}
25+
26+
fn zzz() {()}

0 commit comments

Comments
 (0)