[lld] r249566 - ELF2: Move functions out of line.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 7 09:58:54 PDT 2015
Author: ruiu
Date: Wed Oct 7 11:58:54 2015
New Revision: 249566
URL: http://llvm.org/viewvc/llvm-project?rev=249566&view=rev
Log:
ELF2: Move functions out of line.
Modified:
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/OutputSections.h
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=249566&r1=249565&r2=249566&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed Oct 7 11:58:54 2015
@@ -203,6 +203,36 @@ template <class ELFT> void HashTableSect
S->setDynamicSymbolTableIndex(Hashes.size());
}
+template <class ELFT> void HashTableSection<ELFT>::finalize() {
+ this->Header.sh_link = DynSymSec.getSectionIndex();
+
+ assert(DynSymSec.getNumSymbols() == Hashes.size() + 1);
+ unsigned NumEntries = 2; // nbucket and nchain.
+ NumEntries += DynSymSec.getNumSymbols(); // The chain entries.
+
+ // Create as many buckets as there are symbols.
+ // FIXME: This is simplistic. We can try to optimize it, but implementing
+ // support for SHT_GNU_HASH is probably even more profitable.
+ NumEntries += DynSymSec.getNumSymbols();
+ this->Header.sh_size = NumEntries * sizeof(Elf_Word);
+}
+
+template <class ELFT> void HashTableSection<ELFT>::writeTo(uint8_t *Buf) {
+ unsigned NumSymbols = DynSymSec.getNumSymbols();
+ auto *P = reinterpret_cast<Elf_Word *>(Buf);
+ *P++ = NumSymbols; // nbucket
+ *P++ = NumSymbols; // nchain
+
+ Elf_Word *Buckets = P;
+ Elf_Word *Chains = P + NumSymbols;
+
+ for (unsigned I = 1; I < NumSymbols; ++I) {
+ uint32_t Hash = Hashes[I - 1] % NumSymbols;
+ Chains[I] = Buckets[Hash];
+ Buckets[Hash] = I;
+ }
+}
+
template <class ELFT>
DynamicSection<ELFT>::DynamicSection(SymbolTable &SymTab,
HashTableSection<ELFT> &HashSec,
@@ -499,6 +529,20 @@ SymbolTableSection<ELFT>::SymbolTableSec
Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
}
+template <class ELFT> void SymbolTableSection<ELFT>::finalize() {
+ this->Header.sh_size = getNumSymbols() * sizeof(Elf_Sym);
+ this->Header.sh_link = StrTabSec.getSectionIndex();
+ this->Header.sh_info = NumLocals + 1;
+}
+
+template <class ELFT>
+void SymbolTableSection<ELFT>::addSymbol(StringRef Name, bool isLocal) {
+ StrTabSec.add(Name);
+ ++NumVisible;
+ if (isLocal)
+ ++NumLocals;
+}
+
template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
Buf += sizeof(Elf_Sym);
Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=249566&r1=249565&r2=249566&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Wed Oct 7 11:58:54 2015
@@ -155,23 +155,10 @@ public:
StringTableSection<ELFT::Is64Bits> &StrTabSec,
const OutputSection<ELFT> &BssSec);
- void finalize() override {
- this->Header.sh_size = getNumSymbols() * sizeof(Elf_Sym);
- this->Header.sh_link = StrTabSec.getSectionIndex();
- this->Header.sh_info = NumLocals + 1;
- }
-
+ void finalize() override;
void writeTo(uint8_t *Buf) override;
-
SymbolTable &getSymTable() const { return Table; }
-
- void addSymbol(StringRef Name, bool isLocal = false) {
- StrTabSec.add(Name);
- ++NumVisible;
- if (isLocal)
- ++NumLocals;
- }
-
+ void addSymbol(StringRef Name, bool isLocal = false);
StringTableSection<ELFT::Is64Bits> &getStrTabSec() const { return StrTabSec; }
unsigned getNumSymbols() const { return NumVisible + 1; }
@@ -268,37 +255,8 @@ class HashTableSection final : public Ou
public:
HashTableSection(SymbolTableSection<ELFT> &DynSymSec);
void addSymbol(SymbolBody *S);
-
- void finalize() override {
- this->Header.sh_link = DynSymSec.getSectionIndex();
-
- assert(DynSymSec.getNumSymbols() == Hashes.size() + 1);
- unsigned NumEntries = 2; // nbucket and nchain.
- NumEntries += DynSymSec.getNumSymbols(); // The chain entries.
-
- // Create as many buckets as there are symbols.
- // FIXME: This is simplistic. We can try to optimize it, but implementing
- // support for SHT_GNU_HASH is probably even more profitable.
- NumEntries += DynSymSec.getNumSymbols();
- this->Header.sh_size = NumEntries * sizeof(Elf_Word);
- }
-
- void writeTo(uint8_t *Buf) override {
- unsigned NumSymbols = DynSymSec.getNumSymbols();
- auto *P = reinterpret_cast<Elf_Word *>(Buf);
- *P++ = NumSymbols; // nbucket
- *P++ = NumSymbols; // nchain
-
- Elf_Word *Buckets = P;
- Elf_Word *Chains = P + NumSymbols;
-
- for (unsigned I = 1; I < NumSymbols; ++I) {
- uint32_t Hash = Hashes[I - 1] % NumSymbols;
- Chains[I] = Buckets[Hash];
- Buckets[Hash] = I;
- }
- }
-
+ void finalize() override;
+ void writeTo(uint8_t *Buf) override;
SymbolTableSection<ELFT> &getDynSymSec() { return DynSymSec; }
private:
More information about the llvm-commits
mailing list