From 3819907a5565c53457b826912a10b18eda708f38 Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Thu, 5 Feb 2015 14:16:13 -0500 Subject: [PATCH] cmd/cgo: detect misuse of generated _cgo_export.h Fixes #9742. Change-Id: Ifedf7ff9465bc49534b708d414c8e435ee9ce6cd Reviewed-on: https://go-review.googlesource.com/3970 Reviewed-by: Ian Lance Taylor --- src/cmd/cgo/out.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index a4bd5579d3..346ae94546 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -636,7 +636,7 @@ func (p *Package) writeExports(fgo2, fm io.Writer) { fgcc := creat(*objDir + "_cgo_export.c") fgcch := creat(*objDir + "_cgo_export.h") - fmt.Fprintf(fgcch, "/* Created by cgo - DO NOT EDIT. */\n") + fmt.Fprintf(fgcch, "/* Created by cgo - DO NOT EDIT. */\n/* This file is arch-specific. */\n") fmt.Fprintf(fgcch, "%s\n", p.Preamble) fmt.Fprintf(fgcch, "%s\n", p.gccExportHeaderProlog()) @@ -1310,6 +1310,10 @@ typedef double GoFloat64; typedef __complex float GoComplex64; typedef __complex double GoComplex128; +// static assertion to make sure the file is being used on architecture +// at least with matching size of GoInt. +typedef char _check_for_GOINTBITS_bit_pointer_matching_GoInt[sizeof(void*)==GOINTBITS/8 ? 1:-1]; + typedef struct { char *p; GoInt n; } GoString; typedef void *GoMap; typedef void *GoChan;