How can I view assembly code produced for C functions? [duplicate]

我是研究僧i 提交于 2020-01-01 05:32:29

问题


I need to view the assembly code produced for certain C functions.

What flags should I use when compiling the C code using the g++ compiler?


回答1:


You may add the -S tag to see the assembly code.

Like for a file TEST.c, with gcc, do,

gcc TEST.c -S

clang also outputs the assembly code with a similar -S tag.

After that just look for a file with a .S extension.




回答2:


You can use the command objdump in a binary you have to see the assembler code, in linux




回答3:


With gcc or g++ compiler, you can use the -S flag to see the assembly code generated.

GNU C Compiler Documentation

-S: Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each non-assembler input file specified.

By default, the assembler file name for a source file is made by replacing the suffix .c, .i, etc., with .s.

Input files that don't require compilation are ignored.

Then you have to look for the identifier of your function in the file (if the compiler has not inlined it).



来源:https://stackoverflow.com/questions/16241771/how-can-i-view-assembly-code-produced-for-c-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!