[llvm] 3329cec - [DebugInfo] Don't join DW_AT_comp_dir and directories[0] for DWARF v5 line tables
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 12 14:01:56 PDT 2022
Author: Fangrui Song
Date: 2022-08-12T14:01:52-07:00
New Revision: 3329cec2f79185bafd678f310fafadba2a8c76d2
URL: https://github.com/llvm/llvm-project/commit/3329cec2f79185bafd678f310fafadba2a8c76d2
DIFF: https://github.com/llvm/llvm-project/commit/3329cec2f79185bafd678f310fafadba2a8c76d2.diff
LOG: [DebugInfo] Don't join DW_AT_comp_dir and directories[0] for DWARF v5 line tables
DWARF v5 6.2.4 The Line Number Program Header says:
> The first entry is the current directory of the compilation. Each additional
> path entry is either a full path name or is relative to the current directory of
> the compilation.
When forming a path, relative DW_AT_comp_dir and directories[0] are not supposed
to be joined together. Fix getFileNameByIndex to special case DWARF v5 DirIdx == 0.
Reviewed By: #debug-info, dblaikie
Differential Revision: https://reviews.llvm.org/D131804
Added:
Modified:
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
llvm/test/DebugInfo/X86/symbolize_function_start_v5.s
llvm/test/MC/ELF/debug-prefix-map.s
Removed:
################################################################################
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index d2ed4fe018b50..5ea4c4cded7f2 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1382,10 +1382,12 @@ bool DWARFDebugLine::Prologue::getFileNameByIndex(
IncludeDir = dwarf::toStringRef(IncludeDirectories[Entry.DirIdx - 1]);
}
- // For absolute paths only, include the compilation directory of compile unit.
- // We know that FileName is not absolute, the only way to have an absolute
- // path at this point would be if IncludeDir is absolute.
- if (Kind == FileLineInfoKind::AbsoluteFilePath && !CompDir.empty() &&
+ // For absolute paths only, include the compilation directory of compile unit,
+ // unless v5 DirIdx == 0 (IncludeDir indicates the compilation directory). We
+ // know that FileName is not absolute, the only way to have an absolute path
+ // at this point would be if IncludeDir is absolute.
+ if (Kind == FileLineInfoKind::AbsoluteFilePath &&
+ (getVersion() < 5 || Entry.DirIdx != 0) && !CompDir.empty() &&
!isPathAbsoluteOnWindowsOrPosix(IncludeDir))
sys::path::append(FilePath, Style, CompDir);
diff --git a/llvm/test/DebugInfo/X86/symbolize_function_start_v5.s b/llvm/test/DebugInfo/X86/symbolize_function_start_v5.s
index f7c6a6c7ef348..c04e973ad0c91 100644
--- a/llvm/test/DebugInfo/X86/symbolize_function_start_v5.s
+++ b/llvm/test/DebugInfo/X86/symbolize_function_start_v5.s
@@ -5,8 +5,8 @@
# RUN: llvm-symbolizer --verbose 0x0 --obj=test.o | FileCheck --check-prefix=SYM %s
# RUN: llvm-dwarfdump -lookup=0x1 test.o | FileCheck --check-prefix=LOOKUP %s
-# SYM: Filename: .{{[/\\]}}.{{[/\\]}}test.c
-# SYM: Function start filename: .{{[/\\]}}.{{[/\\]}}test.c
+# SYM: Filename: .{{[/\\]}}test.c
+# SYM: Function start filename: .{{[/\\]}}test.c
# LOOKUP: Line info: line 0, column 0, start file 'test.c', start line 1
diff --git a/llvm/test/MC/ELF/debug-prefix-map.s b/llvm/test/MC/ELF/debug-prefix-map.s
index e7b1721e637ba..4e4041d909ee5 100644
--- a/llvm/test/MC/ELF/debug-prefix-map.s
+++ b/llvm/test/MC/ELF/debug-prefix-map.s
@@ -33,14 +33,12 @@ f:
# MAP_V5: DW_AT_name [DW_FORM_string] ("src.s")
# MAP_V5: DW_AT_comp_dir [DW_FORM_string] ("src_root")
-## FIXME llvm-dwarfdump incorrectly joins include_directories[0] to DW_AT_comp_dir,
-## so there are two src_root path components.
-# MAP_V5: DW_AT_decl_file [DW_FORM_data4] ("src_root{{(/|\\)+}}src_root{{(/|\\)+}}src.s")
+# MAP_V5: DW_AT_decl_file [DW_FORM_data4] ("src_root{{(/|\\)+}}src.s")
# MAP_V5: include_directories[ 0] = .debug_line_str[0x00000000] = "src_root"
# MAPABS_V4: DW_AT_name [DW_FORM_string] ("src.s")
# MAPABS_V4: DW_AT_comp_dir [DW_FORM_string] ("{{(/|\\)+}}src_root")
-# MAPABS_V4: DW_AT_decl_file [DW_FORM_data4] ("{{(/|\\)+}}src_root{{(/|\\)+}}src.s")
+# MAPABS_V4: DW_AT_decl_file [DW_FORM_data4] ("/src_root{{(/|\\)+}}src.s")
# MAPABS_V4-NOT: .foo
# MAPABS_V5: DW_AT_name [DW_FORM_string] ("src.s")
More information about the llvm-commits
mailing list