[lld] r360266 - [WebAssembly] Handle command line options consistently with the ELF backend.

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Wed May 8 09:20:06 PDT 2019


Author: sbc
Date: Wed May  8 09:20:05 2019
New Revision: 360266

URL: http://llvm.org/viewvc/llvm-project?rev=360266&view=rev
Log:
[WebAssembly] Handle command line options consistently with the ELF backend.

Differential Revision: https://reviews.llvm.org/D61645

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Driver.h
    lld/trunk/wasm/Config.h
    lld/trunk/wasm/Driver.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=360266&r1=360265&r2=360266&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed May  8 09:20:05 2019
@@ -71,6 +71,7 @@ Configuration *elf::Config;
 LinkerDriver *elf::Driver;
 
 static void setConfigs(opt::InputArgList &Args);
+static void readConfigs(opt::InputArgList &Args);
 
 bool elf::link(ArrayRef<const char *> Args, bool CanExitEarly,
                raw_ostream &Error) {
@@ -756,7 +757,7 @@ static void parseClangOption(StringRef O
 }
 
 // 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);

Modified: lld/trunk/ELF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.h?rev=360266&r1=360265&r2=360266&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.h (original)
+++ lld/trunk/ELF/Driver.h Wed May  8 09:20:05 2019
@@ -30,7 +30,6 @@ public:
   void addLibrary(StringRef Name);
 
 private:
-  void readConfigs(llvm::opt::InputArgList &Args);
   void createFiles(llvm::opt::InputArgList &Args);
   void inferMachineType();
   template <class ELFT> void link(llvm::opt::InputArgList &Args);

Modified: lld/trunk/wasm/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Config.h?rev=360266&r1=360265&r2=360266&view=diff
==============================================================================
--- lld/trunk/wasm/Config.h (original)
+++ lld/trunk/wasm/Config.h Wed May  8 09:20:05 2019
@@ -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 @@ struct Configuration {
   unsigned LTOO;
   unsigned Optimize;
   unsigned ThinLTOJobs;
+
   llvm::StringRef Entry;
   llvm::StringRef OutputFile;
   llvm::StringRef ThinLTOCacheDir;
@@ -57,6 +62,9 @@ struct Configuration {
   llvm::CachePruningPolicy ThinLTOCachePolicy;
   llvm::Optional<std::vector<std::string>> 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;
 };

Modified: lld/trunk/wasm/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=360266&r1=360265&r2=360266&view=diff
==============================================================================
--- lld/trunk/wasm/Driver.cpp (original)
+++ lld/trunk/wasm/Driver.cpp Wed May  8 09:20:05 2019
@@ -292,11 +292,8 @@ static StringRef getEntry(opt::InputArgL
   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 @@ static void setConfigs(opt::InputArgList
   }
 }
 
+// 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 @@ void LinkerDriver::link(ArrayRef<const c
 
   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 @@ void LinkerDriver::link(ArrayRef<const c
     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 @@ void LinkerDriver::link(ArrayRef<const c
   if (!Config->Relocatable)
     createSyntheticSymbols();
 
-  if (Config->Shared) {
-    Config->ImportMemory = true;
-    Config->ExportDynamic = true;
-    Config->AllowUndefined = true;
-  }
-
   createFiles(Args);
   if (errorCount())
     return;




More information about the llvm-commits mailing list