Skip to content

Commit 836c4c9

Browse files
itrofimowmahesh-attarde
authored andcommitted
[BOLT] Don't emit invalid (gdb-breaking) address ranges in gdb-index (llvm#151923)
Empty address map ranges in gdb-index break gdb, so don't emit them
1 parent 31c20ff commit 836c4c9

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
@@ -100,10 +100,19 @@ void GDBIndex::updateGdbIndexSection(
100100
Data += SymbolTableOffset - CUTypesOffset;
101101

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

109118
// Difference between old and new table (and section) sizes.
@@ -201,10 +210,15 @@ void GDBIndex::updateGdbIndexSection(
201210
const uint32_t UpdatedCUIndex = RemapCUIndex(OriginalCUIndex);
202211
const DebugAddressRangesVector &Ranges = CURangesPair.second;
203212
for (const DebugAddressRange &Range : Ranges) {
204-
write64le(Buffer, Range.LowPC);
205-
write64le(Buffer + 8, Range.HighPC);
206-
write32le(Buffer + 16, UpdatedCUIndex);
207-
Buffer += 20;
213+
// Don't emit ranges that break gdb,
214+
// https://sourceware.org/bugzilla/show_bug.cgi?id=33247.
215+
// We've seen [0, 0) ranges here, for instance.
216+
if (IsValidAddressRange(Range)) {
217+
write64le(Buffer, Range.LowPC);
218+
write64le(Buffer + 8, Range.HighPC);
219+
write32le(Buffer + 16, UpdatedCUIndex);
220+
Buffer += 20;
221+
}
208222
}
209223
}
210224

0 commit comments

Comments
 (0)