https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87702

--- Comment #9 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Mihail Zenkov from comment #7)
> http://www.knk.uwebweb.com/glibc-segfault-2.tar.xz
> 
> I put full command line into exit.cmd and vfscanf.cmd.

Hm, it looks that for the first case __GI_exit gets called with misaligned
stack:

Breakpoint 2, __GI_exit (status=1) at exit.c:138
138     exit.c: No such file or directory.
(gdb) disass
Dump of assembler code for function __GI_exit:
=> 0xf7e241c0 <+0>:     call   0xf7f29629 <__x86.get_pc_thunk.ax>
   0xf7e241c5 <+5>:     add    $0x1a5e3b,%eax
   0xf7e241ca <+10>:    sub    $0xc,%esp
   0xf7e241cd <+13>:    lea    0x3fc(%eax),%eax
   0xf7e241d3 <+19>:    push   $0x1
   0xf7e241d5 <+21>:    push   $0x1
   0xf7e241d7 <+23>:    push   %eax
   0xf7e241d8 <+24>:    pushl  0x1c(%esp)
   0xf7e241dc <+28>:    call   0xf7e23fa0 <__run_exit_handlers>
End of assembler dump.
(gdb) i r $sp
sp             0xffffc424       0xffffc424
(gdb) up
#1  0x0804cdbf in ?? ()
(gdb) i r $sp
sp             0xffffc428       0xffffc428

Following this, __GI_exit calls __run_exit_handlers with misaligned stack:

Breakpoint 1, __run_exit_handlers (status=1, listp=0xf7fca3fc <__exit_funcs>,
run_list_atexit=true, run_dtors=true)
    at exit.c:40
40      in exit.c
(gdb) disass
Dump of assembler code for function __run_exit_handlers:
=> 0xf7e23fa0 <+0>:     push   %ebp
   0xf7e23fa1 <+1>:     push   %edi
   0xf7e23fa2 <+2>:     call   0xf7f29631 <__x86.get_pc_thunk.bp>
   0xf7e23fa7 <+7>:     add    $0x1a6059,%ebp
   0xf7e23fad <+13>:    push   %esi
   0xf7e23fae <+14>:    push   %ebx
   0xf7e23faf <+15>:    sub    $0x2c,%esp
   ...

(gdb) i r $sp
sp             0xffffc404       0xffffc404
(gdb) up
#1  0xf7e241e1 in __GI_exit (status=1) at exit.c:139
139     in exit.c
(gdb) i r $sp
sp             0xffffc408       0xffffc408

This is wrong, gcc assumes 16-byte aligned stack. It looks that busybox is at
fault here, it shouldn't call __GI_exit with misaligned stack.

Reply via email to