From 3ce825ed26684e4105e6606c8862edfc713b9d3a Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 9 Oct 2015 21:07:25 +0000 Subject: [PATCH] ELF2: Make SymbolTable a template class. SymbolTable was not a template class. Instead we had switch-case-based type dispatch to call desired functions. We had to do that because SymbolTable was created before we know what ELF type objects had been passed. Every time I tried to add a new function to the symbol table, I had to define a dispatcher which consist of a single switch statement. It also brought an restriction what the driver can do. For example, we cannot add undefined symbols before any files are added to the symbol table. That's because no symbols can be added until the symbol table knows the ELF type, but when it knows about that, it's too late. In this patch, the driver makes a decision on what ELF type objects are being handled. Then the driver creates a SymbolTable object for an appropriate ELF type. http://reviews.llvm.org/D13544 llvm-svn: 249902 --- lld/ELF/Config.h | 1 - lld/ELF/Driver.cpp | 103 ++++++++++++++++++--------- lld/ELF/Driver.h | 9 ++- lld/ELF/OutputSections.cpp | 23 +++--- lld/ELF/OutputSections.h | 10 +-- lld/ELF/SymbolTable.cpp | 134 ++++++++++------------------------- lld/ELF/SymbolTable.h | 23 +++--- lld/ELF/Writer.cpp | 61 ++++++---------- lld/ELF/Writer.h | 5 +- lld/test/elf2/incompatible.s | 10 +-- lld/test/elf2/no-obj.s | 8 +++ 11 files changed, 179 insertions(+), 208 deletions(-) create mode 100644 lld/test/elf2/no-obj.s diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index a91d187daa2b..bf791b968ad0 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -46,7 +46,6 @@ struct Configuration { bool NoUndefined; bool Shared; bool Static = false; - bool WholeArchive = false; bool ZNow = false; ELFKind ElfKind = ELFNoneKind; uint16_t EMachine = llvm::ELF::EM_NONE; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index b4395e8b8166..8e12dee6f65e 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -20,6 +20,7 @@ using namespace llvm; using namespace llvm::ELF; +using namespace llvm::object; using namespace lld; using namespace lld::elf2; @@ -32,7 +33,7 @@ void lld::elf2::link(ArrayRef Args) { LinkerDriver D; Config = &C; Driver = &D; - Driver->link(Args.slice(1)); + Driver->main(Args.slice(1)); } static void setELFType(StringRef Emul) { @@ -102,28 +103,6 @@ static std::string searchLibrary(StringRef Path) { error(Twine("Unable to find library -l") + Path); } -template