Skip to content

Commit ec6fe0c

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 d20d82d commit ec6fe0c

File tree

2 files changed

+1
-185
lines changed

2 files changed

+1
-185
lines changed

bolt/include/bolt/Rewrite/DWARFRewriter.h

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

151-
/// Rewrite .gdb_index section if present.
152-
void updateGdbIndexSection(CUOffsetMap &CUMap, uint32_t NumCUs);
153-
154151
/// DWARFDie contains a pointer to a DIE and hence gets invalidated once the
155152
/// embedded DIE is destroyed. This wrapper class stores a DIE internally and
156153
/// could be cast to a DWARFDie that is valid even after the initial DIE is
@@ -192,14 +189,6 @@ class DWARFRewriter {
192189
DwoRangesBase[DWOId] = RangesBase;
193190
}
194191

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

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 1 addition & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ namespace bolt {
184184
/// Emits debug information into .debug_info or .debug_types section.
185185
class DIEStreamer : public DwarfStreamer {
186186
DIEBuilder *DIEBldr;
187-
DWARFRewriter &Rewriter;
188187

189188
private:
190189
/// Emit the compilation unit header for \p Unit in the debug_info
@@ -282,8 +281,7 @@ class DIEStreamer : public DwarfStreamer {
282281
DWARFLinkerBase::OutputFileType OutFileType,
283282
raw_pwrite_stream &OutFile,
284283
DWARFLinkerBase::MessageHandlerTy Warning)
285-
: DwarfStreamer(OutFileType, OutFile, Warning), DIEBldr(DIEBldr),
286-
Rewriter(Rewriter){};
284+
: DwarfStreamer(OutFileType, OutFile, Warning), DIEBldr(DIEBldr){};
287285

288286
using DwarfStreamer::emitCompileUnitHeader;
289287

@@ -2055,177 +2053,6 @@ void DWARFRewriter::writeDWOFiles(
20552053
TempOut->keep();
20562054
}
20572055

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

0 commit comments

Comments
 (0)