From 7e6602110b89c066aabeb47445f17f557974eaef Mon Sep 17 00:00:00 2001 From: Michael Trent Date: Tue, 15 Jan 2019 20:41:30 +0000 Subject: [PATCH] llvm-objdump -m -D should disassemble all text segments Summary: When running llvm-objdump with the -macho option objdump will by default disassemble only the __TEXT,__text section (or __TEXT_EXEC,__text when disassembling MH_KEXT_BUNDLE files). The -disassemble-all option is treated no diferently than -disassemble. This change upates llvm-objdump's MachO parsing code to disassemble all __text sections found in a file when -disassemble-all is specified. This is useful for disassembling files with more than one __text section, or when disassembling files whose __text section is not present in __TEXT. I added a lit test case that verifies "llvm-objdump -m -d" and "llvm-objdump -m -D" produce the expected results on a reference binary. I also updated the CommandGuide documentation for llvm-objdump.rst and verified it renders correctly as man and html. rdar://42899338 Reviewers: ab, pete, lhames Reviewed By: lhames Subscribers: rupprecht, llvm-commits Differential Revision: https://reviews.llvm.org/D56649 llvm-svn: 351238 --- llvm/docs/CommandGuide/llvm-objdump.rst | 42 ++++++++++++--------- .../llvm-objdump/X86/Inputs/macho-multiple-text | Bin 0 -> 12580 bytes .../llvm-objdump/X86/macho-disassemble-all.test | 39 +++++++++++++++++++ llvm/tools/llvm-objdump/MachODump.cpp | 15 +++++++- 4 files changed, 77 insertions(+), 19 deletions(-) create mode 100755 llvm/test/tools/llvm-objdump/X86/Inputs/macho-multiple-text create mode 100644 llvm/test/tools/llvm-objdump/X86/macho-disassemble-all.test diff --git a/llvm/docs/CommandGuide/llvm-objdump.rst b/llvm/docs/CommandGuide/llvm-objdump.rst index 0d02915..c3e7c16 100644 --- a/llvm/docs/CommandGuide/llvm-objdump.rst +++ b/llvm/docs/CommandGuide/llvm-objdump.rst @@ -16,12 +16,19 @@ stream. COMMANDS -------- -At least one of the following commands are required, and some commands can be combined with other commands: +At least one of the following commands are required, and some commands can be +combined with other commands: -.. option:: -disassemble +.. option:: -d, -disassemble + + Display assembler mnemonics for the machine instructions. Disassembles all + text sections found in the input file(s). + +.. option:: -D, -disassemble-all + + Display assembler mnemonics for the machine instructions. Disassembles all + sections found in the input file(s). - Display assembler mnemonics for the machine instructions - .. option:: -help Display usage information and exit. Does not stack with other commands. @@ -45,14 +52,14 @@ At least one of the following commands are required, and some commands can be co .. option:: -version Display the version of this program. Does not stack with other commands. - + OPTIONS ------- :program:`llvm-objdump` supports the following options: .. option:: -arch= - Specify the architecture to disassemble. see -version for available + Specify the architecture to disassemble. see ``-version`` for available architectures. .. option:: -cfg @@ -68,14 +75,15 @@ OPTIONS Print line information from debug info if available. -.. option:: -macho +.. option:: -m, -macho - Use Mach-O specific object file parser. + Use Mach-O specific object file parser. Commands and other options may behave + differently when used with ``-macho``. .. option:: -mattr= Target specific attributes. - + .. option:: -mc-x86-disable-arith-relaxation Disable relaxation of arithmetic instruction for X86. @@ -83,26 +91,26 @@ OPTIONS .. option:: -stats Enable statistics output from program. - + .. option:: -triple= - Target triple to disassemble for, see -version for available targets. - + Target triple to disassemble for, see ``-version`` for available targets. + .. option:: -x86-asm-syntax=