diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index b7803a2cab0f..c990543fbc47 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -32,51 +32,41 @@ template void SymbolTable::init() { Undefined("_start", Undefined::Synthetic)); } -void SymbolTable::addELFFile(ELFFileBase *File) { +template void SymbolTable::addELFFile(ELFFileBase *File) { if (const ELFFileBase *Old = getFirstELF()) { if (!Old->isCompatibleWith(*File)) error(Twine(Old->getName() + " is incompatible with " + File->getName())); } else { - switch (File->getELFKind()) { - case ELF32LEKind: - init(); - break; - case ELF32BEKind: - init(); - break; - case ELF64LEKind: - init(); - break; - case ELF64BEKind: - init(); - break; - } + init(); } if (auto *O = dyn_cast(File)) { ObjectFiles.emplace_back(O); - for (SymbolBody *Body : O->getSymbols()) { - switch (File->getELFKind()) { - case ELF32LEKind: - resolve(Body); - break; - case ELF32BEKind: - resolve(Body); - break; - case ELF64LEKind: - resolve(Body); - break; - case ELF64BEKind: - resolve(Body); - break; - } - } + for (SymbolBody *Body : O->getSymbols()) + resolve(Body); } if (auto *S = dyn_cast(File)) SharedFiles.emplace_back(S); } +void SymbolTable::addELFFile(ELFFileBase *File) { + switch (File->getELFKind()) { + case ELF32LEKind: + addELFFile(File); + break; + case ELF32BEKind: + addELFFile(File); + break; + case ELF64LEKind: + addELFFile(File); + break; + case ELF64BEKind: + addELFFile(File); + break; + } +} + void SymbolTable::reportRemainingUndefines() { for (auto &I : Symtab) { SymbolBody *Body = I.second->Body; diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h index 80dc65ebc9e1..01a368f4d0b7 100644 --- a/lld/ELF/SymbolTable.h +++ b/lld/ELF/SymbolTable.h @@ -54,6 +54,7 @@ public: } private: + template void addELFFile(ELFFileBase *File); void addELFFile(ELFFileBase *File); template void init();