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.
llvm-svn: 256880
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 6d88137..cfc173c 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -77,17 +77,17 @@
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));
}
}
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 8dff42d..21727e9 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -453,7 +453,7 @@
}
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 @@
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<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);
diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h
index 4e529c5..3c96e4c 100644
--- a/lld/ELF/InputFiles.h
+++ b/lld/ELF/InputFiles.h
@@ -202,8 +202,8 @@
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
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index f8d5852..4af1b88 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -115,8 +115,7 @@
// 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() {