purego: support structs on ppc64le#475
Merged
hajimehoshi merged 1 commit intoJul 15, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends purego’s struct-by-value support to linux/ppc64le for RegisterFunc / RegisterLibFunc, aligning argument/return handling with the ELFv2 ABI (including HFAs), while explicitly keeping struct callbacks (NewCallback) unsupported.
Changes:
- Add ppc64le support gating for struct arguments/returns in
RegisterFuncand update platform documentation. - Extend the ppc64le syscall trampoline to preserve additional FP return registers (F1–F8) for HFA returns.
- Update struct tests to run on ppc64le and skip known-unhandled register-allocation scenarios.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| sys_ppc64le.s | Store FP return registers F1–F8 to support HFA returns spanning up to 8 members. |
| struct_test.go | Enable tests on ppc64le and skip cases requiring >8 FP arg regs or scalar-float GPR shadowing. |
| struct_ppc64le.go | Implement ppc64le-specific struct argument/return handling, including HFA classification/flattening. |
| README.md | Update Linux platform notes to reflect ppc64le struct support tier/footnote. |
| func.go | Allow ppc64le in struct support gate and add ppc64le-specific hidden return buffer decision logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hajimehoshi
marked this pull request as draft
July 7, 2026 06:26
hajimehoshi
marked this pull request as ready for review
July 7, 2026 07:50
Member
Author
|
@TotallyGamerJet PTAL |
| return allFloats, numFields | ||
| } | ||
|
|
||
| // ppc64leLeaf is a scalar member of a flattened aggregate at byte offset offset. |
Collaborator
There was a problem hiding this comment.
Shouldn't this be in struct_ppc64?
hajimehoshi
force-pushed
the
claude/trusting-khorana-c8f9eb
branch
from
July 8, 2026 15:41
228c2a8 to
57238c4
Compare
hajimehoshi
commented
Jul 8, 2026
hajimehoshi
marked this pull request as draft
July 12, 2026 13:25
Pass and return structs by value when calling C functions under the ELFv2 ABI: a homogeneous floating-point aggregate is passed and returned in the floating-point registers whatever its size, any other aggregate occupies successive doublewords in the general-purpose registers and the parameter save area, and a non-homogeneous aggregate larger than two doublewords is returned through a caller-allocated buffer. Scalar float32 arguments are passed in double-precision format, matching the FMOVD-based convention already used for float32 struct members and float returns; reading float32 callback arguments does the inverse conversion. Widen structReturnInMemory to take the return type rather than its size, so ppc64le can keep a homogeneous floating-point aggregate in registers regardless of size while every other architecture keeps its size-only rule. Struct arguments and returns in callbacks remain unsupported, as on the other non-amd64/arm64 architectures. Aggregates that need more than eight floating-point argument registers, and functions taking mixed scalar floating-point and integer arguments, are not yet handled; the latter needs the ELFv2 general-purpose register shadowing that purego does not model for scalar arguments. Updates ebitengine#474 Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
hajimehoshi
force-pushed
the
claude/trusting-khorana-c8f9eb
branch
from
July 13, 2026 02:55
fa5e1fb to
e70cfc4
Compare
hajimehoshi
marked this pull request as ready for review
July 13, 2026 02:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What issue is this addressing?
Updates #474
What type of issue is this addressing?
feature
What this PR does | solves
Adds struct-by-value support for
linux/ppc64lewhen calling Cfunctions, following the loong64 work in #473.
Under the ELFv2 ABI:
floating-point type) are passed and returned in the floating-point
registers.
registers and the parameter save area. A floating-point argument
shadows and skips a GPR, so an HFA argument advances the integer
registers accordingly.
caller-allocated buffer whose pointer is passed and returned in
r3.Struct arguments and returns in callbacks (
NewCallback) remainunsupported, as on the other non-amd64/arm64 architectures.
Not yet handled (skipped in the tests on ppc64le)
(
LargeFloatStructWithRegs,RectangleWithRegs); purego wires f1–f8.(
IdentityTwoInt64AfterPrims): the scalar float shadows a GPR, whichpurego does not model for scalars without also changing the callback
path.
Testing
The register/stack placement and return-value reconstruction were
validated against GCC/Clang codegen by disassembling the test C for
ppc64le (ELFv2) with
zig cc -target powerpc64le-linux-gnu, plus thefull host test suite. The QEMU-based ppc64le CI job exercises the struct
tests.
🤖 Generated with Claude Code