https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77587
Bug ID: 77587 Summary: C compiler produces incorrect stack alignment with __attribute((weak)) Product: gcc Version: 5.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: andrew.thomas at cogent dot ca Target Milestone: --- Created attachment 39615 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39615&action=edit Test case for weak attribute stack misalignment I have run into a case where GCC produces a stack aligned to 8 bytes instead of the required 16 bytes when using __attribute__((weak)). I originally mistakenly reported this as a problem with sprintf() here: https://sourceware.org/bugzilla/show_bug.cgi?id=20596 This case produces a call to sprintf() with the stack aligned to 8 bytes, but sprintf() calls the MOVAPS instruction which will crash if the stack is not aligned to 16 bytes. The attached test case consists of two files. The compile command is in the comments at the top of stacktest.c. The crash occurs if __attribute__((weak)) is used in the example, and does not occur without it. Change SPRINTF_CRASH from 1 to 0 in stacktest.c to eliminate the crash. My test system is Ubuntu 16.04 LTS. uname -a: Linux mylinux 4.4.0-22-generic #40-Ubuntu SMP Thu May 12 22:03:46 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux gcc -v: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2) glibc: 2.23