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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lld/test/wasm/version.test
Original file line number Diff line number Diff line change
@@ -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 {{.+}}
13 changes: 9 additions & 4 deletions lld/wasm/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lld/wasm/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -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>">,
Expand Down
Loading