[lld] r256180 - Refactor duplicated code. NFC.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 21 11:09:20 PST 2015
Author: rafael
Date: Mon Dec 21 13:09:19 2015
New Revision: 256180
URL: http://llvm.org/viewvc/llvm-project?rev=256180&view=rev
Log:
Refactor duplicated code. NFC.
Modified:
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/SymbolTable.h
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=256180&r1=256179&r2=256180&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Mon Dec 21 13:09:19 2015
@@ -127,9 +127,9 @@ template <class ELFT> bool SymbolTable<E
// Returns a file from which symbol B was created.
// If B does not belong to any file in ObjectFiles, returns a nullptr.
template <class ELFT>
-static ELFFileBase<ELFT> *
-findFile(std::vector<std::unique_ptr<ObjectFile<ELFT>>> &ObjectFiles,
- SymbolBody *B) {
+ELFFileBase<ELFT> *
+elf2::findFile(ArrayRef<std::unique_ptr<ObjectFile<ELFT>>> ObjectFiles,
+ const SymbolBody *B) {
typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
typedef typename ELFFile<ELFT>::Elf_Sym_Range Elf_Sym_Range;
@@ -144,8 +144,8 @@ findFile(std::vector<std::unique_ptr<Obj
template <class ELFT>
std::string SymbolTable<ELFT>::conflictMsg(SymbolBody *Old, SymbolBody *New) {
- ELFFileBase<ELFT> *OldFile = findFile(ObjectFiles, Old);
- ELFFileBase<ELFT> *NewFile = findFile(ObjectFiles, New);
+ ELFFileBase<ELFT> *OldFile = findFile<ELFT>(ObjectFiles, Old);
+ ELFFileBase<ELFT> *NewFile = findFile<ELFT>(ObjectFiles, New);
StringRef Sym = Old->getName();
StringRef F1 = OldFile ? OldFile->getName() : "(internal)";
@@ -257,3 +257,16 @@ template class lld::elf2::SymbolTable<EL
template class lld::elf2::SymbolTable<ELF32BE>;
template class lld::elf2::SymbolTable<ELF64LE>;
template class lld::elf2::SymbolTable<ELF64BE>;
+
+template ELFFileBase<ELF32LE> *
+lld::elf2::findFile(ArrayRef<std::unique_ptr<ObjectFile<ELF32LE>>>,
+ const SymbolBody *);
+template ELFFileBase<ELF32BE> *
+lld::elf2::findFile(ArrayRef<std::unique_ptr<ObjectFile<ELF32BE>>>,
+ const SymbolBody *);
+template ELFFileBase<ELF64LE> *
+lld::elf2::findFile(ArrayRef<std::unique_ptr<ObjectFile<ELF64LE>>>,
+ const SymbolBody *);
+template ELFFileBase<ELF64BE> *
+lld::elf2::findFile(ArrayRef<std::unique_ptr<ObjectFile<ELF64BE>>>,
+ const SymbolBody *);
Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=256180&r1=256179&r2=256180&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Mon Dec 21 13:09:19 2015
@@ -87,6 +87,11 @@ private:
llvm::DenseSet<StringRef> IncludedSoNames;
};
+template <class ELFT>
+ELFFileBase<ELFT> *
+findFile(ArrayRef<std::unique_ptr<ObjectFile<ELFT>>> ObjectFiles,
+ const SymbolBody *B);
+
} // namespace elf2
} // namespace lld
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=256180&r1=256179&r2=256180&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Dec 21 13:09:19 2015
@@ -333,15 +333,7 @@ static void reportUndefined(const Symbol
if (Config->Shared && !Config->NoUndefined)
return;
- const Elf_Sym &SymE = cast<ELFSymbolBody<ELFT>>(Sym).Sym;
- ELFFileBase<ELFT> *SymFile = nullptr;
-
- for (const std::unique_ptr<ObjectFile<ELFT>> &File : S.getObjectFiles()) {
- Elf_Sym_Range Syms = File->getObj().symbols(File->getSymbolTable());
- if (&SymE > Syms.begin() && &SymE < Syms.end())
- SymFile = File.get();
- }
-
+ ELFFileBase<ELFT> *SymFile = findFile<ELFT>(S.getObjectFiles(), &Sym);
std::string Message = "undefined symbol: " + Sym.getName().str();
if (SymFile)
Message += " in " + SymFile->getName().str();
More information about the llvm-commits
mailing list