From: Alessandro Arzilli Date: Sat, 1 May 2021 16:45:57 +0000 (+0200) Subject: cmd/compile: preserve argument order in debug_info X-Git-Tag: go1.17beta1~287 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=169155d61e;p=gostls13.git 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 Trust: Jeremy Faller --- diff --git a/src/cmd/compile/internal/dwarfgen/scope.go b/src/cmd/compile/internal/dwarfgen/scope.go index 4957e24e44..b4ae69e96f 100644 --- a/src/cmd/compile/internal/dwarfgen/scope.go +++ b/src/cmd/compile/internal/dwarfgen/scope.go @@ -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] +}