Skip to content

Commit 5283c9a

Browse files
committed
Remove old code for updating GDB Index
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D58156979
1 parent 7c8a8bd commit 5283c9a

File tree

2 files changed

+0
-182
lines changed

2 files changed

+0
-182
lines changed

bolt/include/bolt/Rewrite/DWARFRewriter.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@ class DWARFRewriter {
150150
/// blocks) to be updated.
151151
void updateDebugAddressRanges();
152152

153-
/// Rewrite .gdb_index section if present.
154-
void updateGdbIndexSection(CUOffsetMap &CUMap, uint32_t NumCUs);
155-
156153
/// DWARFDie contains a pointer to a DIE and hence gets invalidated once the
157154
/// embedded DIE is destroyed. This wrapper class stores a DIE internally and
158155
/// could be cast to a DWARFDie that is valid even after the initial DIE is
@@ -194,14 +191,6 @@ class DWARFRewriter {
194191
DwoRangesBase[DWOId] = RangesBase;
195192
}
196193

197-
/// Adds an GDBIndexTUEntry if .gdb_index seciton exists.
198-
void addGDBTypeUnitEntry(const GDBIndexTUEntry &&Entry);
199-
200-
/// Returns all entries needed for Types CU list
201-
const GDBIndexTUEntryType &getGDBIndexTUEntryVector() const {
202-
return GDBIndexTUEntryVector;
203-
}
204-
205194
using OverriddenSectionsMap = std::unordered_map<DWARFSectionKind, StringRef>;
206195
/// Output .dwo files.
207196
void writeDWOFiles(DWARFUnit &, const OverriddenSectionsMap &,

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 0 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,177 +2062,6 @@ void DWARFRewriter::writeDWOFiles(
20622062
TempOut->keep();
20632063
}
20642064

2065-
void DWARFRewriter::addGDBTypeUnitEntry(const GDBIndexTUEntry &&Entry) {
2066-
std::lock_guard<std::mutex> Lock(DWARFRewriterMutex);
2067-
if (!BC.getGdbIndexSection())
2068-
return;
2069-
GDBIndexTUEntryVector.emplace_back(Entry);
2070-
}
2071-
2072-
void DWARFRewriter::updateGdbIndexSection(CUOffsetMap &CUMap, uint32_t NumCUs) {
2073-
if (!BC.getGdbIndexSection())
2074-
return;
2075-
2076-
// See https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html
2077-
// for .gdb_index section format.
2078-
2079-
StringRef GdbIndexContents = BC.getGdbIndexSection()->getContents();
2080-
2081-
const char *Data = GdbIndexContents.data();
2082-
2083-
// Parse the header.
2084-
const uint32_t Version = read32le(Data);
2085-
if (Version != 7 && Version != 8) {
2086-
errs() << "BOLT-ERROR: can only process .gdb_index versions 7 and 8\n";
2087-
exit(1);
2088-
}
2089-
2090-
// Some .gdb_index generators use file offsets while others use section
2091-
// offsets. Hence we can only rely on offsets relative to each other,
2092-
// and ignore their absolute values.
2093-
const uint32_t CUListOffset = read32le(Data + 4);
2094-
const uint32_t CUTypesOffset = read32le(Data + 8);
2095-
const uint32_t AddressTableOffset = read32le(Data + 12);
2096-
const uint32_t SymbolTableOffset = read32le(Data + 16);
2097-
const uint32_t ConstantPoolOffset = read32le(Data + 20);
2098-
Data += 24;
2099-
2100-
// Map CUs offsets to indices and verify existing index table.
2101-
std::map<uint32_t, uint32_t> OffsetToIndexMap;
2102-
const uint32_t CUListSize = CUTypesOffset - CUListOffset;
2103-
const uint32_t TUListSize = AddressTableOffset - CUTypesOffset;
2104-
const unsigned NUmCUsEncoded = CUListSize / 16;
2105-
unsigned MaxDWARFVersion = BC.DwCtx->getMaxVersion();
2106-
unsigned NumDWARF5TUs =
2107-
getGDBIndexTUEntryVector().size() - BC.DwCtx->getNumTypeUnits();
2108-
bool SkipTypeUnits = false;
2109-
// For DWARF5 Types are in .debug_info.
2110-
// LLD doesn't generate Types CU List, and in CU list offset
2111-
// only includes CUs.
2112-
// GDB 11+ includes only CUs in CU list and generates Types
2113-
// list.
2114-
// GDB 9 includes CUs and TUs in CU list and generates TYpes
2115-
// list. The NumCUs is CUs + TUs, so need to modify the check.
2116-
// For split-dwarf
2117-
// GDB-11, DWARF5: TU units from dwo are not included.
2118-
// GDB-11, DWARF4: TU units from dwo are included.
2119-
if (MaxDWARFVersion >= 5)
2120-
SkipTypeUnits = !TUListSize ? true
2121-
: ((NUmCUsEncoded + NumDWARF5TUs) ==
2122-
BC.DwCtx->getNumCompileUnits());
2123-
2124-
if (!((CUListSize == NumCUs * 16) ||
2125-
(CUListSize == (NumCUs + NumDWARF5TUs) * 16))) {
2126-
errs() << "BOLT-ERROR: .gdb_index: CU count mismatch\n";
2127-
exit(1);
2128-
}
2129-
DenseSet<uint64_t> OriginalOffsets;
2130-
for (unsigned Index = 0, Units = BC.DwCtx->getNumCompileUnits();
2131-
Index < Units; ++Index) {
2132-
const DWARFUnit *CU = BC.DwCtx->getUnitAtIndex(Index);
2133-
if (SkipTypeUnits && CU->isTypeUnit())
2134-
continue;
2135-
const uint64_t Offset = read64le(Data);
2136-
Data += 16;
2137-
if (CU->getOffset() != Offset) {
2138-
errs() << "BOLT-ERROR: .gdb_index CU offset mismatch\n";
2139-
exit(1);
2140-
}
2141-
2142-
OriginalOffsets.insert(Offset);
2143-
OffsetToIndexMap[Offset] = Index;
2144-
}
2145-
2146-
// Ignore old address table.
2147-
const uint32_t OldAddressTableSize = SymbolTableOffset - AddressTableOffset;
2148-
// Move Data to the beginning of symbol table.
2149-
Data += SymbolTableOffset - CUTypesOffset;
2150-
2151-
// Calculate the size of the new address table.
2152-
uint32_t NewAddressTableSize = 0;
2153-
for (const auto &CURangesPair : ARangesSectionWriter->getCUAddressRanges()) {
2154-
const SmallVector<DebugAddressRange, 2> &Ranges = CURangesPair.second;
2155-
NewAddressTableSize += Ranges.size() * 20;
2156-
}
2157-
2158-
// Difference between old and new table (and section) sizes.
2159-
// Could be negative.
2160-
int32_t Delta = NewAddressTableSize - OldAddressTableSize;
2161-
2162-
size_t NewGdbIndexSize = GdbIndexContents.size() + Delta;
2163-
2164-
// Free'd by ExecutableFileMemoryManager.
2165-
auto *NewGdbIndexContents = new uint8_t[NewGdbIndexSize];
2166-
uint8_t *Buffer = NewGdbIndexContents;
2167-
2168-
write32le(Buffer, Version);
2169-
write32le(Buffer + 4, CUListOffset);
2170-
write32le(Buffer + 8, CUTypesOffset);
2171-
write32le(Buffer + 12, AddressTableOffset);
2172-
write32le(Buffer + 16, SymbolTableOffset + Delta);
2173-
write32le(Buffer + 20, ConstantPoolOffset + Delta);
2174-
Buffer += 24;
2175-
2176-
using MapEntry = std::pair<uint32_t, CUInfo>;
2177-
std::vector<MapEntry> CUVector(CUMap.begin(), CUMap.end());
2178-
// Need to sort since we write out all of TUs in .debug_info before CUs.
2179-
std::sort(CUVector.begin(), CUVector.end(),
2180-
[](const MapEntry &E1, const MapEntry &E2) -> bool {
2181-
return E1.second.Offset < E2.second.Offset;
2182-
});
2183-
// Writing out CU List <Offset, Size>
2184-
for (auto &CUInfo : CUVector) {
2185-
// Skipping TU for DWARF5 when they are not included in CU list.
2186-
if (!OriginalOffsets.count(CUInfo.first))
2187-
continue;
2188-
write64le(Buffer, CUInfo.second.Offset);
2189-
// Length encoded in CU doesn't contain first 4 bytes that encode length.
2190-
write64le(Buffer + 8, CUInfo.second.Length + 4);
2191-
Buffer += 16;
2192-
}
2193-
2194-
// Rewrite TU CU List, since abbrevs can be different.
2195-
// Entry example:
2196-
// 0: offset = 0x00000000, type_offset = 0x0000001e, type_signature =
2197-
// 0x418503b8111e9a7b Spec says " triplet, the first value is the CU offset,
2198-
// the second value is the type offset in the CU, and the third value is the
2199-
// type signature" Looking at what is being generated by gdb-add-index. The
2200-
// first entry is TU offset, second entry is offset from it, and third entry
2201-
// is the type signature.
2202-
if (TUListSize)
2203-
for (const GDBIndexTUEntry &Entry : getGDBIndexTUEntryVector()) {
2204-
write64le(Buffer, Entry.UnitOffset);
2205-
write64le(Buffer + 8, Entry.TypeDIERelativeOffset);
2206-
write64le(Buffer + 16, Entry.TypeHash);
2207-
Buffer += sizeof(GDBIndexTUEntry);
2208-
}
2209-
2210-
// Generate new address table.
2211-
for (const std::pair<const uint64_t, DebugAddressRangesVector> &CURangesPair :
2212-
ARangesSectionWriter->getCUAddressRanges()) {
2213-
const uint32_t CUIndex = OffsetToIndexMap[CURangesPair.first];
2214-
const DebugAddressRangesVector &Ranges = CURangesPair.second;
2215-
for (const DebugAddressRange &Range : Ranges) {
2216-
write64le(Buffer, Range.LowPC);
2217-
write64le(Buffer + 8, Range.HighPC);
2218-
write32le(Buffer + 16, CUIndex);
2219-
Buffer += 20;
2220-
}
2221-
}
2222-
2223-
const size_t TrailingSize =
2224-
GdbIndexContents.data() + GdbIndexContents.size() - Data;
2225-
assert(Buffer + TrailingSize == NewGdbIndexContents + NewGdbIndexSize &&
2226-
"size calculation error");
2227-
2228-
// Copy over the rest of the original data.
2229-
memcpy(Buffer, Data, TrailingSize);
2230-
2231-
// Register the new section.
2232-
BC.registerOrUpdateNoteSection(".gdb_index", NewGdbIndexContents,
2233-
NewGdbIndexSize);
2234-
}
2235-
22362065
std::unique_ptr<DebugBufferVector>
22372066
DWARFRewriter::makeFinalLocListsSection(DWARFVersion Version) {
22382067
auto LocBuffer = std::make_unique<DebugBufferVector>();

0 commit comments

Comments
 (0)