mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.link] cmd/link: use Extname in doxcoff
On AIX, when external linking, we need to change the function names to start with a dot and make function descriptors with the names without the dot. Currently this is done through symbol renaming, which is not friendly for switching to the loader. In this CL we use symbol's external name for this. This allows us to get rid of symbol renaming. Change-Id: If72602d17e96f0339fdac2e2321f1edfb292b5f9 Reviewed-on: https://go-review.googlesource.com/c/go/+/224940 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
ed7a491940
commit
ea93ddfaeb
3 changed files with 25 additions and 36 deletions
|
|
@ -1186,9 +1186,9 @@ func (ctxt *Link) doxcoff() {
|
|||
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
|
||||
}
|
||||
|
|
@ -1198,9 +1198,19 @@ func (ctxt *Link) doxcoff() {
|
|||
// 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)
|
||||
//
|
||||
// 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.Lookup(name, 0)
|
||||
desc := ctxt.Syms.Newsym(name, 0)
|
||||
desc.Type = sym.SNOPTRDATA
|
||||
desc.AddAddr(ctxt.Arch, s)
|
||||
desc.AddAddr(ctxt.Arch, toc)
|
||||
|
|
@ -1662,7 +1672,7 @@ func xcoffCreateExportFile(ctxt *Link) (fname string) {
|
|||
if !s.Attr.CgoExport() {
|
||||
continue
|
||||
}
|
||||
if !strings.HasPrefix(s.String(), "_cgoexp_") {
|
||||
if !strings.HasPrefix(s.Extname(), "_cgoexp_") {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2060,35 +2060,12 @@ func (l *Loader) ExtractSymbols(syms *sym.Symbols, rp map[*sym.Symbol]*sym.Symbo
|
|||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,8 +46,10 @@ type Symbols struct {
|
|||
// 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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue