[lld] [lld][ELF] Implement merged .debug_names section. (PR #86508)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 8 18:01:04 PDT 2024
================
@@ -788,6 +792,125 @@ class RelroPaddingSection final : public SyntheticSection {
void writeTo(uint8_t *buf) override {}
};
+template <class ELFT> class DebugNamesSection final : public SyntheticSection {
+ // N.B. Everything in this class assumes that we are using DWARF32.
+ // If we move to DWARF64, most of this data will need to be re-sized,
+ // and the code that handles or manipulates it will need to be updated
+ // accordingly.
+
+public:
+ DebugNamesSection();
+ static DebugNamesSection *create();
+ void writeTo(uint8_t *buf) override;
+ size_t getSize() const override { return sectionSize; }
+ bool isNeeded() const override;
+
+ template <class RelTy>
+ void getNameRelocsImpl(InputSection *sec, ArrayRef<RelTy> rels,
+ llvm::DenseMap<uint32_t, uint32_t> &relocs);
+
+ void getNameRelocs(InputSectionBase *base,
+ llvm::DenseMap<uint32_t, uint32_t> &relocs);
+
+ struct Abbrev : public llvm::FoldingSetNode {
+ uint32_t code;
+ uint32_t tag;
+ SmallVector<llvm::DWARFDebugNames::AttributeEncoding, 2> attributes;
+
+ void Profile(llvm::FoldingSetNodeID &id) const;
+ };
+
+ struct AttrValueData {
+ uint32_t attrValue;
+ uint8_t attrSize;
+ };
+
+ struct IndexEntry {
+ uint32_t abbrevCode;
+ uint32_t poolOffset;
+ union {
+ int32_t parentOffset = -1;
+ IndexEntry *parentEntry;
+ };
+ SmallVector<AttrValueData, 3> attrValues;
+ };
+
+ struct NamedEntry {
+ const char *name;
+ uint32_t hashValue;
+ uint32_t stringOffsetOffset;
+ uint32_t entryOffset;
+ uint32_t relocatedEntryOffset;
+ // The index of the chunk that 'name' points into, for looking up
+ // relocation data for this string.
+ uint32_t chunkIdx;
+ SmallVector<std::unique_ptr<IndexEntry>, 0> indexEntries;
+ };
+
+ struct SectionOffsetLocs {
+ uint64_t stringOffsetsBase;
+ uint64_t entryOffsetsBase;
+ uint64_t entriesBase;
+ };
+
+ struct DebugNamesSectionData {
+ llvm::DWARFDebugNames::Header hdr;
+ llvm::DWARFDebugNames::DWARFDebugNamesOffsets locs;
+ SmallVector<uint32_t, 0> tuOffsets;
+ SmallVector<Abbrev, 0> abbrevTable;
+ SmallVector<uint32_t, 0> entryOffsets;
+ SmallVector<NamedEntry, 0> namedEntries;
+ uint16_t dwarfSize;
+ uint16_t hdrSize;
+ };
+
+ // Per-file data used, while reading in the data, to generate the merged
+ // section information.
+ struct DebugNamesInputChunk {
+ uint32_t baseCuOffsetIdx;
+ std::unique_ptr<llvm::DWARFDebugNames> debugNamesData;
+ std::unique_ptr<LLDDWARFSection> namesSection;
+ SmallVector<DebugNamesSectionData, 0> sectionsData;
+ SmallVector<uint32_t, 0> hashValues;
----------------
MaskRay wrote:
`hashValues` duplicates `hashValue` in entrys. I've removed this member in my branch to reduce memory usage.
https://github.com/llvm/llvm-project/pull/86508
More information about the llvm-commits
mailing list