1
0
mirror of https://github.com/golang/go synced 2024-10-01 05:28:33 -06:00

cmd/compile: don't emit autom's into object file

Don't write Autom records when writing a function to the object file;
we no longer need them in the linker for DWARF processing. So as to
keep the object file format unchanged, write out a zero-length list of
automs to the object, as opposed to removing all references.

Updates #34554.

Change-Id: I42a1d67207ea7114ae4f3a315cf37effba57f190
Reviewed-on: https://go-review.googlesource.com/c/go/+/197499
Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
Than McIntosh 2019-09-26 09:53:37 -04:00
parent e72f002ed0
commit cdd59205c4
3 changed files with 14 additions and 57 deletions

View File

@ -384,13 +384,12 @@ func debuginfo(fnsym *obj.LSym, infosym *obj.LSym, curfn interface{}) ([]dwarf.S
} }
} }
var automDecls []*Node var apdecls []*Node
// Populate Automs for fn. // Populate decls for fn.
for _, n := range fn.Func.Dcl { for _, n := range fn.Func.Dcl {
if n.Op != ONAME { // might be OTYPE or OLITERAL if n.Op != ONAME { // might be OTYPE or OLITERAL
continue continue
} }
var name obj.AddrName
switch n.Class() { switch n.Class() {
case PAUTO: case PAUTO:
if !n.Name.Used() { if !n.Name.Used() {
@ -400,24 +399,15 @@ func debuginfo(fnsym *obj.LSym, infosym *obj.LSym, curfn interface{}) ([]dwarf.S
} }
continue continue
} }
name = obj.NAME_AUTO
case PPARAM, PPARAMOUT: case PPARAM, PPARAMOUT:
name = obj.NAME_PARAM
default: default:
continue continue
} }
automDecls = append(automDecls, n) apdecls = append(apdecls, n)
gotype := ngotype(n).Linksym() fnsym.Func.RecordAutoType(ngotype(n).Linksym())
fnsym.Func.Autom = append(fnsym.Func.Autom, &obj.Auto{
Asym: Ctxt.Lookup(n.Sym.Name),
Aoffset: int32(n.Xoffset),
Name: name,
Gotype: gotype,
})
fnsym.Func.RecordAutoType(gotype)
} }
decls, dwarfVars := createDwarfVars(fnsym, fn.Func, automDecls) decls, dwarfVars := createDwarfVars(fnsym, fn.Func, apdecls)
// For each type referenced by the functions auto vars, attach a // For each type referenced by the functions auto vars, attach a
// dummy relocation to the function symbol to insure that the type // dummy relocation to the function symbol to insure that the type
@ -467,11 +457,11 @@ func debuginfo(fnsym *obj.LSym, infosym *obj.LSym, curfn interface{}) ([]dwarf.S
// createSimpleVars creates a DWARF entry for every variable declared in the // createSimpleVars creates a DWARF entry for every variable declared in the
// function, claiming that they are permanently on the stack. // function, claiming that they are permanently on the stack.
func createSimpleVars(automDecls []*Node) ([]*Node, []*dwarf.Var, map[*Node]bool) { func createSimpleVars(apDecls []*Node) ([]*Node, []*dwarf.Var, map[*Node]bool) {
var vars []*dwarf.Var var vars []*dwarf.Var
var decls []*Node var decls []*Node
selected := make(map[*Node]bool) selected := make(map[*Node]bool)
for _, n := range automDecls { for _, n := range apDecls {
if n.IsAutoTmp() { if n.IsAutoTmp() {
continue continue
} }
@ -559,7 +549,7 @@ func createComplexVars(fn *Func) ([]*Node, []*dwarf.Var, map[*Node]bool) {
// createDwarfVars process fn, returning a list of DWARF variables and the // createDwarfVars process fn, returning a list of DWARF variables and the
// Nodes they represent. // Nodes they represent.
func createDwarfVars(fnsym *obj.LSym, fn *Func, automDecls []*Node) ([]*Node, []*dwarf.Var) { func createDwarfVars(fnsym *obj.LSym, fn *Func, apDecls []*Node) ([]*Node, []*dwarf.Var) {
// Collect a raw list of DWARF vars. // Collect a raw list of DWARF vars.
var vars []*dwarf.Var var vars []*dwarf.Var
var decls []*Node var decls []*Node
@ -567,10 +557,10 @@ func createDwarfVars(fnsym *obj.LSym, fn *Func, automDecls []*Node) ([]*Node, []
if Ctxt.Flag_locationlists && Ctxt.Flag_optimize && fn.DebugInfo != nil { if Ctxt.Flag_locationlists && Ctxt.Flag_optimize && fn.DebugInfo != nil {
decls, vars, selected = createComplexVars(fn) decls, vars, selected = createComplexVars(fn)
} else { } else {
decls, vars, selected = createSimpleVars(automDecls) decls, vars, selected = createSimpleVars(apDecls)
} }
dcl := automDecls dcl := apDecls
if fnsym.WasInlined() { if fnsym.WasInlined() {
dcl = preInliningDcls(fnsym) dcl = preInliningDcls(fnsym)
} }
@ -649,17 +639,8 @@ func createDwarfVars(fnsym *obj.LSym, fn *Func, automDecls []*Node) ([]*Node, []
InlIndex: int32(inlIndex), InlIndex: int32(inlIndex),
ChildIndex: -1, ChildIndex: -1,
}) })
// Append a "deleted auto" entry to the autom list so as to // Record go type of to insure that it gets emitted by the linker.
// insure that the type in question is picked up by the linker. fnsym.Func.RecordAutoType(ngotype(n).Linksym())
// See issue 22941.
gotype := ngotype(n).Linksym()
fnsym.Func.Autom = append(fnsym.Func.Autom, &obj.Auto{
Asym: Ctxt.Lookup(n.Sym.Name),
Aoffset: int32(-1),
Name: obj.NAME_DELETED_AUTO,
Gotype: gotype,
})
fnsym.Func.RecordAutoType(gotype)
} }
return decls, vars return decls, vars

View File

@ -211,9 +211,6 @@ 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
// Indicates that this is a reference to a TOC anchor. // Indicates that this is a reference to a TOC anchor.
NAME_TOCREF NAME_TOCREF
) )
@ -398,7 +395,6 @@ type FuncInfo struct {
Args int32 Args int32
Locals int32 Locals int32
Text *Prog Text *Prog
Autom []*Auto
Autot map[*LSym]struct{} Autot map[*LSym]struct{}
Pcln Pcln Pcln Pcln
InlMarks []InlMark InlMarks []InlMark

View File

@ -31,7 +31,6 @@ type objWriter struct {
nData int nData int
nReloc int nReloc int
nPcdata int nPcdata int
nAutom int
nFuncdata int nFuncdata int
nFile int nFile int
@ -60,7 +59,6 @@ func (w *objWriter) addLengths(s *LSym) {
w.nData += data w.nData += data
w.nPcdata += len(pc.Pcdata) w.nPcdata += len(pc.Pcdata)
w.nAutom += len(s.Func.Autom)
w.nFuncdata += len(pc.Funcdataoff) w.nFuncdata += len(pc.Funcdataoff)
w.nFile += len(pc.File) w.nFile += len(pc.File)
} }
@ -69,7 +67,7 @@ func (w *objWriter) writeLengths() {
w.writeInt(int64(w.nData)) w.writeInt(int64(w.nData))
w.writeInt(int64(w.nReloc)) w.writeInt(int64(w.nReloc))
w.writeInt(int64(w.nPcdata)) w.writeInt(int64(w.nPcdata))
w.writeInt(int64(w.nAutom)) w.writeInt(int64(0)) // TODO: remove at next object file rev
w.writeInt(int64(w.nFuncdata)) w.writeInt(int64(w.nFuncdata))
w.writeInt(int64(w.nFile)) w.writeInt(int64(w.nFile))
} }
@ -206,10 +204,6 @@ func (w *objWriter) writeRefs(s *LSym) {
} }
if s.Type == objabi.STEXT { if s.Type == objabi.STEXT {
for _, a := range s.Func.Autom {
w.writeRef(a.Asym, false)
w.writeRef(a.Gotype, false)
}
pc := &s.Func.Pcln pc := &s.Func.Pcln
for _, d := range pc.Funcdata { for _, d := range pc.Funcdata {
w.writeRef(d, false) w.writeRef(d, false)
@ -364,21 +358,7 @@ func (w *objWriter) writeSym(s *LSym) {
flags |= 1 << 4 flags |= 1 << 4
} }
w.writeInt(flags) w.writeInt(flags)
w.writeInt(int64(len(s.Func.Autom))) w.writeInt(int64(0)) // TODO: remove at next object file rev
for _, a := range s.Func.Autom {
w.writeRefIndex(a.Asym)
w.writeInt(int64(a.Aoffset))
if a.Name == NAME_AUTO {
w.writeInt(objabi.A_AUTO)
} else if a.Name == NAME_PARAM {
w.writeInt(objabi.A_PARAM)
} else if a.Name == NAME_DELETED_AUTO {
w.writeInt(objabi.A_DELETED_AUTO)
} else {
log.Fatalf("%s: invalid local variable type %d", s.Name, a.Name)
}
w.writeRefIndex(a.Gotype)
}
pc := &s.Func.Pcln pc := &s.Func.Pcln
w.writeInt(int64(len(pc.Pcsp.P))) w.writeInt(int64(len(pc.Pcsp.P)))