FS#23277 - [openssl] needs to be compiled stack-aligned to eliminate errors
Attached to Project:
Community Packages
Opened by Devin Cofer (Ranguvar) - Tuesday, 15 March 2011, 01:58 GMT
Last edited by Sven-Hendrik Haase (Svenstaro) - Friday, 17 August 2012, 04:33 GMT
Opened by Devin Cofer (Ranguvar) - Tuesday, 15 March 2011, 01:58 GMT
Last edited by Sven-Hendrik Haase (Svenstaro) - Friday, 17 August 2012, 04:33 GMT
|
Details
There is a bug in GCC right now where it "assume(s) the
stack is aligned" --
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40838
It is being worked on, but it causes issues in some packages currently. OpenSSL is one of these. Several programs in Wine error out in OpenSSL functions. The maintainer of Wine has said : "Your libcrypto is built with sse2 support but doesn't align the stack. That's a variant of That bug is http://bugs.winehq.org/show_bug.cgi?id=22316 After reading Dan Kegel's suggestion of compiling with -mstackrealign (only available with GCC 4.5.0+, this would require a makedepends on that version), I tried compiling openssl and lib32-openssl with -mstackrealign added to $CC and $CXX. The result is good, no more errors. I suggest that the maintainers of openssl and lib32-openssl do add -mstackrealign to $CC and $CXX (and therefore makedepends on gcc>=4.5.0). A short forum thread re. these issues: https://bbs.archlinux.org/viewtopic.php?id=114531 |
This task depends upon
Closed by Sven-Hendrik Haase (Svenstaro)
Friday, 17 August 2012, 04:33 GMT
Reason for closing: Fixed
Additional comments about closing: See comments
Friday, 17 August 2012, 04:33 GMT
Reason for closing: Fixed
Additional comments about closing: See comments
"I am in the process of updating i386 psABI to specify 16byte stack alignment." from January 18th?
I remain hopeful :p
Wine now keeps the stack aligned, so 16byte alignment libs wine calls into should be protected from unaligned calls
Can this be applied to openssl and lib32-openssl or are there issues present with the proposed solution?
Should this be closed?
Of course, Google just killed Picasa for linux, so this will be shortly moot:
http://googleblog.blogspot.com/2012/04/spring-cleaning-in-spring.html
I'm NOT using the Picasa wine package Google provided. Instead I just installed Picasa for Windows under wine. Thanks!
I had problems running different windows applications which used ssl through wine, I can't remember which apps they were and I'm not on the same pc right now.
I was able to reproduce this with picasa - the stack trace goes through wininet, so it should have been aligned. It's possible there's something in wine's make scripts that arn't honoring CFLAGS for bits of code.
and
FS#27560will *not* fix this everywhere, i will try to explain why. (if you don't understand please tell me to rephrase it because my english is not good)these are the top lines of the wine crash report:
Unhandled exception: page fault on read access to 0xffffffff in 32-bit code (0xf75534ea).
Register dump:
CS:0023 SS:002b DS:002b ES:002b FS:0063 GS:006b
EIP:f75534ea ESP:0033c8fc EBP:00000001 EFLAGS:00010246( R- -- I Z- -P- )
EAX:7cc822f8 EBX:f75c7ff4 ECX:00000000 EDX:7de7c499
ESI:7eda222c EDI:ffffffd0
Stack dump:
0x0033c8fc: f73e46c0 00000000 f73e46c0 0033cadc
0x0033c90c: 75676572 0072616c ffa71cf2 ffa71cf1
0x0033c91c: ffa71cf1 ffa71cf1 ffa71cf1 ffa71cf1
0x0033c92c: ffa71cf2 00000000 00000000 00000000
0x0033c93c: 00000000 00000000 00000001 00000000
0x0033c94c: 7cccf830 7c000000 00000000 7ccd1bd0
000c: sel=0067 base=00000000 limit=00000000 16-bit --x
Backtrace:
=>0 0xf75534ea __strcasestr_sse42_nonascii+0x5a() in libc.so.6 (0x00000001)
1 0x7de5f386 in libfreetype.so.6 (+0x62385) (0x00000001)
....
....
and here is the instruction that crashed it:
% gdb -q /usr/lib32/libc.so.6
Reading symbols from /usr/lib32/libc.so.6...(no debugging symbols found)...done.
(gdb) x/i __strcasestr_sse42_nonascii+0x5a
0x12f4ea <__strcasestr_sse42_nonascii+90>: vmovdqa 0x10(%esp),%xmm1
(gdb) quit
as you can you see ESP is 0x0033c8fc which is not 16bytes aligned, but all sse instructions need 16bytes alignment
this happens because wine calls a function from a library and that library calls a function from glibc, so the stack can change to a non-16bytes alignment (from the previous function).
so, glibc and openssl must be recompiled with -mstackrealign because they use sse instructions.
you can reproduce the problem with this assembly code:
.text
.globl _start
_start:
nop
andl $~0x10, %esp
subl $4, %esp
vmovdqa 0x10(%esp), %xmm1
movl $1, %eax
movl $0, %ebx
int $0x80
% as --32 a.s -o a.o
% ld -melf_i386 a.o -o a.out
% ./a.out
Segmentation fault
'subl $4, %esp' will break the alignment, if you remove it then it will not segfault.
they forgot to use _mm_loadu_si128 when they return an __m128i data type.
for some reason i cannot reproduce the openssl bug, if i reproduce it i will try to fix it.
but first we must add the flags before the configure and also we must add -m32 flag because configure will exit with an error without it..
i attached a patch for the PKGBUILD..
FS#27560put the CFLAGS in make's environment, which was not correctly applying -mstackrealign to the whole build, like I guessed above!Does this patch still fix the issue for you? It should be slightly more correct (putting them in configure's environment) and not require the -m32 hack
you can add it after make..
So as I near as I can tell from the barely-documented GCC notes on this, while -mstackrealign will re-align the incoming stack, it also needs to be aware that the incoming stack should be assumed to be 4-byte aligned or it will not always behave properly. This patch shouldn't have any significant performance impact above just -mstackrealign, though I don't pretend to understand GCC logic well enough to assert that it is fully solves the issue -- but it does fix a few more apps that were still failing after
FS#27560