mirror of
https://github.com/golang/go
synced 2024-11-23 15:20:03 -07:00
cmd/link: refactor setCgoAttr
setCgoAttr takes a lookup function, but there's only a single call and setCgoAttr already has access to the lookup function passed at that call. Simplify setCgoAttr by eliminating the lookup parameter and calling the lookup function directly. For #40724. Change-Id: Ib27c0fa2b88c387e30423365f7757e3ba02cf7d5 Reviewed-on: https://go-review.googlesource.com/c/go/+/309338 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
10f883deb7
commit
6208b10d1e
@ -130,7 +130,7 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) {
|
|||||||
|
|
||||||
// Set symbol attributes or flags based on cgo directives.
|
// Set symbol attributes or flags based on cgo directives.
|
||||||
// Any newly discovered HOSTOBJ syms are added to 'hostObjSyms'.
|
// Any newly discovered HOSTOBJ syms are added to 'hostObjSyms'.
|
||||||
func setCgoAttr(ctxt *Link, lookup func(string, int) loader.Sym, file string, pkg string, directives [][]string, hostObjSyms map[loader.Sym]struct{}) {
|
func setCgoAttr(ctxt *Link, file string, pkg string, directives [][]string, hostObjSyms map[loader.Sym]struct{}) {
|
||||||
l := ctxt.loader
|
l := ctxt.loader
|
||||||
for _, f := range directives {
|
for _, f := range directives {
|
||||||
switch f[0] {
|
switch f[0] {
|
||||||
@ -173,7 +173,7 @@ func setCgoAttr(ctxt *Link, lookup func(string, int) loader.Sym, file string, pk
|
|||||||
if i := strings.Index(remote, "#"); i >= 0 {
|
if i := strings.Index(remote, "#"); i >= 0 {
|
||||||
remote, q = remote[:i], remote[i+1:]
|
remote, q = remote[:i], remote[i+1:]
|
||||||
}
|
}
|
||||||
s := lookup(local, 0)
|
s := l.LookupOrCreateSym(local, 0)
|
||||||
st := l.SymType(s)
|
st := l.SymType(s)
|
||||||
if st == 0 || st == sym.SXREF || st == sym.SBSS || st == sym.SNOPTRBSS || st == sym.SHOSTOBJ {
|
if st == 0 || st == sym.SXREF || st == sym.SBSS || st == sym.SNOPTRBSS || st == sym.SHOSTOBJ {
|
||||||
l.SetSymDynimplib(s, lib)
|
l.SetSymDynimplib(s, lib)
|
||||||
@ -199,7 +199,7 @@ func setCgoAttr(ctxt *Link, lookup func(string, int) loader.Sym, file string, pk
|
|||||||
}
|
}
|
||||||
local := f[1]
|
local := f[1]
|
||||||
|
|
||||||
s := lookup(local, 0)
|
s := l.LookupOrCreateSym(local, 0)
|
||||||
su := l.MakeSymbolUpdater(s)
|
su := l.MakeSymbolUpdater(s)
|
||||||
su.SetType(sym.SHOSTOBJ)
|
su.SetType(sym.SHOSTOBJ)
|
||||||
su.SetSize(0)
|
su.SetSize(0)
|
||||||
@ -222,7 +222,7 @@ func setCgoAttr(ctxt *Link, lookup func(string, int) loader.Sym, file string, pk
|
|||||||
// functions. Link.loadlib will resolve any
|
// functions. Link.loadlib will resolve any
|
||||||
// ABI aliases we find here (since we may not
|
// ABI aliases we find here (since we may not
|
||||||
// yet know it's an alias).
|
// yet know it's an alias).
|
||||||
s := lookup(local, 0)
|
s := l.LookupOrCreateSym(local, 0)
|
||||||
|
|
||||||
if l.SymType(s) == sym.SHOSTOBJ {
|
if l.SymType(s) == sym.SHOSTOBJ {
|
||||||
hostObjSyms[s] = struct{}{}
|
hostObjSyms[s] = struct{}{}
|
||||||
@ -230,7 +230,7 @@ func setCgoAttr(ctxt *Link, lookup func(string, int) loader.Sym, file string, pk
|
|||||||
|
|
||||||
switch ctxt.BuildMode {
|
switch ctxt.BuildMode {
|
||||||
case BuildModeCShared, BuildModeCArchive, BuildModePlugin:
|
case BuildModeCShared, BuildModeCArchive, BuildModePlugin:
|
||||||
if s == lookup("main", 0) {
|
if s == l.Lookup("main", 0) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -681,7 +681,7 @@ func (ctxt *Link) loadcgodirectives() {
|
|||||||
l := ctxt.loader
|
l := ctxt.loader
|
||||||
hostObjSyms := make(map[loader.Sym]struct{})
|
hostObjSyms := make(map[loader.Sym]struct{})
|
||||||
for _, d := range ctxt.cgodata {
|
for _, d := range ctxt.cgodata {
|
||||||
setCgoAttr(ctxt, ctxt.loader.LookupOrCreateSym, d.file, d.pkg, d.directives, hostObjSyms)
|
setCgoAttr(ctxt, d.file, d.pkg, d.directives, hostObjSyms)
|
||||||
}
|
}
|
||||||
ctxt.cgodata = nil
|
ctxt.cgodata = nil
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user