1
0
mirror of https://github.com/golang/go synced 2024-11-18 21:44:45 -07: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
// Populate Automs for fn.
var apdecls []*Node
// Populate decls for fn.
for _, n := range fn.Func.Dcl {
if n.Op != ONAME { // might be OTYPE or OLITERAL
continue
}
var name obj.AddrName
switch n.Class() {
case PAUTO:
if !n.Name.Used() {
@ -400,24 +399,15 @@ func debuginfo(fnsym *obj.LSym, infosym *obj.LSym, curfn interface{}) ([]dwarf.S
}
continue
}
name = obj.NAME_AUTO
case PPARAM, PPARAMOUT:
name = obj.NAME_PARAM
default:
continue
}
automDecls = append(automDecls, n)
gotype := 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)
apdecls = append(apdecls, n)
fnsym.Func.RecordAutoType(ngotype(n).Linksym())
}
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
// 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
// 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 decls []*Node
selected := make(map[*Node]bool)
for _, n := range automDecls {
for _, n := range apDecls {
if n.IsAutoTmp() {
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
// 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.
var vars []*dwarf.Var
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 {
decls, vars, selected = createComplexVars(fn)
} else {
decls, vars, selected = createSimpleVars(automDecls)
decls, vars, selected = createSimpleVars(apDecls)
}
dcl := automDecls
dcl := apDecls
if fnsym.WasInlined() {
dcl = preInliningDcls(fnsym)
}
@ -649,17 +639,8 @@ func createDwarfVars(fnsym *obj.LSym, fn *Func, automDecls []*Node) ([]*Node, []
InlIndex: int32(inlIndex),
ChildIndex: -1,
})
// Append a "deleted auto" entry to the autom list so as to
// insure that the type in question is picked up by the linker.
// 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)
// Record go type of to insure that it gets emitted by the linker.
fnsym.Func.RecordAutoType(ngotype(n).Linksym())
}
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
// table for 'name'.
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.
NAME_TOCREF
)
@ -398,7 +395,6 @@ type FuncInfo struct {
Args int32
Locals int32
Text *Prog
Autom []*Auto
Autot map[*LSym]struct{}
Pcln Pcln
InlMarks []InlMark

View File

@ -31,7 +31,6 @@ type objWriter struct {
nData int
nReloc int
nPcdata int
nAutom int
nFuncdata int
nFile int
@ -60,7 +59,6 @@ func (w *objWriter) addLengths(s *LSym) {
w.nData += data
w.nPcdata += len(pc.Pcdata)
w.nAutom += len(s.Func.Autom)
w.nFuncdata += len(pc.Funcdataoff)
w.nFile += len(pc.File)
}
@ -69,7 +67,7 @@ func (w *objWriter) writeLengths() {
w.writeInt(int64(w.nData))
w.writeInt(int64(w.nReloc))
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.nFile))
}
@ -206,10 +204,6 @@ func (w *objWriter) writeRefs(s *LSym) {
}
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
for _, d := range pc.Funcdata {
w.writeRef(d, false)
@ -364,21 +358,7 @@ func (w *objWriter) writeSym(s *LSym) {
flags |= 1 << 4
}
w.writeInt(flags)
w.writeInt(int64(len(s.Func.Autom)))
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)
}
w.writeInt(int64(0)) // TODO: remove at next object file rev
pc := &s.Func.Pcln
w.writeInt(int64(len(pc.Pcsp.P)))