There seems to be a regression in Xcode 11 beta, when AVX is enabled. The C library doesn't make the same assertions regarding alignment as the compiler.
Here is a C-reduced test case:
#include #include #include #include #include typedef struct { char d[16]; void *e; struct { char b[5536]; } f; } i; void g(void) { struct addrinfo hints, *k; memset(&hints, 0, sizeof hints); getaddrinfo(NULL, NULL, &hints, &k); } int main(void) { puts("Hello world"); fflush(stdout); close(open("/dev/null", O_RDONLY)); i context; context.e = open; printf("%p\n", context.d); g(); return 0; }
When compiled with AVX optimizations (e.g. -mavx or more commonly -march=native), this crashes even before `main()` is executed:
cc -mavx -O2 a.c && ./a.out
lldb ./a.out
run
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
frame #0: 0x00007fff65e73316 libdyld.dylib`stack_not_16_byte_aligned_error libdyld.dylib`stack_not_16_byte_aligned_error:
-> 0x7fff65e73316 <+0>: movdqa %xmm0, (%rsp)
Without AVX optimizations, or with Xcode 10, this doesn't happen.
This bug affects real-world applications such as libsodium and dsvpn.
A workaround is to use `-ffreestanding`.