summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2013-10-15 15:00:48 -0400
committerRuss Cox <rsc@golang.org>2013-10-15 15:00:48 -0400
commit726a3b6800205fbfb198fda2bf6d3420c0d91c06 (patch)
tree5f92579c8fc8c50e8c833411b960077bf80d15df
parent8d3a1925674a6116088877473cf5b58c869adf96 (diff)
downloadgo-726a3b6800205fbfb198fda2bf6d3420c0d91c06.tar.gz
cmd/cgo: print the builtin prolog after the per-file preamble
The preamble may want to #define some special symbols and then #include <sys/types.h> itself. The builtin prolog also #includes <sys/types.h>, which would break such a preamble (because the second #include will be a no-op). The use of sys/types.h in the builtin prolog is new since Go 1.1, so this should preserve the semantics of more existing cgo code than we would otherwise. It also fixes src/pkg/syscall/mkall.sh's use of go tool cgo -godefs on some Linux systems. Thanks to fullung@ for identifying the problem. Fixes issue 6558. R=golang-dev, iant CC=golang-dev https://codereview.appspot.com/14684044
-rw-r--r--src/cmd/cgo/gcc.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go
index 40e9c70a1..fd3b01ea2 100644
--- a/src/cmd/cgo/gcc.go
+++ b/src/cmd/cgo/gcc.go
@@ -188,8 +188,8 @@ func (p *Package) Translate(f *File) {
// in the file f and saves relevant renamings in f.Name[name].Define.
func (p *Package) loadDefines(f *File) {
var b bytes.Buffer
- b.WriteString(builtinProlog)
b.WriteString(f.Preamble)
+ b.WriteString(builtinProlog)
stdout := p.gccDefines(b.Bytes())
for _, line := range strings.Split(stdout, "\n") {
@@ -301,8 +301,8 @@ func (p *Package) guessKinds(f *File) []*Name {
}
var b bytes.Buffer
- b.WriteString(builtinProlog)
b.WriteString(f.Preamble)
+ b.WriteString(builtinProlog)
b.WriteString("void __cgo__f__(void) {\n")
// For a #defined expression, clang silences the warning about "unused expression".
@@ -417,8 +417,8 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
// for each entry in names and then dereference the type we
// learn for __cgo__i.
var b bytes.Buffer
- b.WriteString(builtinProlog)
b.WriteString(f.Preamble)
+ b.WriteString(builtinProlog)
for i, n := range names {
fmt.Fprintf(&b, "typeof(%s) *__cgo__%d;\n", n.C, i)
if n.Kind == "const" {