Skip to content

[lld][WebAssembly] Improve -v/-V/--version flag compat #113204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2024

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Oct 21, 2024

Fixes: #112836

@llvmbot
Copy link
Member

llvmbot commented Oct 21, 2024

@llvm/pr-subscribers-lld-wasm

@llvm/pr-subscribers-lld

Author: Sam Clegg (sbc100)

Changes

Fixes: #112836


Full diff: https://github.com/llvm/llvm-project/pull/113204.diff

3 Files Affected:

  • (added) lld/test/wasm/version.test (+12)
  • (modified) lld/wasm/Driver.cpp (+9-4)
  • (modified) lld/wasm/Options.td (+1)
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>">,

@sbc100 sbc100 merged commit 0764e55 into llvm:main Oct 22, 2024
11 checks passed
@sbc100 sbc100 deleted the improve_version_flag branch October 22, 2024 17:48
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 22, 2024

LLVM Buildbot has detected a new failure on builder lldb-aarch64-ubuntu running on linaro-lldb-aarch64-ubuntu while building lld at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/59/builds/6950

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: commands/help/TestHelp.py (167 of 2041)
PASS: lldb-api :: commands/log/invalid-args/TestInvalidArgsLog.py (168 of 2041)
PASS: lldb-api :: commands/platform/basic/TestPlatformPython.py (169 of 2041)
PASS: lldb-api :: commands/platform/basic/TestPlatformCommand.py (170 of 2041)
PASS: lldb-api :: commands/memory/write/TestMemoryWrite.py (171 of 2041)
PASS: lldb-api :: commands/frame/recognizer/TestFrameRecognizer.py (172 of 2041)
PASS: lldb-api :: commands/platform/file/read/TestPlatformFileRead.py (173 of 2041)
PASS: lldb-api :: commands/platform/file/close/TestPlatformFileClose.py (174 of 2041)
PASS: lldb-api :: commands/memory/read/TestMemoryRead.py (175 of 2041)
UNRESOLVED: lldb-api :: commands/gui/spawn-threads/TestGuiSpawnThreads.py (176 of 2041)
******************** TEST 'lldb-api :: commands/gui/spawn-threads/TestGuiSpawnThreads.py' FAILED ********************
Script:
--
/usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --arch aarch64 --build-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/lldb --compiler /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/dsymutil --make /usr/bin/make --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/commands/gui/spawn-threads -p TestGuiSpawnThreads.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 20.0.0git (https://github.com/llvm/llvm-project.git revision 0764e55c91514734ff79ca4d666fbce2fa89fc9d)
  clang revision 0764e55c91514734ff79ca4d666fbce2fa89fc9d
  llvm revision 0764e55c91514734ff79ca4d666fbce2fa89fc9d
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
FAIL: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_gui (TestGuiSpawnThreads.TestGuiSpawnThreadsTest)
======================================================================
ERROR: test_gui (TestGuiSpawnThreads.TestGuiSpawnThreadsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/decorators.py", line 148, in wrapper
    return func(*args, **kwargs)
  File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/commands/gui/spawn-threads/TestGuiSpawnThreads.py", line 44, in test_gui
    self.child.expect_exact(f"thread #{i + 2}: tid =")
  File "/usr/local/lib/python3.10/dist-packages/pexpect/spawnbase.py", line 432, in expect_exact
    return exp.expect_loop(timeout)
  File "/usr/local/lib/python3.10/dist-packages/pexpect/expect.py", line 179, in expect_loop
    return self.eof(e)
  File "/usr/local/lib/python3.10/dist-packages/pexpect/expect.py", line 122, in eof
    raise exc
pexpect.exceptions.EOF: End Of File (EOF). Exception style platform.
<pexpect.pty_spawn.spawn object at 0xffff91270430>
command: /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/lldb
args: ['/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/lldb', '--no-lldbinit', '--no-use-colors', '-O', 'settings clear -all', '-O', 'settings set symbols.enable-external-lookup false', '-O', 'settings set target.inherit-tcc true', '-O', 'settings set target.disable-aslr false', '-O', 'settings set target.detach-on-error false', '-O', 'settings set target.auto-apply-fixits false', '-O', 'settings set plugin.process.gdb-remote.packet-timeout 60', '-O', 'settings set symbols.clang-modules-cache-path "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api"', '-O', 'settings set use-color false', '--file', '/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/commands/gui/spawn-threads/TestGuiSpawnThreads.test_gui/a.out']
buffer (last 100 chars): b''
before (last 100 chars): b'4 0x0000aaaac1162ab0 _start (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/lldb+0x32ab0)\n'
after: <class 'pexpect.exceptions.EOF'>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wasm-ld -v exits without generating output
4 participants