ELF2: Add basic linker script support.
This linker script parser and evaluator is powerful enough to read
Linux's libc.so, which is (despite its name) a linker script that
contains OUTPUT_FORMAT, GROUP and AS_NEEDED directives.
The parser implemented in this patch is a recursive-descendent one.
It does *not* construct an AST but consumes directives in place and
sets the results to Symtab object, like what Driver is doing.
This should be very fast since less objects are allocated, and
this is also more readable.
http://reviews.llvm.org/D13232
llvm-svn: 248918
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index dc39c1d..93d6230 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -16,10 +16,20 @@
using namespace llvm;
using namespace llvm::ELF;
using namespace llvm::object;
+using namespace llvm::sys::fs;
using namespace lld;
using namespace lld::elf2;
+std::unique_ptr<InputFile> lld::elf2::createFile(MemoryBufferRef MB) {
+ file_magic Magic = identify_magic(MB.getBuffer());
+ if (Magic == file_magic::archive)
+ return make_unique<ArchiveFile>(MB);
+ if (Magic == file_magic::elf_shared_object)
+ return createELFFile<SharedFile>(MB);
+ return createELFFile<ObjectFile>(MB);
+}
+
template <class ELFT> static uint16_t getEMachine(const ELFFileBase &B) {
bool IsShared = isa<SharedFileBase>(B);
if (IsShared)