Skip to content

Commit

Permalink
Handle types CU list in updateGdbIndexSection
Browse files Browse the repository at this point in the history
Summary:
Handle types CU list in `updateGdbIndexSection`.

It looks like the types part of `.gdb_index` isn't empty when `-fdebug-types-section` is used. So instead of aborting, we copy the part to new `.gdb_index` section.

(cherry picked from FBD6770460)
  • Loading branch information
wqfish authored and maksfb committed Jan 31, 2018
1 parent d114ef1 commit 2b8194f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions bolt/DWARFRewriter.cpp
Expand Up @@ -508,6 +508,9 @@ void RewriteInstance::updateGdbIndexSection() {
if (!GdbIndexSection)
return;

// See https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html for
// .gdb_index section format.

StringRef GdbIndexContents = GdbIndexSection->getContents();

const auto *Data = GdbIndexContents.data();
Expand All @@ -529,9 +532,6 @@ void RewriteInstance::updateGdbIndexSection() {
const auto ConstantPoolOffset = read32le(Data + 20);
Data += 24;

assert(CUTypesOffset == AddressTableOffset &&
"CU types in .gdb_index should be empty");

// Map CUs offsets to indices and verify existing index table.
std::map<uint32_t, uint32_t> OffsetToIndexMap;
const auto CUListSize = CUTypesOffset - CUListOffset;
Expand All @@ -553,7 +553,8 @@ void RewriteInstance::updateGdbIndexSection() {

// Ignore old address table.
const auto OldAddressTableSize = SymbolTableOffset - AddressTableOffset;
Data += OldAddressTableSize;
// Move Data to the beginning of symbol table.
Data += SymbolTableOffset - CUTypesOffset;

// Calculate the size of the new address table.
uint32_t NewAddressTableSize = 0;
Expand All @@ -580,9 +581,10 @@ void RewriteInstance::updateGdbIndexSection() {
write32le(Buffer + 20, ConstantPoolOffset + Delta);
Buffer += 24;

// Copy over CU list.
memcpy(Buffer, GdbIndexContents.data() + 24, CUListSize);
Buffer += CUListSize;
// Copy over CU list and types CU list.
memcpy(Buffer, GdbIndexContents.data() + 24,
AddressTableOffset - CUListOffset);
Buffer += AddressTableOffset - CUListOffset;

// Generate new address table.
for (const auto &CURangesPair : RangesSectionsWriter->getCUAddressRanges()) {
Expand Down

0 comments on commit 2b8194f

Please sign in to comment.