gcc的窗户上产生的垃圾?窗户VS Linux的 [英] gcc on windows generating garbage? windows vs linux

查看:201
本文介绍了gcc的窗户上产生的垃圾?窗户VS Linux的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出为什么窗口有比Linux同一节目这么多的指令。
所以我只是用 int类型的= 0xbeef; 的printf(测试\\ n); C和编译Linux和Windows。当我调试,拆卸主框架,我得到这个:
在Linux上:

I'm trying to find out why in windows has so much more instructions for the same program than linux. So I just used int a=0xbeef; and printf("test\n"); in C and compiled in Linux and Windows. When I debug and disassembly the main frame I got this: On linux:

0x080483e4 <+0>:     push   %ebp
0x080483e5 <+1>:     mov    %esp,%ebp
0x080483e7 <+3>:     and    $0xfffffff0,%esp
0x080483ea <+6>:     sub    $0x20,%esp
0x080483ed <+9>:     movl   $0xbeef,0x1c(%esp)
0x080483f5 <+17>:    movl   $0x80484d0,(%esp)
0x080483fc <+24>:    call   0x8048318 <puts@plt>
0x08048401 <+29>:    leave  
0x08048402 <+30>:    ret 

好吧这很好。我看到MOVL为0x1c ESP的偏移把价值在那里。

Ok that's nice. I see the movl 0x1c offset of esp to put the value there.

但在Windows我得到这个:

But in windows I got this:

0x401290 <main>:        push   %ebp
0x401291 <main+1>:      mov    %esp,%ebp
0x401293 <main+3>:      sub    $0x18,%esp
0x401296 <main+6>:      and    $0xfffffff0,%esp
0x401299 <main+9>:      mov    $0x0,%eax
0x40129e <main+14>:     add    $0xf,%eax
0x4012a1 <main+17>:     add    $0xf,%eax
0x4012a4 <main+20>:     shr    $0x4,%eax
0x4012a7 <main+23>:     shl    $0x4,%eax
0x4012aa <main+26>:     mov    %eax,0xfffffff8(%ebp)
0x4012ad <main+29>:     mov    0xfffffff8(%ebp),%eax
0x4012b0 <main+32>:     call   0x401720 <_alloca>
0x4012b5 <main+37>:     call   0x4013c0 <__main>
0x4012ba <main+42>:     movl   $0xbeef,0xfffffffc(%ebp)
0x4012c1 <main+49>:     movl   $0x403000,(%esp,1)
0x4012c8 <main+56>:     call   0x401810 <printf>
0x4012cd <main+61>:     mov    $0x0,%eax
0x4012d2 <main+66>:     leave
0x4012d3 <main+67>:     ret

首先,我不知道为什么在Windows编译器(MinGW的)产生大量code。为2x比Linux更多...这让我思考。而另一件事:从主+ 9〜+主我37无法看到,code点

First of all, I don't know why the windows compiler (mingw) generate so much code. Is 2x more than Linux... this makes me thinking. And another thing: from main+9 to main+37 I can't see the point of that code.

如果有人回答这个我要感谢,我只是好奇:)

I would thank if someone answer to this, I'm just curious :)

编辑:
在Linux上-O3说法我得到了相同的和Windows类似魔术happends:

edit: With -O3 argument on linux I got the same and in windows something like magic happends:

0x401290 <main>:        push   %ebp
0x401291 <main+1>:      mov    $0x10,%eax
0x401296 <main+6>:      mov    %esp,%ebp
0x401298 <main+8>:      sub    $0x8,%esp
0x40129b <main+11>:     and    $0xfffffff0,%esp
0x40129e <main+14>:     call   0x401700 <_alloca>
0x4012a3 <main+19>:     call   0x4013a0 <__main>
0x4012a8 <main+24>:     movl   $0x403000,(%esp,1)
0x4012af <main+31>:     call   0x4017f0 <puts>
0x4012b4 <main+36>:     leave
0x4012b5 <main+37>:     xor    %eax,%eax
0x4012b7 <main+39>:     ret

离开的话,那么异RET。 OK:D调用_alloca并调用__main仍然存在。我不知道什么是 0x401291&lt;主+ 1计算值:MOV $ 0×10,%eax中在这里做什么:D

推荐答案

您好像老3.x系列被编译 GCC ,你最好升级。较新的版本不调用的alloca 。我怀疑的alloca 的特定版本可能会使用寄存器约定,以便在 MOV为0x10,%EAX 可能是设置参数该呼叫。

You seem to be compiling with old 3.x series gcc, you'd better upgrade. Newer versions don't invoke alloca. I suspect the particular version of alloca might use register convention so the mov 0x10,%eax is probably setting up the argument for that call.

__主 crtbegin.o 定义的启动函数执行全局构造并注册使用功能 atexit对将运行全局销毁。

__main is a startup function defined in crtbegin.o that executes global constructors and registers a function using atexit that will run the global destructors.

另外请注意,得到特殊待遇,如堆栈对齐code和上述的初始化。这可能是一个好主意,而不是比较纯的功能,如果你是在code生成问题只是感兴趣。

Also note that main gets special treatment, like the stack alignment code and the above-mentioned initialization. It may be a good idea to instead compare a "plain" function if you are just interested in code generation issues.

这篇关于gcc的窗户上产生的垃圾?窗户VS Linux的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆