[lld] r256880 - Do not use templates to instantiate {Object, Shared}Files.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 5 16:09:44 PST 2016
Author: ruiu
Date: Tue Jan 5 18:09:43 2016
New Revision: 256880
URL: http://llvm.org/viewvc/llvm-project?rev=256880&view=rev
Log:
Do not use templates to instantiate {Object,Shared}Files.
createELFFile looked complex because of its use of template,
so I want to keep it private within this file.
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/InputFiles.h
lld/trunk/ELF/Symbols.cpp
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=256880&r1=256879&r2=256880&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue Jan 5 18:09:43 2016
@@ -77,17 +77,17 @@ void LinkerDriver::addFile(StringRef Pat
if (WholeArchive) {
auto File = make_unique<ArchiveFile>(MBRef);
for (MemoryBufferRef &MB : File->getMembers())
- Files.push_back(createELFFile<ObjectFile>(MB));
+ Files.push_back(createObjectFile(MB));
OwningArchives.emplace_back(std::move(File));
return;
}
Files.push_back(make_unique<ArchiveFile>(MBRef));
return;
case file_magic::elf_shared_object:
- Files.push_back(createELFFile<SharedFile>(MBRef));
+ Files.push_back(createSharedFile(MBRef));
return;
default:
- Files.push_back(createELFFile<ObjectFile>(MBRef));
+ Files.push_back(createObjectFile(MBRef));
}
}
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=256880&r1=256879&r2=256880&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Tue Jan 5 18:09:43 2016
@@ -453,7 +453,7 @@ static std::unique_ptr<InputFile> create
}
template <template <class> class T>
-std::unique_ptr<InputFile> elf2::createELFFile(MemoryBufferRef MB) {
+static std::unique_ptr<InputFile> createELFFile(MemoryBufferRef MB) {
std::pair<unsigned char, unsigned char> Type = getElfArchType(MB.getBuffer());
if (Type.second != ELF::ELFDATA2LSB && Type.second != ELF::ELFDATA2MSB)
error("Invalid data encoding: " + MB.getBufferIdentifier());
@@ -471,6 +471,14 @@ std::unique_ptr<InputFile> elf2::createE
error("Invalid file class: " + MB.getBufferIdentifier());
}
+std::unique_ptr<InputFile> elf2::createObjectFile(MemoryBufferRef MB) {
+ return createELFFile<ObjectFile>(MB);
+}
+
+std::unique_ptr<InputFile> elf2::createSharedFile(MemoryBufferRef MB) {
+ return createELFFile<SharedFile>(MB);
+}
+
template class elf2::ELFFileBase<ELF32LE>;
template class elf2::ELFFileBase<ELF32BE>;
template class elf2::ELFFileBase<ELF64LE>;
@@ -485,9 +493,3 @@ template class elf2::SharedFile<ELF32LE>
template class elf2::SharedFile<ELF32BE>;
template class elf2::SharedFile<ELF64LE>;
template class elf2::SharedFile<ELF64BE>;
-
-template std::unique_ptr<InputFile>
-elf2::createELFFile<ObjectFile>(MemoryBufferRef);
-
-template std::unique_ptr<InputFile>
-elf2::createELFFile<SharedFile>(MemoryBufferRef);
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=256880&r1=256879&r2=256880&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Tue Jan 5 18:09:43 2016
@@ -202,8 +202,8 @@ public:
bool isNeeded() const { return !AsNeeded || IsUsed; }
};
-template <template <class> class T>
-std::unique_ptr<InputFile> createELFFile(MemoryBufferRef MB);
+std::unique_ptr<InputFile> createObjectFile(MemoryBufferRef MB);
+std::unique_ptr<InputFile> createSharedFile(MemoryBufferRef MB);
} // namespace elf2
} // namespace lld
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=256880&r1=256879&r2=256880&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Tue Jan 5 18:09:43 2016
@@ -115,8 +115,7 @@ std::unique_ptr<InputFile> Lazy::getMemb
// read from the library.
if (MBRef.getBuffer().empty())
return std::unique_ptr<InputFile>(nullptr);
-
- return createELFFile<ObjectFile>(MBRef);
+ return createObjectFile(MBRef);
}
template <class ELFT> static void doInitSymbols() {
More information about the llvm-commits
mailing list