]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/compile: refactor aux handling in newobj sym traversal
authorThan McIntosh <thanm@google.com>
Mon, 16 Mar 2020 19:24:48 +0000 (15:24 -0400)
committerThan McIntosh <thanm@google.com>
Fri, 20 Mar 2020 16:19:07 +0000 (16:19 +0000)
Generalize symbol traversal code for aux symbols to allow for client
control over whether the walk incldues symbols referenced by
relocations on visited aux syms. This is not needed just yet but will
be required in order to support anonymous aux syms that have
relocations.

Change-Id: I898c1f398213c8d9d777dd3c40524a013b25e348
Reviewed-on: https://go-review.googlesource.com/c/go/+/223668
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/internal/obj/objfile2.go
src/cmd/internal/obj/sym.go

index 359e82e1382ce2f1e381031dcfe0663034b9e509..d3e4bd4beaeff560ccad4fa3127c4677c93c6383 100644 (file)
@@ -454,7 +454,7 @@ func debugAsmEmit(ctxt *Link) {
                        fn := func(par *LSym, aux *LSym) {
                                writeAuxSymDebug(ctxt, par, aux)
                        }
-                       ctxt.traverseAuxSyms(fn)
+                       ctxt.traverseAuxSyms(traverseAux, fn)
                }
        }
 }
index 9cd1786f67c1cd0c049767ce27cc7cd1b1a4b37f..ff5526ed45da82089f11011ba106699498c34f3e 100644 (file)
@@ -297,15 +297,20 @@ func (ctxt *Link) traverseSyms(flag traverseFlag, fn func(*LSym)) {
                                        f := func(parent *LSym, aux *LSym) {
                                                fn(aux)
                                        }
-                                       ctxt.traverseFuncAux(s, f)
+                                       ctxt.traverseFuncAux(flag, s, f)
                                }
                        }
                }
        }
 }
 
-func (ctxt *Link) traverseFuncAux(fsym *LSym, fn func(parent *LSym, aux *LSym)) {
+func (ctxt *Link) traverseFuncAux(flag traverseFlag, fsym *LSym, fn func(parent *LSym, aux *LSym)) {
        pc := &fsym.Func.Pcln
+       if flag&traverseAux == 0 {
+               // NB: should it become necessary to walk aux sym reloc references
+               // without walking the aux syms themselves, this can be changed.
+               panic("should not be here")
+       }
        for _, d := range pc.Funcdata {
                if d != nil {
                        fn(fsym, d)
@@ -331,21 +336,30 @@ func (ctxt *Link) traverseFuncAux(fsym *LSym, fn func(parent *LSym, aux *LSym))
                        continue
                }
                fn(fsym, dws)
+               if flag&traverseRefs != 0 {
+                       for _, r := range dws.R {
+                               if r.Sym != nil {
+                                       fn(dws, r.Sym)
+                               }
+                       }
+               }
        }
 }
 
 // Traverse aux symbols, calling fn for each sym/aux pair.
-func (ctxt *Link) traverseAuxSyms(fn func(parent *LSym, aux *LSym)) {
+func (ctxt *Link) traverseAuxSyms(flag traverseFlag, fn func(parent *LSym, aux *LSym)) {
        lists := [][]*LSym{ctxt.Text, ctxt.Data, ctxt.ABIAliases}
        for _, list := range lists {
                for _, s := range list {
                        if s.Gotype != nil {
-                               fn(s, s.Gotype)
+                               if flag&traverseDefs != 0 {
+                                       fn(s, s.Gotype)
+                               }
                        }
                        if s.Type != objabi.STEXT {
                                continue
                        }
-                       ctxt.traverseFuncAux(s, fn)
+                       ctxt.traverseFuncAux(flag, s, fn)
                }
        }
 }