On Wed, Sep 9, 2020 at 4:59 AM Jan Mercl <
0xj...@gmail.com> wrote:
>
> If the intent is to have Go alignments/offsets of types compatible
> with the C ABI then I think it's safe to say this is a bug.
>
> And the existence of the syscall package, in some cases passing
> Go-defined structs to the kernel that must be binary compatible with
> their C definitions, IMO suggests that the intent is indeed there.
Exact alignment/offset compatibility with the C ABI is not a goal.
Sorry. (It's actually harder than one might think to maintain that
kind of compatibility. For example, on x86, the C ABI uses one
alignment for double variables and a different alignment for double
variables that appear as a field in a struct. Unless, of course, you
use the -malign-double option. And more generally some platforms have
multiple C ABIs, including x86 if you count the MCU psABI.)
The Go structs in the syscall package that need to match C structs are
carefully written to work correctly.
You may find the cgo -godefs option to be helpful, as it provides Go
structs that exactly match C structs, given a particular set of
compiler options.
Ian