Remove the Chunk terminology from ELF.

llvm-svn: 248229
This commit is contained in:
Rafael Espindola 2015-09-22 00:16:19 +00:00
parent de9a44e3e9
commit 7167585c94
7 changed files with 31 additions and 33 deletions

View File

@ -91,13 +91,13 @@ template <class ELFT> void elf2::ObjectFile<ELFT>::parse() {
this->openELF(MB);
// Read section and symbol tables.
initializeChunks();
initializeSections();
initializeSymbols();
}
template <class ELFT> void elf2::ObjectFile<ELFT>::initializeChunks() {
template <class ELFT> void elf2::ObjectFile<ELFT>::initializeSections() {
uint64_t Size = this->ELFObj->getNumSections();
Chunks.resize(Size);
Sections.resize(Size);
unsigned I = 0;
for (const Elf_Shdr &Sec : this->ELFObj->sections()) {
switch (Sec.sh_type) {
@ -119,14 +119,14 @@ template <class ELFT> void elf2::ObjectFile<ELFT>::initializeChunks() {
uint32_t RelocatedSectionIndex = Sec.sh_info;
if (RelocatedSectionIndex >= Size)
error("Invalid relocated section index");
InputSection<ELFT> *RelocatedSection = Chunks[RelocatedSectionIndex];
InputSection<ELFT> *RelocatedSection = Sections[RelocatedSectionIndex];
if (!RelocatedSection)
error("Unsupported relocation reference");
RelocatedSection->RelocSections.push_back(&Sec);
break;
}
default:
Chunks[I] = new (Alloc) InputSection<ELFT>(this, &Sec);
Sections[I] = new (Alloc) InputSection<ELFT>(this, &Sec);
break;
}
++I;
@ -162,8 +162,7 @@ SymbolBody *elf2::ObjectFile<ELFT>::createSymbolBody(StringRef StringTable,
break;
}
if (SecIndex >= Chunks.size() ||
(SecIndex != 0 && !Chunks[SecIndex]))
if (SecIndex >= Sections.size() || (SecIndex != 0 && !Sections[SecIndex]))
error("Invalid section index");
switch (Sym->getBinding()) {
@ -171,7 +170,7 @@ SymbolBody *elf2::ObjectFile<ELFT>::createSymbolBody(StringRef StringTable,
error("unexpected binding");
case STB_GLOBAL:
case STB_WEAK:
return new (Alloc) DefinedRegular<ELFT>(Name, *Sym, *Chunks[SecIndex]);
return new (Alloc) DefinedRegular<ELFT>(Name, *Sym, *Sections[SecIndex]);
}
}

View File

@ -132,7 +132,7 @@ public:
: ObjectFileBase(getStaticELFKind<ELFT>(), M) {}
void parse() override;
ArrayRef<InputSection<ELFT> *> getChunks() const { return Chunks; }
ArrayRef<InputSection<ELFT> *> getSections() const { return Sections; }
SymbolBody *getSymbolBody(uint32_t SymbolIndex) const {
uint32_t FirstNonLocal = this->Symtab->sh_info;
@ -147,13 +147,13 @@ public:
ArrayRef<Elf_Word> getSymbolTableShndx() const { return SymtabSHNDX; };
private:
void initializeChunks();
void initializeSections();
void initializeSymbols();
SymbolBody *createSymbolBody(StringRef StringTable, const Elf_Sym *Sym);
// List of all chunks defined by this file.
std::vector<InputSection<ELFT> *> Chunks;
// List of all sections defined by this file.
std::vector<InputSection<ELFT> *> Sections;
ArrayRef<Elf_Word> SymtabSHNDX;
};

View File

@ -21,7 +21,7 @@ template <class ELFT> class OutputSection;
template <class ELFT> class PltSection;
template <class ELFT> class GotSection;
// A chunk corresponding a section of an input file.
// This corresponds to a section of an input file.
template <class ELFT> class InputSection {
typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela;
@ -32,10 +32,10 @@ template <class ELFT> class InputSection {
public:
InputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header);
// Returns the size of this chunk (even if this is a common or BSS.)
// Returns the size of this section (even if this is a common or BSS.)
size_t getSize() const { return Header->sh_size; }
// Write this chunk to a mmap'ed file, assuming Buf is pointing to
// Write this section to a mmap'ed file, assuming Buf is pointing to
// beginning of the output section.
void writeTo(uint8_t *Buf, const PltSection<ELFT> &PltSec,
const GotSection<ELFT> &GotSec);
@ -72,11 +72,11 @@ private:
const ObjectFile<ELFT> &File, uintX_t BaseAddr,
const PltSection<ELFT> &PltSec, const GotSection<ELFT> &GotSec);
// The offset from beginning of the output sections this chunk was assigned
// The offset from beginning of the output sections this section was assigned
// to. The writer sets a value.
uint64_t OutputSectionOff = 0;
// The file this chunk was created from.
// The file this section is from.
ObjectFile<ELFT> *File;
OutputSection<ELFT> *Out = nullptr;

View File

@ -240,8 +240,8 @@ template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) {
}
template <class ELFT>
void OutputSection<ELFT>::addChunk(InputSection<ELFT> *C) {
Chunks.push_back(C);
void OutputSection<ELFT>::addSection(InputSection<ELFT> *C) {
Sections.push_back(C);
C->setOutputSection(this);
uint32_t Align = C->getAlign();
if (Align > this->Header.sh_addralign)
@ -271,14 +271,14 @@ lld::elf2::getLocalSymVA(const typename ELFFile<ELFT>::Elf_Sym *Sym,
if (SecIndex == SHN_XINDEX)
SecIndex = File.getObj()->getExtendedSymbolTableIndex(
Sym, File.getSymbolTable(), File.getSymbolTableShndx());
ArrayRef<InputSection<ELFT> *> Chunks = File.getChunks();
InputSection<ELFT> *Section = Chunks[SecIndex];
ArrayRef<InputSection<ELFT> *> Sections = File.getSections();
InputSection<ELFT> *Section = Sections[SecIndex];
OutputSection<ELFT> *Out = Section->getOutputSection();
return Out->getVA() + Section->getOutputSectionOff() + Sym->st_value;
}
template <class ELFT> void OutputSection<ELFT>::writeTo(uint8_t *Buf) {
for (InputSection<ELFT> *C : Chunks)
for (InputSection<ELFT> *C : Sections)
C->writeTo(Buf, PltSec, GotSec);
}
@ -323,8 +323,8 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
if (SecIndex == SHN_XINDEX)
SecIndex = File.getObj()->getExtendedSymbolTableIndex(
&Sym, File.getSymbolTable(), File.getSymbolTableShndx());
ArrayRef<InputSection<ELFT> *> Chunks = File.getChunks();
Section = Chunks[SecIndex];
ArrayRef<InputSection<ELFT> *> Sections = File.getSections();
Section = Sections[SecIndex];
assert(Section != nullptr);
Out = Section->getOutputSection();
assert(Out != nullptr);

View File

@ -43,10 +43,10 @@ getLocalSymVA(const typename llvm::object::ELFFile<ELFT>::Elf_Sym *Sym,
bool includeInSymtab(const SymbolBody &B);
// OutputSection represents a section in an output file. It's a
// container of chunks. OutputSection and Chunk are 1:N relationship.
// Chunks cannot belong to more than one OutputSections. The writer
// creates multiple OutputSections and assign them unique,
// This represents a section in an output file.
// Different sub classes represent different types of sections. Some contain
// input sections, others are created by the linker.
// The writer creates multiple OutputSections and assign them unique,
// non-overlapping file offsets and VAs.
template <bool Is64Bits> class OutputSectionBase {
public:
@ -242,11 +242,11 @@ public:
: OutputSectionBase<ELFT::Is64Bits>(Name, sh_type, sh_flags),
PltSec(PltSec), GotSec(GotSec) {}
void addChunk(InputSection<ELFT> *C);
void addSection(InputSection<ELFT> *C);
void writeTo(uint8_t *Buf) override;
private:
std::vector<InputSection<ELFT> *> Chunks;
std::vector<InputSection<ELFT> *> Sections;
const PltSection<ELFT> &PltSec;
const GotSection<ELFT> &GotSec;
};

View File

@ -20,7 +20,6 @@ namespace lld {
namespace elf2 {
class ArchiveFile;
class Chunk;
class InputFile;
class SymbolBody;
template <class ELFT> class ObjectFile;

View File

@ -333,13 +333,13 @@ template <class ELFT> void Writer<ELFT>::createSections() {
SymTabSec.addSymbol(*SymName, true);
}
}
for (InputSection<ELFT> *C : File.getChunks()) {
for (InputSection<ELFT> *C : File.getSections()) {
if (!C)
continue;
const Elf_Shdr *H = C->getSectionHdr();
OutputSection<ELFT> *Sec =
getSection(C->getSectionName(), H->sh_type, H->sh_flags);
Sec->addChunk(C);
Sec->addSection(C);
scanRelocs(*C);
}
}