How do I get a full assembly code from c file?

前端 未结 2 1544
一向
一向 2021-01-24 13:08

I\'m currently trying to figure out the way to produce equivalent assembly code from corresponding c source file. (pardon me for not being able to speak English fluently, I\'m n

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-24 13:50

    _exp is the standard math library function double exp(double); apparently you're on a platform that prepends a leading underscore to C symbol names.

    Given a .s that calls some library functions, build it the same way you would a .c file that calls library functions:

    gcc foo.S -o foo  -lm
    

    You'll get a dynamic executable by default.


    But if you really want all the code in one file with no external dependencies, you can link your .c into a static executable and disassemble that.

    gcc -O3 -march=native foo.c -o foo -static -lm
    objdump -drwC -Mintel foo > foo.s
    

    There's no guarantee that the _exp implementation in libm.a (static library) is identical to the one you'd get in libm.so or libm.dll or whatever, because it's a different file. This is especially true for a function like memcpy where dynamic-linker tricks are often used to select an optimal version (for your CPU) at run-time.

提交回复
热议问题