Skip to content

[llvm-objdump] Handle -M for --macho #113795

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 2 commits into from
Oct 28, 2024

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Oct 27, 2024

--macho -d uses the parseInputMachO code path, which does not handle
-M. Add -M handling for --macho as well.

Close #61019

Created using spr 1.3.5-bogner
@llvmbot
Copy link
Member

llvmbot commented Oct 27, 2024

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

Author: Fangrui Song (MaskRay)

Changes

--macho -d uses the parseInputMachO code path, which does not handle
-M. Add -M handling for --macho as well.

Close #61019


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

4 Files Affected:

  • (added) llvm/test/tools/llvm-objdump/MachO/AArch64/aliases.s (+11)
  • (modified) llvm/tools/llvm-objdump/MachODump.cpp (+4)
  • (modified) llvm/tools/llvm-objdump/llvm-objdump.cpp (+1-1)
  • (modified) llvm/tools/llvm-objdump/llvm-objdump.h (+1)
diff --git a/llvm/test/tools/llvm-objdump/MachO/AArch64/aliases.s b/llvm/test/tools/llvm-objdump/MachO/AArch64/aliases.s
new file mode 100644
index 00000000000000..547f621654857f
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/MachO/AArch64/aliases.s
@@ -0,0 +1,11 @@
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t
+# RUN: llvm-objdump --macho -d -M no-aliases %t | FileCheck %s
+# RUN: llvm-objdump --macho -d --disassembler-options=no-aliases %t | FileCheck %s
+
+# CHECK: orr w1, wzr, w2
+
+# RUN: not llvm-objdump --macho -d -M unknown %t 2>&1 | FileCheck %s -DFILE=%t --check-prefix=ERR
+
+# ERR: error: '[[FILE]]': unrecognized disassembler option: unknown
+
+mov w1, w2
diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp
index b8afb560d2ae9c..ab6f65cd41a365 100644
--- a/llvm/tools/llvm-objdump/MachODump.cpp
+++ b/llvm/tools/llvm-objdump/MachODump.cpp
@@ -7330,6 +7330,10 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
   // comment causing different diffs with the 'C' disassembler library API.
   // IP->setCommentStream(CommentStream);
 
+  for (StringRef Opt : DisassemblerOptions)
+    if (!IP->applyTargetSpecificCLOption(Opt))
+      reportError(Filename, "unrecognized disassembler option: " + Opt);
+
   // Set up separate thumb disassembler if needed.
   std::unique_ptr<const MCRegisterInfo> ThumbMRI;
   std::unique_ptr<const MCAsmInfo> ThumbAsmInfo;
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 8073c898b8a147..86ba9193dff2d1 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -305,11 +305,11 @@ bool objdump::ArchiveHeaders;
 bool objdump::Demangle;
 bool objdump::Disassemble;
 bool objdump::DisassembleAll;
+std::vector<std::string> objdump::DisassemblerOptions;
 bool objdump::SymbolDescription;
 bool objdump::TracebackTable;
 static std::vector<std::string> DisassembleSymbols;
 static bool DisassembleZeroes;
-static std::vector<std::string> DisassemblerOptions;
 static ColorOutput DisassemblyColor;
 DIDumpType objdump::DwarfDumpType;
 static bool DynamicRelocations;
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.h b/llvm/tools/llvm-objdump/llvm-objdump.h
index 7778cf6c2784eb..debaedd33429d0 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.h
+++ b/llvm/tools/llvm-objdump/llvm-objdump.h
@@ -50,6 +50,7 @@ extern DebugVarsFormat DbgVariables;
 extern bool Demangle;
 extern bool Disassemble;
 extern bool DisassembleAll;
+extern std::vector<std::string> DisassemblerOptions;
 extern DIDumpType DwarfDumpType;
 extern std::vector<std::string> FilterSections;
 extern bool LeadingAddr;

Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

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

LGTM, on the assumption that the -M option has an impact on the output displayed in the test (so we'd know if it wasn't doing anything in the future).

# RUN: llvm-objdump --macho -d -M no-aliases %t | FileCheck %s
# RUN: llvm-objdump --macho -d --disassembler-options=no-aliases %t | FileCheck %s

# CHECK: orr w1, wzr, w2
Copy link
Collaborator

Choose a reason for hiding this comment

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

What would be the output of this check without the -M option?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a test without -M.

Created using spr 1.3.5-bogner
@MaskRay MaskRay merged commit 92412c1 into main Oct 28, 2024
5 of 6 checks passed
@MaskRay MaskRay deleted the users/MaskRay/spr/llvm-objdump-handle-m-for-macho branch October 28, 2024 16:40
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
--macho -d uses the `parseInputMachO` code path, which does not handle
-M. Add -M handling for --macho as well.

Close llvm#61019

Pull Request: llvm#113795
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.

objdump -M no-aliases doesn't work with --macho
3 participants