diff options
author | Alessandro Arzilli <alessandro.arzilli@gmail.com> | 2021-05-01 18:45:57 +0200 |
---|---|---|
committer | Than McIntosh <thanm@google.com> | 2021-05-03 16:42:22 +0000 |
commit | 169155d61ede128caa8452bdff3ce9995287c138 (patch) | |
tree | 5b40c6bca7746da8392461d97b735f0f804e1ca3 /src/cmd/compile/internal/dwarfgen | |
parent | 472f519fe26652af2fcef6121e259d7f193b27cf (diff) | |
download | go-169155d61ede128caa8452bdff3ce9995287c138.tar.gz go-169155d61ede128caa8452bdff3ce9995287c138.zip |
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>
Diffstat (limited to 'src/cmd/compile/internal/dwarfgen')
-rw-r--r-- | src/cmd/compile/internal/dwarfgen/scope.go | 28 |
1 files changed, 25 insertions, 3 deletions
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] +} |