[llvm] [BOLT] Don't emit invalid (gdb-breaking) address ranges in gdb-index (PR #151923)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 4 02:04:25 PDT 2025
https://github.com/itrofimow created https://github.com/llvm/llvm-project/pull/151923
Empty address map ranges in gdb-index break gdb, so don't emit them
>From 5f20f5493138f889069e90b9ee7f4ad2b1163f54 Mon Sep 17 00:00:00 2001
From: Ivan Trofimov <i.trofimow at yandex.ru>
Date: Mon, 4 Aug 2025 12:02:39 +0300
Subject: [PATCH] [BOLT] Don't emit invalid (gdb-breaking) address ranges in
gdb-index
---
bolt/lib/Core/GDBIndex.cpp | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/bolt/lib/Core/GDBIndex.cpp b/bolt/lib/Core/GDBIndex.cpp
index c7fb4889646b4..5406f0c4e38d2 100644
--- a/bolt/lib/Core/GDBIndex.cpp
+++ b/bolt/lib/Core/GDBIndex.cpp
@@ -99,10 +99,19 @@ void GDBIndex::updateGdbIndexSection(
Data += SymbolTableOffset - CUTypesOffset;
// Calculate the size of the new address table.
+ const auto IsValidAddressRange = [](const DebugAddressRange &Range) {
+ return Range.HighPC > Range.LowPC;
+ };
+
uint32_t NewAddressTableSize = 0;
for (const auto &CURangesPair : ARangesSectionWriter.getCUAddressRanges()) {
const SmallVector<DebugAddressRange, 2> &Ranges = CURangesPair.second;
- NewAddressTableSize += Ranges.size() * 20;
+ NewAddressTableSize +=
+ llvm::count_if(Ranges,
+ [&IsValidAddressRange](const DebugAddressRange &Range) {
+ return IsValidAddressRange(Range);
+ }) *
+ 20;
}
// Difference between old and new table (and section) sizes.
@@ -163,10 +172,15 @@ void GDBIndex::updateGdbIndexSection(
const uint32_t CUIndex = OffsetToIndexMap[CURangesPair.first];
const DebugAddressRangesVector &Ranges = CURangesPair.second;
for (const DebugAddressRange &Range : Ranges) {
- write64le(Buffer, Range.LowPC);
- write64le(Buffer + 8, Range.HighPC);
- write32le(Buffer + 16, CUIndex);
- Buffer += 20;
+ // Don't emit ranges that break gdb,
+ // https://sourceware.org/bugzilla/show_bug.cgi?id=33247.
+ // We've seen [0, 0) ranges here, for instance.
+ if (IsValidAddressRange(Range)) {
+ write64le(Buffer, Range.LowPC);
+ write64le(Buffer + 8, Range.HighPC);
+ write32le(Buffer + 16, CUIndex);
+ Buffer += 20;
+ }
}
}
More information about the llvm-commits
mailing list