var typelinkpkg *Pkg // fake package for runtime type info (data)
-var weaktypepkg *Pkg // weak references to runtime type info
-
var unsafepkg *Pkg // package unsafe
var trackpkg *Pkg // fake package for field tracking
itabpkg.Name = "go.itab"
itabpkg.Prefix = "go.itab" // not go%2eitab
- weaktypepkg = mkpkg("go.weak.type")
-
- weaktypepkg.Name = "go.weak.type"
- weaktypepkg.Prefix = "go.weak.type" // not go%2eweak%2etype
-
typelinkpkg = mkpkg("go.typelink")
typelinkpkg.Name = "go.typelink"
typelinkpkg.Prefix = "go.typelink" // not go%2etypelink
return n
}
-func weaktypesym(t *Type) *Sym {
- p := Tconv(t, obj.FmtLeft)
- s := Pkglookup(p, weaktypepkg)
-
- //print("weaktypesym: %s -> %+S\n", p, s);
-
- return s
-}
-
// isreflexive reports whether t has a reflexive equality operator.
// That is, if x==x for all x of type t.
func isreflexive(t *Type) bool {
if s == nil || s.Attr.Reachable() {
return
}
- if strings.HasPrefix(s.Name, "go.weak.") {
- return
- }
s.Attr |= AttrReachable
s.Reachparent = parent
markQueue = append(markQueue, s)
}
}
- for _, s := range Ctxt.Allsym {
- if strings.HasPrefix(s.Name, "go.weak.") {
- s.Attr |= AttrSpecial // do not lay out in data segment
- s.Attr |= AttrReachable
- s.Attr |= AttrHidden
- }
- }
-
// record field tracking references
var buf bytes.Buffer
for _, s := range Ctxt.Allsym {
addstrdata(tracksym, buf.String())
}
-func doweak() {
- // resolve weak references only if
- // target symbol will be in binary anyway.
- for _, s := range Ctxt.Allsym {
- if strings.HasPrefix(s.Name, "go.weak.") {
- t := Linkrlookup(Ctxt, s.Name[8:], int(s.Version))
- if t != nil && t.Type != 0 && t.Attr.Reachable() {
- s.Value = t.Value
- s.Type = t.Type
- s.Outer = t
- } else {
- s.Type = obj.SCONST
- s.Value = 0
- }
-
- continue
- }
- }
-}
-
func addexport() {
if HEADTYPE == obj.Hdarwin {
return
symtab()
dodata()
address()
- doweak()
reloc()
Thearch.Asmb()
undef()
// isAuto reports whether sym is an automatically-generated data or constant symbol.
func (p *Prog) isAuto(sym goobj.SymID) bool {
- return strings.HasPrefix(sym.Name, "go.weak.") ||
- strings.HasPrefix(sym.Name, "$f64.") ||
+ return strings.HasPrefix(sym.Name, "$f64.") ||
strings.HasPrefix(sym.Name, "$f32.") ||
linkerDefined[sym.Name]
}
}
}
-// autoConst defines the automatically generated constant symbols needed by p.
-func (p *Prog) autoConst() {
- for sym := range p.Missing {
- switch {
- case strings.HasPrefix(sym.Name, "go.weak."):
- // weak symbol resolves to actual symbol if present, or else nil.
- delete(p.Missing, sym)
- targ := sym
- targ.Name = sym.Name[len("go.weak."):]
- var addr Addr
- if s := p.Syms[targ]; s != nil {
- addr = s.Addr
- }
- p.defineConst(sym.Name, addr)
- }
- }
-}
-
// defineConst defines a new symbol with the given name and constant address.
func (p *Prog) defineConst(name string, addr Addr) {
sym := goobj.SymID{Name: name}
// identical 8-byte sequences.
var autoTests = []string{
"testdata/autosection.6",
- "testdata/autoweak.6",
}
func TestAuto(t *testing.T) {
p.runtime()
p.autoData()
p.layout()
- p.autoConst()
if p.NumError > 0 {
return
}
+++ /dev/null
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Test of go.weak symbols.
-
-TEXT start(SB),7,$0
- MOVQ $autotab(SB),AX
- MOVQ $autoptr(SB),AX
- RET
-
-// go.weak.sym should resolve to sym, because sym is in the binary.
-DATA autotab+0(SB)/8, $go·weak·sym(SB)
-DATA autotab+8(SB)/8, $sym(SB)
-
-// go.weak.missingsym should resolve to 0, because missingsym is not in the binary.
-DATA autotab+16(SB)/8, $go·weak·missingsym(SB)
-DATA autotab+24(SB)/8, $0
-
-// go.weak.deadsym should resolve to 0, because deadsym is discarded during dead code removal
-DATA autotab+32(SB)/8, $go·weak·deadsym(SB)
-DATA autotab+40(SB)/8, $0
-
-GLOBL autotab(SB), $48
-
-GLOBL sym(SB), $1
-
-GLOBL deadsym(SB), $1
-
-GLOBL autoptr(SB), $0