]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/compile: make read-only static temps content-addressable
authorCherry Zhang <cherryyz@google.com>
Thu, 16 Jul 2020 00:01:32 +0000 (20:01 -0400)
committerCherry Zhang <cherryyz@google.com>
Mon, 20 Jul 2020 17:26:05 +0000 (17:26 +0000)
For now, we only do this for symbols without relocations.

Mark static temps "local", as they are not referenced across DSO
boundaries. And deduplicating a local symbol and a non-local
symbol can be problematic.

Change-Id: I0a3dc4138aaeea7fd4f326998f32ab6305da8e4b
Reviewed-on: https://go-review.googlesource.com/c/go/+/243141
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/cmd/compile/internal/gc/order.go
src/cmd/compile/internal/gc/sinit.go
src/cmd/compile/internal/gc/walk.go
src/cmd/internal/obj/objfile2.go
src/cmd/internal/obj/sym.go

index 6b6107290ada62022ca2f0870826699c5a1ab8c0..50d1a2a1b0a069ef73530897867f6679967ad427 100644 (file)
@@ -206,8 +206,7 @@ func (o *Order) addrTemp(n *Node) *Node {
                // TODO: expand this to all static composite literal nodes?
                n = defaultlit(n, nil)
                dowidth(n.Type)
-               vstat := staticname(n.Type)
-               vstat.MarkReadonly()
+               vstat := readonlystaticname(n.Type)
                var s InitSchedule
                s.staticassign(vstat, n)
                if s.out != nil {
index 83274bf6a3eb2eb4496fd803b319c07b616edc1a..4a2edc7d21555bed11a5504589eb9692da33d8f3 100644 (file)
@@ -356,14 +356,22 @@ func (c initContext) String() string {
 
 var statuniqgen int // name generator for static temps
 
-// staticname returns a name backed by a static data symbol.
-// Callers should call n.MarkReadonly on the
-// returned node for readonly nodes.
+// staticname returns a name backed by a (writable) static data symbol.
+// Use readonlystaticname for read-only node.
 func staticname(t *types.Type) *Node {
        // Don't use lookupN; it interns the resulting string, but these are all unique.
        n := newname(lookup(fmt.Sprintf("%s%d", obj.StaticNamePref, statuniqgen)))
        statuniqgen++
        addvar(n, t, PEXTERN)
+       n.Sym.Linksym().Set(obj.AttrLocal, true)
+       return n
+}
+
+// readonlystaticname returns a name backed by a (writable) static data symbol.
+func readonlystaticname(t *types.Type) *Node {
+       n := staticname(t)
+       n.MarkReadonly()
+       n.Sym.Linksym().Set(obj.AttrContentAddressable, true)
        return n
 }
 
@@ -627,9 +635,10 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
 
        mode := getdyn(n, true)
        if mode&initConst != 0 && !isSmallSliceLit(n) {
-               vstat = staticname(t)
                if ctxt == inInitFunction {
-                       vstat.MarkReadonly()
+                       vstat = readonlystaticname(t)
+               } else {
+                       vstat = staticname(t)
                }
                fixedlit(ctxt, initKindStatic, n, vstat, init)
        }
@@ -773,10 +782,8 @@ func maplit(n *Node, m *Node, init *Nodes) {
                dowidth(te)
 
                // make and initialize static arrays
-               vstatk := staticname(tk)
-               vstatk.MarkReadonly()
-               vstate := staticname(te)
-               vstate.MarkReadonly()
+               vstatk := readonlystaticname(tk)
+               vstate := readonlystaticname(te)
 
                datak := nod(OARRAYLIT, nil, nil)
                datae := nod(OARRAYLIT, nil, nil)
@@ -897,8 +904,7 @@ func anylit(n *Node, var_ *Node, init *Nodes) {
 
                if var_.isSimpleName() && n.List.Len() > 4 {
                        // lay out static data
-                       vstat := staticname(t)
-                       vstat.MarkReadonly()
+                       vstat := readonlystaticname(t)
 
                        ctxt := inInitFunction
                        if n.Op == OARRAYLIT {
index 19c185d7355d4d8fca47d4baa3f972166b4b967d..8ae3d9a5c7bc599d80e44cb89ac7421fd8557411 100644 (file)
@@ -1556,8 +1556,7 @@ opswitch:
                if isStaticCompositeLiteral(n) && !canSSAType(n.Type) {
                        // n can be directly represented in the read-only data section.
                        // Make direct reference to the static data. See issue 12841.
-                       vstat := staticname(n.Type)
-                       vstat.MarkReadonly()
+                       vstat := readonlystaticname(n.Type)
                        fixedlit(inInitFunction, initKindStatic, n, vstat, init)
                        n = vstat
                        n = typecheck(n, ctxExpr)
index 858899f3a9c8a9f876dceb74ed8256aa723ba241..6ac23bc4185dd3c5797b98fb369dee46f26e104c 100644 (file)
@@ -333,7 +333,7 @@ func (w *writer) Sym(s *LSym) {
 }
 
 func (w *writer) Hash64(s *LSym) {
-       if !s.ContentAddressable() {
+       if !s.ContentAddressable() || len(s.R) != 0 {
                panic("Hash of non-content-addresable symbol")
        }
        var b goobj2.Hash64Type
@@ -342,7 +342,7 @@ func (w *writer) Hash64(s *LSym) {
 }
 
 func (w *writer) Hash(s *LSym) {
-       if !s.ContentAddressable() {
+       if !s.ContentAddressable() || len(s.R) != 0 { // TODO: currently we don't support content-addressable symbols with relocations
                panic("Hash of non-content-addresable symbol")
        }
        b := goobj2.HashType(sha1.Sum(s.P))
index 4f84fc7d98a0fd6ee7fa037b66653dd4386d9838..6285486c669ac9f2b902f28ba4230c4fe96b2753 100644 (file)
@@ -202,7 +202,7 @@ func (ctxt *Link) NumberSyms() {
 
        var idx, hashedidx, hashed64idx, nonpkgidx int32
        ctxt.traverseSyms(traverseDefs, func(s *LSym) {
-               if s.ContentAddressable() {
+               if s.ContentAddressable() && len(s.R) == 0 { // TODO: currently we don't support content-addressable symbols with relocations
                        if len(s.P) <= 8 {
                                s.PkgIdx = goobj2.PkgIdxHashed64
                                s.SymIdx = hashed64idx