Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: godefs handles gcc pragma pack inconsistently? #8267

Closed
mikioh opened this issue Jun 23, 2014 · 2 comments
Closed

cmd/cgo: godefs handles gcc pragma pack inconsistently? #8267

mikioh opened this issue Jun 23, 2014 · 2 comments

Comments

@mikioh
Copy link
Contributor

mikioh commented Jun 23, 2014

% hg id
36ffbae640bd+ tip

go tool cgo -godefs pack4.go on darwin outputs the following

// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs pack4.go

package pack4

type Pack4k struct {
    X       uint32
    Pad_cgo_0   [8]byte
    Pad_cgo_1   [8]byte
}

instead of

type Pack4k struct {
    X       uint32
    Pad_cgo_0   int64
    Pad_cgo_1   int64
}

fwiw, go1.1 generates the latter.

Attachments:

  1. pack4.go (166 bytes)
@ianlancetaylor
Copy link
Contributor

Comment 1:

The goal is to make a Go struct that corresponds to the C struct.  In Go, int64 is
always aligned to an 8-byte boundary.  In C it sometimes is not.  In particular, it is
not on a 32-bit x86.  Therefore the first Go struct (the one with the [8]byte fields) is
the only correct translation of the C struct in some cases.  The second Go struct (with
the int64 fields) looks right but will do the wrong thing.

Status changed to WorkingAsIntended.

@mikioh
Copy link
Contributor Author

mikioh commented Jun 24, 2014

Comment 2:

For the record, we agreed that for now we leave all stuff that generated previous godefs
as it is. We will fix the stuff when we see serious issues caused by wrong ABI layout.
See revision 7244ce3ae9db.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants