-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[BOLT][DWARF] Add support for .debug_names #81062
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 all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
989cd08
[BOLT][DWARF] Add support for .debug_names
ayermolo 9540fa3
changed from class to struct
ayermolo 6237ac5
changed parent bit allocations
ayermolo 6a1d310
first round of comments
ayermolo 6193f98
changed abbrev handling to be inline with llvm
ayermolo a83812b
removed assert, changed to SmallVector
ayermolo 22ccd1f
changed api name
ayermolo 5f265d7
changed cast, switched to BC.errs()
ayermolo eb29fa0
changed augmenation string
ayermolo 1202925
updated tests
ayermolo 8ec1f39
updated length in tests, and entry offsets
ayermolo 06cc684
changed how string offsets are read. Don't need to use DebugStrOffset…
ayermolo 052d57c
changed from nubmer to constexpr bad address
ayermolo f69898b
changed to explict byte size
ayermolo 0e8d99c
addressed nits
ayermolo 7885bad
added empty line back in
ayermolo 356be19
added empty line back in DIEBuilder
ayermolo 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 |
---|---|---|
@@ -0,0 +1,172 @@ | ||
//===- bolt/Core/DebugNames.h - Debug names support ---*- C++ | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file contains declaration of classes required for generation of | ||
// .debug_names section. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef BOLT_CORE_DEBUG_NAMES_H | ||
#define BOLT_CORE_DEBUG_NAMES_H | ||
|
||
#include "DebugData.h" | ||
#include "llvm/CodeGen/AccelTable.h" | ||
|
||
namespace llvm { | ||
namespace bolt { | ||
class BOLTDWARF5AccelTableData : public DWARF5AccelTableData { | ||
public: | ||
BOLTDWARF5AccelTableData(const uint64_t DieOffset, | ||
const std::optional<uint64_t> DefiningParentOffset, | ||
const unsigned DieTag, const unsigned UnitID, | ||
const bool IsTU, | ||
const std::optional<unsigned> SecondUnitID) | ||
: DWARF5AccelTableData(DieOffset, DefiningParentOffset, DieTag, UnitID, | ||
IsTU), | ||
SecondUnitID(SecondUnitID) {} | ||
|
||
uint64_t getDieOffset() const { return DWARF5AccelTableData::getDieOffset(); } | ||
unsigned getDieTag() const { return DWARF5AccelTableData::getDieTag(); } | ||
unsigned getUnitID() const { return DWARF5AccelTableData::getUnitID(); } | ||
bool isTU() const { return DWARF5AccelTableData::isTU(); } | ||
std::optional<unsigned> getSecondUnitID() const { return SecondUnitID; } | ||
|
||
private: | ||
std::optional<unsigned> SecondUnitID; | ||
}; | ||
|
||
class DWARF5AcceleratorTable { | ||
public: | ||
DWARF5AcceleratorTable(const bool CreateDebugNames, BinaryContext &BC, | ||
DebugStrWriter &MainBinaryStrWriter); | ||
~DWARF5AcceleratorTable() { | ||
for (DebugNamesAbbrev *Abbrev : AbbreviationsVector) | ||
Abbrev->~DebugNamesAbbrev(); | ||
} | ||
/// Add DWARF5 Accelerator table entry. | ||
/// Input is DWARFUnit being processed, DIE that belongs to it, and potential | ||
/// SkeletonCU if the Unit comes from a DWO section. | ||
void addAccelTableEntry(DWARFUnit &Unit, const DIE &Die, | ||
const std::optional<uint64_t> &DWOID); | ||
/// Set current unit being processed. | ||
void setCurrentUnit(DWARFUnit &Unit, const uint64_t UnitStartOffset); | ||
/// Emit Accelerator table. | ||
void emitAccelTable(); | ||
/// Returns true if the table was crated. | ||
bool isCreated() const { return NeedToCreate; } | ||
/// Returns buffer containing the accelerator table. | ||
std::unique_ptr<DebugBufferVector> releaseBuffer() { | ||
return std::move(FullTableBuffer); | ||
} | ||
|
||
private: | ||
BinaryContext &BC; | ||
bool NeedToCreate = false; | ||
BumpPtrAllocator Allocator; | ||
DebugStrWriter &MainBinaryStrWriter; | ||
StringRef StrSection; | ||
uint64_t CurrentUnitOffset = 0; | ||
const DWARFUnit *CurrentUnit = nullptr; | ||
std::unordered_map<uint32_t, uint32_t> AbbrevTagToIndexMap; | ||
|
||
/// Represents a group of entries with identical name (and hence, hash value). | ||
struct HashData { | ||
uint64_t StrOffset; | ||
uint32_t HashValue; | ||
uint32_t EntryOffset; | ||
std::vector<BOLTDWARF5AccelTableData *> Values; | ||
}; | ||
using HashList = std::vector<HashData *>; | ||
using BucketList = std::vector<HashList>; | ||
/// Contains all the offsets of CUs. | ||
SmallVector<uint32_t, 1> CUList; | ||
/// Contains all the offsets of local TUs. | ||
SmallVector<uint32_t, 1> LocalTUList; | ||
/// Contains all the type hashes for split dwarf TUs. | ||
SmallVector<uint64_t, 1> ForeignTUList; | ||
using StringEntries = | ||
MapVector<std::string, HashData, llvm::StringMap<unsigned>>; | ||
StringEntries Entries; | ||
/// FoldingSet that uniques the abbreviations. | ||
FoldingSet<DebugNamesAbbrev> AbbreviationsSet; | ||
/// Vector containing DebugNames abbreviations for iteration in order. | ||
SmallVector<DebugNamesAbbrev *, 5> AbbreviationsVector; | ||
/// The bump allocator to use when creating DIEAbbrev objects in the uniqued | ||
/// storage container. | ||
BumpPtrAllocator Alloc; | ||
uint32_t BucketCount = 0; | ||
uint32_t UniqueHashCount = 0; | ||
uint32_t AbbrevTableSize = 0; | ||
uint32_t CUIndexEncodingSize = 4; | ||
uint32_t TUIndexEncodingSize = 4; | ||
uint32_t AugmentationStringSize = 0; | ||
dwarf::Form CUIndexForm = dwarf::DW_FORM_data4; | ||
dwarf::Form TUIndexForm = dwarf::DW_FORM_data4; | ||
|
||
BucketList Buckets; | ||
|
||
std::unique_ptr<DebugBufferVector> FullTableBuffer; | ||
std::unique_ptr<raw_svector_ostream> FullTableStream; | ||
std::unique_ptr<DebugBufferVector> StrBuffer; | ||
std::unique_ptr<raw_svector_ostream> StrStream; | ||
std::unique_ptr<DebugBufferVector> EntriesBuffer; | ||
std::unique_ptr<raw_svector_ostream> Entriestream; | ||
std::unique_ptr<DebugBufferVector> AugStringBuffer; | ||
std::unique_ptr<raw_svector_ostream> AugStringtream; | ||
llvm::DenseMap<llvm::hash_code, uint64_t> StrCacheToOffsetMap; | ||
// Contains DWO ID to CUList Index. | ||
llvm::DenseMap<uint64_t, uint32_t> CUOffsetsToPatch; | ||
/// Adds Unit to either CUList, LocalTUList or ForeignTUList. | ||
/// Input Unit being processed, and DWO ID if Unit is being processed comes | ||
/// from a DWO section. | ||
void addUnit(DWARFUnit &Unit, const std::optional<uint64_t> &DWOID); | ||
/// Returns number of buckets in .debug_name table. | ||
ArrayRef<HashList> getBuckets() const { return Buckets; } | ||
/// Get encoding for a given attribute. | ||
std::optional<DWARF5AccelTable::UnitIndexAndEncoding> | ||
getIndexForEntry(const BOLTDWARF5AccelTableData &Value) const; | ||
/// Get encoding for a given attribute for second index. | ||
/// Returns nullopt if there is no second index. | ||
std::optional<DWARF5AccelTable::UnitIndexAndEncoding> | ||
getSecondIndexForEntry(const BOLTDWARF5AccelTableData &Value) const; | ||
/// Uniquify Entries. | ||
void finalize(); | ||
/// Computes bucket count. | ||
void computeBucketCount(); | ||
/// Populate Abbreviations Map. | ||
void populateAbbrevsMap(); | ||
/// Write Entries. | ||
void writeEntries(); | ||
/// Write an Entry. | ||
void writeEntry(const BOLTDWARF5AccelTableData &Entry); | ||
/// Write augmentation_string for BOLT. | ||
void writeAugmentationString(); | ||
/// Emit out Header for DWARF5 Accelerator table. | ||
void emitHeader() const; | ||
/// Emit out CU list. | ||
void emitCUList() const; | ||
/// Emit out TU List. Combination of LocalTUList and ForeignTUList. | ||
void emitTUList() const; | ||
/// Emit buckets. | ||
void emitBuckets() const; | ||
/// Emit hashes for hash table. | ||
void emitHashes() const; | ||
/// Emit string offsets for hash table. | ||
void emitStringOffsets() const; | ||
/// Emit Entry Offsets for hash table. | ||
void emitOffsets() const; | ||
/// Emit abbreviation table. | ||
void emitAbbrevs(); | ||
/// Emit entries. | ||
void emitData(); | ||
/// Emit augmentation string. | ||
void emitAugmentationString() const; | ||
}; | ||
} // namespace bolt | ||
} // namespace llvm | ||
#endif |
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
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.