Revert "[ELF] Make InputSection<ELFT>::writeTo virtual"

This reverts commit r286100.

This saves 8 bytes of every InputSection.

llvm-svn: 286235
This commit is contained in:
Rafael Espindola 2016-11-08 14:47:16 +00:00
parent 682a5bc2c1
commit 1a5411238e
4 changed files with 18 additions and 22 deletions

View File

@ -79,6 +79,13 @@ InputSectionBase<ELFT>::InputSectionBase(elf::ObjectFile<ELFT> *File,
this->Offset = Hdr->sh_offset; this->Offset = Hdr->sh_offset;
} }
template <class ELFT> size_t InputSectionBase<ELFT>::getSize() const {
if (auto *D = dyn_cast<InputSection<ELFT>>(this))
if (D->getThunksSize() > 0)
return D->getThunkOff() + D->getThunksSize();
return Data.size();
}
// Returns a string for an error message. // Returns a string for an error message.
template <class SectionT> static std::string getName(SectionT *Sec) { template <class SectionT> static std::string getName(SectionT *Sec) {
return (Sec->getFile()->getName() + "(" + Sec->Name + ")").str(); return (Sec->getFile()->getName() + "(" + Sec->Name + ")").str();
@ -200,11 +207,6 @@ bool InputSection<ELFT>::classof(const InputSectionData *S) {
return S->kind() == Base::Regular; return S->kind() == Base::Regular;
} }
template <class ELFT> size_t InputSection<ELFT>::getSize() const {
return getThunksSize() > 0 ? getThunkOff() + getThunksSize()
: this->Data.size();
}
template <class ELFT> template <class ELFT>
InputSectionBase<ELFT> *InputSection<ELFT>::getRelocatedSection() { InputSectionBase<ELFT> *InputSection<ELFT>::getRelocatedSection() {
assert(this->Type == SHT_RELA || this->Type == SHT_REL); assert(this->Type == SHT_RELA || this->Type == SHT_REL);

View File

@ -52,8 +52,6 @@ private:
unsigned SectionKind : 3; unsigned SectionKind : 3;
public: public:
virtual ~InputSectionData() = default;
InputSectionData(InputSectionData &&) = default;
Kind kind() const { return (Kind)SectionKind; } Kind kind() const { return (Kind)SectionKind; }
unsigned Live : 1; // for garbage collection unsigned Live : 1; // for garbage collection
@ -68,9 +66,6 @@ public:
return llvm::makeArrayRef<T>((const T *)Data.data(), S / sizeof(T)); return llvm::makeArrayRef<T>((const T *)Data.data(), S / sizeof(T));
} }
virtual void writeTo(uint8_t *Buf) {}
virtual size_t getSize() const { return Data.size(); }
// If a section is compressed, this has the uncompressed section data. // If a section is compressed, this has the uncompressed section data.
std::unique_ptr<uint8_t[]> UncompressedData; std::unique_ptr<uint8_t[]> UncompressedData;
@ -118,6 +113,9 @@ public:
// this but instead this->Repl. // this but instead this->Repl.
InputSectionBase<ELFT> *Repl; InputSectionBase<ELFT> *Repl;
// Returns the size of this section (even if this is a common or BSS.)
size_t getSize() const;
static InputSectionBase<ELFT> Discarded; static InputSectionBase<ELFT> Discarded;
ObjectFile<ELFT> *getFile() const { return File; } ObjectFile<ELFT> *getFile() const { return File; }
@ -245,7 +243,7 @@ public:
// Write this section 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. // beginning of the output section.
void writeTo(uint8_t *Buf) override; void writeTo(uint8_t *Buf);
// Relocation sections that refer to this one. // Relocation sections that refer to this one.
llvm::TinyPtrVector<const Elf_Shdr *> RelocSections; llvm::TinyPtrVector<const Elf_Shdr *> RelocSections;
@ -272,9 +270,6 @@ public:
// Size of chunk with thunks code. // Size of chunk with thunks code.
uint64_t getThunksSize() const; uint64_t getThunksSize() const;
// Size of section in bytes.
size_t getSize() const override;
template <class RelTy> template <class RelTy>
void relocateNonAlloc(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels); void relocateNonAlloc(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels);

View File

@ -95,14 +95,14 @@ BuildIdSection<ELFT>::BuildIdSection(size_t HashSize)
".note.gnu.build-id"), ".note.gnu.build-id"),
HashSize(HashSize) { HashSize(HashSize) {
this->Live = true; this->Live = true;
}
template <class ELFT> void BuildIdSection<ELFT>::writeTo(uint8_t *Buf) { Buf.resize(16 + HashSize);
const endianness E = ELFT::TargetEndianness; const endianness E = ELFT::TargetEndianness;
write32<E>(Buf, 4); // Name size write32<E>(Buf.data(), 4); // Name size
write32<E>(Buf + 4, HashSize); // Content size write32<E>(Buf.data() + 4, HashSize); // Content size
write32<E>(Buf + 8, NT_GNU_BUILD_ID); // Type write32<E>(Buf.data() + 8, NT_GNU_BUILD_ID); // Type
memcpy(Buf + 12, "GNU", 4); // Name string memcpy(Buf.data() + 12, "GNU", 4); // Name string
this->Data = ArrayRef<uint8_t>(Buf);
} }
template <class ELFT> template <class ELFT>

View File

@ -24,8 +24,6 @@ public:
// .note.gnu.build-id section. // .note.gnu.build-id section.
template <class ELFT> class BuildIdSection : public InputSection<ELFT> { template <class ELFT> class BuildIdSection : public InputSection<ELFT> {
public: public:
void writeTo(uint8_t *Buf) override;
size_t getSize() const override { return 16 + HashSize; }
virtual void writeBuildId(llvm::MutableArrayRef<uint8_t> Buf) = 0; virtual void writeBuildId(llvm::MutableArrayRef<uint8_t> Buf) = 0;
virtual ~BuildIdSection() = default; virtual ~BuildIdSection() = default;
@ -33,6 +31,7 @@ public:
protected: protected:
BuildIdSection(size_t HashSize); BuildIdSection(size_t HashSize);
std::vector<uint8_t> Buf;
void void
computeHash(llvm::MutableArrayRef<uint8_t> Buf, computeHash(llvm::MutableArrayRef<uint8_t> Buf,