]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add R_USETYPE relocs to func syms for autom types
authorThan McIntosh <thanm@google.com>
Thu, 26 Sep 2019 12:38:33 +0000 (08:38 -0400)
committerThan McIntosh <thanm@google.com>
Fri, 27 Sep 2019 13:56:32 +0000 (13:56 +0000)
During DWARF processing, keep track of the go type symbols for types
directly or indirectly referenced by auto variables in a function,
and add a set of dummy R_USETYPE relocations to the function's DWARF
subprogram DIE symbol.

This change is not useful on its own, but is part of a series of
changes intended to clean up handling of autom's in the compiler
and linker.

Updates #34554.

Change-Id: I974afa9b7092aa5dba808f74e00aa931249d6fe9
Reviewed-on: https://go-review.googlesource.com/c/go/+/197497
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/cmd/compile/internal/gc/pgen.go
src/cmd/internal/obj/link.go
src/cmd/internal/obj/objfile.go

index dd2294e37f1b7767efa3a2887c0d8d188ab34dcc..4d6f579928cd0cfaba37933b83fc5542271539c3 100644 (file)
@@ -376,7 +376,7 @@ func compileFunctions() {
        }
 }
 
-func debuginfo(fnsym *obj.LSym, curfn interface{}) ([]dwarf.Scope, dwarf.InlCalls) {
+func debuginfo(fnsym *obj.LSym, infosym *obj.LSym, curfn interface{}) ([]dwarf.Scope, dwarf.InlCalls) {
        fn := curfn.(*Node)
        if fn.Func.Nname != nil {
                if expect := fn.Func.Nname.Sym.Linksym(); fnsym != expect {
@@ -414,10 +414,26 @@ func debuginfo(fnsym *obj.LSym, curfn interface{}) ([]dwarf.Scope, dwarf.InlCall
                        Name:    name,
                        Gotype:  gotype,
                })
+               fnsym.Func.RecordAutoType(gotype)
        }
 
        decls, dwarfVars := createDwarfVars(fnsym, fn.Func, automDecls)
 
+       // For each type referenced by the functions auto vars, attach a
+       // dummy relocation to the function symbol to insure that the type
+       // included in DWARF processing during linking.
+       typesyms := []*obj.LSym{}
+       for t, _ := range fnsym.Func.Autot {
+               typesyms = append(typesyms, t)
+       }
+       sort.Sort(obj.BySymName(typesyms))
+       for _, sym := range typesyms {
+               r := obj.Addrel(infosym)
+               r.Sym = sym
+               r.Type = objabi.R_USETYPE
+       }
+       fnsym.Func.Autot = nil
+
        var varScopes []ScopeID
        for _, decl := range decls {
                pos := decl.Pos
@@ -643,7 +659,7 @@ func createDwarfVars(fnsym *obj.LSym, fn *Func, automDecls []*Node) ([]*Node, []
                        Name:    obj.NAME_DELETED_AUTO,
                        Gotype:  gotype,
                })
-
+               fnsym.Func.RecordAutoType(gotype)
        }
 
        return decls, vars
index 01701efe801a9cddcc4a8e2fcfd9d1bfd6baae69..4ebfc1d14f6d52d3088e90e86bd66c226d4cb472 100644 (file)
@@ -399,6 +399,7 @@ type FuncInfo struct {
        Locals   int32
        Text     *Prog
        Autom    []*Auto
+       Autot    map[*LSym]struct{}
        Pcln     Pcln
        InlMarks []InlMark
 
@@ -431,6 +432,15 @@ func (fi *FuncInfo) AddInlMark(p *Prog, id int32) {
        fi.InlMarks = append(fi.InlMarks, InlMark{p: p, id: id})
 }
 
+// Record the type symbol for an auto variable so that the linker
+// an emit DWARF type information for the type.
+func (fi *FuncInfo) RecordAutoType(gotype *LSym) {
+       if fi.Autot == nil {
+               fi.Autot = make(map[*LSym]struct{})
+       }
+       fi.Autot[gotype] = struct{}{}
+}
+
 //go:generate stringer -type ABI
 
 // ABI is the calling convention of a text symbol.
@@ -644,7 +654,7 @@ type Link struct {
        Imports            []string
        DiagFunc           func(string, ...interface{})
        DiagFlush          func()
-       DebugInfo          func(fn *LSym, curfn interface{}) ([]dwarf.Scope, dwarf.InlCalls) // if non-nil, curfn is a *gc.Node
+       DebugInfo          func(fn *LSym, info *LSym, curfn interface{}) ([]dwarf.Scope, dwarf.InlCalls) // if non-nil, curfn is a *gc.Node
        GenAbstractFunc    func(fn *LSym)
        Errors             int
 
index dbbcd1240b502f42f3149334c08dfbd823e085e6..165e618d53edcfe0beed5cd7c03af775d9bfa7dd 100644 (file)
@@ -597,7 +597,7 @@ func (ctxt *Link) populateDWARF(curfn interface{}, s *LSym, myimportpath string)
        var scopes []dwarf.Scope
        var inlcalls dwarf.InlCalls
        if ctxt.DebugInfo != nil {
-               scopes, inlcalls = ctxt.DebugInfo(s, curfn)
+               scopes, inlcalls = ctxt.DebugInfo(s, info, curfn)
        }
        var err error
        dwctxt := dwCtxt{ctxt}
@@ -654,7 +654,7 @@ func (ctxt *Link) DwarfAbstractFunc(curfn interface{}, s *LSym, myimportpath str
        if s.Func == nil {
                s.Func = new(FuncInfo)
        }
-       scopes, _ := ctxt.DebugInfo(s, curfn)
+       scopes, _ := ctxt.DebugInfo(s, absfn, curfn)
        dwctxt := dwCtxt{ctxt}
        filesym := ctxt.fileSymbol(s)
        fnstate := dwarf.FnState{
@@ -893,7 +893,7 @@ func (ft *DwarfFixupTable) Finalize(myimportpath string, trace bool) {
                fns[idx] = fn
                idx++
        }
-       sort.Sort(bySymName(fns))
+       sort.Sort(BySymName(fns))
 
        // Should not be called during parallel portion of compilation.
        if ft.ctxt.InParallel {
@@ -921,8 +921,8 @@ func (ft *DwarfFixupTable) Finalize(myimportpath string, trace bool) {
        }
 }
 
-type bySymName []*LSym
+type BySymName []*LSym
 
-func (s bySymName) Len() int           { return len(s) }
-func (s bySymName) Less(i, j int) bool { return s[i].Name < s[j].Name }
-func (s bySymName) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
+func (s BySymName) Len() int           { return len(s) }
+func (s BySymName) Less(i, j int) bool { return s[i].Name < s[j].Name }
+func (s BySymName) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }