return sym.Pkg.Prefix + "." + sym.Name
}
-func (sym *Sym) Linksym() (r *obj.LSym) {
+func (sym *Sym) Linksym() *obj.LSym {
if sym == nil {
return nil
}
- if sym.Func() {
- // This is a function symbol. Mark it as "internal ABI".
- r = Ctxt.LookupABI(sym.LinksymName(), obj.ABIInternal)
- } else {
- r = Ctxt.Lookup(sym.LinksymName())
- }
- if r.Pkg == "" {
+ initPkg := func(r *obj.LSym) {
if sym.Linkname != "" {
r.Pkg = "_"
} else {
r.Pkg = sym.Pkg.Prefix
}
}
- return
+ if sym.Func() {
+ // This is a function symbol. Mark it as "internal ABI".
+ return Ctxt.LookupABIInit(sym.LinksymName(), obj.ABIInternal, initPkg)
+ }
+ return Ctxt.LookupInit(sym.LinksymName(), initPkg)
}
// Less reports whether symbol a is ordered before symbol b.
// LookupABI looks up a symbol with the given ABI.
// If it does not exist, it creates it.
func (ctxt *Link) LookupABI(name string, abi ABI) *LSym {
+ return ctxt.LookupABIInit(name, abi, nil)
+}
+
+// LookupABI looks up a symbol with the given ABI.
+// If it does not exist, it creates it and
+// passes it to init for one-time initialization.
+func (ctxt *Link) LookupABIInit(name string, abi ABI, init func(s *LSym)) *LSym {
var hash map[string]*LSym
switch abi {
case ABI0:
s = &LSym{Name: name}
s.SetABI(abi)
hash[name] = s
+ if init != nil {
+ init(s)
+ }
}
ctxt.hashmu.Unlock()
return s