summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2019-05-08 16:20:05 +0000
committerSam Clegg <sbc@chromium.org>2019-05-08 16:20:05 +0000
commita1282a39badee81b90ebd235b15ea45e9949829e (patch)
tree203d67aeadbf99a7d56b4c1879560286387bfae9
parente62c693c8e71626d9dbf919280fd314cfac7f175 (diff)
downloadbcm5719-llvm-a1282a39badee81b90ebd235b15ea45e9949829e.tar.gz
bcm5719-llvm-a1282a39badee81b90ebd235b15ea45e9949829e.zip
[WebAssembly] Handle command line options consistently with the ELF backend.
Differential Revision: https://reviews.llvm.org/D61645 llvm-svn: 360266
-rw-r--r--lld/ELF/Driver.cpp3
-rw-r--r--lld/ELF/Driver.h1
-rw-r--r--lld/wasm/Config.h8
-rw-r--r--lld/wasm/Driver.cpp44
4 files changed, 34 insertions, 22 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 57b9146a899..6799ea9c041 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -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 Opt, const Twine &Msg) {
}
// 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);
diff --git a/lld/ELF/Driver.h b/lld/ELF/Driver.h
index dd66893b2d5..050bb611fc6 100644
--- a/lld/ELF/Driver.h
+++ b/lld/ELF/Driver.h
@@ -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);
diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h
index ccd7f3717f9..7881d01502d 100644
--- a/lld/wasm/Config.h
+++ b/lld/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 @@ 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;
};
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index f65722fdf2d..d6ee9076717 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -292,11 +292,8 @@ static StringRef getEntry(opt::InputArgList &Args) {
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 &Args) {
}
}
+// 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 char *> ArgsArr) {
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 char *> ArgsArr) {
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 char *> ArgsArr) {
if (!Config->Relocatable)
createSyntheticSymbols();
- if (Config->Shared) {
- Config->ImportMemory = true;
- Config->ExportDynamic = true;
- Config->AllowUndefined = true;
- }
-
createFiles(Args);
if (errorCount())
return;
OpenPOWER on IntegriCloud