]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: refactor gclocals sym creation
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 1 Oct 2021 22:39:21 +0000 (15:39 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 4 Oct 2021 22:38:27 +0000 (22:38 +0000)
It'll be used in second place in a subsequent change.
No functional changes.

Change-Id: I58dd12d7dde45b36995d031fc7fbb27d6eaf48d3
Reviewed-on: https://go-review.googlesource.com/c/go/+/353670
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Trust: David Crawshaw <crawshaw@golang.org>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/cmd/compile/internal/liveness/plive.go
src/cmd/internal/obj/sym.go

index 1e9d5748ccabcd93f1c5a8efcd5f9b5464fdafed..dc778a6fb91cb6d961a555e85877d67ccec36f1f 100644 (file)
@@ -15,7 +15,6 @@
 package liveness
 
 import (
-       "crypto/md5"
        "crypto/sha1"
        "fmt"
        "os"
@@ -1326,19 +1325,9 @@ func (lv *liveness) emit() (argsSym, liveSym *obj.LSym) {
                loff = objw.BitVec(&liveSymTmp, loff, locals)
        }
 
-       // Give these LSyms content-addressable names,
-       // so that they can be de-duplicated.
-       // This provides significant binary size savings.
-       //
        // These symbols will be added to Ctxt.Data by addGCLocals
        // after parallel compilation is done.
-       makeSym := func(tmpSym *obj.LSym) *obj.LSym {
-               return base.Ctxt.LookupInit(fmt.Sprintf("gclocals·%x", md5.Sum(tmpSym.P)), func(lsym *obj.LSym) {
-                       lsym.P = tmpSym.P
-                       lsym.Set(obj.AttrContentAddressable, true)
-               })
-       }
-       return makeSym(&argsSymTmp), makeSym(&liveSymTmp)
+       return base.Ctxt.GCLocalsSym(argsSymTmp.P), base.Ctxt.GCLocalsSym(liveSymTmp.P)
 }
 
 // Entry pointer for Compute analysis. Solves for the Compute of
index a272c517b3b5dd6e2486b713b8a9ab30e655ab33..a8360527ef725fdbaad5957964232e096127f20e 100644 (file)
@@ -34,6 +34,7 @@ package obj
 import (
        "cmd/internal/goobj"
        "cmd/internal/objabi"
+       "crypto/md5"
        "fmt"
        "internal/buildcfg"
        "log"
@@ -172,6 +173,14 @@ func (ctxt *Link) Int64Sym(i int64) *LSym {
        })
 }
 
+// GCLocalsSym generates a content-addressable sym containing data.
+func (ctxt *Link) GCLocalsSym(data []byte) *LSym {
+       return ctxt.LookupInit(fmt.Sprintf("gclocals·%x", md5.Sum(data)), func(lsym *LSym) {
+               lsym.P = data
+               lsym.Set(AttrContentAddressable, true)
+       })
+}
+
 // Assign index to symbols.
 // asm is set to true if this is called by the assembler (i.e. not the compiler),
 // in which case all the symbols are non-package (for now).