[PATCH] D54361: [ELF] .gdb_index: fix CuOff when a .debug_info section more than 1 CU
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 9 23:46:04 PST 2018
MaskRay updated this revision to Diff 173491.
MaskRay added a comment.
Use debug_info_offset to index into CUs
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D54361
Files:
ELF/SyntheticSections.cpp
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -2413,28 +2413,45 @@
}
static std::vector<GdbIndexSection::NameTypeEntry>
-readPubNamesAndTypes(DWARFContext &Dwarf, uint32_t Idx) {
+readPubNamesAndTypes(DWARFContext &Dwarf,
+ const std::vector<GdbIndexSection::CuEntry> &CUs) {
StringRef Sec1 = Dwarf.getDWARFObj().getGnuPubNamesSection();
StringRef Sec2 = Dwarf.getDWARFObj().getGnuPubTypesSection();
std::vector<GdbIndexSection::NameTypeEntry> Ret;
for (StringRef Sec : {Sec1, Sec2}) {
DWARFDebugPubTable Table(Sec, Config->IsLE, true);
- for (const DWARFDebugPubTable::Set &Set : Table.getData())
+ for (const DWARFDebugPubTable::Set &Set : Table.getData()) {
+ // The CU offset should be added to I when the entry is written into the
+ // constant pool.
+ uint32_t I =
+ std::lower_bound(CUs.begin(), CUs.end(), Set.Offset,
+ [](const GdbIndexSection::CuEntry &CU,
+ uint32_t Off) { return CU.CuOffset < Off; }) -
+ CUs.begin();
for (const DWARFDebugPubTable::Entry &Ent : Set.Entries)
Ret.push_back({{Ent.Name, computeGdbHash(Ent.Name)},
- (Ent.Descriptor.toBits() << 24) | Idx});
+ (Ent.Descriptor.toBits() << 24) | I});
+ }
}
return Ret;
}
// Create a list of symbols from a given list of symbol names and types
// by uniquifying them by name.
static std::vector<GdbIndexSection::GdbSymbol>
-createSymbols(ArrayRef<std::vector<GdbIndexSection::NameTypeEntry>> NameTypes) {
+createSymbols(ArrayRef<std::vector<GdbIndexSection::NameTypeEntry>> NameTypes,
+ const std::vector<GdbIndexSection::GdbChunk> &Chunks) {
typedef GdbIndexSection::GdbSymbol GdbSymbol;
typedef GdbIndexSection::NameTypeEntry NameTypeEntry;
+ uint32_t CuOff = 0;
+ std::vector<uint32_t> CuOffs(Chunks.size());
+ for (uint32_t I = 0, E = Chunks.size(); I != E; ++I) {
+ CuOffs[I] = CuOff;
+ CuOff += Chunks[I].CompilationUnits.size();
+ }
+
// The number of symbols we will handle in this function is of the order
// of millions for very large executables, so we use multi-threading to
// speed it up.
@@ -2451,21 +2468,24 @@
// Instantiate GdbSymbols while uniqufying them by name.
std::vector<std::vector<GdbSymbol>> Symbols(NumShards);
parallelForEachN(0, Concurrency, [&](size_t ThreadId) {
+ uint32_t I = 0;
for (ArrayRef<NameTypeEntry> Entries : NameTypes) {
for (const NameTypeEntry &Ent : Entries) {
size_t ShardId = Ent.Name.hash() >> Shift;
if ((ShardId & (Concurrency - 1)) != ThreadId)
continue;
+ uint32_t V = Ent.Type + CuOffs[I];
size_t &Idx = Map[ShardId][Ent.Name];
if (Idx) {
- Symbols[ShardId][Idx - 1].CuVector.push_back(Ent.Type);
+ Symbols[ShardId][Idx - 1].CuVector.push_back(V);
continue;
}
Idx = Symbols[ShardId].size() + 1;
- Symbols[ShardId].push_back({Ent.Name, {Ent.Type}, 0, 0});
+ Symbols[ShardId].push_back({Ent.Name, {V}, 0, 0});
}
+ ++I;
}
});
@@ -2517,12 +2537,12 @@
Chunks[I].Sec = Sections[I];
Chunks[I].CompilationUnits = readCuList(Dwarf);
Chunks[I].AddressAreas = readAddressAreas(Dwarf, Sections[I]);
- NameTypes[I] = readPubNamesAndTypes(Dwarf, I);
+ NameTypes[I] = readPubNamesAndTypes(Dwarf, Chunks[I].CompilationUnits);
});
auto *Ret = make<GdbIndexSection>();
Ret->Chunks = std::move(Chunks);
- Ret->Symbols = createSymbols(NameTypes);
+ Ret->Symbols = createSymbols(NameTypes, Ret->Chunks);
Ret->initOutputSize();
return Ret;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54361.173491.patch
Type: text/x-patch
Size: 3825 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181110/228f97a2/attachment.bin>
More information about the llvm-commits
mailing list