[llvm] d797c2f - [DebugInfo] -fdebug-prefix-map: handle '#line "file"' for asm source

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 14 20:58:29 PDT 2022


Author: Fangrui Song
Date: 2022-08-14T20:58:23-07:00
New Revision: d797c2ffdb591d10de2964907962aaacb2e360ca

URL: https://github.com/llvm/llvm-project/commit/d797c2ffdb591d10de2964907962aaacb2e360ca
DIFF: https://github.com/llvm/llvm-project/commit/d797c2ffdb591d10de2964907962aaacb2e360ca.diff

LOG: [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 https://github.com/llvm/llvm-project/issues/56609

Reviewed By: #debug-info, dblaikie, raj.khem

Differential Revision: https://reviews.llvm.org/D131848

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCDwarf.h
    llvm/lib/MC/MCContext.cpp
    llvm/test/MC/ELF/debug-hash-file.s

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCDwarf.h b/llvm/include/llvm/MC/MCDwarf.h
index 8f648900fa535..557c713575e45 100644
--- a/llvm/include/llvm/MC/MCDwarf.h
+++ b/llvm/include/llvm/MC/MCDwarf.h
@@ -387,6 +387,7 @@ class MCDwarfLineTable {
 
   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
index c6fe3fc566554..29597088a212e 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -869,7 +869,7 @@ void MCContext::RemapDebugPaths() {
   // 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 @@ void MCContext::RemapDebugPaths() {
       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
index 9d4cf6ae68bdc..99e3d6dca9bba 100644
--- 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:


        


More information about the llvm-commits mailing list