atgreen/libffi — Issue #9: Too small FFI_TRAMPOLINE_SIZE with x64 gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Author: WolfgangSt
Created: 2012-02-22 23:50:19+00:00
State: open

The default gcc shipped with x64 Ubuntu (other distributions are affected likely as well)
only defines the following x64 related symbols processor symbols by itself:

#define __x86_64 1
#define __amd64 1
#define __x86_64 1
#define __x86_64__ 1

This leads to defining the trampoline size to 10 bytes as per
https://github.com/atgreen/libffi/blob/master/src/x86/ffitarget.h#L115
Due to neither X86_64 nor X86_DARWIN being defined.

Initializing the closure ion the x64 system writes beyond the allocated limit:
https://github.com/atgreen/libffi/blob/master/src/x86/ffi64.c#L520

This goes unnoticed by valgrind and did not manifest as bugs for us during normal application runtime.
However it gives catastrophic failures as soon one tries to free the initialized closure by signaling SIGABRT.

Current possible workarounds are

1.) overcommit during ffi_closure_alloc()
2.) manually define X86-64 as preprocessor symbol
3.) leak all closures and "pray"