Skip to content

feat: variadic function support + go vet clean (v0.5.2)#49

Merged
kolkov merged 11 commits into
mainfrom
feat/variadic-functions
May 25, 2026
Merged

feat: variadic function support + go vet clean (v0.5.2)#49
kolkov merged 11 commits into
mainfrom
feat/variadic-functions

Conversation

@kolkov
Copy link
Copy Markdown
Contributor

@kolkov kolkov commented May 25, 2026

Summary

  • Variadic function supportPrepareVariadicCallInterface(cif, convention, nfixedargs, returnType, argTypes) for C variadic functions (printf, XCreateIC, etc.). Apple ARM64: variadic args forced to stack per Apple ABI. Closes Support for variadic functions on darwin/arm64 (Apple Silicon) #47
  • go vet clean — fixed dl_unix.go unsafe.Pointer warnings (double-indirection per Go #58625), syscall_linux_stub.s return signature mismatch
  • Private doc links removed — cleaned old docs/dev/ references from CHANGELOG
  • cmd/variadic-test — standalone binary for Apple Silicon verification
  • E2E variadic tests with gcc-compiled C functions
  • Docs: CHANGELOG (v0.5.2), README, ARCHITECTURE, ROADMAP updated

Test plan

  • go build ./... — all 6 platforms
  • go vet ./... — 0 warnings (WSL Linux)
  • go fmt ./... — clean
  • go test ./ffi ./types ./internal/... — all pass
  • CGO_ENABLED=1 go test -race — all pass (WSL Linux)
  • Variadic e2e: 3 tests pass (sum, two_fixed, validation)
  • CHANGELOG: [0.5.2] - 2026-05-25 header included
  • CI: lint, tests (3 OS × CGO=0/1), cross-compile, quality gate

kolkov added 10 commits May 25, 2026 10:27
Zero-value (0) means non-variadic, preserving full backward compatibility.
Values >0 indicate the number of fixed parameters before '...' in the C
prototype. On Apple ARM64, this boundary triggers register exhaustion.
Wraps PrepareCallInterface and sets FixedArgCount on the resulting CIF.
Validates nfixedargs is non-negative and does not exceed total arg count.
On Apple ARM64, the Execute() method reads FixedArgCount to exhaust
register allocators at the fixed/variadic boundary per Apple AAPCS64.
…Darwin

Apple's AAPCS64 extension requires that all variadic arguments go on the
stack regardless of register availability. When FixedArgCount > 0 and
GOOS == darwin, the Execute() method sets gprIdx=8 and fprIdx=8 before
processing the first variadic argument, forcing subsequent arguments into
stack slots. This matches Apple clang and libffi ffi_prep_cif_var() on
Darwin ARM64.

Non-variadic CIFs (FixedArgCount == 0) and non-Darwin ARM64 targets are
completely unaffected — the branch is never entered.
Add sum_variadic and variadic_two_fixed to testdata/structtest.c.
Add ffi/variadic_e2e_test.go with three test functions:
- TestVariadic_SumIntegers (nfixedargs=1, result=60)
- TestVariadic_TwoFixed (nfixedargs=2, result=600)
- TestVariadic_ErrorValidation (validation edge cases)

Extend struct_e2e_test.go build tag from amd64-only to (amd64 || arm64)
so that requireStructLib/structTestLib are available to variadic tests on
arm64 hosts. Move the four AMD64-specific XMM struct return tests to a new
ffi/struct_return_e2e_amd64_test.go with amd64-only build tag.
Compiles testdata/structtest.c via gcc and exercises both
sum_variadic and variadic_two_fixed through PrepareVariadicCallInterface.

Exits 0 on PASS, 1 on FAIL, 0 with SKIP message if gcc is unavailable.
Runs on linux/darwin/freebsd (amd64 and arm64).

Primary use: Apple Silicon verification — confirms variadic args land on
the stack on darwin/arm64 as required by Apple AAPCS64 extension.
…ECTURE, ROADMAP

CHANGELOG: add Unreleased section with PrepareVariadicCallInterface, Apple ARM64
stack-force, cmd/variadic-test, and variadic e2e tests.
README: replace 'Variadic not supported' limitation with Apple ARM64 note;
add variadic feature row to table; add variadic example; update roadmap table.
ARCHITECTURE: add Variadic Function Support section explaining platform
differences, FixedArgCount field semantics, and Darwin ARM64 register flush.
ROADMAP: mark variadic as in-progress in v0.6.0 milestone.
- dl_unix.go: use double-indirection for dlopen/dlsym uintptr→Pointer (go.dev/issue/58625)
- syscall_linux_stub.s: remove unused uint64 return from syscallStub signature (returns via struct field)
@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ffi/ffi.go 77.77% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@kolkov kolkov merged commit 8dfbc56 into main May 25, 2026
13 checks passed
@kolkov kolkov deleted the feat/variadic-functions branch May 25, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for variadic functions on darwin/arm64 (Apple Silicon)

1 participant