Skip to content

64-bit arguments and return values are not fully supported on 32-bit ARM #489

Description

@xakep666

PureGo Version

v0.10.2

Operating System

  • Windows
  • macOS
  • Linux
  • FreeBSD
  • NetBSD
  • Android
  • iOS

Go Version (go version)

1.26.5

What steps will reproduce the problem?

For C functions with signatures like

int64_t some_fn(uintptr_t a1, int64_t a2)

or

int64_t some_fn(uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, int64_t a6)

arguments and return values are corruped when called via purego. This also applies to callbacks.

However, signatures like

int64_t some_fn(uintptr_t a1, uintptr_t a2, int64_t a3)

or

int64_t some_fn(uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6, int64_t a7)

will work.

What is the expected result?

64-bit function arguments are properly serialized and return values are properly deserialized

What happens instead?

I'm getting invalid values

Anything else you feel useful to add?

This happens because purego does not comply with 32-bit AAPCS. Exact points:

C.3 If the argument requires double-word alignment (8-byte), the NCRN is rounded up to the next even register number.
C.7 If the argument required double-word alignment (8-byte), then the NSAA is rounded up to the next double-word address.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions