Skip to content

Commit

Permalink
debuginfo: Don't create debuginfo for statics inlined from other crates.
Browse files Browse the repository at this point in the history
Fixes issue #13213, that is linker errors when the inlined static has been optimized out of the exporting crate.
  • Loading branch information
michaelwoerister authored and alexcrichton committed Apr 10, 2014
1 parent c26d254 commit 5099b8c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/librustc/middle/trans/debuginfo.rs
Expand Up @@ -293,6 +293,13 @@ pub fn create_global_var_metadata(cx: &CrateContext,
return;
}

// Don't create debuginfo for globals inlined from other crates. The other crate should already
// contain debuginfo for it. More importantly, the global might not even exist in un-inlined
// form anywhere which would lead to a linker errors.
if cx.external_srcs.borrow().contains_key(&node_id) {
return;
}

let var_item = cx.tcx.map.get(node_id);

let (ident, span) = match var_item {
Expand Down
27 changes: 27 additions & 0 deletions src/test/auxiliary/issue13213aux.rs
@@ -0,0 +1,27 @@
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![crate_type = "lib"]
// compile-flags:-g

pub use private::P;

pub struct S {
p: P,
}

mod private {
pub struct P {
p: i32,
}
pub static THREE: P = P { p: 3 };
}

pub static A: S = S { p: private::THREE };
26 changes: 26 additions & 0 deletions src/test/debug-info/issue13213.rs
@@ -0,0 +1,26 @@
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-android: FIXME(#10381)

// aux-build:issue13213aux.rs
extern crate issue13213aux;

// compile-flags:-g

// This tests make sure that we get no linker error when using a completely inlined static. Some
// statics that are marked with AvailableExternallyLinkage in the importing crate, may actually not
// be available because they have been optimized out from the exporting crate.
fn main() {
let b: issue13213aux::S = issue13213aux::A;
zzz();
}

fn zzz() {()}

0 comments on commit 5099b8c

Please sign in to comment.