之间&QUOT差异; GCC -x C"和" GCC -x C ++"汇编输出 [英] Difference between "gcc -x c" and "gcc -x c++" assembly output
问题描述
我在main.c文件下面code:
I have the following code in file main.c:
int main() {
int i;
for (i = 0; i < 5; i++) {
}
return 0;
}
当我编译这与 GCC -xc -m32 -S -O0 -o main.s的main.c
(Fedora的16 64位下),我得到这个输出
When I compile this with gcc -x c -m32 -S -O0 -o main.s main.c
(under Fedora 16 64-bit) I get this output:
.file "main.c"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
subl $16, %esp
movl $0, -4(%ebp)
jmp .L2
.L3:
addl $1, -4(%ebp)
.L2:
cmpl $4, -4(%ebp)
jle .L3
movl $0, %eax
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (GNU) 4.6.2 20111027 (Red Hat 4.6.2-1)"
.section .note.GNU-stack,"",@progbits
然而,当我使用的gcc -x C ++ -m32 -S -O0 -o main.s的main.c
我得到的结果相同,除了这些行:
However, when I use gcc -x c++ -m32 -S -O0 -o main.s main.c
I get the same output except for these lines:
.L2:
cmpl $4, -4(%ebp)
setle %al
testb %al, %al
jne .L3
我的问题是:为什么它使用 setle
和 TESTB
而不是 JLE
在C ++中code?是不是更有效?
My question is: why does it use setle
and testb
instead of jle
in C++ code? Is it more effective?
P.S。此外,有没有摆脱这些办法 .cfi _在装配输出*
指令?
P.S. Also, is there a way to get rid of these .cfi_*
directives in an assembly output?
推荐答案
那么,您使用的是不同的编译器,所以它不是真的那么奇怪,你会得到不同的结果。 铛
确实发生编译程序作为C或C ++时给完全相同的结果,如果这是您感兴趣的:
Well, you're using a different compiler, so it's not really that surprising that you get different output. clang
does happen to give exactly the same results when compiling your program as C or C++, if that's of interest to you:
$ cp example.c example.cpp
$ clang -o exampleC example.c
$ clang++ -o exampleC++ example.cpp
$ otool -tV exampleC > C
$ otool -tV exampleC++ > C++
$ diff C C++
1c1
< exampleC:
---
> exampleC++:
$
我从 GCC
和 G ++
我的机器上相同的结果一样,所以看起来它只是一个怪癖的特定编译器的版本。
I get the same results from gcc
and g++
on my machine as well, so it looks like it's just a quirk of your particular compiler version.
这篇关于之间&QUOT差异; GCC -x C&QUOT;和&QUOT; GCC -x C ++&QUOT;汇编输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!