Skip to content

Commit eed0242

Browse files
committed
DebugInfo: Don't use implicit zero addr_base
(found when LLVM fails to emit addr_base for gmlt+DWARFv5)
1 parent 64fa76e commit eed0242

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class DWARFUnit {
210210
StringRef StringSection;
211211
const DWARFSection &StringOffsetSection;
212212
const DWARFSection *AddrOffsetSection;
213-
uint32_t AddrOffsetSectionBase = 0;
213+
Optional<uint64_t> AddrOffsetSectionBase;
214214
bool isLittleEndian;
215215
bool IsDWO;
216216
const DWARFUnitVector &UnitVector;

llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
412412
if (A)
413413
dumpSectionedAddress(AddrOS, DumpOpts, *A);
414414
else
415-
OS << "<no .debug_addr section>";
415+
OS << "<unresolved>";
416416
break;
417417
}
418418
case DW_FORM_flag_present:

llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ DWARFUnit::getAddrOffsetSectionItem(uint32_t Index) const {
228228
if (I != R.end() && std::next(I) == R.end())
229229
return (*I)->getAddrOffsetSectionItem(Index);
230230
}
231-
uint64_t Offset = AddrOffsetSectionBase + Index * getAddressByteSize();
231+
if (!AddrOffsetSectionBase)
232+
return None;
233+
uint64_t Offset = *AddrOffsetSectionBase + Index * getAddressByteSize();
232234
if (AddrOffsetSection->Data.size() < Offset + getAddressByteSize())
233235
return None;
234236
DWARFDataExtractor DA(Context.getDWARFObj(), *AddrOffsetSection,
@@ -360,7 +362,7 @@ void DWARFUnit::clear() {
360362
BaseAddr.reset();
361363
RangeSectionBase = 0;
362364
LocSectionBase = 0;
363-
AddrOffsetSectionBase = 0;
365+
AddrOffsetSectionBase = None;
364366
clearDIEs(false);
365367
DWO.reset();
366368
}
@@ -448,13 +450,13 @@ Error DWARFUnit::tryExtractDIEsIfNeeded(bool CUDieOnly) {
448450
if (Optional<uint64_t> DWOId = toUnsigned(UnitDie.find(DW_AT_GNU_dwo_id)))
449451
Header.setDWOId(*DWOId);
450452
if (!IsDWO) {
451-
assert(AddrOffsetSectionBase == 0);
453+
assert(AddrOffsetSectionBase == None);
452454
assert(RangeSectionBase == 0);
453455
assert(LocSectionBase == 0);
454-
AddrOffsetSectionBase = toSectionOffset(UnitDie.find(DW_AT_addr_base), 0);
456+
AddrOffsetSectionBase = toSectionOffset(UnitDie.find(DW_AT_addr_base));
455457
if (!AddrOffsetSectionBase)
456458
AddrOffsetSectionBase =
457-
toSectionOffset(UnitDie.find(DW_AT_GNU_addr_base), 0);
459+
toSectionOffset(UnitDie.find(DW_AT_GNU_addr_base));
458460
RangeSectionBase = toSectionOffset(UnitDie.find(DW_AT_rnglists_base), 0);
459461
LocSectionBase = toSectionOffset(UnitDie.find(DW_AT_loclists_base), 0);
460462
}
@@ -578,7 +580,8 @@ bool DWARFUnit::parseDWO() {
578580
return false;
579581
DWO = std::shared_ptr<DWARFCompileUnit>(std::move(DWOContext), DWOCU);
580582
// Share .debug_addr and .debug_ranges section with compile unit in .dwo
581-
DWO->setAddrOffsetSection(AddrOffsetSection, AddrOffsetSectionBase);
583+
if (AddrOffsetSectionBase)
584+
DWO->setAddrOffsetSection(AddrOffsetSection, *AddrOffsetSectionBase);
582585
if (getVersion() >= 5) {
583586
DWO->setRangesSection(&Context.getDWARFObj().getRnglistsDWOSection(), 0);
584587
DWARFDataExtractor RangesDA(Context.getDWARFObj(), *RangeSection,

llvm/test/tools/llvm-dwarfdump/X86/debug_info_addrx.s

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
# CHECK: DW_TAG_compile_unit
66
# CHECK: DW_AT_low_pc (0x0000000000000000)
77
# VERBOSE: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000000) address = 0x0000000000000000 ".text")
8-
# FIXME: There is a debug_addr section, it's just that the index is outside its
9-
# bounds (both of the section, and the range defined by the header for the
10-
# debug_addr contribution for this CU)
11-
# CHECK: DW_AT_low_pc (indexed (00000001) address = <no .debug_addr section>)
12-
# VERBOSE: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000001) address = <no .debug_addr section>)
8+
# FIXME: Improve the error message from "unresolved" to describe the specific
9+
# issue (in this case, the index is outside the bounds of the debug_addr
10+
# contribution/debug_addr section)
11+
# CHECK: DW_AT_low_pc (indexed (00000001) address = <unresolved>)
12+
# VERBOSE: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000001) address = <unresolved>)
1313

1414
# CHECK: DW_TAG_compile_unit
1515
# FIXME: Should error "no debug_addr contribution" - rather than parsing debug_addr
1616
# from the start, incorrectly interpreting the header bytes as an address.
17-
# CHECK: DW_AT_low_pc (0x000800050000000c)
18-
# VERBOSE: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000000) address = 0x000800050000000c)
17+
# CHECK: DW_AT_low_pc (indexed (00000000) address = <unresolved>)
18+
# VERBOSE: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000000) address = <unresolved>)
1919

2020
.globl foo # -- Begin function foo
2121
foo: # @foo

0 commit comments

Comments
 (0)