Index: lld/trunk/ELF/Driver.h =================================================================== --- lld/trunk/ELF/Driver.h +++ lld/trunk/ELF/Driver.h @@ -30,7 +30,6 @@ void addLibrary(StringRef Name); private: - void readConfigs(llvm::opt::InputArgList &Args); void createFiles(llvm::opt::InputArgList &Args); void inferMachineType(); template void link(llvm::opt::InputArgList &Args); Index: lld/trunk/ELF/Driver.cpp =================================================================== --- lld/trunk/ELF/Driver.cpp +++ lld/trunk/ELF/Driver.cpp @@ -71,6 +71,7 @@ LinkerDriver *elf::Driver; static void setConfigs(opt::InputArgList &Args); +static void readConfigs(opt::InputArgList &Args); bool elf::link(ArrayRef Args, bool CanExitEarly, raw_ostream &Error) { @@ -756,7 +757,7 @@ } // Initializes Config members by the command line options. -void LinkerDriver::readConfigs(opt::InputArgList &Args) { +static void readConfigs(opt::InputArgList &Args) { errorHandler().Verbose = Args.hasArg(OPT_verbose); errorHandler().FatalWarnings = Args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false); Index: lld/trunk/wasm/Config.h =================================================================== --- lld/trunk/wasm/Config.h +++ lld/trunk/wasm/Config.h @@ -17,6 +17,10 @@ namespace lld { namespace wasm { +// This struct contains the global configuration for the linker. +// Most fields are direct mapping from the command line options +// and such fields have the same name as the corresponding options. +// Most fields are initialized by the driver. struct Configuration { bool AllowUndefined; bool CheckFeatures; @@ -48,6 +52,7 @@ unsigned LTOO; unsigned Optimize; unsigned ThinLTOJobs; + llvm::StringRef Entry; llvm::StringRef OutputFile; llvm::StringRef ThinLTOCacheDir; @@ -57,6 +62,9 @@ llvm::CachePruningPolicy ThinLTOCachePolicy; llvm::Optional> Features; + // The following config options do not directly correspond to any + // particualr command line options. + // True if we are creating position-independent code. bool Pic; }; Index: lld/trunk/wasm/Driver.cpp =================================================================== --- lld/trunk/wasm/Driver.cpp +++ lld/trunk/wasm/Driver.cpp @@ -292,11 +292,8 @@ return Arg->getValue(); } -// Some Config members do not directly correspond to any particular -// command line options, but computed based on other Config values. -// This function initialize such members. See Config.h for the details -// of these values. -static void setConfigs(opt::InputArgList &Args) { +// Initializes Config members by the command line options. +static void readConfigs(opt::InputArgList &Args) { Config->AllowUndefined = Args.hasArg(OPT_allow_undefined); Config->CheckFeatures = Args.hasFlag(OPT_check_features, OPT_no_check_features, true); @@ -356,6 +353,26 @@ } } +// Some Config members do not directly correspond to any particular +// command line options, but computed based on other Config values. +// This function initialize such members. See Config.h for the details +// of these values. +static void setConfigs() { + Config->Pic = Config->Pie || Config->Shared; + + if (Config->Pic) { + if (Config->ExportTable) + error("-shared/-pie is incompatible with --export-table"); + Config->ImportTable = true; + } + + if (Config->Shared) { + Config->ImportMemory = true; + Config->ExportDynamic = true; + Config->AllowUndefined = true; + } +} + // Some command line options or some combinations of them are not allowed. // This function checks for such errors. static void checkOptions(opt::InputArgList &Args) { @@ -514,7 +531,8 @@ errorHandler().ErrorLimit = args::getInteger(Args, OPT_error_limit, 20); - setConfigs(Args); + readConfigs(Args); + setConfigs(); checkOptions(Args); if (auto *Arg = Args.getLastArg(OPT_allow_undefined_file)) @@ -525,14 +543,6 @@ return; } - Config->Pic = Config->Pie || Config->Shared; - - if (Config->Pic) { - if (Config->ExportTable) - error("-shared/-pie is incompatible with --export-table"); - Config->ImportTable = true; - } - // Handle --trace-symbol. for (auto *Arg : Args.filtered(OPT_trace_symbol)) Symtab->trace(Arg->getValue()); @@ -540,12 +550,6 @@ if (!Config->Relocatable) createSyntheticSymbols(); - if (Config->Shared) { - Config->ImportMemory = true; - Config->ExportDynamic = true; - Config->AllowUndefined = true; - } - createFiles(Args); if (errorCount()) return;