Re: gcc forgets to decrease esp after function call

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Here is gdb session dump.
0xb2e13570 is start of called function
0xb2e135a5 is the end.

You can see "ret $0x4" at the end. But the caller
doesn't fixups it.

BTW. The called function
also calls function returning object via shadow parameter.
And we see correct "sub $0x4,%esp" in 0xb2e135a1.

Best regards
Vladimir Simonov

------------------
0xb2e13570 <+0>:        mov 0x8(%esp),%eax
0xb2e13574 <+4>:        mov (%eax),%ecx
0xb2e13576 <+6>:        add 0xffffffe4(%ecx),%eax
0xb2e13579 <+9>:        mov %eax,0x8(%esp)
0xb2e1357d <+13>:       jmp 0xb2e13580 <>
0xb2e1357f <+15>:       nop

0xb2e13580 <+0>:        push   %ebp
0xb2e13581 <+1>:        mov    %esp,%ebp
0xb2e13583 <+3>:        push   %esi
0xb2e13584 <+4>:        sub    $0x14,%esp
0xb2e13587 <+7>:        mov    0xc(%ebp),%eax
0xb2e1358a <+10>:       mov    0x8(%ebp),%esi
0xb2e1358d <+13>:       mov    0x4(%eax),%eax
0xb2e13590 <+16>:       mov    (%eax),%edx
0xb2e13592 <+18>:       mov    %eax,0x4(%esp)
0xb2e13596 <+22>:       mov    %esi,(%esp)
0xb2e13599 <+25>:       call   *0xc(%edx)
0xb2e1359c <+28>:       mov    %esi,%eax
0xb2e1359e <+30>:       mov    0xfffffffc(%ebp),%esi
0xb2e135a1 <+33>:       sub    $0x4,%esp
0xb2e135a4 <+36>:       leave
0xb2e135a5 <+37>:       ret    $0x4


Andrew Haley wrote:
Vladimir Simonov writes:

 > Compiling some complex templated & inlined C++ code by gcc
 > 4.1.1/4.1.2 I've met a problem with -O2 optimization. Objdump'ed
 > text is below.
> > In line 30 the code calls method which returns object via shadow
 > pointer(in %esp). Calling function has "ret 4" at the end as it
 > should be.  But the problem code does not have "sub 0x4,%esp" to
 > fix esp after the call.
> > Obviously, codegenerator knows about calling function prototype(it
 > creates shadow parameter).  But by some reason it does not emit
 > "sub 0x4,%esp" and uses esp in line 41 as if esp's value is not
 > changed by called in line 30 function.  If I "sub 0x4,%esp" in line
 > 33 in gdb all is working fine.
> > Any hints about workarround the problem will be very appritiated.

I don't understand what you're complaining about.  The stack pointer
is not adjusted anywhere in the code you posted, except for the
 >     6:   83 ec 3c                sub    $0x3c,%esp

at the beginning.  The generated code uses offsets from the stack
pointer, which doesn't change.  Where is esp's value changed by the
"called in line 30 function"?  Please show it.

Andrew.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux