]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.11] cmd/cgo: use field alignment when setting field offset
authorIan Lance Taylor <iant@golang.org>
Tue, 20 Nov 2018 23:55:02 +0000 (15:55 -0800)
committerIan Lance Taylor <iant@golang.org>
Mon, 3 Dec 2018 04:59:56 +0000 (04:59 +0000)
commit6fa0ace1288bce4eeb5228caeb7050c11e232858
tree16ed36d1e92f017250758b68a4dbee2d2a753e6d
parent6971090515bab8d4ecf19933736591904f8287bc
[release-branch.go1.11] cmd/cgo: use field alignment when setting field offset

The old code ignored the field alignment, and only looked at the field
offset: if the field offset required padding, cgo added padding. But
while that approach works for Go (at least with the gc toolchain) it
doesn't work for C code using packed structs. With a packed struct the
added padding may leave the struct at a misaligned position, and the
inserted alignment, which cgo is not considering, may introduce
additional, unexpected, padding. Padding that ignores alignment is not
a good idea when the struct is not packed, and Go structs are never
packed. So don't ignore alignment.

Updates #28896
Fixes #28916

Change-Id: Ie50ea15fa6dc35557497097be9fecfecb11efd8a
Reviewed-on: https://go-review.googlesource.com/c/150602
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
(cherry picked from commit fbdaa965634be842647195ee2d610dc363c760d2)
Reviewed-on: https://go-review.googlesource.com/c/151778
TryBot-Result: Gobot Gobot <gobot@golang.org>
misc/cgo/test/cgo_test.go
misc/cgo/test/issue28896.go [new file with mode: 0644]
src/cmd/cgo/gcc.go