This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: i386 prologue
- From: Mark Kettenis <kettenis at gnu dot org>
- To: david at streamline-computing dot com
- Cc: gdb at sources dot redhat dot com
- Date: Fri, 15 Oct 2004 20:50:35 +0200 (CEST)
- Subject: Re: i386 prologue
- References: <1097848160.1773.91.camel@localhost.localdomain>
From: David Lecomber <david@streamline-computing.com>
Content-Type: text/plain
Date: Fri, 15 Oct 2004 14:49:20 +0100
The code there seems very specific to GNU compilers, expecting either an
"enter" - or a pushl %ebp.
Not really; some of the code there is trying to support the System V
compiler. But since I've never seen such a compiler, that code patch
might have suffered some bit rot.
However, the instructions you mention ar really pretty generic. The
`enter' instruction's sole purpose is setting up a stack frame (but
nobody uses it), and `pushl %ebp; movl %esp, %ebp' is the canonical
way to set up a stack frame suggested by the i386 System V psABI.
Well, here's what you get from Intel version
7.1 fortran compiler:
Dump of assembler code for function test:
0x0804afd0 <test+0>: push %ebx
0x0804afd1 <test+1>: mov %esp,%ebx
0x0804afd3 <test+3>: and $0xfffffff0,%esp
0x0804afd6 <test+6>: push %edi
0x0804afd7 <test+7>: push %esi
0x0804afd8 <test+8>: push %ebp
0x0804afd9 <test+9>: sub $0x74,%esp
0x0804afdc <test+12>: movl $0x81d34ac,0x81ad07c
0x0804afe6 <test+22>: movl $0x81d34a0,0x81ad088
0x0804aff0 <test+32>: push $0x81ad06c
0x0804aff5 <test+37>: push $0x4
0x0804aff7 <test+39>: call 0x816ca94 <f_iof>
0x0804affc <test+44>: push $0x81ad098
0x0804b001 <test+49>: push $0x0
0x0804b003 <test+51>: call 0x81698b0 <f_ioc>
0x0804b008 <test+56>: add $0x10,%esp
0x0804b00b <test+59>: test %eax,%eax
That's fairly non-standard indeed. This suggests that on some intel
processors the above performs better than the almost equivalent:
push %ebp
mov %esp, %ebx
and $0xfffffff0, %esp
push %edi
push %esi
push %ebx
I've never seen GCC generate such code.
and even:
0x080b71c8 <kpl_minput+0>: push %ebp
0x080b71c9 <kpl_minput+1>: push %ebx
0x080b71ca <kpl_minput+2>: sub $0x34,%esp
0x080b71cd <kpl_minput+5>: mov 0x40(%esp),%ebx
0x080b71d1 <kpl_minput+9>: mov (%ebx),%edx
0x080b71d3 <kpl_minput+11>: movl $0xffffffff,0x81e4588
0x080b71dd <kpl_minput+21>: test %edx,%edx
0x080b71df <kpl_minput+23>: jle 0x80b7d51 <kpl_minput+2953>
0x080b71e5 <kpl_minput+29>: mov 0x84711b0,%eax
0x080b71ea <kpl_minput+34>: movl $0xd52,0x81e458c
0x080b71f4 <kpl_minput+44>: movl $0xffffffff,0x81e4590
0x080b71fe <kpl_minput+54>: mov 0xfffffffc(%eax,%edx,4),%eax
0x080b7202 <kpl_minput+58>: cmp $0xfffffffe,%eax
0x080b7205 <kpl_minput+61>: je 0x80b7d2f <kpl_minput+2919>
Ah, a frameless leaf-function. I think GCC nowadays generates these
too.
This seriously upsets things.. the stack becomes absolutely useless!!
If there is no other way to unwind the stack, yes.
Is there some alternative -- does libunwind offer a solution? Or is the
prologue stuff the Right Thing To Do [TM]?
Last time I looked libunwind doesn't even try to unwind frameless
functions. The solution is to get the compiler to generate unwind
information. GCC can generate DWARF2 Call Frame Info, which GDB can
use. I don't know if ICC can do that too.
Mark