-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[BOLT][DWARF] Add support for DW_IDX_parent #85285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
#include "llvm/Support/EndianStream.h" | ||
#include "llvm/Support/LEB128.h" | ||
#include <cstdint> | ||
#include <optional> | ||
|
||
namespace llvm { | ||
namespace bolt { | ||
|
@@ -163,10 +164,16 @@ static uint64_t getNameOffset(BinaryContext &BC, DWARFUnit &Unit, | |
Index * DwarfOffsetByteSize); | ||
} | ||
|
||
void DWARF5AcceleratorTable::addAccelTableEntry( | ||
DWARFUnit &Unit, const DIE &Die, const std::optional<uint64_t> &DWOID) { | ||
static uint64_t getEntryID(const BOLTDWARF5AccelTableData &Entry) { | ||
return reinterpret_cast<uint64_t>(&Entry); | ||
} | ||
|
||
std::optional<BOLTDWARF5AccelTableData *> | ||
DWARF5AcceleratorTable::addAccelTableEntry( | ||
DWARFUnit &Unit, const DIE &Die, const std::optional<uint64_t> &DWOID, | ||
std::optional<BOLTDWARF5AccelTableData *> &Parent) { | ||
if (Unit.getVersion() < 5 || !NeedToCreate) | ||
return; | ||
return std::nullopt; | ||
std::string NameToUse = ""; | ||
auto canProcess = [&](const DIE &Die) -> bool { | ||
switch (Die.getTag()) { | ||
|
@@ -217,7 +224,7 @@ void DWARF5AcceleratorTable::addAccelTableEntry( | |
}; | ||
|
||
if (!canProcess(Die)) | ||
return; | ||
return std::nullopt; | ||
|
||
// Addes a Unit to either CU, LocalTU or ForeignTU list the first time we | ||
// encounter it. | ||
|
@@ -227,10 +234,11 @@ void DWARF5AcceleratorTable::addAccelTableEntry( | |
addUnit(Unit, DWOID); | ||
} | ||
|
||
auto addEntry = [&](DIEValue ValName) -> void { | ||
auto addEntry = | ||
[&](DIEValue ValName) -> std::optional<BOLTDWARF5AccelTableData *> { | ||
if ((!ValName || ValName.getForm() == dwarf::DW_FORM_string) && | ||
NameToUse.empty()) | ||
return; | ||
return std::nullopt; | ||
std::string Name = ""; | ||
uint64_t NameIndexOffset = 0; | ||
if (NameToUse.empty()) { | ||
|
@@ -275,13 +283,23 @@ void DWARF5AcceleratorTable::addAccelTableEntry( | |
<< ".\n"; | ||
SecondIndex = Iter->second; | ||
} | ||
std::optional<uint64_t> ParentOffset = | ||
(Parent ? std::optional<uint64_t>(getEntryID(**Parent)) : std::nullopt); | ||
// This will be populated later in writeEntry. | ||
// This way only parent entries get tracked. | ||
// Keeping memory footprint down. | ||
if (ParentOffset) | ||
EntryRelativeOffsets.insert({*ParentOffset, 0}); | ||
It.Values.push_back(new (Allocator) BOLTDWARF5AccelTableData( | ||
Die.getOffset(), std::nullopt, DieTag, UnitID, IsTU, SecondIndex)); | ||
Die.getOffset(), ParentOffset, DieTag, UnitID, IsTU, SecondIndex)); | ||
return It.Values.back(); | ||
}; | ||
|
||
addEntry(Die.findAttribute(dwarf::Attribute::DW_AT_name)); | ||
addEntry(Die.findAttribute(dwarf::Attribute::DW_AT_linkage_name)); | ||
return; | ||
std::optional<BOLTDWARF5AccelTableData *> NameEntry = | ||
addEntry(Die.findAttribute(dwarf::Attribute::DW_AT_name)); | ||
std::optional<BOLTDWARF5AccelTableData *> LinkageNameEntry = | ||
addEntry(Die.findAttribute(dwarf::Attribute::DW_AT_linkage_name)); | ||
return NameEntry ? NameEntry : LinkageNameEntry; | ||
} | ||
|
||
/// Algorithm from llvm implementation. | ||
|
@@ -382,6 +400,11 @@ void DWARF5AcceleratorTable::populateAbbrevsMap() { | |
if (SecondEntryRet) | ||
Abbrev.addAttribute(SecondEntryRet->Encoding); | ||
Abbrev.addAttribute({dwarf::DW_IDX_die_offset, dwarf::DW_FORM_ref4}); | ||
if (std::optional<uint64_t> Offset = Value->getParentDieOffset()) | ||
Abbrev.addAttribute({dwarf::DW_IDX_parent, dwarf::DW_FORM_ref4}); | ||
else | ||
Abbrev.addAttribute( | ||
{dwarf::DW_IDX_parent, dwarf::DW_FORM_flag_present}); | ||
FoldingSetNodeID ID; | ||
Abbrev.Profile(ID); | ||
void *InsertPos; | ||
|
@@ -401,7 +424,11 @@ void DWARF5AcceleratorTable::populateAbbrevsMap() { | |
} | ||
} | ||
|
||
void DWARF5AcceleratorTable::writeEntry(const BOLTDWARF5AccelTableData &Entry) { | ||
void DWARF5AcceleratorTable::writeEntry(BOLTDWARF5AccelTableData &Entry) { | ||
const uint64_t EntryID = getEntryID(Entry); | ||
if (EntryRelativeOffsets.find(EntryID) != EntryRelativeOffsets.end()) | ||
EntryRelativeOffsets[EntryID] = EntriesBuffer->size(); | ||
|
||
const std::optional<DWARF5AccelTable::UnitIndexAndEncoding> EntryRet = | ||
getIndexForEntry(Entry); | ||
// For forgeign type (FTU) units that need to refer to the FTU and to the CU. | ||
|
@@ -456,6 +483,17 @@ void DWARF5AcceleratorTable::writeEntry(const BOLTDWARF5AccelTableData &Entry) { | |
llvm::endianness::little); | ||
break; | ||
} | ||
case dwarf::DW_IDX_parent: { | ||
assert( | ||
(AttrEnc.Form == dwarf::DW_FORM_ref4 && Entry.getParentDieOffset()) || | ||
AttrEnc.Form == dwarf::DW_FORM_flag_present); | ||
if (std::optional<uint64_t> ParentOffset = Entry.getParentDieOffset()) { | ||
Entry.setPatchOffset(EntriesBuffer->size()); | ||
support::endian::write(*Entriestream, static_cast<uint32_t>(0xBADF00D), | ||
ayermolo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
llvm::endianness::little); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -464,13 +502,33 @@ void DWARF5AcceleratorTable::writeEntries() { | |
for (auto &Bucket : getBuckets()) { | ||
for (DWARF5AcceleratorTable::HashData *Hash : Bucket) { | ||
Hash->EntryOffset = EntriesBuffer->size(); | ||
for (const BOLTDWARF5AccelTableData *Value : Hash->Values) { | ||
for (BOLTDWARF5AccelTableData *Value : Hash->Values) { | ||
writeEntry(*Value); | ||
} | ||
support::endian::write(*Entriestream, static_cast<uint8_t>(0), | ||
llvm::endianness::little); | ||
} | ||
} | ||
// Patching parent offsets. | ||
for (auto &Bucket : getBuckets()) { | ||
for (DWARF5AcceleratorTable::HashData *Hash : Bucket) { | ||
for (BOLTDWARF5AccelTableData *Entry : Hash->Values) { | ||
std::optional<uint64_t> ParentOffset = Entry->getParentDieOffset(); | ||
if (!ParentOffset) | ||
continue; | ||
if (const auto Iter = EntryRelativeOffsets.find(*ParentOffset); | ||
Iter != EntryRelativeOffsets.end()) { | ||
const uint64_t PatchOffset = Entry->getPatchOffset(); | ||
uint32_t *Ptr = reinterpret_cast<uint32_t *>( | ||
&EntriesBuffer.get()->data()[PatchOffset]); | ||
*Ptr = Iter->second; | ||
} else { | ||
BC.errs() << "Could not find entry with offset " << *ParentOffset | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it a warning or an error and when can it get triggered? If the former, change the message to: "BOLT-WARNING: could not find...". |
||
<< "\n"; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
void DWARF5AcceleratorTable::writeAugmentationString() { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.