Skip to content

Commit

Permalink
Updates and formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sayhaan committed Jul 11, 2024
1 parent 3755731 commit db8f580
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
11 changes: 6 additions & 5 deletions bolt/include/bolt/Core/DebugData.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ using AddressSectionBuffer = SmallVector<char, 4>;
class DebugAddrWriter {
public:
DebugAddrWriter() = delete;
DebugAddrWriter(BinaryContext *BC_) : DebugAddrWriter(BC_, 255) {};
DebugAddrWriter(BinaryContext *BC_) : DebugAddrWriter(BC_, UCHAR_MAX){};
DebugAddrWriter(BinaryContext *BC_, uint8_t AddressByteSize);
virtual ~DebugAddrWriter(){};
/// Given an address returns an index in .debug_addr.
Expand All @@ -353,10 +353,10 @@ class DebugAddrWriter {
}

/// Returns buffer size.
virtual size_t getBufferSize() { return Buffer->size(); }
virtual size_t getBufferSize() const { return Buffer->size(); }

/// Returns True if Buffer is not empty.
bool isInitialized() { return !Buffer->empty(); }
bool isInitialized() const { return !Buffer->empty(); }

/// Updates address base with the given Offset.
virtual void updateAddrBase(DIEBuilder &DIEBlder, DWARFUnit &CU,
Expand Down Expand Up @@ -445,6 +445,7 @@ class DebugAddrWriterDwarf5 : public DebugAddrWriter {
/// Write out entries in to .debug_addr section for CUs.
virtual std::optional<uint64_t> finalize(const size_t BufferSize) override;

/// Updates address base with the given Offset.
virtual void updateAddrBase(DIEBuilder &DIEBlder, DWARFUnit &CU,
const uint64_t Offset) override;

Expand Down Expand Up @@ -613,7 +614,7 @@ class DebugLoclistWriter : public DebugLocWriter {
DebugLoclistWriter(DWARFUnit &Unit, uint8_t DV, bool SD,
DebugAddrWriter &AddrW)
: DebugLocWriter(DV, LocWriterKind::DebugLoclistWriter),
AddrWriter(&AddrW), CU(Unit), IsSplitDwarf(SD) {
AddrWriter(AddrW), CU(Unit), IsSplitDwarf(SD) {
if (DwarfVersion >= 5) {
LocBodyBuffer = std::make_unique<DebugBufferVector>();
LocBodyStream = std::make_unique<raw_svector_ostream>(*LocBodyBuffer);
Expand Down Expand Up @@ -653,7 +654,7 @@ class DebugLoclistWriter : public DebugLocWriter {
/// Writes out locations in to a local buffer and applies debug info patches.
void finalizeDWARF5(DIEBuilder &DIEBldr, DIE &Die);

DebugAddrWriter *AddrWriter;
DebugAddrWriter &AddrWriter;
DWARFUnit &CU;
bool IsSplitDwarf{false};
// Used for DWARF5 to store location lists before being finalized.
Expand Down
10 changes: 4 additions & 6 deletions bolt/include/bolt/Rewrite/DWARFRewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ class DWARFRewriter {
/// .debug_aranges DWARF section.
std::unique_ptr<DebugARangesSectionWriter> ARangesSectionWriter;

/// Stores and serializes information that will be put into the
/// .debug_addr DWARF section.
std::unique_ptr<DebugAddrWriter> FinalAddrWriter;

/// Stores and serializes information that will be put in to the
/// .debug_addr DWARF section.
/// Does not do de-duplication.
Expand Down Expand Up @@ -146,13 +142,15 @@ class DWARFRewriter {
/// Process and write out CUs that are passsed in.
void finalizeCompileUnits(DIEBuilder &DIEBlder, DIEStreamer &Streamer,
CUOffsetMap &CUMap,
const std::list<DWARFUnit *> &CUs);
const std::list<DWARFUnit *> &CUs,
DebugAddrWriter &FinalAddrWriter);

/// Finalize debug sections in the main binary.
void finalizeDebugSections(DIEBuilder &DIEBlder,
DWARF5AcceleratorTable &DebugNamesTable,
DIEStreamer &Streamer, raw_svector_ostream &ObjOS,
CUOffsetMap &CUMap);
CUOffsetMap &CUMap,
DebugAddrWriter &FinalAddrWriter);

/// Patches the binary for DWARF address ranges (e.g. in functions and lexical
/// blocks) to be updated.
Expand Down
4 changes: 2 additions & 2 deletions bolt/lib/Core/DebugData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,11 @@ void DebugLoclistWriter::addList(DIEBuilder &DIEBldr, DIE &Die,
DIEValue &AttrInfo,
DebugLocationsVector &LocList) {
if (DwarfVersion < 5)
writeLegacyLocList(AttrInfo, LocList, DIEBldr, Die, *AddrWriter, *LocBuffer,
writeLegacyLocList(AttrInfo, LocList, DIEBldr, Die, AddrWriter, *LocBuffer,
CU, *LocStream);
else
writeDWARF5LocList(NumberOfEntries, AttrInfo, LocList, Die, DIEBldr,
*AddrWriter, *LocBodyBuffer, RelativeLocListOffsets, CU,
AddrWriter, *LocBodyBuffer, RelativeLocListOffsets, CU,
*LocBodyStream);
}

Expand Down
41 changes: 23 additions & 18 deletions bolt/lib/Rewrite/DWARFRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,10 @@ void DWARFRewriter::updateDebugInfo() {
errs() << "BOLT-WARNING: --deterministic-debuginfo is being deprecated\n";
}

/// Stores and serializes information that will be put into the
/// .debug_addr DWARF section.
std::unique_ptr<DebugAddrWriter> FinalAddrWriter;

if (BC.isDWARF5Used()) {
FinalAddrWriter = std::make_unique<DebugAddrWriterDwarf5>(&BC);
RangeListsSectionWriter = std::make_unique<DebugRangeListsSectionWriter>();
Expand Down Expand Up @@ -641,28 +645,27 @@ void DWARFRewriter::updateDebugInfo() {
if (std::optional<uint64_t> DWOId = CU.getDWOId()) {
assert(RangeListsWritersByCU.count(*DWOId) == 0 &&
"RangeLists writer for DWO unit already exists.");
auto RangeListSectionWriter =
auto DWORangeListsSectionWriter =
std::make_unique<DebugRangeListsSectionWriter>();
RangeListSectionWriter->initSection(CU);
RangeListSectionWriter->setAddressWriter(AddrW.get());
RangeListsWritersByCU.insert(
{*DWOId, std::move(RangeListSectionWriter)});
DWORangeListsSectionWriter->initSection(CU);
DWORangeListsSectionWriter->setAddressWriter(AddrW.get());
RangeListsWritersByCU[*DWOId] = std::move(DWORangeListsSectionWriter);
}
AddressWritersByCU.insert({CU.getOffset(), std::move(AddrW)});
AddressWritersByCU[CU.getOffset()] = std::move(AddrW);

} else {
auto AddrW =
std::make_unique<DebugAddrWriter>(&BC, CU.getAddressByteSize());
AddressWritersByCU.insert({CU.getOffset(), std::move(AddrW)});
AddressWritersByCU[CU.getOffset()] = std::move(AddrW);
LocListWritersByCU[CUIndex] = std::make_unique<DebugLocWriter>();
if (std::optional<uint64_t> DWOId = CU.getDWOId()) {
assert(LegacyRangesWritersByCU.count(*DWOId) == 0 &&
"LegacyRangeLists writer for DWO unit already exists.");
auto LegacyRangesSectionWriterByCU =
std::make_unique<DebugRangesSectionWriter>();
LegacyRangesSectionWriterByCU->initSection(CU);
LegacyRangesWritersByCU.insert(
{*DWOId, std::move(LegacyRangesSectionWriterByCU)});
LegacyRangesWritersByCU[*DWOId] =
std::move(LegacyRangesSectionWriterByCU);
}
}
return LocListWritersByCU[CUIndex++].get();
Expand Down Expand Up @@ -768,7 +771,7 @@ void DWARFRewriter::updateDebugInfo() {
for (DWARFUnit *CU : DIEBlder.getProcessedCUs())
processUnitDIE(CU, &DIEBlder);
finalizeCompileUnits(DIEBlder, *Streamer, OffsetMap,
DIEBlder.getProcessedCUs());
DIEBlder.getProcessedCUs(), *FinalAddrWriter);
}
} else {
// Update unit debug info in parallel
Expand All @@ -783,8 +786,8 @@ void DWARFRewriter::updateDebugInfo() {
if (opts::WriteDWP)
finalizeDWP(State);

finalizeDebugSections(DIEBlder, DebugNamesTable, *Streamer, *ObjOS,
OffsetMap);
finalizeDebugSections(DIEBlder, DebugNamesTable, *Streamer, *ObjOS, OffsetMap,
*FinalAddrWriter);
GDBIndexSection.updateGdbIndexSection(OffsetMap, CUIndex,
*ARangesSectionWriter);
}
Expand Down Expand Up @@ -1522,7 +1525,8 @@ CUOffsetMap DWARFRewriter::finalizeTypeSections(DIEBuilder &DIEBlder,

void DWARFRewriter::finalizeDebugSections(
DIEBuilder &DIEBlder, DWARF5AcceleratorTable &DebugNamesTable,
DIEStreamer &Streamer, raw_svector_ostream &ObjOS, CUOffsetMap &CUMap) {
DIEStreamer &Streamer, raw_svector_ostream &ObjOS, CUOffsetMap &CUMap,
DebugAddrWriter &FinalAddrWriter) {
if (StrWriter->isInitialized()) {
RewriteInstance::addToDebugSectionsToOverwrite(".debug_str");
std::unique_ptr<DebugStrBufferVector> DebugStrSectionContents =
Expand Down Expand Up @@ -1575,9 +1579,9 @@ void DWARFRewriter::finalizeDebugSections(
LocationListSectionContents->size());
}

if (FinalAddrWriter->isInitialized()) {
if (FinalAddrWriter.isInitialized()) {
std::unique_ptr<AddressSectionBuffer> AddressSectionContents =
FinalAddrWriter->releaseBuffer();
FinalAddrWriter.releaseBuffer();
BC.registerOrUpdateNoteSection(".debug_addr",
copyByteArray(*AddressSectionContents),
AddressSectionContents->size());
Expand Down Expand Up @@ -1633,13 +1637,14 @@ void DWARFRewriter::finalizeDebugSections(
void DWARFRewriter::finalizeCompileUnits(DIEBuilder &DIEBlder,
DIEStreamer &Streamer,
CUOffsetMap &CUMap,
const std::list<DWARFUnit *> &CUs) {
const std::list<DWARFUnit *> &CUs,
DebugAddrWriter &FinalAddrWriter) {
for (DWARFUnit *CU : CUs) {
auto AddressWriterIterator = AddressWritersByCU.find(CU->getOffset());
assert(AddressWriterIterator != AddressWritersByCU.end() &&
"AddressWriter does not exist for CU");
DebugAddrWriter *AddressWriter = AddressWriterIterator->second.get();
const size_t BufferOffset = FinalAddrWriter->getBufferSize();
const size_t BufferOffset = FinalAddrWriter.getBufferSize();
std::optional<uint64_t> Offset = AddressWriter->finalize(BufferOffset);
/// If Offset already exists in UnmodifiedAddressOffsets, then update with
/// Offset, else update with BufferOffset.
Expand All @@ -1650,7 +1655,7 @@ void DWARFRewriter::finalizeCompileUnits(DIEBuilder &DIEBlder,
if (AddressWriter->isInitialized()) {
std::unique_ptr<AddressSectionBuffer> AddressSectionContents =
AddressWriter->releaseBuffer();
FinalAddrWriter->appendToAddressBuffer(*AddressSectionContents);
FinalAddrWriter.appendToAddressBuffer(*AddressSectionContents);
}
if (CU->getVersion() != 4)
continue;
Expand Down

0 comments on commit db8f580

Please sign in to comment.