[PATCH] D76250: [llvm-objdump] Only reject -long-option in objdump mode
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 16 13:07:58 PDT 2020
MaskRay created this revision.
MaskRay added a reviewer: compnerd.
Herald added subscribers: llvm-commits, rupprecht.
Herald added a reviewer: jhenderson.
Herald added a project: LLVM.
MaskRay updated this revision to Diff 250620.
MaskRay retitled this revision from "[llvm-objdump] Support -long-option in otool mode" to "[llvm-objdump] Only reject -long-option in objdump mode".
MaskRay added a comment.
Repurpose
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D76250
Files:
llvm/test/tools/llvm-objdump/long-option-style.test
llvm/tools/llvm-objdump/llvm-objdump.cpp
Index: llvm/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -2339,9 +2339,11 @@
// Register the target printer for --version.
cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
+ // If called objdump, follow GNU long option style and reject -long-option.
+ StringRef Stem = sys::path::stem(argv[0]);
+ bool LongOptionsUseDoubleDash = Stem.startswith("objdump");
cl::ParseCommandLineOptions(argc, argv, "llvm object file dumper\n", nullptr,
- /*EnvVar=*/nullptr,
- /*LongOptionsUseDoubleDash=*/true);
+ /*EnvVar=*/nullptr, LongOptionsUseDoubleDash);
if (StartAddress >= StopAddress)
reportCmdLineError("start address should be less than stop address");
Index: llvm/test/tools/llvm-objdump/long-option-style.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/long-option-style.test
@@ -0,0 +1,21 @@
+## Don't make symlinks on Windows.
+# UNSUPPORTED: system-windows
+
+# RUN: rm -rf %t
+# RUN: mkdir %t
+# RUN: ln -s llvm-objdump %t/objdump
+# RUN: ln -s llvm-objdump %t/objdump-11
+
+# RUN: llvm-objdump --help
+# RUN: llvm-objdump -help
+
+## -long-option does not fit with grouped short options.
+## Disallow them in objdump mode.
+# RUN: %t/objdump --help
+# RUN: not %t/objdump -help 2>&1 | FileCheck --check-prefix=UNKNOWN %s
+
+## objdump may be suffixed by a version.
+# RUN: %t/objdump-11 --help
+# RUN: not %t/objdump-11 -help 2>&1 | FileCheck --check-prefix=UNKNOWN %s
+
+# UNKNOWN: Unknown command line argument '-help'.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76250.250620.patch
Type: text/x-patch
Size: 1787 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200316/5c94fd30/attachment.bin>
More information about the llvm-commits
mailing list