diff options
| author | Matthew Dempsky <mdempsky@google.com> | 2014-08-05 18:12:32 -0700 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2014-08-05 18:12:32 -0700 |
| commit | f7a8adbd511e921111fc0682d380a6f7a33e0c93 (patch) | |
| tree | ad4c08167f3e0c6b142f9b1540bc794d7d415f09 /src | |
| parent | 48e75337839d21079c9763d3447ade409ee2c32a (diff) | |
| download | go-f7a8adbd511e921111fc0682d380a6f7a33e0c93.tar.xz | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/cgo/gcc.go | 4 | ||||
| -rw-r--r-- | src/cmd/cgo/out.go | 10 | ||||
| -rw-r--r-- | src/pkg/runtime/defs_linux.go | 1 |
3 files changed, 6 insertions, 9 deletions
diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index 13e8340291..6b0ecd1099 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -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) diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index c6c27c4dbf..1ef78b757c 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -1148,16 +1148,10 @@ __cgo_size_assert(double, 8) ` const builtinProlog = ` -#include <sys/types.h> /* for size_t below */ +#include <stddef.h> /* for ptrdiff_t and size_t below */ /* Define intgo when compiling with GCC. */ -#ifdef __PTRDIFF_TYPE__ -typedef __PTRDIFF_TYPE__ intgo; -#elif defined(_LP64) -typedef long long intgo; -#else -typedef int intgo; -#endif +typedef ptrdiff_t intgo; typedef struct { char *p; intgo n; } _GoString_; typedef struct { char *p; intgo n; intgo c; } _GoBytes_; diff --git a/src/pkg/runtime/defs_linux.go b/src/pkg/runtime/defs_linux.go index 2f4e03a016..8657dbb0ec 100644 --- a/src/pkg/runtime/defs_linux.go +++ b/src/pkg/runtime/defs_linux.go @@ -28,6 +28,7 @@ package runtime #include <asm-generic/errno.h> #include <asm-generic/poll.h> #include <linux/eventpoll.h> +#undef size_t */ import "C" |
