if ctxt.LinkMode == LinkExternal {
// Change rt0_go name to match name in runtime/cgo:main().
rt0 := ctxt.Syms.ROLookup("runtime.rt0_go", 0)
- ctxt.Syms.Rename(rt0.Name, "runtime_rt0_go", 0)
+ rt0.SetExtname("runtime_rt0_go")
- for _, s := range ctxt.Syms.Allsym {
+ for _, s := range ctxt.Textp {
if !s.Attr.CgoExport() {
continue
}
// On AIX, a exported function must have two symbols:
// - a .text symbol which must start with a ".".
// - a .data symbol which is a function descriptor.
- ctxt.Syms.Rename(s.Name, "."+name, 0)
-
- desc := ctxt.Syms.Lookup(name, 0)
+ //
+ // XXX the old code was quite confusing -- it always
+ // rename a version 0 symbol, even if s.Version is not
+ // 0, but the descriptor still points to s.
+ // And in xcoffCreateExportFile, it seems to expect a
+ // name before the renaming.
+ // I guess this happens to work as the ABIALIAS symbol
+ // and the TEXT symbol have the same address.
+ // (Do the same here for now, but using Extname.)
+ s0 := ctxt.Syms.ROLookup(s.Name, 0)
+ s0.SetExtname("." + name)
+
+ desc := ctxt.Syms.Newsym(name, 0)
desc.Type = sym.SNOPTRDATA
desc.AddAddr(ctxt.Arch, s)
desc.AddAddr(ctxt.Arch, toc)
if !s.Attr.CgoExport() {
continue
}
- if !strings.HasPrefix(s.String(), "_cgoexp_") {
+ if !strings.HasPrefix(s.Extname(), "_cgoexp_") {
continue
}
i := l.Lookup(name, ver)
return l.Syms[i]
}
- syms.Rename = func(old, new string, ver int) {
- // annoying... maybe there is a better way to do this
- if ver >= 2 {
- panic("cannot rename static symbol")
- }
- i := l.Lookup(old, ver)
- s := l.Syms[i]
- s.Name = new
- if s.Extname() == old {
- s.SetExtname(new)
- }
- delete(l.symsByName[ver], old)
-
- // This mirrors the old code. But I'm not sure if the logic of
- // handling dup in the old code actually works, or necessary.
- dupi := l.symsByName[ver][new]
- dup := l.Syms[dupi]
- if dup == nil {
- l.symsByName[ver][new] = i
- } else {
- if s.Type == 0 {
- dup.Attr |= s.Attr
- *s = *dup
- } else if dup.Type == 0 {
- s.Attr |= dup.Attr
- *dup = *s
- l.symsByName[ver][new] = i
- }
- }
+ syms.Newsym = func(name string, ver int) *sym.Symbol {
+ i := l.newExtSym(name, ver)
+ s := l.allocSym(name, ver)
+ l.installSym(i, s)
+ syms.Allsym = append(syms.Allsym, s) // XXX see above
+ return s
}
}
// if it is not found.
ROLookup func(name string, v int) *Symbol
- // Rename renames a symbol.
- Rename func(old, new string, v int)
+ // Create a symbol with the given name and version. The new symbol
+ // is not added to the lookup table and is not dedup'd with existing
+ // symbols (if any).
+ Newsym func(name string, v int) *Symbol
}
func NewSymbols() *Symbols {