[llvm] r342635 - [DWARF] - Emit the correct value for DW_AT_addr_base.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 20 02:17:37 PDT 2018


Author: grimar
Date: Thu Sep 20 02:17:36 2018
New Revision: 342635

URL: http://llvm.org/viewvc/llvm-project?rev=342635&view=rev
Log:
[DWARF] - Emit the correct value for DW_AT_addr_base.

Currently, we emit DW_AT_addr_base that points to the beginning of
the .debug_addr section. That is not correct for the DWARF5 case because address
table contains the header and the attribute should point to the first entry
following the header.

This is currently the reason why LLDB does not work with such executables correctly.
Patch fixes the issue.

Differential revision: https://reviews.llvm.org/D52168

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/AddressPool.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/AddressPool.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
    llvm/trunk/test/DebugInfo/PowerPC/tls-fission.ll
    llvm/trunk/test/DebugInfo/X86/debug_addr.ll
    llvm/trunk/test/DebugInfo/X86/tls.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AddressPool.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AddressPool.cpp?rev=342635&r1=342634&r2=342635&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AddressPool.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AddressPool.cpp Thu Sep 20 02:17:36 2018
@@ -27,8 +27,6 @@ unsigned AddressPool::getIndex(const MCS
 
 void AddressPool::emitHeader(AsmPrinter &Asm, MCSection *Section) {
   static const uint8_t AddrSize = Asm.getDataLayout().getPointerSize();
-  Asm.OutStreamer->SwitchSection(Section);
-
   uint64_t Length = sizeof(uint16_t) // version
                   + sizeof(uint8_t)  // address_size
                   + sizeof(uint8_t)  // segment_selector_size
@@ -41,15 +39,19 @@ void AddressPool::emitHeader(AsmPrinter
 
 // Emit addresses into the section given.
 void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {
+  // Start the dwarf addr section.
+  Asm.OutStreamer->SwitchSection(AddrSection);
+
   if (Asm.getDwarfVersion() >= 5)
     emitHeader(Asm, AddrSection);
 
+  // Define the symbol that marks the start of the contribution.
+  // It is referenced via DW_AT_addr_base.
+  Asm.OutStreamer->EmitLabel(AddressTableBaseSym);
+
   if (Pool.empty())
     return;
 
-  // Start the dwarf addr section.
-  Asm.OutStreamer->SwitchSection(AddrSection);
-
   // Order the address pool entries by ID
   SmallVector<const MCExpr *, 64> Entries(Pool.size());
 

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AddressPool.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AddressPool.h?rev=342635&r1=342634&r2=342635&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AddressPool.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AddressPool.h Thu Sep 20 02:17:36 2018
@@ -51,8 +51,14 @@ public:
 
   void resetUsedFlag() { HasBeenUsed = false; }
 
+  MCSymbol *getLabel() { return AddressTableBaseSym; }
+  void setLabel(MCSymbol *Sym) { AddressTableBaseSym = Sym; }
+
 private:
   void emitHeader(AsmPrinter &Asm, MCSection *Section);
+
+  /// Symbol designates the start of the contribution to the address table.
+  MCSymbol *AddressTableBaseSym = nullptr;
 };
 
 } // end namespace llvm

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=342635&r1=342634&r2=342635&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Thu Sep 20 02:17:36 2018
@@ -675,6 +675,10 @@ void DwarfDebug::beginModule() {
     (useSplitDwarf() ? SkeletonHolder : InfoHolder)
         .setRnglistsTableBaseSym(Asm->createTempSymbol("rnglists_table_base"));
 
+  // Create the symbol that points to the first entry following the debug
+  // address table (.debug_addr) header.
+  AddrPool.setLabel(Asm->createTempSymbol("addr_table_base"));
+
   for (DICompileUnit *CUNode : M->debug_compile_units()) {
     // FIXME: Move local imported entities into a list attached to the
     // subprogram, then this search won't be needed and a
@@ -792,11 +796,9 @@ void DwarfDebug::finalizeModuleInfo() {
       }
       // We don't keep track of which addresses are used in which CU so this
       // is a bit pessimistic under LTO.
-      if (!AddrPool.isEmpty()) {
-        const MCSymbol *Sym = TLOF.getDwarfAddrSection()->getBeginSymbol();
-        SkCU->addSectionLabel(SkCU->getUnitDie(), dwarf::DW_AT_GNU_addr_base,
-                              Sym, Sym);
-      }
+      if (!AddrPool.isEmpty())
+        SkCU->addAddrTableBase();
+
       if (getDwarfVersion() < 5 && !SkCU->getRangeLists().empty()) {
         const MCSymbol *Sym = TLOF.getDwarfRangesSection()->getBeginSymbol();
         SkCU->addSectionLabel(SkCU->getUnitDie(), dwarf::DW_AT_GNU_ranges_base,

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=342635&r1=342634&r2=342635&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Thu Sep 20 02:17:36 2018
@@ -1648,3 +1648,10 @@ void DwarfUnit::addRnglistsBase() {
                   DU->getRnglistsTableBaseSym(),
                   TLOF.getDwarfRnglistsSection()->getBeginSymbol());
 }
+
+void DwarfUnit::addAddrTableBase() {
+  const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
+  MCSymbol *Label = DD->getAddressPool().getLabel();
+  addSectionLabel(getUnitDie(), dwarf::DW_AT_GNU_addr_base, Label,
+                  TLOF.getDwarfAddrSection()->getBeginSymbol());
+}

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h?rev=342635&r1=342634&r2=342635&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h Thu Sep 20 02:17:36 2018
@@ -299,6 +299,9 @@ public:
   /// Add the DW_AT_rnglists_base attribute to the unit DIE.
   void addRnglistsBase();
 
+  /// Add the DW_AT_addr_base attribute to the unit DIE.
+  void addAddrTableBase();
+
   virtual DwarfCompileUnit &getCU() = 0;
 
   void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy);

Modified: llvm/trunk/test/DebugInfo/PowerPC/tls-fission.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PowerPC/tls-fission.ll?rev=342635&r1=342634&r2=342635&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/PowerPC/tls-fission.ll (original)
+++ llvm/trunk/test/DebugInfo/PowerPC/tls-fission.ll Thu Sep 20 02:17:36 2018
@@ -14,6 +14,7 @@
 ; CHECK-NEXT: .byte 224
 ; check that the expected TLS address description is the first thing in the debug_addr section
 ; CHECK: .section .debug_addr,"", at progbits
+; CHECK-NEXT: .Laddr_table_base0:
 ; CHECK-NEXT: .quad tls at DTPREL+32768
 
 source_filename = "test/DebugInfo/PowerPC/tls-fission.ll"

Modified: llvm/trunk/test/DebugInfo/X86/debug_addr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/debug_addr.ll?rev=342635&r1=342634&r2=342635&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/debug_addr.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/debug_addr.ll Thu Sep 20 02:17:36 2018
@@ -31,7 +31,7 @@
 ; DWARF5: DW_TAG_compile_unit
 ; DWARF5-NOT: DW_TAG_{{.*}}
 ; DWARF5: DW_AT_GNU_dwo_name{{.*}}test.dwo
-; DWARF5: DW_AT_GNU_addr_base{{.*}}0x00000000
+; DWARF5: DW_AT_GNU_addr_base{{.*}}0x00000008
 ; DWARF5: .debug_addr contents:
 ; DWARF5-NEXT: 0x00000000: Addr Section: length = 0x0000000c, version = 0x0005, addr_size = 0x04, seg_size = 0x00
 ; DWARF5-NEXT: Addrs: [

Modified: llvm/trunk/test/DebugInfo/X86/tls.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/tls.ll?rev=342635&r1=342634&r2=342635&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/tls.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/tls.ll Thu Sep 20 02:17:36 2018
@@ -78,6 +78,7 @@
 
 ; check that the expected TLS address description is the first thing in the debug_addr section
 ; FISSION: .section    .debug_addr
+; FISSION-NEXT: .Laddr_table_base0:
 ; FISSION-NEXT: .quad  tls at DTPOFF
 ; FISSION-NEXT: .quad  glbl
 ; FISSION-NOT: .quad  glbl




More information about the llvm-commits mailing list