mirror of
https://github.com/golang/go
synced 2024-11-20 03:04:40 -07:00
cmd/link: refactor addlib
* extract pkgname() and findlib() from the function for #18190. * rename const pkgname to const pkgdef to avoid confliction. Change-Id: Ie62509bfbddcf19cf92b5b12b598679a069e6e74 Reviewed-on: https://go-review.googlesource.com/59417 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
738acbc2f0
commit
4eca0898ec
@ -86,19 +86,18 @@ func (ctxt *Link) readImportCfg(file string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addlib(ctxt *Link, src string, obj string, pathname string) *Library {
|
func pkgname(lib string) string {
|
||||||
name := path.Clean(pathname)
|
name := path.Clean(lib)
|
||||||
|
|
||||||
// runtime.a -> runtime, runtime.6 -> runtime
|
// runtime.a -> runtime, runtime.6 -> runtime
|
||||||
pkg := name
|
pkg := name
|
||||||
if len(pkg) >= 2 && pkg[len(pkg)-2] == '.' {
|
if len(pkg) >= 2 && pkg[len(pkg)-2] == '.' {
|
||||||
pkg = pkg[:len(pkg)-2]
|
pkg = pkg[:len(pkg)-2]
|
||||||
}
|
}
|
||||||
|
return pkg
|
||||||
|
}
|
||||||
|
|
||||||
// already loaded?
|
func findlib(ctxt *Link, lib string) (string, bool) {
|
||||||
if l := ctxt.LibraryByPkg[pkg]; l != nil {
|
name := path.Clean(lib)
|
||||||
return l
|
|
||||||
}
|
|
||||||
|
|
||||||
var pname string
|
var pname string
|
||||||
isshlib := false
|
isshlib := false
|
||||||
@ -110,12 +109,13 @@ func addlib(ctxt *Link, src string, obj string, pathname string) *Library {
|
|||||||
pname = ctxt.PackageFile[name]
|
pname = ctxt.PackageFile[name]
|
||||||
if pname == "" {
|
if pname == "" {
|
||||||
ctxt.Logf("cannot find package %s (using -importcfg)\n", name)
|
ctxt.Logf("cannot find package %s (using -importcfg)\n", name)
|
||||||
return nil
|
return "", false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if filepath.IsAbs(name) {
|
if filepath.IsAbs(name) {
|
||||||
pname = name
|
pname = name
|
||||||
} else {
|
} else {
|
||||||
|
pkg := pkgname(lib)
|
||||||
// try dot, -L "libdir", and then goroot.
|
// try dot, -L "libdir", and then goroot.
|
||||||
for _, dir := range ctxt.Libdir {
|
for _, dir := range ctxt.Libdir {
|
||||||
if *FlagLinkshared {
|
if *FlagLinkshared {
|
||||||
@ -134,6 +134,19 @@ func addlib(ctxt *Link, src string, obj string, pathname string) *Library {
|
|||||||
pname = path.Clean(pname)
|
pname = path.Clean(pname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return pname, isshlib
|
||||||
|
}
|
||||||
|
|
||||||
|
func addlib(ctxt *Link, src string, obj string, lib string) *Library {
|
||||||
|
pkg := pkgname(lib)
|
||||||
|
|
||||||
|
// already loaded?
|
||||||
|
if l := ctxt.LibraryByPkg[pkg]; l != nil {
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
|
||||||
|
pname, isshlib := findlib(ctxt, lib)
|
||||||
|
|
||||||
if ctxt.Debugvlog > 1 {
|
if ctxt.Debugvlog > 1 {
|
||||||
ctxt.Logf("%5.2f addlib: %s %s pulls in %s isshlib %v\n", elapsed(), obj, src, pname, isshlib)
|
ctxt.Logf("%5.2f addlib: %s %s pulls in %s isshlib %v\n", elapsed(), obj, src, pname, isshlib)
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ func (w *outBuf) Offset() int64 {
|
|||||||
|
|
||||||
var coutbuf outBuf
|
var coutbuf outBuf
|
||||||
|
|
||||||
const pkgname = "__.PKGDEF"
|
const pkgdef = "__.PKGDEF"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Set if we see an object compiled by the host compiler that is not
|
// Set if we see an object compiled by the host compiler that is not
|
||||||
@ -811,7 +811,7 @@ func objfile(ctxt *Link, lib *Library) {
|
|||||||
goto out
|
goto out
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.HasPrefix(arhdr.name, pkgname) {
|
if !strings.HasPrefix(arhdr.name, pkgdef) {
|
||||||
Errorf(nil, "%s: cannot find package header", lib.File)
|
Errorf(nil, "%s: cannot find package header", lib.File)
|
||||||
goto out
|
goto out
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user