Created attachment 6575 [details] patch __m128i_strloadu_tolower function in sysdeps/x86_64/multiarch/strcasestr-nonascii.c does not use _mm_loadu_si128() to return the variable. So, if the caller has unaligned stack the program will crash. We had crashes with openssl and glibc when we use Wine and the solution was to use _mm_loadu_si128(). Here are the bug reports: https://bugs.archlinux.org/task/23277 https://bugs.archlinux.org/task/31020 I attached the patch. Thanks.
Created attachment 6576 [details] patch v2 I decided to run Coccinelle to see if the same bug exists in other places and I found it in one more function which is a testcase. I attached a 2nd version of the patch.
The function returns an object of type __m128i - which is be properly aligned if the stack is properly aligned. Looking at the arch reports, this looks related to this gcc bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40838 The question is should glibc work around those problems and be on the safe side - or does this need fixing in other libraries and programs? I'm adding HJ and Jakub for discusion since both have been involved in the GCC bug.
Any other functions that they return an object of type __m128i they use _mm_loadu_si128 function. e.g. the functions that are in sysdeps/x86_64/multiarch/strstr.c
grep shows: sysdeps/x86_64/multiarch/strcspn-c.c: mask = _mm_loadu_si128 ((__m128i *) a); sysdeps/x86_64/multiarch/varshift.h: _mm_loadu_si128 ((__m128i *) (___m128i_shift_right sysdeps/x86_64/multiarch/strspn-c.c: mask = _mm_loadu_si128 ((__m128i *) a); sysdeps/x86_64/multiarch/strstr.c: return _mm_loadu_si128 ((__m128i *) p); And looking at the files, it's (except varshift.h) the input parameter that is returned. In these cases the loadu is always needed.
Indeed.. I also tried __attribute__((__aligned__(16))) and still crashes. Only with _mm_loadu_si128 it did not.
Whatever function in the backtrace misaligned the stack should be fixed. So, if it is openssl, the fix needs to be done there, if it is some glibc routine, you need to state which one. If you use -mpreferred-stack-boundary=2 or similar on some code, you can do that only if you don't call any code built without that option from such code.
Waiting for submitter to provide the name of the glibc function which misaligns the stack. I agree with Jakub, making each function robust in the face of a misaligned stack is not correct. The program must conform the ABI and keep the stack aligned as required at function call time. If there are no glibc functions which misalign the stack then this issue should be closed as RESOLVED WONTFIX.
I did some deeper debugging and it's not glibc's fault. You can close it if you want.
Thanks! Marking RESOLVED WONTFIX.
Not a bug.