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
}
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)
}
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)
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 {
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)
}
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
}
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))
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