使用GCC输出带C源代码的汇编文件有两种方式,
第一种方式
gcc –c –S source.c
objdump –S source.o
首先生成带生成目标文件,然后使用objdump命令,显示源代码与汇编代码的混合文件
这种方式生成的信息较少,但是主要的信息是足够了
第二种方式
使用GNU C Assembler的列表功能来完成,例如:
gcc –c –g –Wa,-adlhn source.c > source.s
这个命令的说明如下:
-Wa,option :把选项option传递给汇编器.如果option含有逗号,就在逗号处分割成多个选项.也就是Gas,至于Gas的命令参数,可以查看相应的文档,其中-a[cdghlns]参数的作用是打开列表功能。
这种方式可以显示足够的信息,但是命令稍微复杂,参数比较多,不太容易选择。
Gas的命令行参数概要信息摘录如下:
1:a: -a[cdghlns] enable listings2:alternate: --alternate enable alternate macro syntax3:D: -D for compatibility4:f: -f to work faster5:I: -I for .include search path6:K: -K for difference tables7:L: -L to retain local symbols8:listing: --listing-XXX to configure listing output9:M: -M or --mri to assemble in MRI compatibility mode10:MD: --MD for dependency tracking11:o: -o to name the object file12:R: -R to join data and text sections13:statistics: --statistics to see statistics about assembly14:traditional-format: --traditional-format for compatible output15:v: -v to announce version16:W: -W, --no-warn, --warn, --fatal-warnings to control warnings17:Z: -Z to make object file even after errors