diff --git a/lld/test/wasm/driver.s b/lld/test/wasm/driver.s --- a/lld/test/wasm/driver.s +++ b/lld/test/wasm/driver.s @@ -5,6 +5,9 @@ .functype _start () -> () end_function +# RUN: not wasm-ld %t -o 2>&1 | FileCheck --check-prefix=NO_O_VAL %s +# NO_O_VAL: error: -o: missing argument + # RUN: not wasm-ld -o %t.exe 2>&1 | FileCheck -check-prefix=IN %s # IN: error: no input files diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp --- a/lld/wasm/Driver.cpp +++ b/lld/wasm/Driver.cpp @@ -184,6 +184,9 @@ args = this->ParseArgs(vec, missingIndex, missingCount); handleColorDiagnostics(args); + if (missingCount) + error(Twine(args.getArgString(missingIndex)) + ": missing argument"); + for (auto *arg : args.filtered(OPT_UNKNOWN)) error("unknown argument: " + arg->getAsString(args)); return args; @@ -810,6 +813,12 @@ }); } +static const char *getReproduceOption(opt::InputArgList &args) { + if (auto *arg = args.getLastArg(OPT_reproduce)) + return arg->getValue(); + return getenv("LLD_REPRODUCE"); +} + static bool isKnownZFlag(StringRef s) { // For now, we only support a very limited set of -z flags return s.startswith("stack-size="); @@ -847,8 +856,8 @@ } // Handle --reproduce - if (auto *arg = args.getLastArg(OPT_reproduce)) { - StringRef path = arg->getValue(); + // Note that --reproduce is a debug option so you can ignore it + if (const char *path = getReproduceOption(args)) { Expected> errOrWriter = TarWriter::create(path, path::stem(path)); if (errOrWriter) { diff --git a/lld/wasm/Options.td b/lld/wasm/Options.td --- a/lld/wasm/Options.td +++ b/lld/wasm/Options.td @@ -1,5 +1,18 @@ include "llvm/Option/OptParser.td" +// Convenience classes for long options which only accept two dashes. For lld +// specific or newer long options, we prefer two dashes to avoid collision with +// short options. For many others, we have to accept both forms to be compatible +// with GNU ld. +class FF : Flag<["--"], name>; +class JJ: Joined<["--"], name>; + +multiclass EEq { + def NAME: Separate<["--"], name>; + def NAME # _eq: Joined<["--"], name # "=">, Alias(NAME)>, + HelpText; +} + // For options whose names are multiple letters, either one dash or // two can precede the option name except those that start with 'o'. class F: Flag<["--", "-"], name>; @@ -99,7 +112,7 @@ def relocatable: F<"relocatable">, HelpText<"Create relocatable object file">; -defm reproduce: Eq<"reproduce", "Dump linker invocation and input files for debugging">; +defm reproduce: EEq<"reproduce", "Dump linker invocation and input files for debugging">; defm rsp_quoting: Eq<"rsp-quoting", "Quoting style for response files">, MetaVarName<"[posix,windows]">;