@@ -793,35 +793,19 @@ class RelroPaddingSection final : public SyntheticSection {
793
793
void writeTo (uint8_t *buf) override {}
794
794
};
795
795
796
- template <class ELFT > class DebugNamesSection final : public SyntheticSection {
797
- // N.B. Everything in this class assumes that we are using DWARF32.
798
- // If we move to DWARF64, most of this data will need to be re-sized,
799
- // and the code that handles or manipulates it will need to be updated
800
- // accordingly.
801
-
796
+ // Used by the merged DWARF32 .debug_names (a per-module index). If we
797
+ // move to DWARF64, most of this data will need to be re-sized.
798
+ class DebugNamesBaseSection : public SyntheticSection {
802
799
public:
803
- DebugNamesSection ();
804
- static DebugNamesSection *create ();
805
- void writeTo (uint8_t *buf) override ;
806
- size_t getSize () const override { return sectionSize; }
807
- bool isNeeded () const override ;
808
-
809
- template <class RelTy >
810
- void getNameRelocsImpl (InputSection *sec, ArrayRef<RelTy> rels,
811
- llvm::DenseMap<uint32_t , uint32_t > &relocs);
812
-
813
- void getNameRelocs (InputSectionBase *base,
814
- llvm::DenseMap<uint32_t , uint32_t > &relocs);
815
-
816
- struct Abbrev : public llvm ::FoldingSetNode {
800
+ struct Abbrev : llvm::FoldingSetNode {
817
801
uint32_t code;
818
802
uint32_t tag;
819
803
SmallVector<llvm::DWARFDebugNames::AttributeEncoding, 2 > attributes;
820
804
821
805
void Profile (llvm::FoldingSetNodeID &id) const ;
822
806
};
823
807
824
- struct AttrValueData {
808
+ struct AttrValue {
825
809
uint32_t attrValue;
826
810
uint8_t attrSize;
827
811
};
@@ -830,86 +814,103 @@ template <class ELFT> class DebugNamesSection final : public SyntheticSection {
830
814
uint32_t abbrevCode;
831
815
uint32_t poolOffset;
832
816
union {
833
- int32_t parentOffset = - 1 ;
817
+ uint64_t parentOffset = 0 ;
834
818
IndexEntry *parentEntry;
835
819
};
836
- SmallVector<AttrValueData , 3 > attrValues;
820
+ SmallVector<AttrValue , 3 > attrValues;
837
821
};
838
822
839
- struct NamedEntry {
823
+ struct NameEntry {
840
824
const char *name;
841
825
uint32_t hashValue;
842
- uint32_t stringOffsetOffset ;
826
+ uint32_t stringOffset ;
843
827
uint32_t entryOffset;
844
- uint32_t relocatedEntryOffset;
845
- // The index of the chunk that 'name' points into, for looking up
846
- // relocation data for this string.
828
+ // Used to relocate `stringOffset` in the merged section.
847
829
uint32_t chunkIdx;
848
- SmallVector<std::unique_ptr<IndexEntry>, 0 > indexEntries;
849
- };
830
+ SmallVector<IndexEntry *, 0 > indexEntries;
850
831
851
- struct SectionOffsetLocs {
852
- uint64_t stringOffsetsBase;
853
- uint64_t entryOffsetsBase;
854
- uint64_t entriesBase;
832
+ llvm::iterator_range<
833
+ llvm::pointee_iterator<typename SmallVector<IndexEntry *, 0 >::iterator>>
834
+ entries () {
835
+ return llvm::make_pointee_range (indexEntries);
836
+ }
855
837
};
856
838
857
- struct DebugNamesSectionData {
839
+ // One name index described by an input .debug_names section. An InputChunk
840
+ // typically contains one single name index.
841
+ struct NameData {
858
842
llvm::DWARFDebugNames::Header hdr;
859
- llvm::DWARFDebugNames::DWARFDebugNamesOffsets locs;
860
- SmallVector<uint32_t , 0 > tuOffsets;
861
- SmallVector<Abbrev, 0 > abbrevTable;
862
- SmallVector<uint32_t , 0 > entryOffsets;
863
- SmallVector<NamedEntry, 0 > namedEntries;
864
- uint16_t dwarfSize;
865
- uint16_t hdrSize;
843
+ llvm::DenseMap<uint32_t , uint32_t > abbrevCodeMap;
844
+ SmallVector<NameEntry, 0 > nameEntries;
866
845
};
867
846
868
- // Per-file data used, while reading in the data, to generate the merged
869
- // section information.
870
- struct DebugNamesInputChunk {
871
- uint32_t baseCuOffsetIdx;
872
- std::unique_ptr<llvm::DWARFDebugNames> debugNamesData;
873
- std::unique_ptr<LLDDWARFSection> namesSection;
874
- SmallVector<DebugNamesSectionData, 0 > sectionsData;
875
- SmallVector<uint32_t , 0 > hashValues;
876
- llvm::DenseMap<uint32_t , uint32_t > abbrevCodeMap;
847
+ // InputChunk and OutputChunk hold per-file contribution to the merged index.
848
+ // InputChunk instances will be discarded after `create` completes.
849
+ struct InputChunk {
850
+ uint32_t baseCuIdx;
851
+ LLDDWARFSection section;
852
+ SmallVector<NameData, 0 > nameData;
853
+ std::optional<llvm::DWARFDebugNames> llvmDebugNames;
877
854
};
878
855
879
- // Per-file data needed for correctly writing out the .debug_names section.
880
- struct DebugNamesOutputChunk {
881
- // Pointer to .debug_info section for this chunk/file, used for
882
- // calculating correct relocated CU offsets in the merged index.
883
- InputSection *sec;
884
- SmallVector<uint32_t , 0 > compilationUnits;
885
- SmallVector<uint32_t , 0 > typeUnits;
856
+ struct OutputChunk {
857
+ // Pointer to the .debug_info section that contains compile units, used to
858
+ // compute the relocated CU offsets.
859
+ InputSection *infoSec;
860
+ SmallVector<uint32_t , 0 > compUnits;
886
861
};
887
862
888
- void collectMergedCounts (MutableArrayRef<DebugNamesInputChunk> &inputChunks);
889
- std::pair<uint8_t , llvm::dwarf::Form> getMergedCuSizeData ();
890
- void getMergedAbbrevTable (MutableArrayRef<DebugNamesInputChunk> &inputChunks);
891
- void getMergedSymbols (MutableArrayRef<DebugNamesInputChunk> &inputChunks);
892
- void computeUniqueHashes (MutableArrayRef<DebugNamesInputChunk> &inputChunks);
893
- void generateBuckets ();
894
- void calculateEntriesSizeAndOffsets ();
895
- void updateParentIndexEntries ();
896
- uint64_t calculateMergedSectionSize ();
863
+ DebugNamesBaseSection ();
864
+ size_t getSize () const override { return size; }
865
+ bool isNeeded () const override { return numChunks > 0 ; }
897
866
867
+ protected:
868
+ void init (llvm::function_ref<void (InputFile *, InputChunk &, OutputChunk &)>);
869
+ static void
870
+ parseDebugNames (InputChunk &inputChunk, OutputChunk &chunk,
871
+ llvm::DWARFDataExtractor &namesExtractor,
872
+ llvm::DataExtractor &strExtractor,
873
+ llvm::function_ref<SmallVector<uint32_t , 0 >(
874
+ const llvm::DWARFDebugNames::Header &hdr,
875
+ const llvm::DWARFDebugNames::DWARFDebugNamesOffsets &)>
876
+ readOffsets);
877
+ void computeHdrAndAbbrevTable (MutableArrayRef<InputChunk>);
878
+ std::pair<uint32_t , uint32_t > computeEntryPool (MutableArrayRef<InputChunk>);
879
+
880
+ // Input .debug_names sections for relocating string offsets in the name table
881
+ // in finalizeContents.
882
+ SmallVector<InputSection *, 0 > inputSections;
883
+
884
+ llvm::DWARFDebugNames::Header hdr;
885
+ size_t numChunks;
886
+ std::unique_ptr<OutputChunk[]> chunks;
898
887
llvm::SpecificBumpPtrAllocator<Abbrev> abbrevAlloc;
888
+ SmallVector<Abbrev *, 0 > abbrevTable;
889
+ SmallVector<char , 0 > abbrevTableBuf;
890
+
891
+ // Sharded name entries that will be used to compute bucket_count and the
892
+ // count name table.
893
+ static constexpr size_t numShards = 32 ;
894
+ SmallVector<NameEntry, 0 > nameVecs[numShards];
895
+ };
896
+
897
+ // Complement DebugNamesBaseSection for ELFT-aware code: reading offsets,
898
+ // relocating string offsets, and writeTo.
899
+ template <class ELFT >
900
+ class DebugNamesSection final : public DebugNamesBaseSection {
901
+ public:
902
+ DebugNamesSection ();
903
+ void finalizeContents () override ;
904
+ void writeTo (uint8_t *buf) override ;
905
+
906
+ template <class RelTy >
907
+ void getNameRelocs (InputSection *sec, ArrayRef<RelTy> rels,
908
+ llvm::DenseMap<uint32_t , uint32_t > &relocs);
899
909
900
910
private:
901
- size_t sectionSize;
902
- uint32_t mergedTotalEntriesSize;
903
- uint32_t numChunks;
904
- llvm::DWARFDebugNames::DWARFDebugNamesOffsets mergedOffsets;
905
- std::unique_ptr<DebugNamesOutputChunk[]> outputChunks;
906
- // Pointers to the original .debug_names sections; used for find the correct'
907
- // string relocation values when writing out the merged index.
908
- SmallVector<InputSectionBase *, 0 > inputDebugNamesSections;
909
- llvm::DWARFDebugNames::Header mergedHdr;
910
- SmallVector<Abbrev *, 0 > mergedAbbrevTable;
911
- SmallVector<NamedEntry, 0 > mergedEntries;
912
- SmallVector<SmallVector<NamedEntry *, 0 >, 0 > bucketList;
911
+ static void readOffsets (InputChunk &inputChunk, OutputChunk &chunk,
912
+ llvm::DWARFDataExtractor &namesExtractor,
913
+ llvm::DataExtractor &strExtractor);
913
914
};
914
915
915
916
class GdbIndexSection final : public SyntheticSection {
@@ -1487,6 +1488,7 @@ struct InStruct {
1487
1488
std::unique_ptr<IBTPltSection> ibtPlt;
1488
1489
std::unique_ptr<RelocationBaseSection> relaPlt;
1489
1490
// Non-SHF_ALLOC sections
1491
+ std::unique_ptr<SyntheticSection> debugNames;
1490
1492
std::unique_ptr<GdbIndexSection> gdbIndex;
1491
1493
std::unique_ptr<StringTableSection> shStrTab;
1492
1494
std::unique_ptr<StringTableSection> strTab;
0 commit comments