mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/dwarfgen: fix DWARF param DIE ordering
The DWARF standard requires that the DIEs in a subprogram corresponding to input and output parameters appear in declaration order; this patch adds some new code in dwarfgen to enforce this ordering (relying on the existing fn.Dcl ordering is not sufficient). Prior to the register ABI, it was easy to keep vars/decls sorted during DWARF generation since you could always rely on frame offset; with the ABI sorting by frame offset no longer gives you the original declaration order in all cases. Fixes #46055. Change-Id: I0e070cb781d6453caba896e5d3bee7cd5388050d Reviewed-on: https://go-review.googlesource.com/c/go/+/318829 Trust: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Alessandro Arzilli <alessandro.arzilli@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
parent
a63cded5e4
commit
fd4631e24f
2 changed files with 72 additions and 13 deletions
|
|
@ -222,9 +222,64 @@ func createDwarfVars(fnsym *obj.LSym, complexOK bool, fn *ir.Func, apDecls []*ir
|
|||
fnsym.Func().RecordAutoType(reflectdata.TypeLinksym(n.Type()))
|
||||
}
|
||||
|
||||
// Sort decls and vars.
|
||||
sortDeclsAndVars(fn, decls, vars)
|
||||
|
||||
return decls, vars
|
||||
}
|
||||
|
||||
// sortDeclsAndVars sorts the decl and dwarf var lists according to
|
||||
// parameter declaration order, so as to insure that when a subprogram
|
||||
// DIE is emitted, its parameter children appear in declaration order.
|
||||
// Prior to the advent of the register ABI, sorting by frame offset
|
||||
// would achieve this; with the register we now need to go back to the
|
||||
// original function signature.
|
||||
func sortDeclsAndVars(fn *ir.Func, decls []*ir.Name, vars []*dwarf.Var) {
|
||||
paramOrder := make(map[*ir.Name]int)
|
||||
idx := 1
|
||||
for _, selfn := range types.RecvsParamsResults {
|
||||
fsl := selfn(fn.Type()).FieldSlice()
|
||||
for _, f := range fsl {
|
||||
if n, ok := f.Nname.(*ir.Name); ok {
|
||||
paramOrder[n] = idx
|
||||
idx++
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Stable(varsAndDecls{decls, vars, paramOrder})
|
||||
}
|
||||
|
||||
type varsAndDecls struct {
|
||||
decls []*ir.Name
|
||||
vars []*dwarf.Var
|
||||
paramOrder map[*ir.Name]int
|
||||
}
|
||||
|
||||
func (v varsAndDecls) Len() int {
|
||||
return len(v.decls)
|
||||
}
|
||||
|
||||
func (v varsAndDecls) Less(i, j int) bool {
|
||||
nameLT := func(ni, nj *ir.Name) bool {
|
||||
oi, foundi := v.paramOrder[ni]
|
||||
oj, foundj := v.paramOrder[nj]
|
||||
if foundi {
|
||||
if foundj {
|
||||
return oi < oj
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
return nameLT(v.decls[i], v.decls[j])
|
||||
}
|
||||
|
||||
func (v varsAndDecls) Swap(i, j int) {
|
||||
v.vars[i], v.vars[j] = v.vars[j], v.vars[i]
|
||||
v.decls[i], v.decls[j] = v.decls[j], v.decls[i]
|
||||
}
|
||||
|
||||
// Given a function that was inlined at some point during the
|
||||
// compilation, return a sorted list of nodes corresponding to the
|
||||
// autos/locals in that function prior to inlining. If this is a
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue