Discussion:
Bug#948396: New glibc broke existing app due to historic stack alignment
(too old to reply)
Petr Vandrovec
2020-01-08 04:50:02 UTC
Permalink
Package: libc6-i386
Version: 2.29-8

Since updating my system today our build system binaries started crashing.

Upon further investigation problem is that __mktime_internal code in
libc6-i386 now started using 'movaps' instruction without aligning stack
on 16 byte boundary.

As far as I can tell, while x86-64 ABI requires stack to be aligned on
entry to the functions, x86 ABI does not have any such requirement, and
so glibc should align stack itself if it wants to use XMM instructions that
require aligned values.

It seems that libc6:i386 is compiled correctly, so I worked around by installing
that instead of libc6-i386:amd64.


[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `/build/toolchain/lin32/p7zip-9.20/bin/7za x -y -tzip /bhavesh/home/petr/drboss/'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0xf7dbe0e2 in __mktime_internal (tp=0xffb60f8c, convert=0xf7dbd990 <__GI___gmtime_r>, offset=0xf7ee6350 <gmtime_offset>) at mktime.c:387
387 mktime.c: No such file or directory.
(gdb) bt
#0 0xf7dbe0e2 in __mktime_internal (tp=0xffb60f8c, convert=0xf7dbd990 <__GI___gmtime_r>, offset=0xf7ee6350 <gmtime_offset>) at mktime.c:387
#1 0xf7dc114d in timegm (tmp=0xffb60f8c) at timegm.c:33
#2 0x0804aa2b in ?? ()
#3 0x080704fc in ?? ()
#4 0x080f6859 in ?? ()
#5 0x0807fdf8 in ?? ()
#6 0x080804de in ?? ()
#7 0x080fa53a in ?? ()
#8 0x0808d0f9 in ?? ()
#9 0x0808f118 in ?? ()
#10 0x08054101 in ?? ()
#11 0x08057edf in ?? ()
#12 0xf7d2b811 in __libc_start_main (main=0x8057eb0, argc=6, argv=0xffb61be4, init=0x804a190, fini=0x8141ab0, rtld_fini=0xf7f41300 <_dl_fini>, stack_end=0xffb61bdc) at ../csu/libc-start.c:308
#13 0x0804a871 in ?? ()
(gdb) x /10i $eip-19
0xf7dbe0cf <__mktime_internal+591>: psubq %xmm1,%xmm0
0xf7dbe0d3 <__mktime_internal+595>: movd %xmm0,0x78(%esp)
0xf7dbe0d9 <__mktime_internal+601>: movq %xmm0,0x90(%esp)
=> 0xf7dbe0e2 <__mktime_internal+610>: movaps %xmm0,(%esp)
0xf7dbe0e6 <__mktime_internal+614>: movaps %xmm0,0x10(%esp)
0xf7dbe0eb <__mktime_internal+619>: mov 0x40(%esp),%eax
0xf7dbe0ef <__mktime_internal+623>: mov %edi,%ecx
0xf7dbe0f1 <__mktime_internal+625>: mov %esi,%edx
0xf7dbe0f3 <__mktime_internal+627>: call 0xf7dbdc10 <ranged_convert>
0xf7dbe0f8 <__mktime_internal+632>: test %eax,%eax
(gdb) print /x $esp
$1 = 0xffb60e24
Florian Weimer
2020-01-08 05:40:01 UTC
Permalink
Post by Petr Vandrovec
As far as I can tell, while x86-64 ABI requires stack to be aligned
on entry to the functions, x86 ABI does not have any such
requirement, and so glibc should align stack itself if it wants to
use XMM instructions that require aligned values.
The i386 ABI was changed after its initial release to require
additional stack alignment.

If you want to build glibc for i386 with SSE2 enabled (for example,
with -march=x86-64), you need to build it with -mrealignstack as well.
I'm not aware of any remaining issues with this combination.
Petr Vandrovec
2020-01-08 08:30:01 UTC
Permalink
Post by Florian Weimer
Post by Petr Vandrovec
As far as I can tell, while x86-64 ABI requires stack to be aligned
on entry to the functions, x86 ABI does not have any such
requirement, and so glibc should align stack itself if it wants to
use XMM instructions that require aligned values.
The i386 ABI was changed after its initial release to require
additional stack alignment.
That's a problem.
Post by Florian Weimer
If you want to build glibc for i386 with SSE2 enabled (for example,
with -march=x86-64), you need to build it with -mrealignstack as well.
I'm not aware of any remaining issues with this combination.
I do not want to rebuild anything, I just want things to work :-(
libc6:i386 is built without SSE2 support, and takes precedence over
libc6-i386, so that is how I've "solved" problem.

Should be libc6-i386 named (after obsolete/virtual) libc6-i686 if it
requires SSE2 and new stack alignment?

Thanks,
Petr
Florian Weimer
2020-01-14 09:20:01 UTC
Permalink
Post by Petr Vandrovec
Post by Florian Weimer
Post by Petr Vandrovec
As far as I can tell, while x86-64 ABI requires stack to be aligned
on entry to the functions, x86 ABI does not have any such
requirement, and so glibc should align stack itself if it wants to
use XMM instructions that require aligned values.
The i386 ABI was changed after its initial release to require
additional stack alignment.
That's a problem.
Post by Florian Weimer
If you want to build glibc for i386 with SSE2 enabled (for example,
with -march=x86-64), you need to build it with -mrealignstack as well.
I'm not aware of any remaining issues with this combination.
I do not want to rebuild anything, I just want things to work :-(
This comment was directed at the glibc maintainers, sorry. (The
option is actually called -mstackrealign.)
Post by Petr Vandrovec
libc6:i386 is built without SSE2 support, and takes precedence over
libc6-i386, so that is how I've "solved" problem.
Should be libc6-i386 named (after obsolete/virtual) libc6-i686 if it
requires SSE2 and new stack alignment?
I think the proper fix would be to build glibc with -mstackrealign.
Loading...