cmd/compile: preserve argument order in debug_info

When regabi is used sorting by stack offset will not preserve the order
of function arguments. Trust that variables are already ordered
correctly when creating debug_info entries.

Fixes #45720

Change-Id: I1dbdd185975273f70244a23302d34f082347603d
Reviewed-on: https://go-review.googlesource.com/c/go/+/315280
Reviewed-by: Than McIntosh <thanm@google.com>
Trust: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
Alessandro Arzilli 2021-05-01 18:45:57 +02:00 committed by Than McIntosh
parent 472f519fe2
commit 169155d61e

View file

@ -36,7 +36,7 @@ func assembleScopes(fnsym *obj.LSym, fn *ir.Func, dwarfVars []*dwarf.Var, varSco
dwarfScopes[i+1].Parent = int32(parent)
}
scopeVariables(dwarfVars, varScopes, dwarfScopes)
scopeVariables(dwarfVars, varScopes, dwarfScopes, fnsym.ABI() != obj.ABI0)
if fnsym.Func().Text != nil {
scopePCs(fnsym, fn.Marks, dwarfScopes)
}
@ -44,8 +44,12 @@ func assembleScopes(fnsym *obj.LSym, fn *ir.Func, dwarfVars []*dwarf.Var, varSco
}
// scopeVariables assigns DWARF variable records to their scopes.
func scopeVariables(dwarfVars []*dwarf.Var, varScopes []ir.ScopeID, dwarfScopes []dwarf.Scope) {
sort.Stable(varsByScopeAndOffset{dwarfVars, varScopes})
func scopeVariables(dwarfVars []*dwarf.Var, varScopes []ir.ScopeID, dwarfScopes []dwarf.Scope, regabi bool) {
if regabi {
sort.Stable(varsByScope{dwarfVars, varScopes})
} else {
sort.Stable(varsByScopeAndOffset{dwarfVars, varScopes})
}
i0 := 0
for i := range dwarfVars {
@ -112,3 +116,21 @@ func (v varsByScopeAndOffset) Swap(i, j int) {
v.vars[i], v.vars[j] = v.vars[j], v.vars[i]
v.scopes[i], v.scopes[j] = v.scopes[j], v.scopes[i]
}
type varsByScope struct {
vars []*dwarf.Var
scopes []ir.ScopeID
}
func (v varsByScope) Len() int {
return len(v.vars)
}
func (v varsByScope) Less(i, j int) bool {
return v.scopes[i] < v.scopes[j]
}
func (v varsByScope) Swap(i, j int) {
v.vars[i], v.vars[j] = v.vars[j], v.vars[i]
v.scopes[i], v.scopes[j] = v.scopes[j], v.scopes[i]
}