48

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.

6 Answers 6

60

objdump is part of binutils.

5
  • 8
    Homebrew has it too! :) Commented Dec 7, 2011 at 2:26
  • 9
    I was hoping homebrew has it! Thanks! brew install binutils
    – nacho4d
    Commented Sep 9, 2013 at 8:37
  • 12
    MacPorts binutils installs objdump as gobjdump.
    – user267739
    Commented Oct 29, 2013 at 6:54
  • 1
    -bash: objdump: command not found Commented May 11, 2016 at 21:58
  • 1
    brew install binutils also installs it as gobjdump Commented Apr 5, 2017 at 20:31
33

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.

4
  • 16
    +1 for otool - use otool -tV <executable> to disassemble
    – Paul R
    Commented Nov 3, 2010 at 8:54
  • 2
    dwarftool also offers some similar functionality. Commented Oct 19, 2012 at 7:30
  • 4
    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
    Commented Mar 13, 2013 at 13:17
  • 2
    -bash: dwarftool: command not found Commented May 11, 2016 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.

1
  • 4
    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
    Commented Jun 19, 2017 at 14:17
7

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
2

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.

0

After binutils installation through brew install binutils, if you still can not find gobjdump in your $PATH, the reason perhaps is that homebrew forgot to create soft link to the binary.

$ cd /opt/homebrew/bin

// $ ls -l ../Cellar/binutils/2.37/bin/gobjdump
// lrwxr-xr-x  1 steve  admin  7 Jul 19  2021 ../Cellar/binutils/2.37/bin/gobjdump -> objdump

// change this command to fit your objdump binary path
$ link ../Cellar/binutils/2.37/bin/gobjdump  gobjdump

My environment:

$ uname -a
Darwin localhost 20.5.0 Darwin Kernel Version 20.5.0: Sat May  8 05:10:31 PDT 2021; root:xnu-7195.121.3~9/RELEASE_ARM64_T8101 arm64
$ brew --version
Homebrew 3.4.3
Homebrew/homebrew-core (git revision 1f841cb3044; last commit 2022-03-27)
Homebrew/homebrew-cask (git revision 60208d8c20; last commit 2022-03-26)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .