Skip to content

[llvm-ranlib] Change -v (alias for --version) to -V #87661

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

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Apr 4, 2024

-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

Created using spr 1.3.5-bogner
@llvmbot
Copy link
Member

llvmbot commented Apr 4, 2024

@llvm/pr-subscribers-llvm-binary-utilities

Author: Fangrui Song (MaskRay)

Changes

-V prints the version information in both BSD and GNU ar/ranlib.

-v enables verbose output in BSD ranlib and 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 lld 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


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

2 Files Affected:

  • (modified) llvm/test/tools/llvm-ranlib/help-message.test (+13-4)
  • (modified) llvm/tools/llvm-ar/llvm-ar.cpp (+2-2)
diff --git a/llvm/test/tools/llvm-ranlib/help-message.test b/llvm/test/tools/llvm-ranlib/help-message.test
index 8d8824ac46121a..97212aa035b313 100644
--- a/llvm/test/tools/llvm-ranlib/help-message.test
+++ b/llvm/test/tools/llvm-ranlib/help-message.test
@@ -5,13 +5,22 @@
 # RUN: llvm-ranlib -help | FileCheck %s --check-prefix=HELP
 # RUN: llvm-ranlib --help | FileCheck %s --check-prefix=HELP
 # RUN: llvm-ranlib --version | FileCheck %s --check-prefix=VERSION
-# RUN: llvm-ranlib -version | FileCheck %s --check-prefix=VERSION
-# RUN: llvm-ranlib -v | FileCheck %s --check-prefix=VERSION
+# RUN: llvm-ranlib -V | FileCheck %s --check-prefix=VERSION
 
 ## Also check combined options (first -h/-v flag wins)
 # RUN: llvm-ranlib -Dh | FileCheck %s --check-prefix=HELP
-# RUN: llvm-ranlib -Dvh | FileCheck %s --check-prefix=VERSION
-# RUN: llvm-ranlib -Dhv | FileCheck %s --check-prefix=HELP
+# RUN: llvm-ranlib -DVh | FileCheck %s --check-prefix=VERSION
+# RUN: llvm-ranlib -DhV | FileCheck %s --check-prefix=HELP
 
 # HELP: USAGE: llvm-ranlib
 # VERSION: version
+
+## -v enables verbose output in BSD ranlib and GNU ar but is another alias
+## for --version in GNU ranlib. Reject -v.
+# RUN: not llvm-ranlib -v 2>&1 | FileCheck %s --check-prefix=ERR1
+# RUN: not llvm-ranlib -version 2>&1 | FileCheck %s --check-prefix=ERR2
+# RUN: not llvm-ranlib -Dvh 2>&1 | FileCheck %s --check-prefix=ERR3
+
+# ERR1: error: Invalid option: '-v'
+# ERR2: error: Invalid option: '-version'
+# ERR3: error: Invalid option: '-vh'
diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp
index 294b8531b08f13..3b842b76d5c870 100644
--- a/llvm/tools/llvm-ar/llvm-ar.cpp
+++ b/llvm/tools/llvm-ar/llvm-ar.cpp
@@ -65,7 +65,7 @@ static void printRanLibHelp(StringRef ToolName) {
          << "USAGE: " + ToolName + " archive...\n\n"
          << "OPTIONS:\n"
          << "  -h --help             - Display available options\n"
-         << "  -v --version          - Display the version of this program\n"
+         << "  -V --version          - Display the version of this program\n"
          << "  -D                    - Use zero for timestamps and uids/gids "
             "(default)\n"
          << "  -U                    - Use actual timestamps and uids/gids\n"
@@ -1439,7 +1439,7 @@ static int ranlib_main(int argc, char **argv) {
         } else if (arg.front() == 'h') {
           printHelpMessage();
           return 0;
-        } else if (arg.front() == 'v') {
+        } else if (arg.front() == 'V') {
           cl::PrintVersionMessage();
           return 0;
         } else if (arg.front() == 'X') {

MaskRay added a commit to MaskRay/llvm-project that referenced this pull request Apr 4, 2024
-V prints the version information in both BSD and GNU ar/ranlib.

-v enables verbose output in BSD ranlib and 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 lld 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 llvm#87654

Pull Request: llvm#87661
@emaste
Copy link
Member

emaste commented Apr 5, 2024

hrm, GNU ranlib help output shows -v for version but accepts both -v and -V.

Usage: /usr/local/bin/ranlib [options] archive
 Generate an index to speed access to archives
 The options are:
  @<file>                      Read options from <file>
  --plugin <name>              Load the specified plugin
  -D                           Use zero for symbol map timestamp (default)
  -U                           Use an actual symbol map timestamp
  -t                           Update the archive's symbol map timestamp
  -h --help                    Print this help message
  -v --version                 Print version information

but given there's conflicting functionality between BSD and GNU ranlib for -v already I have no problem with removing the option.

As an aside I suspect that the ranlib invocations in the FreeBSD ports collection are all unnecessary and are just leftover from build systems created for much earlier toolchains, but it's a slow process to get rid of them.

Copy link
Member

@arichardson arichardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Created using spr 1.3.5-bogner
@MaskRay MaskRay merged commit 7e4883f into main Apr 5, 2024
@MaskRay MaskRay deleted the users/MaskRay/spr/llvm-ranlib-change-v-alias-for-version-to-v branch April 5, 2024 16:24
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.

llvm-ranlib: -V option not supported (used by configure tests)
4 participants