Skip to content

Commit fba1f8f

Browse files
committed
[LLVM-3.9] Setup the compile unit information immediately
Since LLVM reversed the order of the debug info graphs, we need to have a compile unit that exists *before* any functions (`DISubprogram`s) are created. This allows the LLVM debug info builder to automatically link the functions to the compile unit.
1 parent 7420874 commit fba1f8f

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

src/librustc_trans/context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,9 @@ impl<'tcx> LocalCrateContext<'tcx> {
558558
&llmod_id[..]);
559559

560560
let dbg_cx = if shared.tcx.sess.opts.debuginfo != NoDebugInfo {
561-
Some(debuginfo::CrateDebugContext::new(llmod))
561+
let dctx = debuginfo::CrateDebugContext::new(llmod);
562+
debuginfo::metadata::compile_unit_metadata(shared, &dctx, shared.tcx.sess);
563+
Some(dctx)
562564
} else {
563565
None
564566
};

src/librustc_trans/debuginfo/metadata.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use super::utils::{debug_context, DIB, span_start, bytes_to_bits, size_and_align
1818
fn_should_be_ignored, is_node_local_to_unit};
1919
use super::namespace::mangled_name_of_item;
2020
use super::type_names::{compute_debuginfo_type_name, push_debuginfo_type_name};
21-
use super::{declare_local, VariableKind, VariableAccess};
21+
use super::{declare_local, VariableKind, VariableAccess, CrateDebugContext};
22+
use context::SharedCrateContext;
23+
use session::Session;
2224

2325
use llvm::{self, ValueRef};
2426
use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, DICompositeType};
@@ -48,7 +50,6 @@ use syntax::ast;
4850
use syntax::parse::token;
4951
use syntax_pos::{self, Span};
5052

51-
5253
// From DWARF 5.
5354
// See http://www.dwarfstd.org/ShowIssue.php?issue=140129.1
5455
const DW_LANG_RUST: c_uint = 0x1c;
@@ -981,14 +982,17 @@ fn pointer_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
981982
return ptr_metadata;
982983
}
983984

984-
pub fn compile_unit_metadata(cx: &CrateContext) -> DIDescriptor {
985-
let work_dir = &cx.sess().working_dir;
986-
let compile_unit_name = match cx.sess().local_crate_source_file {
987-
None => fallback_path(cx),
985+
pub fn compile_unit_metadata(scc: &SharedCrateContext,
986+
debug_context: &CrateDebugContext,
987+
sess: &Session)
988+
-> DIDescriptor {
989+
let work_dir = &sess.working_dir;
990+
let compile_unit_name = match sess.local_crate_source_file {
991+
None => fallback_path(scc),
988992
Some(ref abs_path) => {
989993
if abs_path.is_relative() {
990-
cx.sess().warn("debuginfo: Invalid path to crate's local root source file!");
991-
fallback_path(cx)
994+
sess.warn("debuginfo: Invalid path to crate's local root source file!");
995+
fallback_path(scc)
992996
} else {
993997
match abs_path.strip_prefix(work_dir) {
994998
Ok(ref p) if p.is_relative() => {
@@ -998,7 +1002,7 @@ pub fn compile_unit_metadata(cx: &CrateContext) -> DIDescriptor {
9981002
path2cstr(&Path::new(".").join(p))
9991003
}
10001004
}
1001-
_ => fallback_path(cx)
1005+
_ => fallback_path(scc)
10021006
}
10031007
}
10041008
}
@@ -1015,19 +1019,19 @@ pub fn compile_unit_metadata(cx: &CrateContext) -> DIDescriptor {
10151019
let split_name = "\0";
10161020
return unsafe {
10171021
llvm::LLVMDIBuilderCreateCompileUnit(
1018-
debug_context(cx).builder,
1022+
debug_context.builder,
10191023
DW_LANG_RUST,
10201024
compile_unit_name,
10211025
work_dir.as_ptr(),
10221026
producer.as_ptr(),
1023-
cx.sess().opts.optimize != config::OptLevel::No,
1027+
sess.opts.optimize != config::OptLevel::No,
10241028
flags.as_ptr() as *const _,
10251029
0,
10261030
split_name.as_ptr() as *const _)
10271031
};
10281032

1029-
fn fallback_path(cx: &CrateContext) -> CString {
1030-
CString::new(cx.link_meta().crate_name.clone()).unwrap()
1033+
fn fallback_path(scc: &::context::SharedCrateContext) -> CString {
1034+
CString::new(scc.link_meta().crate_name.clone()).unwrap()
10311035
}
10321036
}
10331037

src/librustc_trans/debuginfo/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use self::utils::{DIB, span_start, create_DIArray, is_node_local_to_unit};
1818
use self::namespace::mangled_name_of_item;
1919
use self::type_names::compute_debuginfo_type_name;
2020
use self::metadata::{type_metadata, diverging_type_metadata};
21-
use self::metadata::{file_metadata, scope_metadata, TypeMap, compile_unit_metadata};
21+
use self::metadata::{file_metadata, scope_metadata, TypeMap};
2222
use self::source_loc::InternalDebugLocation::{self, UnknownLocation};
2323

2424
use llvm;
@@ -50,7 +50,7 @@ pub mod gdb;
5050
mod utils;
5151
mod namespace;
5252
mod type_names;
53-
mod metadata;
53+
pub mod metadata;
5454
mod create_scope_map;
5555
mod source_loc;
5656

@@ -168,7 +168,6 @@ pub fn finalize(cx: &CrateContext) {
168168
}
169169

170170
debug!("finalize");
171-
let _ = compile_unit_metadata(cx);
172171

173172
if gdb::needs_gdb_debug_scripts_section(cx) {
174173
// Add a .debug_gdb_scripts section to this compile-unit. This will

0 commit comments

Comments
 (0)