]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: preserve argument order in debug_info
authorAlessandro Arzilli <alessandro.arzilli@gmail.com>
Sat, 1 May 2021 16:45:57 +0000 (18:45 +0200)
committerThan McIntosh <thanm@google.com>
Mon, 3 May 2021 16:42:22 +0000 (16:42 +0000)
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>

src/cmd/compile/internal/dwarfgen/scope.go

index 4957e24e447978cc504d84009fefbe2f016d6270..b4ae69e96fa7c4f64adca5a488286a7838f1ce8e 100644 (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]
+}