44

I want to get the source code of a small command line tool using objdump on Mac OS X.

I've used arm-linux-objdump on Linux and find it a great tool.

Is there any way to install objdump on OS X? I've searched Google and found information about arm-apple-dawin9-objdump, but failed to find anything to download.

54

objdump is part of binutils.

  • 8
    Homebrew has it too! :) – Adrian Petrescu Dec 7 '11 at 2:26
  • 9
    I was hoping homebrew has it! Thanks! brew install binutils – nacho4d Sep 9 '13 at 8:37
  • 11
    MacPorts binutils installs objdump as gobjdump. – user267739 Oct 29 '13 at 6:54
  • 1
    -bash: objdump: command not found – IgorGanapolsky May 11 '16 at 21:58
  • 1
    brew install binutils also installs it as gobjdump – Joseph Sheedy Apr 5 '17 at 20:31
31

If you have XCode Tools installed on your Mac, you can use the otool that comes with it. I believe it does pretty much what objdump is capable of.

  • 13
    +1 for otool - use otool -tV <executable> to disassemble – Paul R Nov 3 '10 at 8:54
  • 1
    dwarftool also offers some similar functionality. – Mike Weller Oct 19 '12 at 7:30
  • 3
    does otool have an option like objdump -S, which gives assembly output annotated with source code? Couldn't really figure out from the --help output. – rgngl Mar 13 '13 at 13:17
  • 1
    -bash: dwarftool: command not found – IgorGanapolsky May 11 '16 at 21:59
8

If your file is 64bits, you should use otool instead of gobjdump from binutils. On Mac OSX, gobjdump is for 32bits.

  • 2
    As of 2017, gobjdump 2.27 (I think I got it from homebrew?) does work well with 64 bits in macOS Sierra (10.12) – hmijail Jun 19 '17 at 14:17
6

You can install it with Homebrew:

$ brew install binutils
==> Downloading https://homebrew.bintray.com/bottles/binutils-2.25.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring binutils-2.25.yosemite.bottle.tar.gz
🍺  /usr/local/Cellar/binutils/2.25: 107 files, 140M
$ which gobjdump
/usr/local/bin/gobjdump
1

You should use otool because objdump is a binutils tool for the ELF binary format on Linux and most other UNIX systems. otool is the the disassembler for MacOS's Mach-O binary format. Type $ man otool for instructions on use.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.