[llvm] r204094 - DebugInfo: Do not rely on the compilation dir (index 0) for files in line tables shared between compilation units

David Blaikie dblaikie at gmail.com
Mon Mar 17 17:11:48 PDT 2014


Author: dblaikie
Date: Mon Mar 17 19:11:48 2014
New Revision: 204094

URL: http://llvm.org/viewvc/llvm-project?rev=204094&view=rev
Log:
DebugInfo: Do not rely on the compilation dir (index 0) for files in line tables shared between compilation units

When emitting assembly there's no support for emitting separate line
tables for each compilation unit - so LLVM emits .loc directives
producing a single line table.

Line tables have an implicit directory (index 0) equal to the
compilation directory (DW_AT_comp_dir) of the compilation unit that
references them.

If multiple compilation units (with possibly disparate compilation
directories) reference the same line table, we must avoid relying on
this ambiguous directory.

Achieve this my simply not setting the compilation directory on the line
table when we're in this situation (multiple units while emitting
assembly).

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
    llvm/trunk/test/DebugInfo/lto-comp-dir.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=204094&r1=204093&r2=204094&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Mon Mar 17 19:11:48 2014
@@ -674,7 +674,8 @@ void DwarfDebug::addGnuPubAttributes(Dwa
 
 // Create new DwarfCompileUnit for the given metadata node with tag
 // DW_TAG_compile_unit.
-DwarfCompileUnit *DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
+DwarfCompileUnit *DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit,
+                                                        bool Singular) {
   StringRef FN = DIUnit.getFilename();
   CompilationDir = DIUnit.getDirectory();
 
@@ -682,8 +683,9 @@ DwarfCompileUnit *DwarfDebug::constructD
   DwarfCompileUnit *NewCU = new DwarfCompileUnit(
       InfoHolder.getUnits().size(), Die, DIUnit, Asm, this, &InfoHolder);
   InfoHolder.addUnit(NewCU);
-  Asm->OutStreamer.getContext().setMCLineTableCompilationDir(
-      NewCU->getUniqueID(), CompilationDir);
+  if (!Asm->OutStreamer.hasRawTextSupport() || Singular)
+    Asm->OutStreamer.getContext().setMCLineTableCompilationDir(
+        NewCU->getUniqueID(), CompilationDir);
 
   NewCU->addString(Die, dwarf::DW_AT_producer, DIUnit.getProducer());
   NewCU->addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
@@ -814,9 +816,13 @@ void DwarfDebug::beginModule() {
   // Emit initial sections so we can reference labels later.
   emitSectionLabels();
 
-  for (MDNode *N : CU_Nodes->operands()) {
+  auto Operands = CU_Nodes->operands();
+
+  bool SingleCU = std::next(Operands.begin()) == Operands.end();
+
+  for (MDNode *N : Operands) {
     DICompileUnit CUNode(N);
-    DwarfCompileUnit *CU = constructDwarfCompileUnit(CUNode);
+    DwarfCompileUnit *CU = constructDwarfCompileUnit(CUNode, SingleCU);
     DIArray ImportedEntities = CUNode.getImportedEntities();
     for (unsigned i = 0, e = ImportedEntities.getNumElements(); i != e; ++i)
       ScopesWithImportedEntities.push_back(std::make_pair(

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=204094&r1=204093&r2=204094&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Mon Mar 17 19:11:48 2014
@@ -630,7 +630,8 @@ class DwarfDebug : public AsmPrinterHand
 
   /// \brief Create new DwarfCompileUnit for the given metadata node with tag
   /// DW_TAG_compile_unit.
-  DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit);
+  DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit,
+                                              bool Singular);
 
   /// \brief Construct subprogram DIE.
   void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N);

Modified: llvm/trunk/test/DebugInfo/lto-comp-dir.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/lto-comp-dir.ll?rev=204094&r1=204093&r2=204094&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/lto-comp-dir.ll (original)
+++ llvm/trunk/test/DebugInfo/lto-comp-dir.ll Mon Mar 17 19:11:48 2014
@@ -1,4 +1,5 @@
 ; RUN: %llc_dwarf < %s -filetype=obj | llvm-dwarfdump -debug-dump=line - | FileCheck %s
+; RUN: %llc_dwarf < %s -filetype=asm | FileCheck --check-prefix=ASM %s
 
 ; CHECK: .debug_line contents:
 ; CHECK-NEXT: Line table prologue:
@@ -11,6 +12,9 @@
 ; CHECK: file_names[   1]   0 {{.*}} b.cpp
 ; CHECK-NOT: file_names
 
+; ASM: .file   1 "/tmp/dbginfo/a/a.cpp"
+; ASM: .file   2 "/tmp/dbginfo/b/b.cpp"
+
 ; Generated from the following source compiled to bitcode from within their
 ; respective directories (with debug info) and linked together with llvm-link
 





More information about the llvm-commits mailing list