Skip to content

Commit 7e4883f

Browse files
authored
[llvm-ranlib] Change -v (alias for --version) to -V
-V prints the version information in both BSD and GNU ar/ranlib. BSD ranlib rejects -v while -v enables verbose output in GNU ar but is another alias for --version in GNU ranlib. The GNU ranlib behavior is inconsistent: `ranlib -v` is different from `ar -sv`. But it's not a major concern in practice: * Users typically use ranlib solely for creating archive symbol tables, and they don't need verbose output. * Verbose output in ranlib seems a no-op. * GNU ar creates an archive symbol table by default. Many ranlib uses have been eliminated. * Modern linkers like lld/ELF (since version 14) and mold don't rely on archive symbol tables anymore. https://reviews.llvm.org/D71554 introduced -v. This patch removes it so that `llvm-ranlib -v` and `llvm-ranlib -version` lead to errors (GNU ranlib rejects `-version` as well). -V is added as an alias for --version. Close #87654 Pull Request: #87661
1 parent 29cc80f commit 7e4883f

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

llvm/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ Changes to the LLVM tools
174174
* llvm-ar now allows specifying COFF archive format with ``--format`` argument
175175
and uses it by default for COFF targets.
176176

177+
* llvm-ranlib now supports ``-V`` as an alias for ``--version``.
178+
``-v`` (``--verbose`` in llvm-ar) has been removed.
179+
(`#87661 <https://github.com/llvm/llvm-project/pull/87661>`_)
180+
177181
* llvm-objcopy now supports ``--set-symbol-visibility`` and
178182
``--set-symbols-visibility`` options for ELF input to change the
179183
visibility of symbols.

llvm/test/tools/llvm-ranlib/help-message.test

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@
55
# RUN: llvm-ranlib -help | FileCheck %s --check-prefix=HELP
66
# RUN: llvm-ranlib --help | FileCheck %s --check-prefix=HELP
77
# RUN: llvm-ranlib --version | FileCheck %s --check-prefix=VERSION
8-
# RUN: llvm-ranlib -version | FileCheck %s --check-prefix=VERSION
9-
# RUN: llvm-ranlib -v | FileCheck %s --check-prefix=VERSION
8+
# RUN: llvm-ranlib -V | FileCheck %s --check-prefix=VERSION
109

1110
## Also check combined options (first -h/-v flag wins)
1211
# RUN: llvm-ranlib -Dh | FileCheck %s --check-prefix=HELP
13-
# RUN: llvm-ranlib -Dvh | FileCheck %s --check-prefix=VERSION
14-
# RUN: llvm-ranlib -Dhv | FileCheck %s --check-prefix=HELP
12+
# RUN: llvm-ranlib -DVh | FileCheck %s --check-prefix=VERSION
13+
# RUN: llvm-ranlib -DhV | FileCheck %s --check-prefix=HELP
1514

1615
# HELP: USAGE: llvm-ranlib
1716
# VERSION: version
17+
18+
## -v enables verbose output in BSD ranlib and GNU ar but is another alias
19+
## for --version in GNU ranlib. Reject -v.
20+
# RUN: not llvm-ranlib -v 2>&1 | FileCheck %s --check-prefix=ERR1
21+
# RUN: not llvm-ranlib -version 2>&1 | FileCheck %s --check-prefix=ERR2
22+
# RUN: not llvm-ranlib -Dvh 2>&1 | FileCheck %s --check-prefix=ERR3
23+
24+
# ERR1: error: Invalid option: '-v'
25+
# ERR2: error: Invalid option: '-version'
26+
# ERR3: error: Invalid option: '-vh'

llvm/tools/llvm-ar/llvm-ar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static void printRanLibHelp(StringRef ToolName) {
6565
<< "USAGE: " + ToolName + " archive...\n\n"
6666
<< "OPTIONS:\n"
6767
<< " -h --help - Display available options\n"
68-
<< " -v --version - Display the version of this program\n"
68+
<< " -V --version - Display the version of this program\n"
6969
<< " -D - Use zero for timestamps and uids/gids "
7070
"(default)\n"
7171
<< " -U - Use actual timestamps and uids/gids\n"
@@ -1439,7 +1439,7 @@ static int ranlib_main(int argc, char **argv) {
14391439
} else if (arg.front() == 'h') {
14401440
printHelpMessage();
14411441
return 0;
1442-
} else if (arg.front() == 'v') {
1442+
} else if (arg.front() == 'V') {
14431443
cl::PrintVersionMessage();
14441444
return 0;
14451445
} else if (arg.front() == 'X') {

0 commit comments

Comments
 (0)