diff --git a/src/core/ffi.c b/src/core/ffi.c index e2c07634..8064cac6 100644 --- a/src/core/ffi.c +++ b/src/core/ffi.c @@ -1225,7 +1225,15 @@ static Janet janet_ffi_sysv64(JanetFFISignature *signature, void *function_point ret_mem = alloca(type_size(signature->ret.type)); regs[0] = (uint64_t) ret_mem; } +/* GCC aligns alloca to the widest allowed vector type (32 bytes for AVX) which can pad + * between the stack pointer and this block, but stack args start at the stack pointer, + * so we must ask for the calling convention's 16 byte alignment */ +/* Both GCC and CLANG define GNUC. */ +#if defined(__GNUC__) + uint64_t *stack = __builtin_alloca_with_align(sizeof(uint64_t) * signature->stack_count, 128); +#else uint64_t *stack = alloca(sizeof(uint64_t) * signature->stack_count); +#endif for (uint32_t i = 0; i < signature->arg_count; i++) { uint64_t *to; int32_t n = i + 2;