[lld] r346972 - [WebAssembly] Refactor config setting and checking. NFC.
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 15 10:09:41 PST 2018
Author: sbc
Date: Thu Nov 15 10:09:41 2018
New Revision: 346972
URL: http://llvm.org/viewvc/llvm-project?rev=346972&view=rev
Log:
[WebAssembly] Refactor config setting and checking. NFC.
This matches the way the ELF backend does it.
Differential Revision: https://reviews.llvm.org/D54559
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/wasm/Driver.cpp
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=346972&r1=346971&r2=346972&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Nov 15 10:09:41 2018
@@ -275,7 +275,7 @@ static void initLLVM() {
// Some command line options or some combinations of them are not allowed.
// This function checks for such errors.
-static void checkOptions(opt::InputArgList &Args) {
+static void checkOptions() {
// The MIPS ABI as of 2016 does not support the GNU-style symbol lookup
// table which is a relatively new feature.
if (Config->EMachine == EM_MIPS && Config->GnuHash)
@@ -429,7 +429,7 @@ void LinkerDriver::main(ArrayRef<const c
inferMachineType();
setConfigs(Args);
- checkOptions(Args);
+ checkOptions();
if (errorCount())
return;
Modified: lld/trunk/wasm/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=346972&r1=346971&r2=346972&view=diff
==============================================================================
--- lld/trunk/wasm/Driver.cpp (original)
+++ lld/trunk/wasm/Driver.cpp Thu Nov 15 10:09:41 2018
@@ -325,49 +325,11 @@ static void handleWeakUndefines() {
}
}
-// Force Sym to be entered in the output. Used for -u or equivalent.
-static Symbol *handleUndefined(StringRef Name) {
- Symbol *Sym = Symtab->find(Name);
- if (!Sym)
- return nullptr;
-
- // Since symbol S may not be used inside the program, LTO may
- // eliminate it. Mark the symbol as "used" to prevent it.
- Sym->IsUsedInRegularObj = true;
-
- if (auto *LazySym = dyn_cast<LazySymbol>(Sym))
- LazySym->fetch();
-
- return Sym;
-}
-
-void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
- WasmOptTable Parser;
- opt::InputArgList Args = Parser.parse(ArgsArr.slice(1));
-
- // Handle --help
- if (Args.hasArg(OPT_help)) {
- Parser.PrintHelp(outs(),
- (std::string(ArgsArr[0]) + " [options] file...").c_str(),
- "LLVM Linker", false);
- return;
- }
-
- // Handle --version
- if (Args.hasArg(OPT_version) || Args.hasArg(OPT_v)) {
- outs() << getLLDVersion() << "\n";
- return;
- }
-
- // Parse and evaluate -mllvm options.
- std::vector<const char *> V;
- V.push_back("wasm-ld (LLVM option parsing)");
- for (auto *Arg : Args.filtered(OPT_mllvm))
- V.push_back(Arg->getValue());
- cl::ParseCommandLineOptions(V.size(), V.data());
-
- errorHandler().ErrorLimit = args::getInteger(Args, OPT_error_limit, 20);
-
+// 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) {
Config->AllowUndefined = Args.hasArg(OPT_allow_undefined);
Config->CompressRelocations = Args.hasArg(OPT_compress_relocations);
Config->Demangle = Args.hasFlag(OPT_demangle, OPT_no_demangle, true);
@@ -414,7 +376,11 @@ void LinkerDriver::link(ArrayRef<const c
Config->MaxMemory = args::getInteger(Args, OPT_max_memory, 0);
Config->ZStackSize =
args::getZOptionValue(Args, OPT_z, "stack-size", WasmPageSize);
+}
+// Some command line options or some combinations of them are not allowed.
+// This function checks for such errors.
+static void checkOptions(opt::InputArgList &Args) {
if (!Config->StripDebug && !Config->StripAll && Config->CompressRelocations)
error("--compress-relocations is incompatible with output debug"
" information. Please pass --strip-debug or --strip-all");
@@ -426,14 +392,6 @@ void LinkerDriver::link(ArrayRef<const c
if (Config->ThinLTOJobs == 0)
error("--thinlto-jobs: number of threads must be > 0");
- if (auto *Arg = Args.getLastArg(OPT_allow_undefined_file))
- readImportFile(Arg->getValue());
-
- if (!Args.hasArg(OPT_INPUT)) {
- error("no input files");
- return;
- }
-
if (Config->Pie && Config->Shared)
error("-shared and -pie may not be used together");
@@ -455,6 +413,61 @@ void LinkerDriver::link(ArrayRef<const c
if (Config->Pie)
error("-r and -pie may not be used together");
}
+}
+
+// Force Sym to be entered in the output. Used for -u or equivalent.
+static Symbol *handleUndefined(StringRef Name) {
+ Symbol *Sym = Symtab->find(Name);
+ if (!Sym)
+ return nullptr;
+
+ // Since symbol S may not be used inside the program, LTO may
+ // eliminate it. Mark the symbol as "used" to prevent it.
+ Sym->IsUsedInRegularObj = true;
+
+ if (auto *LazySym = dyn_cast<LazySymbol>(Sym))
+ LazySym->fetch();
+
+ return Sym;
+}
+
+void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
+ WasmOptTable Parser;
+ opt::InputArgList Args = Parser.parse(ArgsArr.slice(1));
+
+ // Handle --help
+ if (Args.hasArg(OPT_help)) {
+ Parser.PrintHelp(outs(),
+ (std::string(ArgsArr[0]) + " [options] file...").c_str(),
+ "LLVM Linker", false);
+ return;
+ }
+
+ // Handle --version
+ if (Args.hasArg(OPT_version) || Args.hasArg(OPT_v)) {
+ outs() << getLLDVersion() << "\n";
+ return;
+ }
+
+ // Parse and evaluate -mllvm options.
+ std::vector<const char *> V;
+ V.push_back("wasm-ld (LLVM option parsing)");
+ for (auto *Arg : Args.filtered(OPT_mllvm))
+ V.push_back(Arg->getValue());
+ cl::ParseCommandLineOptions(V.size(), V.data());
+
+ errorHandler().ErrorLimit = args::getInteger(Args, OPT_error_limit, 20);
+
+ setConfigs(Args);
+ checkOptions(Args);
+
+ if (auto *Arg = Args.getLastArg(OPT_allow_undefined_file))
+ readImportFile(Arg->getValue());
+
+ if (!Args.hasArg(OPT_INPUT)) {
+ error("no input files");
+ return;
+ }
Config->Pic = Config->Pie || Config->Shared;
More information about the llvm-commits
mailing list