0

how can i see the assembly of standard c library functions in an elf? for example, i have a binary that i have the source code of this binary and i know that printf is called in main function. i want to see the assembly of printf function in this elf. please notice that i want to see the assembly in elf itself. i search a lot but i don't find anything

taranom
  • 153
  • 2
  • 12

1 Answers1

4

You can compile with

~$ gcc -static prog.c

while prog.c uses the functions you the assembly of. That will statically link the libraries used to the binary.

Then you can just:

~$ objdump --disassemble a.out

EDIT

You can even take a simpler way: just objdump the libc library:

~$ objdump --disassemble /usr/lib/libc.so.6 // or whatever the path of libc is
YoavKlein
  • 2,005
  • 9
  • 38
  • thank you. if i don't do statically linking to libraries can't i? i want to know is there the code of these functions (printf and scanf and ... ) in a binary or not? – taranom Dec 30 '20 at 06:07
  • I didn't quite understand. If you want the assembly of it, you can `objdump` the `libc.so.6` itself, as I added in the EDIT. If you want the source code, you can just look for it in the internt, it's open source. – YoavKlein Dec 30 '20 at 14:06
  • `ldd a.out` can help find the path to `/lib/libc.so.6` if you're not sure what it is. Also, highly recommend other objdump options, like `objdump -drwC` to show symbol relocations, and not line-wrap. C++ demangle won't be relevant for libc, but `-drwC` is just a recipe my fingers remember. For x86, `-Mintel` is also nice if you don't like AT&T syntax. Anything in [How to disassemble a binary executable in Linux to get the assembly code?](https://stackoverflow.com/q/5125896) applies – Peter Cordes Apr 21 '22 at 12:49