Skip to content

Commit e0ec301

Browse files
cmticeMaskRay
authored andcommitted
[lld][ELF] Implement merged .debug_names section.
Update debug-names*.s tests, to use split file format rather than multiple files. Reduce the use of 'auto' in DebugNamesSection work, replacing it with actual type names. Use UINT*_MAXINT rather than constant values.
1 parent 9cbf145 commit e0ec301

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

lld/ELF/SyntheticSections.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,7 +2761,7 @@ template <class ELFT> void DebugNamesSection<ELFT>::writeTo(uint8_t *buf) {
27612761
}
27622762

27632763
// Update the entries with the relocated string offsets.
2764-
for (auto &stringEntry : mergedEntries) {
2764+
for (NamedEntry &stringEntry : mergedEntries) {
27652765
uint32_t oldOffset = stringEntry.stringOffsetOffset;
27662766
uint32_t idx = stringEntry.chunkIdx;
27672767
stringEntry.relocatedEntryOffset = chunksRelocs[idx][oldOffset];
@@ -2802,7 +2802,7 @@ template <class ELFT> void DebugNamesSection<ELFT>::writeTo(uint8_t *buf) {
28022802
// Write the hash table.
28032803
// ... Write the buckets
28042804
uint32_t idx = 1;
2805-
for (const auto &bucket : bucketList) {
2805+
for (const SmallVector<NamedEntry *, 0> &bucket : bucketList) {
28062806
if (!bucket.empty())
28072807
endian::write32<ELFT::Endianness>(buf + 0, idx);
28082808
idx += bucket.size();
@@ -2819,7 +2819,7 @@ template <class ELFT> void DebugNamesSection<ELFT>::writeTo(uint8_t *buf) {
28192819
}
28202820

28212821
// Write the string offsets.
2822-
for (const auto &entry : mergedEntries) {
2822+
for (const NamedEntry &entry : mergedEntries) {
28232823
endian::write32<ELFT::Endianness>(buf + 0, entry.relocatedEntryOffset);
28242824
buf += 4;
28252825
}
@@ -2831,10 +2831,10 @@ template <class ELFT> void DebugNamesSection<ELFT>::writeTo(uint8_t *buf) {
28312831
}
28322832

28332833
// Write the abbrev table.
2834-
for (const auto *abbrev : mergedAbbrevTable) {
2834+
for (const Abbrev *abbrev : mergedAbbrevTable) {
28352835
buf += encodeULEB128(abbrev->code, buf);
28362836
buf += encodeULEB128(abbrev->tag, buf);
2837-
for (auto attr : abbrev->attributes) {
2837+
for (DWARFDebugNames::AttributeEncoding attr : abbrev->attributes) {
28382838
buf += encodeULEB128(attr.Index, buf);
28392839
buf += encodeULEB128(attr.Form, buf);
28402840
}
@@ -2846,7 +2846,7 @@ template <class ELFT> void DebugNamesSection<ELFT>::writeTo(uint8_t *buf) {
28462846
// Write the entry pool.
28472847
for (const auto &stringEntry : mergedEntries) {
28482848
// Write all the entries for the string.
2849-
for (const auto &entry : stringEntry.indexEntries) {
2849+
for (const std::unique_ptr<IndexEntry> &entry : stringEntry.indexEntries) {
28502850
buf += encodeULEB128(entry->abbrevCode, buf);
28512851
for (const auto &value : entry->attrValues) {
28522852
endian::write32<ELFT::Endianness>(buf + 0, value.attrValue);
@@ -2901,7 +2901,7 @@ static void readAttributeValues(
29012901
const LLDDWARFSection &namesSection = *chunk.namesSection;
29022902
uint64_t *offsetPtr = &offset;
29032903
typename DebugNamesSection<ELFT>::AttrValueData cuOrTuAttr = {0, 0};
2904-
for (auto attr : abbrev.Attributes) {
2904+
for (DWARFDebugNames::AttributeEncoding attr : abbrev.Attributes) {
29052905
Error err = Error::success();
29062906
typename DebugNamesSection<ELFT>::AttrValueData newAttr;
29072907
uint32_t value;
@@ -3154,13 +3154,13 @@ std::pair<uint8_t, dwarf::Form> DebugNamesSection<ELFT>::getMergedCuSizeData() {
31543154
uint8_t size;
31553155
dwarf::Form form;
31563156
// TODO: Investigate possibly using DIEInteger::BestForm here
3157-
if (mergedHdr.CompUnitCount > 0xffffffff) {
3157+
if (mergedHdr.CompUnitCount > UINT32_MAX) {
31583158
form = DW_FORM_data8;
31593159
size = 8;
3160-
} else if (mergedHdr.CompUnitCount > 0xffff) {
3160+
} else if (mergedHdr.CompUnitCount > UINT16_MAX) {
31613161
form = DW_FORM_data4;
31623162
size = 4;
3163-
} else if (mergedHdr.CompUnitCount > 0xff) {
3163+
} else if (mergedHdr.CompUnitCount > UINT8_MAX) {
31643164
form = DW_FORM_data2;
31653165
size = 2;
31663166
} else {
@@ -3192,7 +3192,8 @@ void DebugNamesSection<ELFT>::getMergedAbbrevTable(
31923192
compileUnitAttrForm);
31933193
newAbbrev.code = abbrev.Code;
31943194
newAbbrev.tag = abbrev.Tag;
3195-
for (const auto attr : abbrev.Attributes) {
3195+
for (const DWARFDebugNames::AttributeEncoding attr :
3196+
abbrev.Attributes) {
31963197
DWARFDebugNames::AttributeEncoding newAttr(attr.Index, attr.Form);
31973198
if (attr.Index == DW_IDX_compile_unit)
31983199
// Save it, to put it at the end.
@@ -3233,7 +3234,7 @@ void DebugNamesSection<ELFT>::getMergedAbbrevTable(
32333234
for (Abbrev *a : mergedAbbrevTable) {
32343235
mergedHdr.AbbrevTableSize += getULEB128Size(a->code);
32353236
mergedHdr.AbbrevTableSize += getULEB128Size(a->tag);
3236-
for (const auto &attr : a->attributes) {
3237+
for (const DWARFDebugNames::AttributeEncoding &attr : a->attributes) {
32373238
mergedHdr.AbbrevTableSize += getULEB128Size(attr.Index);
32383239
mergedHdr.AbbrevTableSize += getULEB128Size(attr.Form);
32393240
}
@@ -3268,22 +3269,22 @@ void DebugNamesSection<ELFT>::getMergedSymbols(
32683269
parallelFor(0, concurrency, [&](size_t threadId) {
32693270
for (size_t i = 0, e = numChunks; i != e; ++i) {
32703271
DebugNamesInputChunk &chunk = inputChunks[i];
3271-
for (auto &secData : chunk.sectionsData) {
3272+
for (DebugNamesSectionData &secData : chunk.sectionsData) {
32723273
// Deduplicate the NamedEntry records (based on the string/name),
32733274
// using a map from string/name to NamedEntry records.
32743275
// Note there is a twist: If there is already a record for the current
32753276
// 'string' in the nameMap, we append all the indexEntries from the
32763277
// current record to the record that's in the nameMap. I.e. we
32773278
// deduplicate the *strings* but we keep all the IndexEntry records
32783279
// (moving them to the appropriate 'kept' NamedEntry record).
3279-
for (auto &stringEntry : secData.namedEntries) {
3280+
for (NamedEntry &stringEntry : secData.namedEntries) {
32803281
size_t shardId = stringEntry.hashValue >> shift;
32813282
if ((shardId & (concurrency - 1)) != threadId)
32823283
continue;
32833284

32843285
auto &shard = shards[shardId];
32853286
stringEntry.chunkIdx = i;
3286-
for (auto &entry : stringEntry.indexEntries) {
3287+
for (std::unique_ptr<IndexEntry> &entry : stringEntry.indexEntries) {
32873288
// The DW_IDX_compile_unit is always the last attribute (we set it
32883289
// up that way when we read/created the attributes). We need to
32893290
// update the index value to use the correct merged offset, and we
@@ -3313,7 +3314,7 @@ void DebugNamesSection<ELFT>::getMergedSymbols(
33133314
});
33143315

33153316
// Combined the shared symbols into mergedEntries
3316-
for (auto &shard : shards)
3317+
for (ShardData &shard : shards)
33173318
for (auto &mapEntry : shard.nameMap)
33183319
mergedEntries.push_back(std::move(mapEntry.second));
33193320
mergedHdr.NameCount = mergedEntries.size();
@@ -3330,14 +3331,14 @@ void DebugNamesSection<ELFT>::computeUniqueHashes(
33303331

33313332
template <class ELFT> void DebugNamesSection<ELFT>::generateBuckets() {
33323333
bucketList.resize(mergedHdr.BucketCount);
3333-
for (auto &entry : mergedEntries) {
3334+
for (NamedEntry &entry : mergedEntries) {
33343335
uint32_t bucketIdx = entry.hashValue % mergedHdr.BucketCount;
33353336
bucketList[bucketIdx].push_back(&entry);
33363337
}
33373338

33383339
// Sort the contents of the buckets by hash value so that the hash collisions
33393340
// end up together.
3340-
for (auto &bucket : bucketList)
3341+
for (SmallVector<NamedEntry *, 0> &bucket : bucketList)
33413342
stable_sort(bucket, [](NamedEntry *lhs, NamedEntry *rhs) {
33423343
return lhs->hashValue < rhs->hashValue;
33433344
});
@@ -3348,7 +3349,7 @@ void DebugNamesSection<ELFT>::calculateEntriesSizeAndOffsets() {
33483349
uint32_t offset = 0;
33493350
for (NamedEntry &stringEntry : mergedEntries) {
33503351
stringEntry.entryOffset = offset;
3351-
for (auto &entry : stringEntry.indexEntries) {
3352+
for (std::unique_ptr<IndexEntry> &entry : stringEntry.indexEntries) {
33523353
uint32_t entrySize = 0;
33533354
entry->poolOffset = offset;
33543355
entrySize += getULEB128Size(entry->abbrevCode);
@@ -3364,7 +3365,7 @@ void DebugNamesSection<ELFT>::calculateEntriesSizeAndOffsets() {
33643365

33653366
template <class ELFT> void DebugNamesSection<ELFT>::updateParentIndexEntries() {
33663367
for (NamedEntry &stringEntry : mergedEntries) {
3367-
for (auto &childEntry : stringEntry.indexEntries) {
3368+
for (std::unique_ptr<IndexEntry> &childEntry : stringEntry.indexEntries) {
33683369
if (!childEntry->parentEntry)
33693370
continue;
33703371

@@ -3377,7 +3378,7 @@ template <class ELFT> void DebugNamesSection<ELFT>::updateParentIndexEntries() {
33773378
// correct parent offset (in the merged entry pool).
33783379
for (size_t idx = 0, size = abbrev->attributes.size(); idx != size;
33793380
++idx) {
3380-
auto attr = abbrev->attributes[idx];
3381+
DWARFDebugNames::AttributeEncoding attr = abbrev->attributes[idx];
33813382
if (attr.Index == DW_IDX_parent && attr.Form == DW_FORM_ref4)
33823383
childEntry->attrValues[idx].attrValue =
33833384
childEntry->parentEntry->poolOffset;

0 commit comments

Comments
 (0)