Commit 88c2fb9d authored by Than McIntosh's avatar Than McIntosh

cmd/compile: fix bug in DWARF inl handling of unused autos

The DWARF inline info generation hooks weren't properly
handling unused auto vars in certain cases, triggering an assert (now
fixed). Also with this change, introduce a new autom "flavor" to
use for autom entries that are added to insure that a specific
auto type makes it into the linker (this is a follow-on to the fix
for 22941).

Fixes #22962.

Change-Id: I7a2d8caf47f6ca897b12acb6a6de0eb25f5cac8f
Reviewed-on: https://go-review.googlesource.com/81557
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDavid Chase <drchase@google.com>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent 03c93eaa
...@@ -322,7 +322,11 @@ func debuginfo(fnsym *obj.LSym, curfn interface{}) ([]dwarf.Scope, dwarf.InlCall ...@@ -322,7 +322,11 @@ func debuginfo(fnsym *obj.LSym, curfn interface{}) ([]dwarf.Scope, dwarf.InlCall
switch n.Class() { switch n.Class() {
case PAUTO: case PAUTO:
if !n.Name.Used() { if !n.Name.Used() {
Fatalf("debuginfo unused node (AllocFrame should truncate fn.Func.Dcl)") // Text == nil -> generating abstract function
if fnsym.Func.Text != nil {
Fatalf("debuginfo unused node (AllocFrame should truncate fn.Func.Dcl)")
}
continue
} }
name = obj.NAME_AUTO name = obj.NAME_AUTO
case PPARAM, PPARAMOUT: case PPARAM, PPARAMOUT:
...@@ -558,15 +562,14 @@ func createDwarfVars(fnsym *obj.LSym, debugInfo *ssa.FuncDebug, automDecls []*No ...@@ -558,15 +562,14 @@ func createDwarfVars(fnsym *obj.LSym, debugInfo *ssa.FuncDebug, automDecls []*No
InlIndex: int32(inlIndex), InlIndex: int32(inlIndex),
ChildIndex: -1, ChildIndex: -1,
}) })
// Note: the auto that we're appending here is simply to insure // Append a "deleted auto" entry to the autom list so as to
// that the DWARF type in question is picked up by the linker -- // insure that the type in question is picked up by the linker.
// there isn't a real auto variable with this name. This is // See issue 22941.
// to fix issue 22941.
gotype := ngotype(n).Linksym() gotype := ngotype(n).Linksym()
fnsym.Func.Autom = append(fnsym.Func.Autom, &obj.Auto{ fnsym.Func.Autom = append(fnsym.Func.Autom, &obj.Auto{
Asym: Ctxt.Lookup(n.Sym.Name), Asym: Ctxt.Lookup(n.Sym.Name),
Aoffset: int32(-1), Aoffset: int32(-1),
Name: obj.NAME_AUTO, Name: obj.NAME_DELETED_AUTO,
Gotype: gotype, Gotype: gotype,
}) })
......
...@@ -208,6 +208,9 @@ const ( ...@@ -208,6 +208,9 @@ const (
// A reference to name@GOT(SB) is a reference to the entry in the global offset // A reference to name@GOT(SB) is a reference to the entry in the global offset
// table for 'name'. // table for 'name'.
NAME_GOTREF NAME_GOTREF
// Indicates auto that was optimized away, but whose type
// we want to preserve in the DWARF debug info.
NAME_DELETED_AUTO
) )
type AddrType uint8 type AddrType uint8
......
...@@ -351,6 +351,8 @@ func (w *objWriter) writeSym(s *LSym) { ...@@ -351,6 +351,8 @@ func (w *objWriter) writeSym(s *LSym) {
w.writeInt(objabi.A_AUTO) w.writeInt(objabi.A_AUTO)
} else if a.Name == NAME_PARAM { } else if a.Name == NAME_PARAM {
w.writeInt(objabi.A_PARAM) w.writeInt(objabi.A_PARAM)
} else if a.Name == NAME_DELETED_AUTO {
w.writeInt(objabi.A_DELETED_AUTO)
} else { } else {
log.Fatalf("%s: invalid local variable type %d", s.Name, a.Name) log.Fatalf("%s: invalid local variable type %d", s.Name, a.Name)
} }
......
...@@ -34,4 +34,5 @@ package objabi ...@@ -34,4 +34,5 @@ package objabi
const ( const (
A_AUTO = 1 + iota A_AUTO = 1 + iota
A_PARAM A_PARAM
A_DELETED_AUTO
) )
...@@ -857,7 +857,7 @@ func defdwsymb(ctxt *Link, s *sym.Symbol, str string, t SymbolType, v int64, got ...@@ -857,7 +857,7 @@ func defdwsymb(ctxt *Link, s *sym.Symbol, str string, t SymbolType, v int64, got
} }
fallthrough fallthrough
case AutoSym, ParamSym: case AutoSym, ParamSym, DeletedAutoSym:
dt = defgotype(ctxt, gotype) dt = defgotype(ctxt, gotype)
} }
......
...@@ -1964,6 +1964,7 @@ func doversion() { ...@@ -1964,6 +1964,7 @@ func doversion() {
type SymbolType int8 type SymbolType int8
const ( const (
// see also http://9p.io/magic/man2html/1/nm
TextSym SymbolType = 'T' TextSym SymbolType = 'T'
DataSym = 'D' DataSym = 'D'
BSSSym = 'B' BSSSym = 'B'
...@@ -1972,6 +1973,9 @@ const ( ...@@ -1972,6 +1973,9 @@ const (
FrameSym = 'm' FrameSym = 'm'
ParamSym = 'p' ParamSym = 'p'
AutoSym = 'a' AutoSym = 'a'
// Deleted auto (not a real sym, just placeholder for type)
DeletedAutoSym = 'x'
) )
func genasmsym(ctxt *Link, put func(*Link, *sym.Symbol, string, SymbolType, int64, *sym.Symbol)) { func genasmsym(ctxt *Link, put func(*Link, *sym.Symbol, string, SymbolType, int64, *sym.Symbol)) {
...@@ -2096,6 +2100,11 @@ func genasmsym(ctxt *Link, put func(*Link, *sym.Symbol, string, SymbolType, int6 ...@@ -2096,6 +2100,11 @@ func genasmsym(ctxt *Link, put func(*Link, *sym.Symbol, string, SymbolType, int6
continue continue
} }
for _, a := range s.FuncInfo.Autom { for _, a := range s.FuncInfo.Autom {
if a.Name == objabi.A_DELETED_AUTO {
put(ctxt, nil, "", DeletedAutoSym, 0, a.Gotype)
continue
}
// Emit a or p according to actual offset, even if label is wrong. // Emit a or p according to actual offset, even if label is wrong.
// This avoids negative offsets, which cannot be encoded. // This avoids negative offsets, which cannot be encoded.
if a.Name != objabi.A_AUTO && a.Name != objabi.A_PARAM { if a.Name != objabi.A_AUTO && a.Name != objabi.A_PARAM {
......
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package a
func F() {
if x := 0; false {
_ = x
}
}
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package b
import "a"
var V = func() { a.F() }
// compiledir
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ignored
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