authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-03 13:02:46-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-03 13:46:08-04:00
loge673d865fb2dfa6588505d572765ea8c5b4470ee
tree67eeb6401b166803cb7d23b6c5cbd5501b60ede5
parente9530ce97bbbda9724dce3d6755217fd7880955c
signaturelock-open Commit is signed but in an unrecognized format.

fix stack traces on macos when passing absolute path to root source file

The comment added by this commit is copied here: For macOS stack traces, we want to avoid having to parse the compilation unit debug info. As long as each debug info file has a path independent of the compilation unit directory (DW_AT_comp_dir), then we never have to look at the compilation unit debug info. If we provide an absolute path to LLVM here for the compilation unit debug info, LLVM will emit DWARF info that depends on DW_AT_comp_dir. To avoid this, we pass "." for the compilation unit directory. This forces each debug file to have a directory rather than be relative to DW_AT_comp_dir. According to DWARF 5, debug files will no longer reference DW_AT_comp_dir, for the purpose of being able to support the common practice of stripping all but the line number sections from an executable. closes #2700

2 files changed, 15 insertions(+), 1 deletions(-)

src/codegen.cpp+14-1
...@@ -8457,8 +8457,21 @@ static void init(CodeGen *g) {...@@ -8457,8 +8457,21 @@ static void init(CodeGen *g) {
8457 Buf *producer = buf_sprintf("zig %d.%d.%d", ZIG_VERSION_MAJOR, ZIG_VERSION_MINOR, ZIG_VERSION_PATCH);8457 Buf *producer = buf_sprintf("zig %d.%d.%d", ZIG_VERSION_MAJOR, ZIG_VERSION_MINOR, ZIG_VERSION_PATCH);
8458 const char *flags = "";8458 const char *flags = "";
8459 unsigned runtime_version = 0;8459 unsigned runtime_version = 0;
8460
8461 // For macOS stack traces, we want to avoid having to parse the compilation unit debug
8462 // info. As long as each debug info file has a path independent of the compilation unit
8463 // directory (DW_AT_comp_dir), then we never have to look at the compilation unit debug
8464 // info. If we provide an absolute path to LLVM here for the compilation unit debug info,
8465 // LLVM will emit DWARF info that depends on DW_AT_comp_dir. To avoid this, we pass "."
8466 // for the compilation unit directory. This forces each debug file to have a directory
8467 // rather than be relative to DW_AT_comp_dir. According to DWARF 5, debug files will
8468 // no longer reference DW_AT_comp_dir, for the purpose of being able to support the
8469 // common practice of stripping all but the line number sections from an executable.
8470 const char *compile_unit_dir = target_os_is_darwin(g->zig_target->os) ? "." :
8471 buf_ptr(&g->root_package->root_src_dir);
8472
8460 ZigLLVMDIFile *compile_unit_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(g->root_out_name),8473 ZigLLVMDIFile *compile_unit_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(g->root_out_name),
8461 buf_ptr(&g->root_package->root_src_dir));8474 compile_unit_dir);
8462 g->compile_unit = ZigLLVMCreateCompileUnit(g->dbuilder, ZigLLVMLang_DW_LANG_C99(),8475 g->compile_unit = ZigLLVMCreateCompileUnit(g->dbuilder, ZigLLVMLang_DW_LANG_C99(),
8463 compile_unit_file, buf_ptr(producer), is_optimized, flags, runtime_version,8476 compile_unit_file, buf_ptr(producer), is_optimized, flags, runtime_version,
8464 "", 0, !g->strip_debug_symbols);8477 "", 0, !g->strip_debug_symbols);
src/zig_llvm.cpp+1
...@@ -842,6 +842,7 @@ const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) {...@@ -842,6 +842,7 @@ const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) {
842842
843void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module) {843void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module) {
844 unwrap(module)->addModuleFlag(Module::Warning, "Debug Info Version", DEBUG_METADATA_VERSION);844 unwrap(module)->addModuleFlag(Module::Warning, "Debug Info Version", DEBUG_METADATA_VERSION);
845 unwrap(module)->addModuleFlag(Module::Warning, "Dwarf Version", 4);
845}846}
846847
847void ZigLLVMAddModuleCodeViewFlag(LLVMModuleRef module) {848void ZigLLVMAddModuleCodeViewFlag(LLVMModuleRef module) {