Skip to content

Commit 5f20f54

Browse files
committed
[BOLT] Don't emit invalid (gdb-breaking) address ranges in gdb-index
1 parent b16fe13 commit 5f20f54

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

bolt/lib/Core/GDBIndex.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,19 @@ void GDBIndex::updateGdbIndexSection(
9999
Data += SymbolTableOffset - CUTypesOffset;
100100

101101
// Calculate the size of the new address table.
102+
const auto IsValidAddressRange = [](const DebugAddressRange &Range) {
103+
return Range.HighPC > Range.LowPC;
104+
};
105+
102106
uint32_t NewAddressTableSize = 0;
103107
for (const auto &CURangesPair : ARangesSectionWriter.getCUAddressRanges()) {
104108
const SmallVector<DebugAddressRange, 2> &Ranges = CURangesPair.second;
105-
NewAddressTableSize += Ranges.size() * 20;
109+
NewAddressTableSize +=
110+
llvm::count_if(Ranges,
111+
[&IsValidAddressRange](const DebugAddressRange &Range) {
112+
return IsValidAddressRange(Range);
113+
}) *
114+
20;
106115
}
107116

108117
// Difference between old and new table (and section) sizes.
@@ -163,10 +172,15 @@ void GDBIndex::updateGdbIndexSection(
163172
const uint32_t CUIndex = OffsetToIndexMap[CURangesPair.first];
164173
const DebugAddressRangesVector &Ranges = CURangesPair.second;
165174
for (const DebugAddressRange &Range : Ranges) {
166-
write64le(Buffer, Range.LowPC);
167-
write64le(Buffer + 8, Range.HighPC);
168-
write32le(Buffer + 16, CUIndex);
169-
Buffer += 20;
175+
// Don't emit ranges that break gdb,
176+
// https://sourceware.org/bugzilla/show_bug.cgi?id=33247.
177+
// We've seen [0, 0) ranges here, for instance.
178+
if (IsValidAddressRange(Range)) {
179+
write64le(Buffer, Range.LowPC);
180+
write64le(Buffer + 8, Range.HighPC);
181+
write32le(Buffer + 16, CUIndex);
182+
Buffer += 20;
183+
}
170184
}
171185
}
172186

0 commit comments

Comments
 (0)