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.

Gaff
  • 18,569
  • 15
  • 57
  • 68
Chilly Zhong
  • 581
  • 1
  • 4
  • 4

6 Answers6

60

objdump is part of binutils.

Ignacio Vazquez-Abrams
  • 111,361
  • 10
  • 201
  • 247
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.

ayaz
  • 11,068
  • 1
  • 21
  • 26
8

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

ahuigo
  • 181
  • 1
  • 4
  • 3
    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
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
Daniel
  • 171
  • 1
  • 2
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.

Rian Rizvi
  • 121
  • 3
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)
Steve Lau
  • 101
  • 2