From 81424389382316220944322305c9935119dba5ce Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 21 Mar 2012 18:56:20 -0400 Subject: [PATCH] Avoid mangling names differently in debug builds to work around a build error. Fix up file name and path debug information, and build one compilation unit for a crate instead of one per source file. --- Makefile.in | 3 ++ mk/host.mk | 9 ++-- mk/platform.mk | 1 + src/rustc/driver/driver.rs | 13 +++-- src/rustc/driver/rustc.rs | 2 +- src/rustc/middle/trans/base.rs | 7 ++- src/rustc/middle/trans/common.rs | 2 +- src/rustc/middle/trans/debuginfo.rs | 78 ++++++++++++++++------------- src/rustdoc/astsrv.rs | 2 +- 9 files changed, 65 insertions(+), 52 deletions(-) diff --git a/Makefile.in b/Makefile.in index 3318264253f..fffd9414228 100644 --- a/Makefile.in +++ b/Makefile.in @@ -114,6 +114,9 @@ CFG_LIBRUSTC :=$(call CFG_LIB_NAME,rustc) STDLIB_GLOB :=$(call CFG_LIB_GLOB,std) CORELIB_GLOB :=$(call CFG_LIB_GLOB,core) LIBRUSTC_GLOB :=$(call CFG_LIB_GLOB,rustc) +STDLIB_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,std) +CORELIB_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,core) +LIBRUSTC_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,rustc) # version-string calculation CFG_GIT_DIR := $(CFG_SRC_DIR).git diff --git a/mk/host.mk b/mk/host.mk index e7692512235..a92d10faf4b 100644 --- a/mk/host.mk +++ b/mk/host.mk @@ -31,7 +31,8 @@ $$(HLIB$(2)_H_$(4))/$$(CFG_LIBRUSTC): \ $$(HSTDLIB_DEFAULT$(2)_H_$(3)) @$$(call E, cp: $$@) $$(Q)cp $$< $$@ - $$(Q)cp $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBRUSTC_GLOB) \ + $$(Q)cp -R $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBRUSTC_GLOB) \ + $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBRUSTC_DSYM_GLOB) \ $$(HLIB$(2)_H_$(4)) $$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME): \ @@ -44,7 +45,8 @@ $$(HLIB$(2)_H_$(4))/$$(CFG_CORELIB): \ $$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME) @$$(call E, cp: $$@) $$(Q)cp $$< $$@ - $$(Q)cp $$(TLIB$(1)_T_$(4)_H_$(3))/$(CORELIB_GLOB) \ + $$(Q)cp -R $$(TLIB$(1)_T_$(4)_H_$(3))/$(CORELIB_GLOB) \ + $$(TLIB$(1)_T_$(4)_H_$(3))/$(CORELIB_DSYM_GLOB) \ $$(HLIB$(2)_H_$(4)) $$(HLIB$(2)_H_$(4))/$$(CFG_STDLIB): \ @@ -53,7 +55,8 @@ $$(HLIB$(2)_H_$(4))/$$(CFG_STDLIB): \ $$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME) @$$(call E, cp: $$@) $$(Q)cp $$< $$@ - $$(Q)cp $$(TLIB$(1)_T_$(4)_H_$(3))/$(STDLIB_GLOB) \ + $$(Q)cp -R $$(TLIB$(1)_T_$(4)_H_$(3))/$(STDLIB_GLOB) \ + $$(TLIB$(1)_T_$(4)_H_$(3))/$(STDLIB_DSYM_GLOB) \ $$(HLIB$(2)_H_$(4)) $$(HLIB$(2)_H_$(4))/libcore.rlib: \ diff --git a/mk/platform.mk b/mk/platform.mk index ee09a4811a6..b9c02591cf5 100644 --- a/mk/platform.mk +++ b/mk/platform.mk @@ -85,6 +85,7 @@ endif ifneq ($(findstring darwin,$(CFG_OSTYPE)),) CFG_LIB_NAME=lib$(1).dylib CFG_LIB_GLOB=lib$(1)-*.dylib + CFG_LIB_DSYM_GLOB=lib$(1)-*.dylib.dSYM CFG_UNIXY := 1 CFG_LDENV := DYLD_LIBRARY_PATH CFG_GCCISH_LINK_FLAGS += -dynamiclib -lpthread -framework CoreServices -Wl,-no_compact_unwind diff --git a/src/rustc/driver/driver.rs b/src/rustc/driver/driver.rs index c9e7c0c5da1..2df43dfd978 100644 --- a/src/rustc/driver/driver.rs +++ b/src/rustc/driver/driver.rs @@ -449,19 +449,18 @@ fn build_session_options(match: getopts::match, ret sopts; } -fn build_session(sopts: @session::options, input: str, +fn build_session(sopts: @session::options, demitter: diagnostic::emitter) -> session { let codemap = codemap::new_codemap(); let diagnostic_handler = diagnostic::mk_handler(some(demitter)); let span_diagnostic_handler = diagnostic::mk_span_handler(diagnostic_handler, codemap); - build_session_(sopts, input, codemap, demitter, - span_diagnostic_handler) + build_session_(sopts, codemap, demitter, span_diagnostic_handler) } fn build_session_( - sopts: @session::options, input: str, + sopts: @session::options, codemap: codemap::codemap, demitter: diagnostic::emitter, span_diagnostic_handler: diagnostic::span_handler @@ -488,7 +487,7 @@ fn build_session_( span_diagnostic: span_diagnostic_handler, filesearch: filesearch, mutable building_library: false, - working_dir: path::dirname(input)} + working_dir: os::getcwd()} } fn parse_pretty(sess: session, &&name: str) -> pp_mode { @@ -636,7 +635,7 @@ fn test_switch_implies_cfg_test() { getopts::fail_str(f); } }; let sessopts = build_session_options(match, diagnostic::emit); - let sess = build_session(sessopts, "", diagnostic::emit); + let sess = build_session(sessopts, diagnostic::emit); let cfg = build_configuration(sess, "whatever", "whatever"); assert (attr::contains_name(cfg, "test")); } @@ -652,7 +651,7 @@ fn test_switch_implies_cfg_test_unless_cfg_test() { getopts::fail_str(f); } }; let sessopts = build_session_options(match, diagnostic::emit); - let sess = build_session(sessopts, "", diagnostic::emit); + let sess = build_session(sessopts, diagnostic::emit); let cfg = build_configuration(sess, "whatever", "whatever"); let test_items = attr::find_meta_items_by_name(cfg, "test"); assert (vec::len(test_items) == 1u); diff --git a/src/rustc/driver/rustc.rs b/src/rustc/driver/rustc.rs index f1debe39f4c..f2ed6817244 100644 --- a/src/rustc/driver/rustc.rs +++ b/src/rustc/driver/rustc.rs @@ -99,7 +99,7 @@ fn run_compiler(args: [str], demitter: diagnostic::emitter) { }; let sopts = build_session_options(match, demitter); - let sess = build_session(sopts, ifile, demitter); + let sess = build_session(sopts, demitter); let odir = getopts::opt_maybe_str(match, "out-dir"); let ofile = getopts::opt_maybe_str(match, "o"); let cfg = build_configuration(sess, binary, ifile); diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index 648ac24208a..fba5e20da6a 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -402,7 +402,7 @@ fn declare_tydesc(ccx: @crate_ctxt, t: ty::t) -> @tydesc_info { llsize = llsize_of(ccx, llty); llalign = llalign_of(ccx, llty); let name; - if ccx.sess.opts.debuginfo { + if false /*ccx.sess.opts.debuginfo*/ { //XXX this triggers duplicate LLVM symbols name = mangle_internal_name_by_type_only(ccx, t, "tydesc"); } else { name = mangle_internal_name_by_seq(ccx, "tydesc"); } note_unique_llvm_symbol(ccx, name); @@ -427,7 +427,7 @@ fn declare_generic_glue(ccx: @crate_ctxt, t: ty::t, llfnty: TypeRef, name: str) -> ValueRef { let name = name; let fn_nm; - if ccx.sess.opts.debuginfo { + if false /*ccx.sess.opts.debuginfo*/ { //XXX this triggers duplicate LLVM symbols fn_nm = mangle_internal_name_by_type_only(ccx, t, "glue_" + name); } else { fn_nm = mangle_internal_name_by_seq(ccx, "glue_" + name); @@ -4672,8 +4672,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt, lib::llvm::associate_type(tn, "tydesc", tydesc_type); let crate_map = decl_crate_map(sess, link_meta.name, llmod); let dbg_cx = if sess.opts.debuginfo { - option::some(@{llmetadata: map::int_hash(), - names: new_namegen()}) + option::some(debuginfo::mk_ctxt(llmod_id)) } else { option::none }; diff --git a/src/rustc/middle/trans/common.rs b/src/rustc/middle/trans/common.rs index df5f03e9922..ba547c6aecd 100644 --- a/src/rustc/middle/trans/common.rs +++ b/src/rustc/middle/trans/common.rs @@ -114,7 +114,7 @@ fn new_namegen() -> namegen { builder: BuilderRef_res, shape_cx: shape::ctxt, crate_map: ValueRef, - dbg_cx: option<@debuginfo::debug_ctxt>, + dbg_cx: option, mutable do_not_commit_warning_issued: bool}; // Types used for llself. diff --git a/src/rustc/middle/trans/debuginfo.rs b/src/rustc/middle/trans/debuginfo.rs index 98b5224f9ff..1088ef59ac8 100644 --- a/src/rustc/middle/trans/debuginfo.rs +++ b/src/rustc/middle/trans/debuginfo.rs @@ -1,3 +1,4 @@ +import std::map; import std::map::hashmap; import lib::llvm::llvm; import lib::llvm::ValueRef; @@ -17,6 +18,7 @@ export create_arg; export update_source_pos; export debug_ctxt; +export mk_ctxt; const LLVMDebugVersion: int = (9 << 16); @@ -75,8 +77,7 @@ fn llnull() -> ValueRef unsafe { fn add_named_metadata(cx: @crate_ctxt, name: str, val: ValueRef) { str::as_c_str(name, {|sbuf| - llvm::LLVMAddNamedMetadataOperand(cx.llmod, sbuf, - val) + llvm::LLVMAddNamedMetadataOperand(cx.llmod, sbuf, val) }) } @@ -84,9 +85,16 @@ fn add_named_metadata(cx: @crate_ctxt, name: str, val: ValueRef) { type debug_ctxt = { llmetadata: metadata_cache, - names: namegen + names: namegen, + crate_file: str }; +fn mk_ctxt(crate: str) -> debug_ctxt { + {llmetadata: map::int_hash(), + names: new_namegen(), + crate_file: crate} +} + fn update_cache(cache: metadata_cache, mdtag: int, val: debug_metadata) { let existing = if cache.contains_key(mdtag) { cache.get(mdtag) @@ -99,7 +107,7 @@ fn update_cache(cache: metadata_cache, mdtag: int, val: debug_metadata) { type metadata = {node: ValueRef, data: T}; type file_md = {path: str}; -type compile_unit_md = {path: str}; +type compile_unit_md = {name: str}; type subprogram_md = {id: ast::node_id}; type local_var_md = {id: ast::node_id}; type tydesc_md = {hash: uint}; @@ -154,41 +162,35 @@ fn cached_metadata(cache: metadata_cache, mdtag: int, ret option::none; } -fn create_compile_unit(cx: @crate_ctxt, full_path: str) +fn create_compile_unit(cx: @crate_ctxt) -> @metadata unsafe { let cache = get_cache(cx); + let crate_name = option::get(cx.dbg_cx).crate_file; let tg = CompileUnitTag; alt cached_metadata::<@metadata>(cache, tg, - {|md| md.data.path == full_path}) { + {|md| md.data.name == crate_name}) { option::some(md) { ret md; } option::none {} } - let work_dir = cx.sess.working_dir; - let file_path = if str::starts_with(full_path, work_dir) { - str::slice(full_path, str::len(work_dir), str::len(full_path)) - } else { - full_path - }; + let (_, work_dir) = get_file_path_and_dir(cx.sess.working_dir, + crate_name); let unit_metadata = [lltag(tg), llunused(), lli32(DW_LANG_RUST), - llstr(file_path), + llstr(crate_name), llstr(work_dir), llstr(#env["CFG_VERSION"]), - lli1(false), // main compile unit + lli1(true), // deprecated: main compile unit lli1(cx.sess.opts.optimize != 0u), llstr(""), // flags (???) lli32(0) // runtime version (???) - // list of enum types - // list of retained values - // list of subprograms - // list of global variables ]; let unit_node = llmdnode(unit_metadata); add_named_metadata(cx, "llvm.dbg.cu", unit_node); - let mdval = @{node: unit_node, data: {path: full_path}}; + let mdval = @{node: unit_node, data: {name: crate_name}}; update_cache(cache, tg, compile_unit_metadata(mdval)); + ret mdval; } @@ -196,6 +198,15 @@ fn get_cache(cx: @crate_ctxt) -> metadata_cache { option::get(cx.dbg_cx).llmetadata } +fn get_file_path_and_dir(work_dir: str, full_path: str) -> (str, str) { + (if str::starts_with(full_path, work_dir) { + str::slice(full_path, str::len(work_dir) + 1u, + str::len(full_path)) + } else { + full_path + }, work_dir) +} + fn create_file(cx: @crate_ctxt, full_path: str) -> @metadata { let cache = get_cache(cx);; let tg = FileDescriptorTag; @@ -205,12 +216,12 @@ fn create_file(cx: @crate_ctxt, full_path: str) -> @metadata { option::none {} } - let fname = path::basename(full_path); - let path = path::dirname(full_path); - let unit_node = create_compile_unit(cx, full_path).node; + let (file_path, work_dir) = get_file_path_and_dir(cx.sess.working_dir, + full_path); + let unit_node = create_compile_unit(cx).node; let file_md = [lltag(tg), - llstr(fname), - llstr(path), + llstr(file_path), + llstr(work_dir), unit_node]; let val = llmdnode(file_md); let mdval = @{node: val, data: {path: full_path}}; @@ -310,7 +321,7 @@ fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: ast::prim_ty, span: span) let fname = filename_from_span(cx, span); let file_node = create_file(cx, fname); - let cu_node = create_compile_unit(cx, fname); + let cu_node = create_compile_unit(cx); let (size, align) = size_and_align_of(cx, t); let lldata = [lltag(tg), cu_node.node, @@ -463,7 +474,7 @@ fn create_composite_type(type_tag: int, name: str, file: ValueRef, line: int, lli32(line), // source line definition lli64(size), // size of members lli64(align), // align - lli64(offset), // offset + lli32/*64*/(offset), // offset lli32(0), // flags if option::is_none(derived) { llnull() @@ -781,13 +792,9 @@ fn create_function(fcx: fn_ctxt) -> @metadata { option::none {} } - let path = path_str(fcx.path); - let loc = codemap::lookup_char_pos(cx.sess.codemap, sp.lo); let file_node = create_file(cx, loc.file.name).node; - let key = if cx.item_symbols.contains_key(fcx.id) { fcx.id } else { id }; - let mangled = cx.item_symbols.get(key); let ty_node = if cx.sess.opts.extra_debuginfo { alt ret_ty.node { ast::ty_nil { llnull() } @@ -804,17 +811,17 @@ fn create_function(fcx: fn_ctxt) -> @metadata { llunused(), file_node, llstr(ident), - llstr(path), //XXX fully-qualified C++ name - llstr(mangled), //XXX MIPS name????? + llstr(ident), //XXX fully-qualified C++ name + llstr(""), //XXX MIPS name????? file_node, lli32(loc.line as int), sub_node, lli1(false), //XXX static (check export) - lli1(true), // not extern + lli1(true), // defined in compilation unit lli32(DW_VIRTUALITY_none), // virtual-ness lli32(0i), //index into virt func - llnull(), // base type with vtbl - lli1(false), // artificial + /*llnull()*/ lli32(0), // base type with vtbl + lli32(256), // flags lli1(cx.sess.opts.optimize != 0u), fcx.llfn //list of template params @@ -825,5 +832,6 @@ fn create_function(fcx: fn_ctxt) -> @metadata { add_named_metadata(cx, "llvm.dbg.sp", val); let mdval = @{node: val, data: {id: id}}; update_cache(cache, SubprogramTag, subprogram_metadata(mdval)); + ret mdval; } diff --git a/src/rustdoc/astsrv.rs b/src/rustdoc/astsrv.rs index 4773f67a0ad..2b0d502cb09 100644 --- a/src/rustdoc/astsrv.rs +++ b/src/rustdoc/astsrv.rs @@ -155,7 +155,7 @@ fn build_session() -> (session::session, @mutable bool) { let error_handlers = build_error_handlers(codemap); let {emitter, span_handler, ignore_errors} = error_handlers; - let session = driver::build_session_(sopts, ".", codemap, emitter, + let session = driver::build_session_(sopts, codemap, emitter, span_handler); (session, ignore_errors) } -- GitLab