Windows int32
Goroot string
- // Map for fast access of symbols based on name.
- HashName map[string]*LSym
- // Fallback map based also on version, for symbols
- // with more than one version (see func _lookup).
- HashVersion map[symVer]*LSym
+ // Symbol lookup based on name and indexed by version.
+ Hash []map[string]*LSym
Allsym []*LSym
Tlsg *LSym
}
}
+func (l *Link) IncVersion() {
+ l.Version++
+ l.Hash = append(l.Hash, make(map[string]*LSym))
+}
+
type LinkArch struct {
ByteOrder binary.ByteOrder
Name string
func linknew(arch *LinkArch) *Link {
ctxt := &Link{
- HashName: make(map[string]*LSym, 100000), // preallocate about 2mb for hash
- HashVersion: make(map[symVer]*LSym),
- Allsym: make([]*LSym, 0, 100000),
- Arch: arch,
- Version: obj.HistVersion,
- Goroot: obj.Getgoroot(),
+ Hash: []map[string]*LSym{
+ // preallocate about 2mb for hash of
+ // non static symbols
+ make(map[string]*LSym, 100000),
+ },
+ Allsym: make([]*LSym, 0, 100000),
+ Arch: arch,
+ Goroot: obj.Getgoroot(),
}
p := obj.Getgoarch()
return ctxt
}
-func linknewsym(ctxt *Link, symb string, v int) *LSym {
+func linknewsym(ctxt *Link, name string, v int) *LSym {
batch := ctxt.LSymBatch
if len(batch) == 0 {
batch = make([]LSym, 1000)
s.Dynid = -1
s.Plt = -1
s.Got = -1
- s.Name = symb
+ s.Name = name
s.Version = int16(v)
ctxt.Allsym = append(ctxt.Allsym, s)
return s
}
-type symVer struct {
- sym string
- ver int
-}
-
-func _lookup(ctxt *Link, symb string, v int, creat int) *LSym {
- // Most symbols have only a single version, and a string key
- // is faster to search for. So we store the first symbol in HashName,
- // keyed only by symbol name. If there are name collisions, the
- // alternate versions are stored in the spill over map
- // HashVersion.
- s, exist := ctxt.HashName[symb]
+func Linklookup(ctxt *Link, name string, v int) *LSym {
+ m := ctxt.Hash[v]
+ s := m[name]
if s != nil {
- if int(s.Version) == v {
- return s
- }
- s = ctxt.HashVersion[symVer{symb, v}]
- if s != nil {
- return s
- }
- }
- if creat == 0 {
- return nil
+ return s
}
-
- s = linknewsym(ctxt, symb, v)
+ s = linknewsym(ctxt, name, v)
s.Extname = s.Name
- if exist {
- ctxt.HashVersion[symVer{symb, v}] = s
- } else {
- ctxt.HashName[symb] = s
- }
+ m[name] = s
return s
}
-func Linklookup(ctxt *Link, name string, v int) *LSym {
- return _lookup(ctxt, name, v, 1)
-}
-
// read-only lookup
func Linkrlookup(ctxt *Link, name string, v int) *LSym {
- return _lookup(ctxt, name, v, 0)
+ return ctxt.Hash[v][name]
}
func Headstr(v int) string {