Reputation: 3
I am trying to view the x86 Assembly for a compiled C program in Linux, for which I do not have the source code. Can this be done with GCC, or do I need a different tool? Thanks.
Upvotes: 0
Views: 253
Reputation: 224964
GCC is a compiler. What you're looking for is a disassembler. On linux, you can use objdump(1)
.
An example (some objdump
output snipped for ease of reading):
$ cat example.c
#include <stdio.h>
int main(void)
{
printf("Hello, world!\n");
return 0;
}
$ clang -Wall -Wextra -O2 -o example example.c
$ ./example
Hello, world!
$ objdump -d example | grep -A10 '<main>'
0000000000400500 <main>:
400500: 55 push %rbp
400501: 48 89 e5 mov %rsp,%rbp
400504: bf 0c 06 40 00 mov $0x40060c,%edi
400509: e8 e2 fe ff ff callq 4003f0 <puts@plt>
40050e: 31 c0 xor %eax,%eax
400510: 5d pop %rbp
400511: c3 retq
400512: 90 nop
400513: 90 nop
400514: 90 nop
Upvotes: 1