diff options
author | Ian Lance Taylor <iant@golang.org> | 2019-01-28 12:31:55 -0800 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2019-02-01 21:26:14 +0000 |
commit | 396ff0df0a0988a9a23b7132d03ad072e3be554c (patch) | |
tree | 0c2c52b2e6344d8236c9515ddb3f049557d943eb | |
parent | d4cf10b9d6c5fecff11609a180e23d1d49112bd3 (diff) | |
download | go-396ff0df0a0988a9a23b7132d03ad072e3be554c.tar.gz go-396ff0df0a0988a9a23b7132d03ad072e3be554c.zip |
[release-branch.go1.10] cmd/cgo: disable GCC 9 warnings triggered by cgo code
GCC 9 has started emitting warnings when taking the address of a field
in a packed struct may cause a misaligned pointer. We use packed
structs in cgo to ensure that our field layout matches the C
compiler's layout. Our pointers are always aligned, so disable the warning
Updates #29962
Fixes #29966
Change-Id: I7e290a7cf694a2c2958529e340ebed9fcd62089c
Reviewed-on: https://go-review.googlesource.com/c/159859
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
(cherry picked from commit f2a416b90ac68596ea05b97cefa8c72e7416e98f)
Reviewed-on: https://go-review.googlesource.com/c/160450
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
-rw-r--r-- | src/cmd/cgo/out.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index 070429f442..d0e0b0a756 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -743,6 +743,10 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) { fmt.Fprintf(fgcc, "#include <stdlib.h>\n") fmt.Fprintf(fgcc, "#include \"_cgo_export.h\"\n\n") + // We use packed structs, but they are always aligned. + fmt.Fprintf(fgcc, "#pragma GCC diagnostic ignored \"-Wpragmas\"\n") + fmt.Fprintf(fgcc, "#pragma GCC diagnostic ignored \"-Waddress-of-packed-member\"\n") + fmt.Fprintf(fgcc, "extern void crosscall2(void (*fn)(void *, int, __SIZE_TYPE__), void *, int, __SIZE_TYPE__);\n") fmt.Fprintf(fgcc, "extern __SIZE_TYPE__ _cgo_wait_runtime_init_done();\n") fmt.Fprintf(fgcc, "extern void _cgo_release_context(__SIZE_TYPE__);\n\n") @@ -1334,6 +1338,10 @@ __cgo_size_assert(double, 8) extern char* _cgo_topofstack(void); +/* We use packed structs, but they are always aligned. */ +#pragma GCC diagnostic ignored "-Wpragmas" +#pragma GCC diagnostic ignored "-Waddress-of-packed-member" + #include <errno.h> #include <string.h> ` |