如何做到这一点呢?
如果我想分析某些东西是如何编译的,我该如何获得发出的程序集代码?
如何做到这一点呢?
如果我想分析某些东西是如何编译的,我该如何获得发出的程序集代码?
当前回答
如果您正在寻找LLVM程序集:
llvm-gcc -emit-llvm -S hello.c
其他回答
使用-S选项:
gcc -S program.c
使用-S开关:
g++ -S main.cpp
或者也可以用gcc:
gcc -S main.c
还有这个。
从FAQ如何让GCC生成汇编代码:
gcc -c -g -Wa,-a,-ad[其他gcc选项]foo.c > foo.lst
作为philrephly的答案的替代方案。
或者像大家说的,用-S。
以下命令行来自Christian Garbin的博客:
g++ -g -O -Wa,-aslh horton_ex2_05.cpp >list.txt
我从Windows XP上的DOS窗口运行g++,针对的是一个包含隐式强制转换的例程
cd C:\gpp_code
g++ -g -O -Wa,-aslh horton_ex2_05.cpp > list.txt
输出:
horton_ex2_05.cpp: In function `int main()':
horton_ex2_05.cpp:92: warning: assignment to `int' from `double'
输出是组装生成的代码,其中穿插着原始的c++代码(c++代码在生成的汇编语言流中显示为注释)。
16:horton_ex2_05.cpp **** using std::setw;
17:horton_ex2_05.cpp ****
18:horton_ex2_05.cpp **** void disp_Time_Line (void);
19:horton_ex2_05.cpp ****
20:horton_ex2_05.cpp **** int main(void)
21:horton_ex2_05.cpp **** {
164 %ebp
165 subl $128,%esp
?GAS LISTING C:\DOCUME~1\CRAIGM~1\LOCALS~1\Temp\ccx52rCc.s
166 0128 55 call ___main
167 0129 89E5 .stabn 68,0,21,LM2-_main
168 012b 81EC8000 LM2:
168 0000
169 0131 E8000000 LBB2:
169 00
170 .stabn 68,0,25,LM3-_main
171 LM3:
172 movl $0,-16(%ebp)
如果您正在寻找LLVM程序集:
llvm-gcc -emit-llvm -S hello.c