// 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);
}
const InputSection<ELFT> *)>;
public:
- void run(SymbolTable<ELFT> *Symtab);
+ void run();
private:
uint64_t NextId = 1;
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);
}
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));
}
// 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);
}
// 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>();
namespace lld {
namespace elf {
-
-template <class ELFT> class SymbolTable;
-
-template <class ELFT> void doIcf(SymbolTable<ELFT> *);
+template <class ELFT> void doIcf();
}
}
// 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;
// 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
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>();
template <class ELFT> void writeResult(SymbolTable<ELFT> *Symtab);
-template <class ELFT> void markLive(SymbolTable<ELFT> *Symtab);
+template <class ELFT> void markLive();
}
}