mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/cgo: fix handling of defs_linux.go
Instead of including <sys/types.h> to get size_t, instead include the ISO C standard <stddef.h> header, which defines fewer additional types at risk of colliding with the user code. In particular, this prevents collisions between <sys/types.h>'s userspace definitions with the kernel definitions needed by defs_linux.go. Also, -cdefs mode uses #pragma pack, so we can keep misaligned fields. Fixes #8477. LGTM=iant R=golang-codereviews, iant CC=golang-codereviews https://golang.org/cl/120610043
This commit is contained in:
parent
48e7533783
commit
f7a8adbd51
6 changed files with 48 additions and 9 deletions
|
|
@ -1587,12 +1587,14 @@ func (c *typeConv) Struct(dt *dwarf.StructType, pos token.Pos) (expr *ast.Struct
|
|||
talign = size
|
||||
}
|
||||
|
||||
if talign > 0 && f.ByteOffset%talign != 0 {
|
||||
if talign > 0 && f.ByteOffset%talign != 0 && !*cdefs {
|
||||
// Drop misaligned fields, the same way we drop integer bit fields.
|
||||
// The goal is to make available what can be made available.
|
||||
// Otherwise one bad and unneeded field in an otherwise okay struct
|
||||
// makes the whole program not compile. Much of the time these
|
||||
// structs are in system headers that cannot be corrected.
|
||||
// Exception: In -cdefs mode, we use #pragma pack, so misaligned
|
||||
// fields should still work.
|
||||
continue
|
||||
}
|
||||
n := len(fld)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue