Commit f4abbc0e authored by Keith Randall's avatar Keith Randall

cmd/link,compile: Provide size for func types

They are currently not given a size, which makes the DWARF reader
very confused. Particularly things like [4]func() get a size of -4, not 32.

Fixes #21097

Change-Id: I01e754134d82fbbe6567e3c7847a4843792a3776
Reviewed-on: https://go-review.googlesource.com/55551Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 77a9cb9b
......@@ -467,6 +467,7 @@ var abbrevs = [DW_NABRV]dwAbbrev{
DW_CHILDREN_yes,
[]dwAttrForm{
{DW_AT_name, DW_FORM_string},
{DW_AT_byte_size, DW_FORM_udata},
// {DW_AT_type, DW_FORM_ref_addr},
{DW_AT_go_kind, DW_FORM_data1},
},
......
......@@ -430,6 +430,7 @@ func newtype(ctxt *Link, gotype *Symbol) *dwarf.DWDie {
case objabi.KindFunc:
die = newdie(ctxt, &dwtypes, dwarf.DW_ABRV_FUNCTYPE, name, 0)
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0)
dotypedef(ctxt, &dwtypes, name, die)
newrefattr(die, dwarf.DW_AT_type, mustFind(ctxt, "void"))
nfields := decodetypeFuncInCount(ctxt.Arch, gotype)
......
......@@ -192,3 +192,46 @@ func findMembers(rdr *dwarf.Reader) (map[string]bool, error) {
}
return memberEmbedded, nil
}
func TestSizes(t *testing.T) {
// DWARF sizes should never be -1.
// See issue #21097
const prog = `
package main
var x func()
var y [4]func()
func main() {
x = nil
y[0] = nil
}
`
dir, err := ioutil.TempDir("", "TestSizes")
if err != nil {
t.Fatalf("could not create directory: %v", err)
}
defer os.RemoveAll(dir)
f := gobuild(t, dir, prog)
defer f.Close()
d, err := f.DWARF()
if err != nil {
t.Fatalf("error reading DWARF: %v", err)
}
rdr := d.Reader()
for entry, err := rdr.Next(); entry != nil; entry, err = rdr.Next() {
if err != nil {
t.Fatalf("error reading DWARF: %v", err)
}
switch entry.Tag {
case dwarf.TagArrayType, dwarf.TagPointerType, dwarf.TagStructType, dwarf.TagBaseType, dwarf.TagSubroutineType, dwarf.TagTypedef:
default:
continue
}
typ, err := d.Type(entry.Offset)
if err != nil {
t.Fatalf("can't read type: %v", err)
}
if typ.Size() < 0 {
t.Errorf("subzero size %s %s %T", typ, entry.Tag, typ)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment