[英]Generate assembler code from C file in linux
我想知道如何使用Unix从C程序生成汇编代码。 我试过gcc: gcc -c file.c
我也首先使用cpp
然后尝试as
但我收到错误。
我正在尝试从3个不同的程序构建汇编程序
prog1.c prog2.c prog.h
做gcc -S prog1.c prog2.c prog.h
是否正确? 似乎不正确。 我不知道是否必须从它们中生成汇编程序然后将它们链接起来
谢谢
根据手册:
`-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.
所以试试gcc -S file.c
来自man gcc
:
-S Stop after the stage of compilation proper; do not
assemble. The output is an assembler code file for
each non-assembler input file specified.
By default, GCC makes the assembler file name for a
source file by replacing the suffix `.c', `.i',
etc., with `.s'. Use -o to select another name.
GCC ignores any input files that don't require com-
pilation.
如果你正在使用gcc(看起来像)它是gcc -S。
如果需要,请不要忘记使用-I指定包含路径。
gcc -I ../my_includes -S my_file.c
并且您将使用Assembler指令获取my_file.s。
objdump -d也很好用,并且会给你整个二进制文件(exe或共享库)的汇编列表。
这比使用编译器生成的asm要清楚得多,因为对同一源文件中的函数的调用可能会显示尚未解析到它们的最终位置。
使用-g构建代码,您还可以将-line和/或--source添加到objdump标志中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.