]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj: eliminate LSym.Version
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 20 Apr 2017 14:13:02 +0000 (07:13 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 20 Apr 2017 21:56:23 +0000 (21:56 +0000)
There were only two versions, 0 and 1,
and the only user of version 1 was the assembler,
to indicate that a symbol was static.

Rename LSym.Version to Static,
and add it to LSym.Attributes.
Simplify call-sites.

Passes toolstash-check.

Change-Id: Iabd39918f5019cce78f381d13f0481ae09f3871f
Reviewed-on: https://go-review.googlesource.com/41201
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
20 files changed:
src/cmd/asm/internal/asm/parse.go
src/cmd/compile/internal/gc/obj.go
src/cmd/compile/internal/gc/pgen.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/ssa/export_test.go
src/cmd/internal/obj/arm/asm5.go
src/cmd/internal/obj/arm/obj5.go
src/cmd/internal/obj/arm64/obj7.go
src/cmd/internal/obj/line_test.go
src/cmd/internal/obj/link.go
src/cmd/internal/obj/mips/obj0.go
src/cmd/internal/obj/objfile.go
src/cmd/internal/obj/plist.go
src/cmd/internal/obj/ppc64/asm9.go
src/cmd/internal/obj/ppc64/obj9.go
src/cmd/internal/obj/s390x/objz.go
src/cmd/internal/obj/sizeof_test.go
src/cmd/internal/obj/sym.go
src/cmd/internal/obj/x86/asm6.go
src/cmd/internal/obj/x86/obj6.go

index 07f023c3d82c8bb3a93cae2ff53ad1c9adc9bcea..a6e13db74961767dd841cfb4de26fbfcfcfbcce0 100644 (file)
@@ -585,16 +585,20 @@ func (p *Parser) symbolReference(a *obj.Addr, name string, prefix rune) {
                a.Type = obj.TYPE_INDIR
        }
        // Weirdness with statics: Might now have "<>".
-       isStatic := 0 // TODO: Really a boolean, but ctxt.Lookup wants a "version" integer.
+       isStatic := false
        if p.peek() == '<' {
-               isStatic = 1
+               isStatic = true
                p.next()
                p.get('>')
        }
        if p.peek() == '+' || p.peek() == '-' {
                a.Offset = int64(p.expr())
        }
-       a.Sym = p.ctxt.Lookup(name, isStatic)
+       if isStatic {
+               a.Sym = p.ctxt.LookupStatic(name)
+       } else {
+               a.Sym = p.ctxt.Lookup(name)
+       }
        if p.peek() == scanner.EOF {
                if prefix == 0 && p.isJump {
                        // Symbols without prefix or suffix are jump labels.
@@ -607,7 +611,7 @@ func (p *Parser) symbolReference(a *obj.Addr, name string, prefix rune) {
        p.get('(')
        reg := p.get(scanner.Ident).String()
        p.get(')')
-       p.setPseudoRegister(a, reg, isStatic != 0, prefix)
+       p.setPseudoRegister(a, reg, isStatic, prefix)
 }
 
 // setPseudoRegister sets the NAME field of addr for a pseudo-register reference such as (SB).
index 419a6ec057160f86cce5864fc6f2e7e3beddee6f..3ff5c6fa208cf5c658fb09a5acdc90c96bf76804 100644 (file)
@@ -266,7 +266,7 @@ func Linksym(s *types.Sym) *obj.LSym {
                return nil
        }
        if s.Lsym == nil {
-               s.Lsym = Ctxt.Lookup(linksymname(s), 0)
+               s.Lsym = Ctxt.Lookup(linksymname(s))
        }
        return s.Lsym
 }
@@ -337,7 +337,7 @@ func stringsym(s string) (data *obj.LSym) {
        const prefix = "go.string."
        symdataname := prefix + symname
 
-       symdata := Ctxt.Lookup(symdataname, 0)
+       symdata := Ctxt.Lookup(symdataname)
 
        if !symdata.SeenGlobl() {
                // string data
index 090cbe427aed22dced1ea90617a36c66a8d41bb5..6a3a345bf45731238916eca2781c96b36c935b01 100644 (file)
@@ -264,7 +264,7 @@ func debuginfo(fnsym *obj.LSym, curfn interface{}) []*dwarf.Var {
 
                gotype := Linksym(ngotype(n))
                fnsym.Func.Autom = append(fnsym.Func.Autom, &obj.Auto{
-                       Asym:    Ctxt.Lookup(n.Sym.Name, 0),
+                       Asym:    Ctxt.Lookup(n.Sym.Name),
                        Aoffset: int32(n.Xoffset),
                        Name:    name,
                        Gotype:  gotype,
@@ -279,7 +279,7 @@ func debuginfo(fnsym *obj.LSym, curfn interface{}) []*dwarf.Var {
                        Name:   n.Sym.Name,
                        Abbrev: abbrev,
                        Offset: int32(offs),
-                       Type:   Ctxt.Lookup(typename, 0),
+                       Type:   Ctxt.Lookup(typename),
                })
        }
 
index 1703a9a67dba18db01dfad426e789d60c5516974..3f9bf40a95c0d38cc591ba66c1cef7d8742be255 100644 (file)
@@ -447,7 +447,7 @@ func dimportpath(p *types.Pkg) {
                str = p.Path
        }
 
-       s := Ctxt.Lookup("type..importpath."+p.Prefix+".", 0)
+       s := Ctxt.Lookup("type..importpath." + p.Prefix + ".")
        ot := dnameData(s, 0, str, "", nil, false)
        ggloblLSym(s, int32(ot), obj.DUPOK|obj.RODATA)
        p.Pathsym = s
@@ -468,7 +468,7 @@ func dgopkgpathLSym(s *obj.LSym, ot int, pkg *types.Pkg) int {
                // type..importpath.""., which the linker will rewrite using the correct import path.
                // Every package that imports this one directly defines the symbol.
                // See also https://groups.google.com/forum/#!topic/golang-dev/myb9s53HxGQ.
-               ns := Ctxt.Lookup(`type..importpath."".`, 0)
+               ns := Ctxt.Lookup(`type..importpath."".`)
                return dsymptrLSym(s, ot, ns, 0)
        }
 
@@ -487,7 +487,7 @@ func dgopkgpathOffLSym(s *obj.LSym, ot int, pkg *types.Pkg) int {
                // type..importpath.""., which the linker will rewrite using the correct import path.
                // Every package that imports this one directly defines the symbol.
                // See also https://groups.google.com/forum/#!topic/golang-dev/myb9s53HxGQ.
-               ns := Ctxt.Lookup(`type..importpath."".`, 0)
+               ns := Ctxt.Lookup(`type..importpath."".`)
                return dsymptrOffLSym(s, ot, ns, 0)
        }
 
@@ -591,7 +591,7 @@ func dname(name, tag string, pkg *types.Pkg, exported bool) *obj.LSym {
                sname = fmt.Sprintf(`%s"".%d`, sname, dnameCount)
                dnameCount++
        }
-       s := Ctxt.Lookup(sname, 0)
+       s := Ctxt.Lookup(sname)
        if len(s.P) > 0 {
                return s
        }
@@ -1478,7 +1478,7 @@ func dumptypestructs() {
        // process ptabs
        if localpkg.Name == "main" && len(ptabs) > 0 {
                ot := 0
-               s := Ctxt.Lookup("go.plugin.tabs", 0)
+               s := Ctxt.Lookup("go.plugin.tabs")
                for _, p := range ptabs {
                        // Dump ptab symbol into go.pluginsym package.
                        //
@@ -1493,7 +1493,7 @@ func dumptypestructs() {
                ggloblLSym(s, int32(ot), int16(obj.RODATA))
 
                ot = 0
-               s = Ctxt.Lookup("go.plugin.exports", 0)
+               s = Ctxt.Lookup("go.plugin.exports")
                for _, p := range ptabs {
                        ot = dsymptrLSym(s, ot, Linksym(p.s), 0)
                }
index 1b18d745750561163bbf2543dfcf8c9defb52b94..e2d8a2d69b4337bfe014d27de0ba87df986736a1 100644 (file)
@@ -114,7 +114,7 @@ func (DummyFrontend) Line(_ src.XPos) string {
 func (DummyFrontend) AllocFrame(f *Func) {
 }
 func (d DummyFrontend) Syslook(s string) *obj.LSym {
-       return d.ctxt.Lookup(s, 0)
+       return d.ctxt.Lookup(s)
 }
 func (DummyFrontend) UseWriteBarrier() bool {
        return true // only writebarrier_test cares
index 447643935048c09763edf9eab1935ac9c6b5a40a..cdf41f8fd55778a91bfda09532675228eee97aa9 100644 (file)
@@ -1314,12 +1314,12 @@ func buildop(ctxt *obj.Link) {
                return
        }
 
-       deferreturn = ctxt.Lookup("runtime.deferreturn", 0)
+       deferreturn = ctxt.Lookup("runtime.deferreturn")
 
-       symdiv = ctxt.Lookup("_div", 0)
-       symdivu = ctxt.Lookup("_divu", 0)
-       symmod = ctxt.Lookup("_mod", 0)
-       symmodu = ctxt.Lookup("_modu", 0)
+       symdiv = ctxt.Lookup("_div")
+       symdivu = ctxt.Lookup("_divu")
+       symmod = ctxt.Lookup("_mod")
+       symmodu = ctxt.Lookup("_modu")
 
        var n int
 
index 49a24c9b5fc695794badeef46e53b62ce3db25e3..858d06ab7900b7849e4cddb51123b8ed507760f9 100644 (file)
@@ -66,7 +66,7 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
                        if objabi.GOARM < 7 {
                                // Replace it with BL runtime.read_tls_fallback(SB) for ARM CPUs that lack the tls extension.
                                if progedit_tlsfallback == nil {
-                                       progedit_tlsfallback = ctxt.Lookup("runtime.read_tls_fallback", 0)
+                                       progedit_tlsfallback = ctxt.Lookup("runtime.read_tls_fallback")
                                }
 
                                // MOVW LR, R11
@@ -136,9 +136,9 @@ func (c *ctxt5) rewriteToUseGot(p *obj.Prog) {
                //     CALL (R9)
                var sym *obj.LSym
                if p.As == obj.ADUFFZERO {
-                       sym = c.ctxt.Lookup("runtime.duffzero", 0)
+                       sym = c.ctxt.Lookup("runtime.duffzero")
                } else {
-                       sym = c.ctxt.Lookup("runtime.duffcopy", 0)
+                       sym = c.ctxt.Lookup("runtime.duffcopy")
                }
                offset := p.To.Offset
                p.As = AMOVW
@@ -637,7 +637,7 @@ func (c *ctxt5) softfloat() {
                return
        }
 
-       symsfloat := c.ctxt.Lookup("_sfloat", 0)
+       symsfloat := c.ctxt.Lookup("_sfloat")
 
        wasfloat := 0
        for p := c.cursym.Func.Text; p != nil; p = p.Link {
@@ -846,7 +846,7 @@ func (c *ctxt5) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
        case !c.cursym.Func.Text.From.Sym.NeedCtxt():
                morestack = "runtime.morestack_noctxt"
        }
-       call.To.Sym = c.ctxt.Lookup(morestack, 0)
+       call.To.Sym = c.ctxt.Lookup(morestack)
 
        // B start
        b := obj.Appendp(call, c.newprog)
index a4d9ee4a8b59a23adfb5e4473c94cf6608d8b868..7aa0c8df223037898d6f21e5e9a52fdd6000fefd 100644 (file)
@@ -208,7 +208,7 @@ func (c *ctxt7) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
        case !c.cursym.Func.Text.From.Sym.NeedCtxt():
                morestack = "runtime.morestack_noctxt"
        }
-       call.To.Sym = c.ctxt.Lookup(morestack, 0)
+       call.To.Sym = c.ctxt.Lookup(morestack)
 
        // B    start
        jmp := obj.Appendp(call, c.newprog)
@@ -333,9 +333,9 @@ func (c *ctxt7) rewriteToUseGot(p *obj.Prog) {
                //     CALL REGTMP
                var sym *obj.LSym
                if p.As == obj.ADUFFZERO {
-                       sym = c.ctxt.Lookup("runtime.duffzero", 0)
+                       sym = c.ctxt.Lookup("runtime.duffzero")
                } else {
-                       sym = c.ctxt.Lookup("runtime.duffcopy", 0)
+                       sym = c.ctxt.Lookup("runtime.duffcopy")
                }
                offset := p.To.Offset
                p.As = AMOVD
index 329f245464c284e09967d970e775d9531dd77f67..6b21abecd25c07d9ea58eb6be2ec9e27ac3ed1cf 100644 (file)
@@ -13,7 +13,7 @@ import (
 func TestLinkgetlineFromPos(t *testing.T) {
        ctxt := new(Link)
        ctxt.hash = make(map[string]*LSym)
-       ctxt.vhash = make(map[string]*LSym)
+       ctxt.statichash = make(map[string]*LSym)
 
        afile := src.NewFileBase("a.go", "a.go")
        bfile := src.NewFileBase("b.go", "/foo/bar/b.go")
index dafb9359aecceb0cd5f8354cc556ec7b7b81e5e8..d324eebbba54997547d67d96b36e532156d2d47d 100644 (file)
@@ -308,9 +308,8 @@ const (
 
 // An LSym is the sort of symbol that is written to an object file.
 type LSym struct {
-       Name    string
-       Type    objabi.SymKind
-       Version int16
+       Name string
+       Type objabi.SymKind
        Attribute
 
        RefIdx int // Index of this symbol in the symbol reference list.
@@ -347,6 +346,7 @@ const (
        AttrNoFrame
        AttrSeenGlobl
        AttrOnList
+       AttrStatic
 
        // MakeTypelink means that the type should have an entry in the typelink table.
        AttrMakeTypelink
@@ -380,6 +380,7 @@ func (a Attribute) Local() bool         { return a&AttrLocal != 0 }
 func (a Attribute) Wrapper() bool       { return a&AttrWrapper != 0 }
 func (a Attribute) NeedCtxt() bool      { return a&AttrNeedCtxt != 0 }
 func (a Attribute) NoFrame() bool       { return a&AttrNoFrame != 0 }
+func (a Attribute) Static() bool        { return a&AttrStatic != 0 }
 
 func (a *Attribute) Set(flag Attribute, value bool) {
        if value {
@@ -405,6 +406,7 @@ var textAttrStrings = [...]struct {
        {bit: AttrWrapper, s: "WRAPPER"},
        {bit: AttrNeedCtxt, s: "NEEDCTXT"},
        {bit: AttrNoFrame, s: "NOFRAME"},
+       {bit: AttrStatic, s: "STATIC"},
 }
 
 // TextAttrString formats a for printing in as part of a TEXT prog.
@@ -480,8 +482,8 @@ type Link struct {
        Flag_optimize bool
        Bso           *bufio.Writer
        Pathname      string
-       hash          map[string]*LSym // name -> sym mapping for version == 0
-       vhash         map[string]*LSym // name -> sym mapping for version == 1
+       hash          map[string]*LSym // name -> sym mapping
+       statichash    map[string]*LSym // name -> sym mapping for static syms
        PosTable      src.PosTable
        InlTree       InlTree // global inlining tree used by gc/inl.go
        Imports       []string
index fd53c3212e7bd4bbce005c0cf65155598dc4015d..7ed4e4d9cb525294667c118f949f46206b5fbfb8 100644 (file)
@@ -759,11 +759,11 @@ func (c *ctxt0) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
        p.As = AJAL
        p.To.Type = obj.TYPE_BRANCH
        if c.cursym.CFunc() {
-               p.To.Sym = c.ctxt.Lookup("runtime.morestackc", 0)
+               p.To.Sym = c.ctxt.Lookup("runtime.morestackc")
        } else if !c.cursym.Func.Text.From.Sym.NeedCtxt() {
-               p.To.Sym = c.ctxt.Lookup("runtime.morestack_noctxt", 0)
+               p.To.Sym = c.ctxt.Lookup("runtime.morestack_noctxt")
        } else {
-               p.To.Sym = c.ctxt.Lookup("runtime.morestack", 0)
+               p.To.Sym = c.ctxt.Lookup("runtime.morestack")
        }
        p.Mark |= BRANCH
 
index d83ccca9a66f7390f8be5e1dda45c0cbfb80ad7b..b81d5693481f77a6fd2b33db0948b35711cebb57 100644 (file)
@@ -151,17 +151,13 @@ func (w *objWriter) writeRef(s *LSym, isPath bool) {
                return
        }
        var m map[string]int
-       switch s.Version {
-       case 0:
+       if !s.Static() {
                m = w.refIdx
-       case 1:
+       } else {
                m = w.vrefIdx
-       default:
-               log.Fatalf("%s: invalid version number %d", s.Name, s.Version)
        }
 
-       idx := m[s.Name]
-       if idx != 0 {
+       if idx := m[s.Name]; idx != 0 {
                s.RefIdx = idx
                return
        }
@@ -171,7 +167,12 @@ func (w *objWriter) writeRef(s *LSym, isPath bool) {
        } else {
                w.writeString(s.Name)
        }
-       w.writeInt(int64(s.Version))
+       // Write "version".
+       if s.Static() {
+               w.writeInt(1)
+       } else {
+               w.writeInt(0)
+       }
        w.nRefs++
        s.RefIdx = w.nRefs
        m[s.Name] = w.nRefs
@@ -194,13 +195,13 @@ func (w *objWriter) writeRefs(s *LSym) {
                        w.writeRef(d, false)
                }
                for _, f := range pc.File {
-                       fsym := w.ctxt.Lookup(f, 0)
+                       fsym := w.ctxt.Lookup(f)
                        w.writeRef(fsym, true)
                }
                for _, call := range pc.InlTree.nodes {
                        w.writeRef(call.Func, false)
                        f, _ := linkgetlineFromPos(w.ctxt, call.Pos)
-                       fsym := w.ctxt.Lookup(f, 0)
+                       fsym := w.ctxt.Lookup(f)
                        w.writeRef(fsym, true)
                }
        }
@@ -209,12 +210,12 @@ func (w *objWriter) writeRefs(s *LSym) {
 func (w *objWriter) writeSymDebug(s *LSym) {
        ctxt := w.ctxt
        fmt.Fprintf(ctxt.Bso, "%s ", s.Name)
-       if s.Version != 0 {
-               fmt.Fprintf(ctxt.Bso, "v=%d ", s.Version)
-       }
        if s.Type != 0 {
                fmt.Fprintf(ctxt.Bso, "%v ", s.Type)
        }
+       if s.Static() {
+               fmt.Fprint(ctxt.Bso, "static ")
+       }
        if s.DuplicateOK() {
                fmt.Fprintf(ctxt.Bso, "dupok ")
        }
@@ -364,14 +365,14 @@ func (w *objWriter) writeSym(s *LSym) {
        }
        w.writeInt(int64(len(pc.File)))
        for _, f := range pc.File {
-               fsym := ctxt.Lookup(f, 0)
+               fsym := ctxt.Lookup(f)
                w.writeRefIndex(fsym)
        }
        w.writeInt(int64(len(pc.InlTree.nodes)))
        for _, call := range pc.InlTree.nodes {
                w.writeInt(int64(call.Parent))
                f, l := linkgetlineFromPos(w.ctxt, call.Pos)
-               fsym := ctxt.Lookup(f, 0)
+               fsym := ctxt.Lookup(f)
                w.writeRefIndex(fsym)
                w.writeInt(int64(l))
                w.writeRefIndex(call.Func)
@@ -456,7 +457,7 @@ func (ctxt *Link) dwarfSym(s *LSym) *LSym {
                ctxt.Diag("dwarfSym of non-TEXT %v", s)
        }
        if s.Func.dwarfSym == nil {
-               s.Func.dwarfSym = ctxt.Lookup(dwarf.InfoPrefix+s.Name, int(s.Version))
+               s.Func.dwarfSym = ctxt.LookupDerived(s, dwarf.InfoPrefix+s.Name)
        }
        return s.Func.dwarfSym
 }
@@ -472,5 +473,5 @@ func (ctxt *Link) populateDWARF(curfn interface{}, s *LSym) {
        if ctxt.DebugInfo != nil {
                vars = ctxt.DebugInfo(s, curfn)
        }
-       dwarf.PutFunc(dwCtxt{ctxt}, dsym, s.Name, s.Version == 0, s, s.Size, vars)
+       dwarf.PutFunc(dwCtxt{ctxt}, dsym, s.Name, !s.Static(), s, s.Size, vars)
 }
index 84858b479cdf57494b6d57bca24971282175a8ca..fbc902696f2e43c87193f90d54551b3cf191f425 100644 (file)
@@ -58,7 +58,7 @@ func Flushplist(ctxt *Link, plist *Plist, newprog ProgAlloc) {
                                if p.From.Type != TYPE_CONST || p.From.Offset != objabi.FUNCDATA_ArgsPointerMaps {
                                        ctxt.Diag("FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps")
                                }
-                               p.To.Sym = ctxt.Lookup(fmt.Sprintf("%s.args_stackmap", curtext.Name), int(curtext.Version))
+                               p.To.Sym = ctxt.LookupDerived(curtext, curtext.Name+".args_stackmap")
                        }
 
                }
@@ -95,7 +95,7 @@ func Flushplist(ctxt *Link, plist *Plist, newprog ProgAlloc) {
                        p.From.Offset = objabi.FUNCDATA_ArgsPointerMaps
                        p.To.Type = TYPE_MEM
                        p.To.Name = NAME_EXTERN
-                       p.To.Sym = ctxt.Lookup(fmt.Sprintf("%s.args_stackmap", s.Name), int(s.Version))
+                       p.To.Sym = ctxt.LookupDerived(s, s.Name+".args_stackmap")
                }
        }
 
index c835ef7f1789c1be9e0ca853b1ff18aaeb9d8b2b..c3f0a0d187bed1741784bc5da50b431daf7cbebc 100644 (file)
@@ -2292,7 +2292,7 @@ func (c *ctxt9) asmout(p *obj.Prog, o *Optab, out []uint32) {
                                // that knows the name of the tls variable. Possibly
                                // we could add some assembly syntax so that the name
                                // of the variable does not have to be assumed.
-                               rel.Sym = c.ctxt.Lookup("runtime.tls_g", 0)
+                               rel.Sym = c.ctxt.Lookup("runtime.tls_g")
                                rel.Type = objabi.R_POWER_TLS
                        }
                        o1 = AOP_RRR(c.opstorex(p.As), uint32(p.From.Reg), uint32(p.To.Index), uint32(r))
@@ -2323,7 +2323,7 @@ func (c *ctxt9) asmout(p *obj.Prog, o *Optab, out []uint32) {
                                rel := obj.Addrel(c.cursym)
                                rel.Off = int32(c.pc)
                                rel.Siz = 4
-                               rel.Sym = c.ctxt.Lookup("runtime.tls_g", 0)
+                               rel.Sym = c.ctxt.Lookup("runtime.tls_g")
                                rel.Type = objabi.R_POWER_TLS
                        }
                        o1 = AOP_RRR(c.oploadx(p.As), uint32(p.To.Reg), uint32(p.From.Index), uint32(r))
index e4c6f63ca2d3c225be595beb304972cff4b1dba1..25a7bbf79ab8f47035c2792f0cea337e3bd43bdd 100644 (file)
@@ -119,9 +119,9 @@ func (c *ctxt9) rewriteToUseGot(p *obj.Prog) {
                //     BL (CTR)
                var sym *obj.LSym
                if p.As == obj.ADUFFZERO {
-                       sym = c.ctxt.Lookup("runtime.duffzero", 0)
+                       sym = c.ctxt.Lookup("runtime.duffzero")
                } else {
-                       sym = c.ctxt.Lookup("runtime.duffcopy", 0)
+                       sym = c.ctxt.Lookup("runtime.duffcopy")
                }
                offset := p.To.Offset
                p.As = AMOVD
@@ -489,7 +489,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                                rel := obj.Addrel(c.cursym)
                                rel.Off = 0
                                rel.Siz = 8
-                               rel.Sym = c.ctxt.Lookup(".TOC.", 0)
+                               rel.Sym = c.ctxt.Lookup(".TOC.")
                                rel.Type = objabi.R_ADDRPOWER_PCREL
                        }
 
@@ -950,11 +950,11 @@ func (c *ctxt9) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
 
        var morestacksym *obj.LSym
        if c.cursym.CFunc() {
-               morestacksym = c.ctxt.Lookup("runtime.morestackc", 0)
+               morestacksym = c.ctxt.Lookup("runtime.morestackc")
        } else if !c.cursym.Func.Text.From.Sym.NeedCtxt() {
-               morestacksym = c.ctxt.Lookup("runtime.morestack_noctxt", 0)
+               morestacksym = c.ctxt.Lookup("runtime.morestack_noctxt")
        } else {
-               morestacksym = c.ctxt.Lookup("runtime.morestack", 0)
+               morestacksym = c.ctxt.Lookup("runtime.morestack")
        }
 
        if c.ctxt.Flag_shared {
index 80aee60fd2b4c1c7a084329ae7559cbf42da353a..3d3571a4611df4c0a2eb152ac22af54cd7160ae6 100644 (file)
@@ -682,11 +682,11 @@ func (c *ctxtz) stacksplitPost(p *obj.Prog, pPre *obj.Prog, pPreempt *obj.Prog,
        p.As = ABL
        p.To.Type = obj.TYPE_BRANCH
        if c.cursym.CFunc() {
-               p.To.Sym = c.ctxt.Lookup("runtime.morestackc", 0)
+               p.To.Sym = c.ctxt.Lookup("runtime.morestackc")
        } else if !c.cursym.Func.Text.From.Sym.NeedCtxt() {
-               p.To.Sym = c.ctxt.Lookup("runtime.morestack_noctxt", 0)
+               p.To.Sym = c.ctxt.Lookup("runtime.morestack_noctxt")
        } else {
-               p.To.Sym = c.ctxt.Lookup("runtime.morestack", 0)
+               p.To.Sym = c.ctxt.Lookup("runtime.morestack")
        }
 
        // BR   start
index bc28fea34625e1cd3ab8f725cf86dc43eb72a7e8..601e9e2ea64dacef09276e059a360293f9976892 100644 (file)
@@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) {
                _64bit uintptr     // size on 64bit platforms
        }{
                {Addr{}, 32, 48},
-               {LSym{}, 60, 104},
+               {LSym{}, 56, 104},
                {Prog{}, 124, 184},
        }
 
index 83f5a18801f8ec4ad662f72736296bbeffe59167..dcaed5062de9af3d6e4940f832af95395e6d108b 100644 (file)
@@ -41,7 +41,7 @@ import (
 func Linknew(arch *LinkArch) *Link {
        ctxt := new(Link)
        ctxt.hash = make(map[string]*LSym)
-       ctxt.vhash = make(map[string]*LSym)
+       ctxt.statichash = make(map[string]*LSym)
        ctxt.Arch = arch
        ctxt.Pathname = objabi.WorkingDir()
 
@@ -55,32 +55,43 @@ func Linknew(arch *LinkArch) *Link {
        return ctxt
 }
 
-// Lookup looks up the symbol with name name and version v.
-// If it does not exist, it creates it.
-func (ctxt *Link) Lookup(name string, v int) *LSym {
-       return ctxt.LookupInit(name, v, nil)
+// LookupDerived looks up or creates the symbol with name name derived from symbol s.
+// The resulting symbol will be static iff s is.
+func (ctxt *Link) LookupDerived(s *LSym, name string) *LSym {
+       if s.Static() {
+               return ctxt.LookupStatic(name)
+       }
+       return ctxt.Lookup(name)
 }
 
-// LookupInit looks up the symbol with name name and version v.
-// If it does not exist, it creates it and passes it to initfn for one-time initialization.
-func (ctxt *Link) LookupInit(name string, v int, init func(s *LSym)) *LSym {
-       var m map[string]*LSym
-       switch v {
-       case 0:
-               m = ctxt.hash
-       case 1:
-               m = ctxt.vhash
-       default:
-               ctxt.Diag("LookupInit: bad version %d", v)
-       }
-       if s := m[name]; s != nil {
-               return s
+// LookupStatic looks up the static symbol with name name.
+// If it does not exist, it creates it.
+func (ctxt *Link) LookupStatic(name string) *LSym {
+       s := ctxt.statichash[name]
+       if s == nil {
+               s = &LSym{Name: name, Attribute: AttrStatic}
+               ctxt.statichash[name] = s
        }
+       return s
+}
+
+// Lookup looks up the symbol with name name.
+// If it does not exist, it creates it.
+func (ctxt *Link) Lookup(name string) *LSym {
+       return ctxt.LookupInit(name, nil)
+}
 
-       s := &LSym{Name: name, Version: int16(v)}
-       m[name] = s
-       if init != nil {
-               init(s)
+// LookupInit looks up the symbol with name name.
+// If it does not exist, it creates it and
+// passes it to init for one-time initialization.
+func (ctxt *Link) LookupInit(name string, init func(s *LSym)) *LSym {
+       s := ctxt.hash[name]
+       if s == nil {
+               s = &LSym{Name: name}
+               ctxt.hash[name] = s
+               if init != nil {
+                       init(s)
+               }
        }
        return s
 }
@@ -88,7 +99,7 @@ func (ctxt *Link) LookupInit(name string, v int, init func(s *LSym)) *LSym {
 func (ctxt *Link) Float32Sym(f float32) *LSym {
        i := math.Float32bits(f)
        name := fmt.Sprintf("$f32.%08x", i)
-       return ctxt.LookupInit(name, 0, func(s *LSym) {
+       return ctxt.LookupInit(name, func(s *LSym) {
                s.Size = 4
                s.Set(AttrLocal, true)
        })
@@ -97,7 +108,7 @@ func (ctxt *Link) Float32Sym(f float32) *LSym {
 func (ctxt *Link) Float64Sym(f float64) *LSym {
        i := math.Float64bits(f)
        name := fmt.Sprintf("$f64.%016x", i)
-       return ctxt.LookupInit(name, 0, func(s *LSym) {
+       return ctxt.LookupInit(name, func(s *LSym) {
                s.Size = 8
                s.Set(AttrLocal, true)
        })
@@ -105,7 +116,7 @@ func (ctxt *Link) Float64Sym(f float64) *LSym {
 
 func (ctxt *Link) Int64Sym(i int64) *LSym {
        name := fmt.Sprintf("$i64.%016x", uint64(i))
-       return ctxt.LookupInit(name, 0, func(s *LSym) {
+       return ctxt.LookupInit(name, func(s *LSym) {
                s.Size = 8
                s.Set(AttrLocal, true)
        })
index 721768a18585af809d2fd7b4b031036f3802ad30..cb811e82b91374797f8fd7924e0f21315de33b2b 100644 (file)
@@ -1977,9 +1977,9 @@ func instinit(ctxt *obj.Link) {
 
        switch ctxt.Headtype {
        case objabi.Hplan9:
-               plan9privates = ctxt.Lookup("_privates", 0)
+               plan9privates = ctxt.Lookup("_privates")
        case objabi.Hnacl:
-               deferreturn = ctxt.Lookup("runtime.deferreturn", 0)
+               deferreturn = ctxt.Lookup("runtime.deferreturn")
        }
 
        for i := 1; optab[i].as != 0; i++ {
@@ -4093,7 +4093,7 @@ func (asmbuf *AsmBuf) doasm(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog) {
                                                                r.Off = int32(p.Pc + int64(asmbuf.Len()))
                                                                r.Type = objabi.R_CALL
                                                                r.Siz = 4
-                                                               r.Sym = ctxt.Lookup("__x86.get_pc_thunk."+strings.ToLower(rconv(int(dst))), 0)
+                                                               r.Sym = ctxt.Lookup("__x86.get_pc_thunk." + strings.ToLower(rconv(int(dst))))
                                                                asmbuf.PutInt32(0)
 
                                                                asmbuf.Put2(0x8B, byte(2<<6|reg[dst]|(reg[dst]<<3)))
index c25352d0bc3124daa23c2259d21a5fbde06888f1..4289dbcf8209f5ff5d775ee467c7300b85422714 100644 (file)
@@ -325,9 +325,9 @@ func rewriteToUseGot(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
                //     CALL $reg
                var sym *obj.LSym
                if p.As == obj.ADUFFZERO {
-                       sym = ctxt.Lookup("runtime.duffzero", 0)
+                       sym = ctxt.Lookup("runtime.duffzero")
                } else {
-                       sym = ctxt.Lookup("runtime.duffcopy", 0)
+                       sym = ctxt.Lookup("runtime.duffcopy")
                }
                offset := p.To.Offset
                p.As = mov
@@ -428,7 +428,7 @@ func rewriteToUseGot(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
                p1.As = ALEAL
                p1.From.Type = obj.TYPE_MEM
                p1.From.Name = obj.NAME_STATIC
-               p1.From.Sym = ctxt.Lookup("_GLOBAL_OFFSET_TABLE_", 0)
+               p1.From.Sym = ctxt.Lookup("_GLOBAL_OFFSET_TABLE_")
                p1.To.Type = obj.TYPE_REG
                p1.To.Reg = REG_BX
 
@@ -536,7 +536,7 @@ func rewriteToPcrel(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
        r.RegTo2 = 1
        q.As = obj.ACALL
        thunkname := "__x86.get_pc_thunk." + strings.ToLower(rconv(int(dst)))
-       q.To.Sym = ctxt.LookupInit(thunkname, 0, func(s *obj.LSym) { s.Set(obj.AttrLocal, true) })
+       q.To.Sym = ctxt.LookupInit(thunkname, func(s *obj.LSym) { s.Set(obj.AttrLocal, true) })
        q.To.Type = obj.TYPE_MEM
        q.To.Name = obj.NAME_EXTERN
        r.As = p.As
@@ -1154,7 +1154,7 @@ func stacksplit(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog, newprog obj.ProgA
        case !cursym.Func.Text.From.Sym.NeedCtxt():
                morestack = "runtime.morestack_noctxt"
        }
-       call.To.Sym = ctxt.Lookup(morestack, 0)
+       call.To.Sym = ctxt.Lookup(morestack)
        // When compiling 386 code for dynamic linking, the call needs to be adjusted
        // to follow PIC rules. This in turn can insert more instructions, so we need
        // to keep track of the start of the call (where the jump will be to) and the