Remove GdbIndexSection::finalizeContents.

GdbIndexSection doesn't need lazy finalization because when an instance
of the class is created, we already know all debug info sections.
We can initialize the instnace in the ctor.

llvm-svn: 310931
This commit is contained in:
Rui Ueyama
2017-08-15 17:01:39 +00:00
parent e5d642cf5b
commit 2b6631bb36
3 changed files with 28 additions and 38 deletions

View File

@@ -1708,10 +1708,6 @@ unsigned PltSection::getPltRelocOff() const {
return (HeaderSize == 0) ? InX::Plt->getSize() : 0;
}
GdbIndexSection::GdbIndexSection(std::vector<GdbIndexChunk> &&Chunks)
: SyntheticSection(0, SHT_PROGBITS, 1, ".gdb_index"),
StringPool(llvm::StringTableBuilder::ELF), Chunks(std::move(Chunks)) {}
// The hash function used for .gdb_index version 5 or above.
static uint32_t gdbHash(StringRef Str) {
uint32_t R = 0;
@@ -1793,7 +1789,7 @@ void GdbIndexSection::buildIndex() {
bool IsNew;
GdbSymbol *Sym;
std::tie(IsNew, Sym) = SymbolTable.add(Hash, Offset);
std::tie(IsNew, Sym) = HashTab.add(Hash, Offset);
if (IsNew) {
Sym->CuVectorIndex = CuVectors.size();
CuVectors.resize(CuVectors.size() + 1);
@@ -1840,44 +1836,37 @@ static size_t getAddressAreaSize(ArrayRef<GdbIndexChunk> Arr) {
return Ret;
}
void GdbIndexSection::finalizeContents() {
if (Finalized)
return;
Finalized = true;
GdbIndexSection::GdbIndexSection(std::vector<GdbIndexChunk> &&C)
: SyntheticSection(0, SHT_PROGBITS, 1, ".gdb_index"),
StringPool(llvm::StringTableBuilder::ELF), Chunks(std::move(C)) {
buildIndex();
SymbolTable.finalizeContents();
HashTab.finalizeContents();
// GdbIndex header consist from version fields
// and 5 more fields with different kinds of offsets.
CuTypesOffset = CuListOffset + getCuSize(Chunks) * CompilationUnitSize;
SymTabOffset = CuTypesOffset + getAddressAreaSize(Chunks) * AddressEntrySize;
ConstantPoolOffset =
SymTabOffset + SymbolTable.getCapacity() * SymTabEntrySize;
ConstantPoolOffset = SymTabOffset + HashTab.getCapacity() * SymTabEntrySize;
for (std::set<uint32_t> &CuVec : CuVectors) {
CuVectorsOffset.push_back(CuVectorsSize);
CuVectorsSize += OffsetTypeSize * (CuVec.size() + 1);
}
StringPoolOffset = ConstantPoolOffset + CuVectorsSize;
StringPool.finalizeInOrder();
}
size_t GdbIndexSection::getSize() const {
const_cast<GdbIndexSection *>(this)->finalizeContents();
return StringPoolOffset + StringPool.getSize();
}
void GdbIndexSection::writeTo(uint8_t *Buf) {
write32le(Buf, 7); // Write version.
write32le(Buf + 4, CuListOffset); // CU list offset.
write32le(Buf + 8, CuTypesOffset); // Types CU list offset.
write32le(Buf + 12, CuTypesOffset); // Address area offset.
write32le(Buf + 16, SymTabOffset); // Symbol table offset.
write32le(Buf + 20, ConstantPoolOffset); // Constant pool offset.
write32le(Buf, 7); // Write version
write32le(Buf + 4, CuListOffset); // CU list offset
write32le(Buf + 8, CuTypesOffset); // Types CU list offset
write32le(Buf + 12, CuTypesOffset); // Address area offset
write32le(Buf + 16, SymTabOffset); // Symbol table offset
write32le(Buf + 20, ConstantPoolOffset); // Constant pool offset
Buf += 24;
// Write the CU list.
@@ -1902,8 +1891,8 @@ void GdbIndexSection::writeTo(uint8_t *Buf) {
}
// Write the symbol table.
for (size_t I = 0; I < SymbolTable.getCapacity(); ++I) {
GdbSymbol *Sym = SymbolTable.getSymbol(I);
for (size_t I = 0; I < HashTab.getCapacity(); ++I) {
GdbSymbol *Sym = HashTab.getSymbol(I);
if (Sym) {
size_t NameOffset =
Sym->NameOffset + StringPoolOffset - ConstantPoolOffset;

View File

@@ -504,14 +504,14 @@ class GdbIndexSection final : public SyntheticSection {
public:
GdbIndexSection(std::vector<GdbIndexChunk> &&Chunks);
void finalizeContents() override;
void writeTo(uint8_t *Buf) override;
size_t getSize() const override;
bool empty() const override;
private:
// Symbol table is a hash table for types and names.
// It is the area of gdb index.
GdbHashTab SymbolTable;
GdbHashTab HashTab;
// CU vector is a part of constant pool area of section.
std::vector<std::set<uint32_t>> CuVectors;
@@ -523,7 +523,6 @@ public:
// object and used to build different areas of gdb index.
std::vector<GdbIndexChunk> Chunks;
private:
void buildIndex();
uint32_t CuTypesOffset;
@@ -533,8 +532,6 @@ private:
size_t CuVectorsSize = 0;
std::vector<size_t> CuVectorsOffset;
bool Finalized = false;
};
template <class ELFT> GdbIndexSection *createGdbIndex();

View File

@@ -1293,14 +1293,18 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// Dynamic section must be the last one in this list and dynamic
// symbol table section (DynSymTab) must be the first one.
applySynthetic({InX::DynSymTab, InX::Bss, InX::BssRelRo,
InX::GnuHashTab, In<ELFT>::HashTab, InX::SymTab,
InX::ShStrTab, InX::StrTab, In<ELFT>::VerDef,
InX::DynStrTab, InX::GdbIndex, InX::Got,
InX::MipsGot, InX::IgotPlt, InX::GotPlt,
In<ELFT>::RelaDyn, In<ELFT>::RelaIplt, In<ELFT>::RelaPlt,
InX::Plt, InX::Iplt, In<ELFT>::EhFrameHdr,
In<ELFT>::VerSym, In<ELFT>::VerNeed, InX::Dynamic},
applySynthetic({InX::DynSymTab, InX::Bss,
InX::BssRelRo, InX::GnuHashTab,
In<ELFT>::HashTab, InX::SymTab,
InX::ShStrTab, InX::StrTab,
In<ELFT>::VerDef, InX::DynStrTab,
InX::Got, InX::MipsGot,
InX::IgotPlt, InX::GotPlt,
In<ELFT>::RelaDyn, In<ELFT>::RelaIplt,
In<ELFT>::RelaPlt, InX::Plt,
InX::Iplt, In<ELFT>::EhFrameHdr,
In<ELFT>::VerSym, In<ELFT>::VerNeed,
InX::Dynamic},
[](SyntheticSection *SS) { SS->finalizeContents(); });
// Some architectures use small displacements for jump instructions.