How can I extract the raw machine code of a function from a .o object file? Built from gnu c++ using g++. File format is 32-bit relocatable LSB ELF, architecture i386. Any thoughts? Thanks in advance
Asked
Active
Viewed 945 times
0
-
[objdump](https://linux.die.net/man/1/objdump) ? – Paul R Jun 01 '18 at 22:19
-
Does that give raw machine code of a specific function? – Jun 01 '18 at 22:22
-
Click on the link to the man page above - there is an option to disassemble, and you can probably find an option to just dump the raw bytes too. Be aware though that since .o files have not been linked there will be placeholders for function/data addresses etc which need to be resolved at link time. – Paul R Jun 01 '18 at 22:32
-
See also: [readelf](https://linux.die.net/man/1/readelf). – Paul R Jun 01 '18 at 22:35
1 Answers
2
objdump -dw mybinary
The above command always works, but objdump provides more human friendly results if you compile with debugging enabled, namely the g++ -g option.

srking
- 4,512
- 1
- 30
- 46
-
I like `objdump -drwC -Mintel`. `-r` gives symbol-relocation info, which is necessary in a `.o` because addresses of external symbols are still all-zero (or actually an offset relative to some symbol), not a real address. `-C` is C++ name demangling. – Peter Cordes Jun 01 '18 at 23:56