From 041787280976d0bad15c646fc7c7bbfef76d7ee5 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 20 Nov 2015 13:53:18 -0800 Subject: [PATCH] cmd/cgo: ignore vars with no name or type if they have a AttrSpecification Fixes #13344. Change-Id: I33c6721fd33d144c85c87840ddf27ce15aa72328 Reviewed-on: https://go-review.googlesource.com/17151 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Minux Ma --- misc/cgo/test/issue1635.go | 5 +++++ src/cmd/cgo/gcc.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/misc/cgo/test/issue1635.go b/misc/cgo/test/issue1635.go index 6bfe110fdf40bb..cc4be9093d1a07 100644 --- a/misc/cgo/test/issue1635.go +++ b/misc/cgo/test/issue1635.go @@ -14,6 +14,11 @@ void scatter() { printf("scatter = %p\n", p); } +// Adding this explicit extern declaration makes this a test for +// https://gcc.gnu.org/PR68072 aka https://golang.org/issue/13344 . +// It used to cause a cgo error when building with GCC 6. +extern int hola; + // this example is in issue 3253 int hola = 0; int testHola() { return hola; } diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index 5a9a3c22920d77..ed121dad810662 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -491,6 +491,11 @@ func (p *Package) loadDWARF(f *File, names []*Name) { name, _ := e.Val(dwarf.AttrName).(string) typOff, _ := e.Val(dwarf.AttrType).(dwarf.Offset) if name == "" || typOff == 0 { + if e.Val(dwarf.AttrSpecification) != nil { + // Since we are reading all the DWARF, + // assume we will see the variable elsewhere. + break + } fatalf("malformed DWARF TagVariable entry") } if !strings.HasPrefix(name, "__cgo__") {