[lld] [lld][WebAssembly] Improve -v/-V/--version flag compat (PR #113204)
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 21 12:05:05 PDT 2024
https://github.com/sbc100 created https://github.com/llvm/llvm-project/pull/113204
Fixes: #112836
>From c322bba65a59b2f81e2b9d83d9ea5311a5cd3edb Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc at chromium.org>
Date: Mon, 21 Oct 2024 12:04:10 -0700
Subject: [PATCH] [lld][WebAssembly] Improve -v/-V/--version flag compat
Fixes: #112836
---
lld/test/wasm/version.test | 12 ++++++++++++
lld/wasm/Driver.cpp | 13 +++++++++----
lld/wasm/Options.td | 1 +
3 files changed, 22 insertions(+), 4 deletions(-)
create mode 100644 lld/test/wasm/version.test
diff --git a/lld/test/wasm/version.test b/lld/test/wasm/version.test
new file mode 100644
index 00000000000000..54a80976552559
--- /dev/null
+++ b/lld/test/wasm/version.test
@@ -0,0 +1,12 @@
+## Copied from lld/test/ELF/version.test
+
+## --version skips input file processing.
+# RUN: wasm-ld --version %t/not-exist 2>&1 | FileCheck %s
+
+## -v/-V don't skip processing if there is any input.
+# RUN: wasm-ld -v 2>&1 | FileCheck %s
+# RUN: not wasm-ld -v %t/not-exist 2>&1 | FileCheck %s
+# RUN: wasm-ld -V 2>&1 | FileCheck %s
+# RUN: not wasm-ld -V %t/not-exist 2>&1 | FileCheck %s
+
+# CHECK: LLD {{.+}}
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 289c1217ff5ead..9a27fc90457f08 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -1218,11 +1218,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
return;
}
- // Handle --version
- if (args.hasArg(OPT_version) || args.hasArg(OPT_v)) {
+ // Handle -v or -version.
+ if (args.hasArg(OPT_v) || args.hasArg(OPT_version))
lld::outs() << getLLDVersion() << "\n";
- return;
- }
// Handle --reproduce
if (const char *path = getReproduceOption(args)) {
@@ -1248,6 +1246,13 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
readConfigs(args);
setConfigs();
+ // The behavior of -v or --version is a bit strange, but this is
+ // needed for compatibility with GNU linkers.
+ if (args.hasArg(OPT_v) && !args.hasArg(OPT_INPUT))
+ return;
+ if (args.hasArg(OPT_version))
+ return;
+
createFiles(args);
if (errorCount())
return;
diff --git a/lld/wasm/Options.td b/lld/wasm/Options.td
index c5febd145a54f3..cff29e709a1a09 100644
--- a/lld/wasm/Options.td
+++ b/lld/wasm/Options.td
@@ -288,6 +288,7 @@ def: Flag<["-"], "S">, Alias<strip_debug>, HelpText<"Alias for --strip-debug">;
def: Flag<["-"], "t">, Alias<trace>, HelpText<"Alias for --trace">;
def: JoinedOrSeparate<["-"], "y">, Alias<trace_symbol>, HelpText<"Alias for --trace-symbol">;
def: JoinedOrSeparate<["-"], "u">, Alias<undefined>;
+def: Flag<["-"], "V">, Alias<v>, HelpText<"Alias for -v">;
// LTO-related options.
def lto_O: JJ<"lto-O">, MetaVarName<"<opt-level>">,
More information about the llvm-commits
mailing list