Index: lib/CodeGen/AsmPrinter/AddressPool.h =================================================================== --- lib/CodeGen/AsmPrinter/AddressPool.h +++ lib/CodeGen/AsmPrinter/AddressPool.h @@ -43,7 +43,7 @@ /// label/symbol. unsigned getIndex(const MCSymbol *Sym, bool TLS = false); - void emit(AsmPrinter &Asm, MCSection *AddrSection); + void emit(AsmPrinter &Asm, MCSection *AddrSection, MCSymbol *AddrBase); bool isEmpty() { return Pool.empty(); } @@ -52,7 +52,7 @@ void resetUsedFlag() { HasBeenUsed = false; } private: - void emitHeader(AsmPrinter &Asm, MCSection *Section); + void emitHeader(AsmPrinter &Asm, MCSection *Section, MCSymbol *AddrBase); }; } // end namespace llvm Index: lib/CodeGen/AsmPrinter/AddressPool.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AddressPool.cpp +++ lib/CodeGen/AsmPrinter/AddressPool.cpp @@ -24,8 +24,8 @@ return IterBool.first->second.Number; } - -void AddressPool::emitHeader(AsmPrinter &Asm, MCSection *Section) { +void AddressPool::emitHeader(AsmPrinter &Asm, MCSection *Section, + MCSymbol *AddrBase) { static const uint8_t AddrSize = Asm.getDataLayout().getPointerSize(); Asm.OutStreamer->SwitchSection(Section); @@ -37,12 +37,18 @@ Asm.emitInt16(Asm.getDwarfVersion()); Asm.emitInt8(AddrSize); Asm.emitInt8(0); // TODO: Support non-zero segment_selector_size. + + // Define the symbol that marks the start of the contribution. + // It is referenced via DW_AT_addr_base. + if (AddrBase) + Asm.OutStreamer->EmitLabel(AddrBase); } // Emit addresses into the section given. -void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) { +void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection, + MCSymbol *AddrBase) { if (Asm.getDwarfVersion() >= 5) - emitHeader(Asm, AddrSection); + emitHeader(Asm, AddrSection, AddrBase); if (Pool.empty()) return; Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -675,6 +675,12 @@ (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. + if (getDwarfVersion() >= 5 && useSplitDwarf()) + SkeletonHolder.setAddrTableBaseSym( + 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 +798,9 @@ } // 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, @@ -2376,7 +2380,8 @@ // Emit DWO addresses. void DwarfDebug::emitDebugAddr() { assert(useSplitDwarf() && "No split dwarf?"); - AddrPool.emit(*Asm, Asm->getObjFileLowering().getDwarfAddrSection()); + AddrPool.emit(*Asm, Asm->getObjFileLowering().getDwarfAddrSection(), + SkeletonHolder.getAddrTableBaseSym()); } MCDwarfDwoLineTable *DwarfDebug::getDwoLineTable(const DwarfCompileUnit &CU) { Index: lib/CodeGen/AsmPrinter/DwarfFile.h =================================================================== --- lib/CodeGen/AsmPrinter/DwarfFile.h +++ lib/CodeGen/AsmPrinter/DwarfFile.h @@ -54,6 +54,10 @@ /// The table is shared by all units. MCSymbol *RnglistsTableBaseSym = nullptr; + /// DWARF v5: The symbol that designates the start of the contribution to the + /// address table. + MCSymbol *AddressTableBaseSym = nullptr; + /// The variables of a lexical scope. struct ScopeVars { /// We need to sort Args by ArgNo and check for duplicates. This could also @@ -125,6 +129,9 @@ void setRnglistsTableBaseSym(MCSymbol *Sym) { RnglistsTableBaseSym = Sym; } + MCSymbol *getAddrTableBaseSym() const { return AddressTableBaseSym; } + void setAddrTableBaseSym(MCSymbol *Sym) { AddressTableBaseSym = Sym; } + /// \returns false if the variable was merged with a previous one. bool addScopeVariable(LexicalScope *LS, DbgVariable *Var); Index: lib/CodeGen/AsmPrinter/DwarfUnit.h =================================================================== --- lib/CodeGen/AsmPrinter/DwarfUnit.h +++ lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -299,6 +299,9 @@ /// 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); Index: lib/CodeGen/AsmPrinter/DwarfUnit.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -1648,3 +1648,12 @@ DU->getRnglistsTableBaseSym(), TLOF.getDwarfRnglistsSection()->getBeginSymbol()); } + +void DwarfUnit::addAddrTableBase() { + const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); + MCSymbol *Base = DU->getAddrTableBaseSym(); + if (!Base) + Base = TLOF.getDwarfAddrSection()->getBeginSymbol(); + addSectionLabel(getUnitDie(), dwarf::DW_AT_GNU_addr_base, Base, + TLOF.getDwarfAddrSection()->getBeginSymbol()); +} Index: test/DebugInfo/X86/debug_addr.ll =================================================================== --- test/DebugInfo/X86/debug_addr.ll +++ test/DebugInfo/X86/debug_addr.ll @@ -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: [