[PATCH] D124920: [llvm-otool] Make `llvm-otool -l` output compatible with otool for LC_BUILD_VERSION
Nico Weber via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 4 06:11:25 PDT 2022
thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added a subscriber: rupprecht.
Herald added a reviewer: jhenderson.
Herald added a reviewer: MaskRay.
Herald added a project: All.
thakis requested review of this revision.
Herald added a subscriber: StephenFan.
Herald added a project: LLVM.
Namely, only "symbolize" platform and tool names if `-v` is passed.
(`llvm-otool -lv` output still isn't quite the same as `otool -lv` output, but
`-v` output is arguably for consumption by humans, so I'm not changing that
at this point. Someone else could change it if it was important to them.)
https://reviews.llvm.org/D124920
Files:
llvm/test/tools/llvm-objdump/MachO/build-version.yaml
llvm/tools/llvm-objdump/MachODump.cpp
Index: llvm/tools/llvm-objdump/MachODump.cpp
===================================================================
--- llvm/tools/llvm-objdump/MachODump.cpp
+++ llvm/tools/llvm-objdump/MachODump.cpp
@@ -9163,14 +9163,20 @@
outs() << " size " << Nt.size << "\n";
}
-static void PrintBuildToolVersion(MachO::build_tool_version bv) {
- outs() << " tool " << MachOObjectFile::getBuildTool(bv.tool) << "\n";
+static void PrintBuildToolVersion(MachO::build_tool_version bv, bool verbose) {
+ outs() << " tool ";
+ if (verbose)
+ outs() << MachOObjectFile::getBuildTool(bv.tool);
+ else
+ outs() << bv.tool;
+ outs() << "\n";
outs() << " version " << MachOObjectFile::getVersionString(bv.version)
<< "\n";
}
static void PrintBuildVersionLoadCommand(const MachOObjectFile *obj,
- MachO::build_version_command bd) {
+ MachO::build_version_command bd,
+ bool verbose) {
outs() << " cmd LC_BUILD_VERSION\n";
outs() << " cmdsize " << bd.cmdsize;
if (bd.cmdsize !=
@@ -9179,8 +9185,12 @@
outs() << " Incorrect size\n";
else
outs() << "\n";
- outs() << " platform " << MachOObjectFile::getBuildPlatform(bd.platform)
- << "\n";
+ outs() << " platform ";
+ if (verbose)
+ outs() << MachOObjectFile::getBuildPlatform(bd.platform);
+ else
+ outs() << bd.platform;
+ outs() << "\n";
if (bd.sdk)
outs() << " sdk " << MachOObjectFile::getVersionString(bd.sdk)
<< "\n";
@@ -9191,7 +9201,7 @@
outs() << " ntools " << bd.ntools << "\n";
for (unsigned i = 0; i < bd.ntools; ++i) {
MachO::build_tool_version bv = obj->getBuildToolVersion(i);
- PrintBuildToolVersion(bv);
+ PrintBuildToolVersion(bv, verbose);
}
}
@@ -10168,7 +10178,7 @@
} else if (Command.C.cmd == MachO::LC_BUILD_VERSION) {
MachO::build_version_command Bv =
Obj->getBuildVersionLoadCommand(Command);
- PrintBuildVersionLoadCommand(Obj, Bv);
+ PrintBuildVersionLoadCommand(Obj, Bv, verbose);
} else if (Command.C.cmd == MachO::LC_SOURCE_VERSION) {
MachO::source_version_command Sd = Obj->getSourceVersionCommand(Command);
PrintSourceVersionCommand(Sd);
Index: llvm/test/tools/llvm-objdump/MachO/build-version.yaml
===================================================================
--- llvm/test/tools/llvm-objdump/MachO/build-version.yaml
+++ llvm/test/tools/llvm-objdump/MachO/build-version.yaml
@@ -1,4 +1,6 @@
# RUN: yaml2obj %s | llvm-objdump --macho --private-headers - | FileCheck %s
+# RUN: yaml2obj %s | llvm-otool -lv - | FileCheck %s
+# RUN: yaml2obj %s | llvm-otool -l - | FileCheck --check-prefix=SHORT %s
--- !mach-o
FileHeader:
@@ -55,3 +57,13 @@
CHECK-NEXT: ntools 1
CHECK-NEXT: tool clang
CHECK-NEXT: version 0.0
+
+SHORT: Load command 1
+SHORT-NEXT: cmd LC_BUILD_VERSION
+SHORT-NEXT: cmdsize 32
+SHORT-NEXT: platform 2
+SHORT-NEXT: sdk 9.0
+SHORT-NEXT: minos 8.0
+SHORT-NEXT: ntools 1
+SHORT-NEXT: tool 1
+SHORT-NEXT: version 0.0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124920.426980.patch
Type: text/x-patch
Size: 3160 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220504/458b5f1f/attachment.bin>
More information about the llvm-commits
mailing list