diff --git a/llvm/include/llvm/MC/MCDwarf.h b/llvm/include/llvm/MC/MCDwarf.h --- a/llvm/include/llvm/MC/MCDwarf.h +++ b/llvm/include/llvm/MC/MCDwarf.h @@ -387,6 +387,7 @@ bool hasRootFile() const { return !Header.RootFile.Name.empty(); } + MCDwarfFile &getRootFile() { return Header.RootFile; } const MCDwarfFile &getRootFile() const { return Header.RootFile; } // Report whether MD5 usage has been consistent (all-or-none). diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -869,7 +869,7 @@ // Remap compilation directory. remapDebugPath(CompilationDir); - // Remap MCDwarfDirs in all compilation units. + // Remap MCDwarfDirs and RootFile.Name in all compilation units. SmallString<256> P; for (auto &CUIDTablePair : MCDwarfLineTablesCUMap) { for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs()) { @@ -877,6 +877,12 @@ remapDebugPath(P); Dir = std::string(P); } + + // Used by DW_TAG_compile_unit's DT_AT_name and DW_TAG_label's + // DW_AT_decl_file for DWARF v5 generated for assembly source. + P = CUIDTablePair.second.getRootFile().Name; + remapDebugPath(P); + CUIDTablePair.second.getRootFile().Name = std::string(P); } } diff --git a/llvm/test/MC/ELF/debug-hash-file.s b/llvm/test/MC/ELF/debug-hash-file.s --- a/llvm/test/MC/ELF/debug-hash-file.s +++ b/llvm/test/MC/ELF/debug-hash-file.s @@ -23,6 +23,26 @@ // DWARF5-NEXT: dir_index: 0 // DWARF5-NOT: file_names[ 1]: +// RUN: llvm-mc -triple=x86_64 -filetype=obj -g -dwarf-version=4 -fdebug-prefix-map=/MyTest=/src_root %s -o %t.4.o +// RUN: llvm-dwarfdump -debug-info -debug-line %t.4.o | FileCheck %s --check-prefixes=MAP,MAP_V4 +// RUN: llvm-mc -triple=x86_64 -filetype=obj -g -dwarf-version=5 -fdebug-prefix-map=/MyTest=/src_root %s -o %t.5.o +// RUN: llvm-dwarfdump -debug-info -debug-line %t.5.o | FileCheck %s --check-prefixes=MAP,MAP_V5 + +// MAP-LABEL: DW_TAG_compile_unit +// MAP: DW_AT_name ("/src_root{{(/|\\)+}}Inputs/other.S") +// MAP-LABEL: DW_TAG_label +// MAP: DW_AT_decl_file ("/src_root{{(/|\\)+}}Inputs/other.S") + +// MAP_V4: include_directories[ 1] = "/src_root{{(/|\\)+}}Inputs" +// MAP_V4-NEXT: file_names[ 1]: +// MAP_V4-NEXT: name: "other.S" +// MAP_V4-NEXT: dir_index: 1 + +// MAP_V5: include_directories[ 0] = "{{.*}}" +// MAP_V5-NEXT: file_names[ 0]: +// MAP_V5-NEXT: name: "/src_root{{(/|\\)+}}Inputs/other.S" +// MAP_V5-NEXT: dir_index: 0 + # 1 "/MyTest/Inputs/other.S" foo: