Unit test for FFI calls to and from variadic C functions.
This test file is extremely important for verifying ABI-compliance, as the rules for passing variadic arguments differ significantly between platforms, even on the same architecture.
The test covers:
- Forward Variadic Call (Primitives): A call is made to a
printf-like function with a mix of fixed and variadic arguments (*char, int, double). This tests the core variadic calling mechanism.
- Forward Variadic Call (Aggregates): A call is made passing a struct as a variadic argument. This is highly platform-dependent:
- On System V, the struct is passed on the stack.
- On Windows x64, a pointer to the struct is passed in a GPR.
- On AArch64, the struct is passed on the stack.
- Reverse Variadic Callback: A reverse trampoline is created for a variadic function. The test verifies that when the JIT-compiled function pointer is called with variadic arguments, the C handler receives them correctly via
va_list/va_arg.
- Platform-Specific ABI Deviations: Includes dedicated subtests for known tricky variadic cases, such as passing floats/doubles on Windows x64 (which requires them to be passed in both GPRs and XMM registers) and passing structs on macOS on ARM (which has its own unique stack-passing rules).