Skip to content

Commit e4aa104

Browse files
MaskRaytru
authored andcommitted
[DebugInfo] -fdebug-prefix-map: handle '#line "file"' for asm source
`getContext().setMCLineTableRootFile` (from D62074) sets `RootFile.Name` to `FirstCppHashFilename`. `RootFile.Name` is not processed by -fdebug-prefix-map and will go to DW_TAG_compile_unit's DT_AT_name and DW_TAG_label's DW_AT_decl_file. Remap `RootFile.Name`. Fix another issue reported by #56609 Reviewed By: #debug-info, dblaikie, raj.khem Differential Revision: https://reviews.llvm.org/D131848 (cherry picked from commit d797c2f)
1 parent 655a1cb commit e4aa104

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

llvm/include/llvm/MC/MCDwarf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ class MCDwarfLineTable {
387387

388388
bool hasRootFile() const { return !Header.RootFile.Name.empty(); }
389389

390+
MCDwarfFile &getRootFile() { return Header.RootFile; }
390391
const MCDwarfFile &getRootFile() const { return Header.RootFile; }
391392

392393
// Report whether MD5 usage has been consistent (all-or-none).

llvm/lib/MC/MCContext.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,14 +869,20 @@ void MCContext::RemapDebugPaths() {
869869
// Remap compilation directory.
870870
remapDebugPath(CompilationDir);
871871

872-
// Remap MCDwarfDirs in all compilation units.
872+
// Remap MCDwarfDirs and RootFile.Name in all compilation units.
873873
SmallString<256> P;
874874
for (auto &CUIDTablePair : MCDwarfLineTablesCUMap) {
875875
for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs()) {
876876
P = Dir;
877877
remapDebugPath(P);
878878
Dir = std::string(P);
879879
}
880+
881+
// Used by DW_TAG_compile_unit's DT_AT_name and DW_TAG_label's
882+
// DW_AT_decl_file for DWARF v5 generated for assembly source.
883+
P = CUIDTablePair.second.getRootFile().Name;
884+
remapDebugPath(P);
885+
CUIDTablePair.second.getRootFile().Name = std::string(P);
880886
}
881887
}
882888

llvm/test/MC/ELF/debug-hash-file.s

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@
2323
// DWARF5-NEXT: dir_index: 0
2424
// DWARF5-NOT: file_names[ 1]:
2525

26+
// RUN: llvm-mc -triple=x86_64 -filetype=obj -g -dwarf-version=4 -fdebug-prefix-map=/MyTest=/src_root %s -o %t.4.o
27+
// RUN: llvm-dwarfdump -debug-info -debug-line %t.4.o | FileCheck %s --check-prefixes=MAP,MAP_V4
28+
// RUN: llvm-mc -triple=x86_64 -filetype=obj -g -dwarf-version=5 -fdebug-prefix-map=/MyTest=/src_root %s -o %t.5.o
29+
// RUN: llvm-dwarfdump -debug-info -debug-line %t.5.o | FileCheck %s --check-prefixes=MAP,MAP_V5
30+
31+
// MAP-LABEL: DW_TAG_compile_unit
32+
// MAP: DW_AT_name ("/src_root/Inputs{{(/|\\)+}}other.S")
33+
// MAP-LABEL: DW_TAG_label
34+
// MAP: DW_AT_decl_file ("/src_root/Inputs{{(/|\\)+}}other.S")
35+
36+
// MAP_V4: include_directories[ 1] = "/src_root/Inputs"
37+
// MAP_V4-NEXT: file_names[ 1]:
38+
// MAP_V4-NEXT: name: "other.S"
39+
// MAP_V4-NEXT: dir_index: 1
40+
41+
// MAP_V5: include_directories[ 0] = "{{.*}}"
42+
// MAP_V5-NEXT: file_names[ 0]:
43+
// MAP_V5-NEXT: name: "/src_root/Inputs/other.S"
44+
// MAP_V5-NEXT: dir_index: 0
45+
2646
# 1 "/MyTest/Inputs/other.S"
2747

2848
foo:

0 commit comments

Comments
 (0)