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.

Gareth
  • 19,080

6 Answers6

60

objdump is part of binutils.

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,970
8

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

ahuigo
  • 181
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
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)
Steve Lau
  • 101