https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77330
Bug ID: 77330 Summary: __float128 segfaults on 32-bit x86 due to 8-byte malloc alignment Product: gcc Version: 6.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: mikulas at artax dot karlin.mff.cuni.cz Target Milestone: --- Host: x86_64-pc-linux-gnu Target: x86_64-pc-linux-gnu Build: x86_64-pc-linux-gnu On 32-bit x86 system, glibc malloc aligns allocated memory to 8 bytes. The type __float128 has 16-byte alignment (__alignof__(__float128) return 16), however this alignment can't be guaranteed because of 8-byte malloc alignment. GCC uses aligned SSE instructions when accessing the __float128 type, these instructions cause a crash when accessing heap memory that is aligned only to 8 bytes. This program will crash if compiled with "gcc -m32 -march=athlon64" (with or without optimization). #include <stdio.h> #include <stdlib.h> struct s { __float128 f1; }; int main(void) { struct s *p = malloc(sizeof(struct s)); printf("%p\n", p); p->f1 = 1.234; return 0; } The misgenerated code is this: 0804842b <main>: 804842b: 55 push %ebp 804842c: 89 e5 mov %esp,%ebp 804842e: 83 e4 f0 and $0xfffffff0,%esp 8048431: 83 ec 20 sub $0x20,%esp 8048434: c7 04 24 10 00 00 00 movl $0x10,(%esp) 804843b: e8 a0 fe ff ff call 80482e0 <malloc@plt> 8048440: 89 44 24 1c mov %eax,0x1c(%esp) 8048444: 8b 44 24 1c mov 0x1c(%esp),%eax 8048448: 89 44 24 04 mov %eax,0x4(%esp) 804844c: c7 04 24 10 85 04 08 movl $0x8048510,(%esp) 8048453: e8 78 fe ff ff call 80482d0 <printf@plt> 8048458: 8b 44 24 1c mov 0x1c(%esp),%eax 804845c: 66 0f 6f 05 20 85 04 movdqa 0x8048520,%xmm0 8048463: 08 8048464: 0f 29 00 movaps %xmm0,(%eax) 8048467: b8 00 00 00 00 mov $0x0,%eax 804846c: c9 leave 804846d: c3 ret