diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-08-05 13:55:34 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-08-05 13:55:34 +0000 |
commit | e7a00e326aeb825102c10d122a62468d83e38e29 (patch) | |
tree | e774b1187a79db861879965a16f914bcbd980858 | |
parent | 96530b3a43e16df4bca6e7ca007d7ec9c77d6366 (diff) | |
download | bcm5719-llvm-e7a00e326aeb825102c10d122a62468d83e38e29.tar.gz bcm5719-llvm-e7a00e326aeb825102c10d122a62468d83e38e29.zip |
For now we only have on Chunk type. Simplify.
The others we have in sight are
* common symbols.
* entries in SHF_MERGE sections.
They will have a substantially different treatment. It is not clear if it is
worth it putting them all in a single list just to dispatch based on the kind on
the other side.
I hope to implement common symbols soon, and then we will be in a position
to have a concrete discussion. For now this is simpler for the the implemented
features.
llvm-svn: 244042
-rw-r--r-- | lld/ELF/Chunks.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/Chunks.h | 9 | ||||
-rw-r--r-- | lld/ELF/InputFiles.h | 12 | ||||
-rw-r--r-- | lld/ELF/Writer.cpp | 23 | ||||
-rw-r--r-- | lld/ELF/Writer.h | 3 |
5 files changed, 20 insertions, 29 deletions
diff --git a/lld/ELF/Chunks.cpp b/lld/ELF/Chunks.cpp index cf3ad7d45cf..121fe552954 100644 --- a/lld/ELF/Chunks.cpp +++ b/lld/ELF/Chunks.cpp @@ -19,7 +19,7 @@ using namespace lld::elf2; template <class ELFT> SectionChunk<ELFT>::SectionChunk(object::ELFFile<ELFT> *Obj, const Elf_Shdr *Header) - : Chunk(SectionKind), Obj(Obj), Header(Header) { + : Obj(Obj), Header(Header) { // Initialize SectionName. ErrorOr<StringRef> Name = Obj->getSectionName(Header); error(Name); diff --git a/lld/ELF/Chunks.h b/lld/ELF/Chunks.h index 836a980f216..e2e7d9a74a1 100644 --- a/lld/ELF/Chunks.h +++ b/lld/ELF/Chunks.h @@ -26,8 +26,6 @@ class OutputSection; // doesn't even have actual data (if common or bss). class Chunk { public: - enum Kind { SectionKind, OtherKind }; - Kind kind() const { return ChunkKind; } virtual ~Chunk() = default; // Returns the size of this chunk (even if this is a common or BSS.) @@ -56,9 +54,6 @@ public: OutputSection *getOutputSection() { return Out; } protected: - Chunk(Kind K = OtherKind) : ChunkKind(K) {} - const Kind ChunkKind; - // The VA of this chunk in the output. The writer sets a value. uint64_t VA = 0; @@ -85,10 +80,6 @@ public: StringRef getSectionName() const override { return SectionName; } const Elf_Shdr *getSectionHdr() const { return Header; } - static bool classof(const Chunk *C) { - return C->kind() == SectionKind; - } - private: // A file this chunk was created from. llvm::object::ELFFile<ELFT> *Obj; diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index f498416b772..66a8c9d5b48 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -10,13 +10,13 @@ #ifndef LLD_ELF_INPUT_FILES_H #define LLD_ELF_INPUT_FILES_H +#include "Chunks.h" #include "lld/Core/LLVM.h" #include "llvm/Object/ELF.h" namespace lld { namespace elf2 { class SymbolBody; -class Chunk; // The root class of input files. class InputFile { @@ -50,16 +50,11 @@ public: return K >= Object32LEKind && K <= Object64BEKind; } - ArrayRef<Chunk *> getChunks() { return Chunks; } ArrayRef<SymbolBody *> getSymbols() override { return SymbolBodies; } virtual bool isCompatibleWith(const ObjectFileBase &Other) const = 0; protected: - // List of all chunks defined by this file. This includes both section - // chunks and non-section chunks for common symbols. - std::vector<Chunk *> Chunks; - // List of all symbols referenced or defined by this file. std::vector<SymbolBody *> SymbolBodies; @@ -93,6 +88,8 @@ public: // Returns the underying ELF file. llvm::object::ELFFile<ELFT> *getObj() const { return ELFObj.get(); } + ArrayRef<SectionChunk<ELFT> *> getChunks() { return Chunks; } + private: void initializeChunks(); void initializeSymbols(); @@ -100,6 +97,9 @@ private: SymbolBody *createSymbolBody(StringRef StringTable, const Elf_Sym *Sym); std::unique_ptr<llvm::object::ELFFile<ELFT>> ELFObj; + + // List of all chunks defined by this file. + std::vector<SectionChunk<ELFT> *> Chunks; }; } // namespace elf2 diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 91cb16e52ea..28428d6dbb9 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -51,7 +51,7 @@ void OutputSection::setFileOffset(uint64_t Off) { } template <class ELFT> -void OutputSection::addChunk(Chunk *C) { +void OutputSection::addSectionChunk(SectionChunk<ELFT> *C) { Chunks.push_back(C); C->setOutputSection(this); uint64_t Off = Header.sh_size; @@ -60,10 +60,8 @@ void OutputSection::addChunk(Chunk *C) { C->setFileOff(Off); Off += C->getSize(); Header.sh_size = Off; - if (auto SC = dyn_cast<SectionChunk<ELFT>>(C)) { - Header.sh_type = SC->getSectionHdr()->sh_type; - Header.sh_flags |= SC->getSectionHdr()->sh_flags; - } + Header.sh_type = C->getSectionHdr()->sh_type; + Header.sh_flags |= C->getSectionHdr()->sh_flags; } template <class ELFT> @@ -83,14 +81,15 @@ void OutputSection::writeHeaderTo(Elf_Shdr_Impl<ELFT> *SHdr) { // Create output section objects and add them to OutputSections. template <class ELFT> void Writer<ELFT>::createSections() { SmallDenseMap<StringRef, OutputSection *> Map; - for (std::unique_ptr<ObjectFileBase> &File : Symtab->ObjectFiles) { - for (Chunk *C : File->getChunks()) { + for (std::unique_ptr<ObjectFileBase> &FileB : Symtab->ObjectFiles) { + auto &File = cast<ObjectFile<ELFT>>(*FileB); + for (SectionChunk<ELFT> *C : File.getChunks()) { OutputSection *&Sec = Map[C->getSectionName()]; if (!Sec) { Sec = new (CAlloc.Allocate()) OutputSection(C->getSectionName()); OutputSections.push_back(Sec); } - Sec->addChunk<ELFT>(C); + Sec->addSectionChunk<ELFT>(C); } } } @@ -177,9 +176,9 @@ template class Writer<ELF32BE>; template class Writer<ELF64LE>; template class Writer<ELF64BE>; -template void OutputSection::addChunk<ELF32LE>(Chunk *); -template void OutputSection::addChunk<ELF32BE>(Chunk *); -template void OutputSection::addChunk<ELF64LE>(Chunk *); -template void OutputSection::addChunk<ELF64BE>(Chunk *); +template void OutputSection::addSectionChunk<ELF32LE>(SectionChunk<ELF32LE> *); +template void OutputSection::addSectionChunk<ELF32BE>(SectionChunk<ELF32BE> *); +template void OutputSection::addSectionChunk<ELF64LE>(SectionChunk<ELF64LE> *); +template void OutputSection::addSectionChunk<ELF64BE>(SectionChunk<ELF64BE> *); } } diff --git a/lld/ELF/Writer.h b/lld/ELF/Writer.h index 80e476c0c29..1feb68bdf4b 100644 --- a/lld/ELF/Writer.h +++ b/lld/ELF/Writer.h @@ -10,6 +10,7 @@ #ifndef LLD_ELF_WRITER_H #define LLD_ELF_WRITER_H +#include "Chunks.h" #include "SymbolTable.h" #include "llvm/Support/FileOutputBuffer.h" @@ -25,7 +26,7 @@ public: OutputSection(StringRef Name) : Name(Name), Header({}) {} void setVA(uint64_t); void setFileOffset(uint64_t); - template <class ELFT> void addChunk(Chunk *C); + template <class ELFT> void addSectionChunk(SectionChunk<ELFT> *C); std::vector<Chunk *> &getChunks() { return Chunks; } template <class ELFT> void writeHeaderTo(llvm::object::Elf_Shdr_Impl<ELFT> *SHdr); |