[ELF] - Detemplate GdbIndexSection.

Patch moves Sections array to
InputFile (root class for input files).

That allows to detemplate GdbIndexSection.

Differential revision: https://reviews.llvm.org/D30976

llvm-svn: 298345
This commit is contained in:
George Rimar 2017-03-21 08:19:34 +00:00
parent a9611ea4c0
commit 35e846e14d
4 changed files with 23 additions and 30 deletions

View File

@ -74,6 +74,13 @@ public:
StringRef getName() const { return MB.getBufferIdentifier(); }
MemoryBufferRef MB;
// If it is a file that can have sections, like object file or binary file,
// then method returns them.
ArrayRef<InputSectionBase *> getSections() const {
assert(FileKind == ObjectKind || FileKind == BinaryKind);
return Sections;
}
// Filename of .a which contained this file. If this file was
// not in an archive file, it is the empty string. We use this
// string for creating error messages.
@ -88,6 +95,8 @@ public:
protected:
InputFile(Kind K, MemoryBufferRef M) : MB(M), FileKind(K) {}
std::vector<InputSectionBase *> Sections;
private:
const Kind FileKind;
};
@ -190,9 +199,6 @@ private:
bool shouldMerge(const Elf_Shdr &Sec);
SymbolBody *createSymbolBody(const Elf_Sym *Sym);
// List of all sections defined by this file.
std::vector<InputSectionBase *> Sections;
// List of all symbols referenced or defined by this file.
std::vector<SymbolBody *> SymbolBodies;
@ -320,10 +326,6 @@ public:
explicit BinaryFile(MemoryBufferRef M) : InputFile(BinaryKind, M) {}
static bool classof(const InputFile *F) { return F->kind() == BinaryKind; }
template <class ELFT> void parse();
ArrayRef<InputSectionBase *> getSections() const { return Sections; }
private:
std::vector<InputSectionBase *> Sections;
};
InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName = "",

View File

@ -1674,8 +1674,7 @@ unsigned PltSection::getPltRelocOff() const {
return (HeaderSize == 0) ? InX::Plt->getSize() : 0;
}
template <class ELFT>
GdbIndexSection<ELFT>::GdbIndexSection()
GdbIndexSection::GdbIndexSection()
: SyntheticSection(0, SHT_PROGBITS, 1, ".gdb_index"),
StringPool(llvm::StringTableBuilder::ELF) {}
@ -1707,7 +1706,6 @@ static InputSectionBase *findSection(ArrayRef<InputSectionBase *> Arr,
return nullptr;
}
template <class ELFT>
static std::vector<AddressEntry>
readAddressArea(DWARFContext &Dwarf, InputSection *Sec, size_t CurrentCU) {
std::vector<AddressEntry> Ret;
@ -1716,9 +1714,7 @@ readAddressArea(DWARFContext &Dwarf, InputSection *Sec, size_t CurrentCU) {
DWARFAddressRangesVector Ranges;
CU->collectAddressRanges(Ranges);
ArrayRef<InputSectionBase *> Sections =
Sec->template getFile<ELFT>()->getSections();
ArrayRef<InputSectionBase *> Sections = Sec->File->getSections();
for (std::pair<uint64_t, uint64_t> &R : Ranges)
if (InputSectionBase *S = findSection(Sections, R.first))
Ret.push_back({S, R.first - S->getOffsetInFile(),
@ -1754,7 +1750,7 @@ class ObjInfoTy : public llvm::LoadedObjectInfo {
std::unique_ptr<llvm::LoadedObjectInfo> clone() const override { return {}; }
};
template <class ELFT> void GdbIndexSection<ELFT>::readDwarf(InputSection *Sec) {
void GdbIndexSection::readDwarf(InputSection *Sec) {
Expected<std::unique_ptr<object::ObjectFile>> Obj =
object::ObjectFile::createObjectFile(Sec->File->MB);
if (!Obj) {
@ -1769,11 +1765,11 @@ template <class ELFT> void GdbIndexSection<ELFT>::readDwarf(InputSection *Sec) {
for (std::pair<uint64_t, uint64_t> &P : readCuList(Dwarf, Sec))
CompilationUnits.push_back(P);
for (AddressEntry &Ent : readAddressArea<ELFT>(Dwarf, Sec, CuId))
for (AddressEntry &Ent : readAddressArea(Dwarf, Sec, CuId))
AddressArea.push_back(Ent);
std::vector<std::pair<StringRef, uint8_t>> NamesAndTypes =
readPubNamesAndTypes(Dwarf, ELFT::TargetEndianness == support::little);
readPubNamesAndTypes(Dwarf, Config->IsLE);
for (std::pair<StringRef, uint8_t> &Pair : NamesAndTypes) {
uint32_t Hash = hash(Pair.first);
@ -1792,7 +1788,7 @@ template <class ELFT> void GdbIndexSection<ELFT>::readDwarf(InputSection *Sec) {
}
}
template <class ELFT> void GdbIndexSection<ELFT>::finalizeContents() {
void GdbIndexSection::finalizeContents() {
if (Finalized)
return;
Finalized = true;
@ -1821,12 +1817,12 @@ template <class ELFT> void GdbIndexSection<ELFT>::finalizeContents() {
StringPool.finalizeInOrder();
}
template <class ELFT> size_t GdbIndexSection<ELFT>::getSize() const {
const_cast<GdbIndexSection<ELFT> *>(this)->finalizeContents();
size_t GdbIndexSection::getSize() const {
const_cast<GdbIndexSection *>(this)->finalizeContents();
return StringPoolOffset + StringPool.getSize();
}
template <class ELFT> void GdbIndexSection<ELFT>::writeTo(uint8_t *Buf) {
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.
@ -1880,7 +1876,7 @@ template <class ELFT> void GdbIndexSection<ELFT>::writeTo(uint8_t *Buf) {
StringPool.write(Buf);
}
template <class ELFT> bool GdbIndexSection<ELFT>::empty() const {
bool GdbIndexSection::empty() const {
return !Out::DebugInfo;
}
@ -2239,6 +2235,7 @@ BuildIdSection *InX::BuildId;
InputSection *InX::Common;
StringTableSection *InX::DynStrTab;
InputSection *InX::Interp;
GdbIndexSection *InX::GdbIndex;
GotPltSection *InX::GotPlt;
IgotPltSection *InX::IgotPlt;
MipsGotSection *InX::MipsGot;
@ -2321,11 +2318,6 @@ template class elf::HashTableSection<ELF32BE>;
template class elf::HashTableSection<ELF64LE>;
template class elf::HashTableSection<ELF64BE>;
template class elf::GdbIndexSection<ELF32LE>;
template class elf::GdbIndexSection<ELF32BE>;
template class elf::GdbIndexSection<ELF64LE>;
template class elf::GdbIndexSection<ELF64BE>;
template class elf::EhFrameHeader<ELF32LE>;
template class elf::EhFrameHeader<ELF32BE>;
template class elf::EhFrameHeader<ELF64LE>;

View File

@ -497,7 +497,7 @@ private:
size_t HeaderSize;
};
template <class ELFT> class GdbIndexSection final : public SyntheticSection {
class GdbIndexSection final : public SyntheticSection {
const unsigned OffsetTypeSize = 4;
const unsigned CuListOffset = 6 * OffsetTypeSize;
const unsigned CompilationUnitSize = 16;
@ -762,6 +762,7 @@ struct InX {
static InputSection *Common;
static StringTableSection *DynStrTab;
static InputSection *Interp;
static GdbIndexSection *GdbIndex;
static GotPltSection *GotPlt;
static IgotPltSection *IgotPlt;
static MipsGotSection *MipsGot;
@ -777,7 +778,6 @@ template <class ELFT> struct In : public InX {
static SymbolTableSection<ELFT> *DynSymTab;
static EhFrameHeader<ELFT> *EhFrameHdr;
static GnuHashTableSection<ELFT> *GnuHashTab;
static GdbIndexSection<ELFT> *GdbIndex;
static GotSection<ELFT> *Got;
static EhFrameSection<ELFT> *EhFrame;
static HashTableSection<ELFT> *HashTab;
@ -793,7 +793,6 @@ template <class ELFT> struct In : public InX {
template <class ELFT> DynamicSection<ELFT> *In<ELFT>::Dynamic;
template <class ELFT> SymbolTableSection<ELFT> *In<ELFT>::DynSymTab;
template <class ELFT> EhFrameHeader<ELFT> *In<ELFT>::EhFrameHdr;
template <class ELFT> GdbIndexSection<ELFT> *In<ELFT>::GdbIndex;
template <class ELFT> GnuHashTableSection<ELFT> *In<ELFT>::GnuHashTab;
template <class ELFT> GotSection<ELFT> *In<ELFT>::Got;
template <class ELFT> EhFrameSection<ELFT> *In<ELFT>::EhFrame;

View File

@ -428,7 +428,7 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
Add(In<ELFT>::IgotPlt);
if (Config->GdbIndex) {
In<ELFT>::GdbIndex = make<GdbIndexSection<ELFT>>();
In<ELFT>::GdbIndex = make<GdbIndexSection>();
Add(In<ELFT>::GdbIndex);
}