0

I've been trying to disassemble C code into intel assembly code on my m1 macbook pro but can't find any way to do it (i've tried to look up how to do it using gdb, lldb, objdump, but no succes so far). So my question is: is it possible and if so, how and with which library/program? Would it also be possible to do with an IDE like CLion or Xcode?

Thanks in advance!

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 4
    I'm not sure what you mean by “disassemble” here. C code is *compiled* into assembly or machine code. If you compile to machine code, you can then *disassemble* the machine code into assembly code, but going directly from C to assembly is usually a better idea. Anyway, have you tried passing something like `-target amd64` to the C compiler? – fuz Nov 29 '21 at 14:36
  • 2
    I'd strongly recommend to use https://godbolt.org/ online compiler + disassembler. I use that one even though I have x86 disassemblers available locally. – Lundin Nov 29 '21 at 14:37
  • The LLVM option that some tools use is `--x86-asm-syntax=intel`, e.g. for `llvm-objdump -d`. But disassembly is useful if you have *machine code*. If you're compiling in the first place from C, that option can make clang emit Intel-syntax asm. – Peter Cordes Nov 29 '21 at 15:06
  • Actual GDB has an option `set disassembly-flavor intel` – Peter Cordes Nov 29 '21 at 15:16
  • I don't have access to an M1 Mac, but do you have `otool`? On intel macs, otool disassembles x86, arm; so I would hope the same would be true on an M1. – mevets Nov 29 '21 at 15:45
  • if you can run clang or gcc on an m1 mac, then of course you can make a cross toolchain and use that toolchain for whatever target is supported by gcc or clang – old_timer Nov 29 '21 at 19:29
  • I suspect the actual answer you're after is due to a misunderstanding. Unless you're cross-compiling, the native code generated for an M1 uses the 64-bit ARM instruction set (ARMv8.x / AArch64). – Brett Hale Nov 29 '21 at 21:08

1 Answers1

0

I have solution, you can use brew install x86_64-elf-binutils, then you will have a set of tools which are same with what you normally used in x86 platform linux such as x86_64-elf-gcc, and x86_64-elf-objdump is one of them. Then you can easily use it as what you use objdump in x86 linux enviroment.

  • Doesn't MacOS (or at least LLVM) already come with the ability to disassemble machine code for various ISAs? Like `llvm-objdump` or `otool` should just work on any binary. (e.g. on my x86-64 Linux desktop, `llvm-objdump -d` can disassemble ARM / MIPS / AArch64 / etc. object files.) For Intel-syntax disassembly of x86 code instead of AT&T, `--x86-asm-syntax=intel`. But sure, GNU Binutils could work, too. – Peter Cordes Mar 18 '22 at 15:11