Skip to content

Commit

Permalink
cmd/compile: remove var sorting from DWARF inline generation
Browse files Browse the repository at this point in the history
When generation DWARF inline info records, the current implementation
includes a sorting pass that reorders a subprogram's child variable
DIEs based on class (param/auto) and name. This sorting is no longer
needed, and can cause problems for a debugger (if we want to use the
DWARF info for creating a call to an optimized function); this patch
removes it.

Ordering of DWARF subprogram variable/parameter DIEs is still
deterministic with this change, since it is keyed off the order in
which vars appear in the pre-inlining function "Dcl" list.

Updates #27039

Change-Id: I3b91290d11bb3b9b36fb61271d80b801841401ee
Reviewed-on: https://go-review.googlesource.com/131895
Reviewed-by: Heschi Kreinick <[email protected]>
  • Loading branch information
thanm committed Aug 29, 2018
1 parent 225981f commit 7b88b22
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 54 deletions.
27 changes: 0 additions & 27 deletions src/cmd/compile/internal/gc/dwinl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"cmd/internal/dwarf"
"cmd/internal/obj"
"cmd/internal/src"
"sort"
"strings"
)

Expand Down Expand Up @@ -96,7 +95,6 @@ func assembleInlines(fnsym *obj.LSym, dwVars []*dwarf.Var) dwarf.InlCalls {
// the pre-inlining decls for the target function and assign child
// index accordingly.
for ii, sl := range vmap {
sort.Sort(byClassThenName(sl))
var m map[varPos]int
if ii == 0 {
if !fnsym.WasInlined() {
Expand Down Expand Up @@ -311,31 +309,6 @@ func beginRange(calls []dwarf.InlCall, p *obj.Prog, ii int, imap map[int]int) *d
return &call.Ranges[len(call.Ranges)-1]
}

func cmpDwarfVar(a, b *dwarf.Var) bool {
// named before artificial
aart := 0
if strings.HasPrefix(a.Name, "~r") {
aart = 1
}
bart := 0
if strings.HasPrefix(b.Name, "~r") {
bart = 1
}
if aart != bart {
return aart < bart
}

// otherwise sort by name
return a.Name < b.Name
}

// byClassThenName implements sort.Interface for []*dwarf.Var using cmpDwarfVar.
type byClassThenName []*dwarf.Var

func (s byClassThenName) Len() int { return len(s) }
func (s byClassThenName) Less(i, j int) bool { return cmpDwarfVar(s[i], s[j]) }
func (s byClassThenName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

func dumpInlCall(inlcalls dwarf.InlCalls, idx, ilevel int) {
for i := 0; i < ilevel; i++ {
Ctxt.Logf(" ")
Expand Down
27 changes: 0 additions & 27 deletions src/cmd/compile/internal/gc/pgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"fmt"
"math/rand"
"sort"
"strings"
"sync"
"time"
)
Expand Down Expand Up @@ -594,35 +593,9 @@ func preInliningDcls(fnsym *obj.LSym) []*Node {
}
rdcl = append(rdcl, n)
}
sort.Sort(byNodeName(rdcl))
return rdcl
}

func cmpNodeName(a, b *Node) bool {
aart := 0
if strings.HasPrefix(a.Sym.Name, "~") {
aart = 1
}
bart := 0
if strings.HasPrefix(b.Sym.Name, "~") {
bart = 1
}
if aart != bart {
return aart < bart
}

aname := unversion(a.Sym.Name)
bname := unversion(b.Sym.Name)
return aname < bname
}

// byNodeName implements sort.Interface for []*Node using cmpNodeName.
type byNodeName []*Node

func (s byNodeName) Len() int { return len(s) }
func (s byNodeName) Less(i, j int) bool { return cmpNodeName(s[i], s[j]) }
func (s byNodeName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

// stackOffset returns the stack location of a LocalSlot relative to the
// stack pointer, suitable for use in a DWARF location entry. This has nothing
// to do with its offset in the user variable.
Expand Down

0 comments on commit 7b88b22

Please sign in to comment.