Do not pass Symtab to markLive/doICF since Symtab is globally accessible.
authorRui Ueyama <ruiu@google.com>
Mon, 2 May 2016 19:30:42 +0000 (19:30 +0000)
committerRui Ueyama <ruiu@google.com>
Mon, 2 May 2016 19:30:42 +0000 (19:30 +0000)
llvm-svn: 268286

lld/ELF/Driver.cpp
lld/ELF/ICF.cpp
lld/ELF/ICF.h
lld/ELF/MarkLive.cpp
lld/ELF/Writer.h

index cc78552..b8882c2 100644 (file)
@@ -489,8 +489,8 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
 
   // Write the result to the file.
   if (Config->GcSections)
-    markLive<ELFT>(&Symtab);
+    markLive<ELFT>();
   if (Config->ICF)
-    doIcf<ELFT>(&Symtab);
+    doIcf<ELFT>();
   writeResult<ELFT>(&Symtab);
 }
index acb36fa..10a2603 100644 (file)
@@ -83,7 +83,7 @@ template <class ELFT> class ICF {
                                         const InputSection<ELFT> *)>;
 
 public:
-  void run(SymbolTable<ELFT> *Symtab);
+  void run();
 
 private:
   uint64_t NextId = 1;
@@ -92,7 +92,7 @@ private:
   static uint64_t relSize(InputSection<ELFT> *S);
   static uint64_t getHash(InputSection<ELFT> *S);
   static bool isEligible(InputSectionBase<ELFT> *Sec);
-  static std::vector<InputSection<ELFT> *> getSections(SymbolTable<ELFT> *S);
+  static std::vector<InputSection<ELFT> *> getSections();
 
   void segregate(InputSection<ELFT> **Begin, InputSection<ELFT> **End,
                  Comparator Eq);
@@ -146,10 +146,10 @@ template <class ELFT> bool ICF<ELFT>::isEligible(InputSectionBase<ELFT> *Sec) {
 }
 
 template <class ELFT>
-std::vector<InputSection<ELFT> *>
-ICF<ELFT>::getSections(SymbolTable<ELFT> *Symtab) {
+std::vector<InputSection<ELFT> *> ICF<ELFT>::getSections() {
   std::vector<InputSection<ELFT> *> V;
-  for (const std::unique_ptr<ObjectFile<ELFT>> &F : Symtab->getObjectFiles())
+  for (const std::unique_ptr<ObjectFile<ELFT>> &F :
+       Symtab<ELFT>::X->getObjectFiles())
     for (InputSectionBase<ELFT> *S : F->getSections())
       if (isEligible(S))
         V.push_back(cast<InputSection<ELFT>>(S));
@@ -289,11 +289,11 @@ bool ICF<ELFT>::equalsVariable(const InputSection<ELFT> *A,
 }
 
 // The main function of ICF.
-template <class ELFT> void ICF<ELFT>::run(SymbolTable<ELFT> *Symtab) {
+template <class ELFT> void ICF<ELFT>::run() {
   // Initially, we use hash values as section group IDs. Therefore,
   // if two sections have the same ID, they are likely (but not
   // guaranteed) to have the same static contents in terms of ICF.
-  std::vector<InputSection<ELFT> *> V = getSections(Symtab);
+  std::vector<InputSection<ELFT> *> V = getSections();
   for (InputSection<ELFT> *S : V)
     // Set MSB on to avoid collisions with serial group IDs
     S->GroupId = getHash(S) | (uint64_t(1) << 63);
@@ -337,11 +337,9 @@ template <class ELFT> void ICF<ELFT>::run(SymbolTable<ELFT> *Symtab) {
 }
 
 // ICF entry point function.
-template <class ELFT> void elf::doIcf(SymbolTable<ELFT> *Symtab) {
-  ICF<ELFT>().run(Symtab);
-}
+template <class ELFT> void elf::doIcf() { ICF<ELFT>().run(); }
 
-template void elf::doIcf(SymbolTable<ELF32LE> *);
-template void elf::doIcf(SymbolTable<ELF32BE> *);
-template void elf::doIcf(SymbolTable<ELF64LE> *);
-template void elf::doIcf(SymbolTable<ELF64BE> *);
+template void elf::doIcf<ELF32LE>();
+template void elf::doIcf<ELF32BE>();
+template void elf::doIcf<ELF64LE>();
+template void elf::doIcf<ELF64BE>();
index 63ad780..502e128 100644 (file)
 
 namespace lld {
 namespace elf {
-
-template <class ELFT> class SymbolTable;
-
-template <class ELFT> void doIcf(SymbolTable<ELFT> *);
+template <class ELFT> void doIcf();
 }
 }
 
index b605269..5b20ccc 100644 (file)
@@ -133,7 +133,7 @@ template <class ELFT> static bool isReserved(InputSectionBase<ELFT> *Sec) {
 // This is the main function of the garbage collector.
 // Starting from GC-root sections, this function visits all reachable
 // sections to set their "Live" bits.
-template <class ELFT> void elf::markLive(SymbolTable<ELFT> *Symtab) {
+template <class ELFT> void elf::markLive() {
   typedef typename ELFT::uint uintX_t;
   SmallVector<InputSection<ELFT> *, 256> Q;
 
@@ -160,20 +160,21 @@ template <class ELFT> void elf::markLive(SymbolTable<ELFT> *Symtab) {
   // Add GC root symbols.
   if (Config->EntrySym)
     MarkSymbol(Config->EntrySym->body());
-  MarkSymbol(Symtab->find(Config->Init));
-  MarkSymbol(Symtab->find(Config->Fini));
+  MarkSymbol(Symtab<ELFT>::X->find(Config->Init));
+  MarkSymbol(Symtab<ELFT>::X->find(Config->Fini));
   for (StringRef S : Config->Undefined)
-    MarkSymbol(Symtab->find(S));
+    MarkSymbol(Symtab<ELFT>::X->find(S));
 
   // Preserve externally-visible symbols if the symbols defined by this
   // file can interrupt other ELF file's symbols at runtime.
-  for (const Symbol *S : Symtab->getSymbols())
+  for (const Symbol *S : Symtab<ELFT>::X->getSymbols())
     if (S->includeInDynsym())
       MarkSymbol(S->body());
 
   // Preserve special sections and those which are specified in linker
   // script KEEP command.
-  for (const std::unique_ptr<ObjectFile<ELFT>> &F : Symtab->getObjectFiles())
+  for (const std::unique_ptr<ObjectFile<ELFT>> &F :
+       Symtab<ELFT>::X->getObjectFiles())
     for (InputSectionBase<ELFT> *Sec : F->getSections())
       if (Sec && Sec != &InputSection<ELFT>::Discarded) {
         // .eh_frame is always marked as live now, but also it can reference to
@@ -190,7 +191,7 @@ template <class ELFT> void elf::markLive(SymbolTable<ELFT> *Symtab) {
     forEachSuccessor<ELFT>(Q.pop_back_val(), Enqueue);
 }
 
-template void elf::markLive<ELF32LE>(SymbolTable<ELF32LE> *);
-template void elf::markLive<ELF32BE>(SymbolTable<ELF32BE> *);
-template void elf::markLive<ELF64LE>(SymbolTable<ELF64LE> *);
-template void elf::markLive<ELF64BE>(SymbolTable<ELF64BE> *);
+template void elf::markLive<ELF32LE>();
+template void elf::markLive<ELF32BE>();
+template void elf::markLive<ELF64LE>();
+template void elf::markLive<ELF64BE>();
index fdd4adf..f60ac89 100644 (file)
@@ -17,7 +17,7 @@ template <class ELFT> class SymbolTable;
 
 template <class ELFT> void writeResult(SymbolTable<ELFT> *Symtab);
 
-template <class ELFT> void markLive(SymbolTable<ELFT> *Symtab);
+template <class ELFT> void markLive();
 }
 }