mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: use file content, not suffix, to distinguish .a and .o files
This allows reading from package storage systems that may not preserve the .a suffix (used with -importcfg). Fixes #20579 (combined with CLs earlier in stack). Change-Id: If2fc6a3d01bd0170a757e1f2ba9a22a4d9be7dbf Reviewed-on: https://go-review.googlesource.com/44853 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
4f2269edbd
commit
3c1914fc46
1 changed files with 17 additions and 24 deletions
|
|
@ -750,21 +750,6 @@ func arsize(b *bufio.Reader, name string) int {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func skiptopkgdef(b *bufio.Reader) bool {
|
|
||||||
// archive header
|
|
||||||
p, err := b.ReadString('\n')
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("reading input: %v", err)
|
|
||||||
}
|
|
||||||
if p != "!<arch>\n" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// package export block should be first
|
|
||||||
sz := arsize(b, "__.PKGDEF")
|
|
||||||
return sz > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
var idirs []string
|
var idirs []string
|
||||||
|
|
||||||
func addidir(dir string) {
|
func addidir(dir string) {
|
||||||
|
|
@ -975,14 +960,6 @@ func importfile(f *Val) *types.Pkg {
|
||||||
defer impf.Close()
|
defer impf.Close()
|
||||||
imp := bufio.NewReader(impf)
|
imp := bufio.NewReader(impf)
|
||||||
|
|
||||||
const pkgSuffix = ".a"
|
|
||||||
if strings.HasSuffix(file, pkgSuffix) {
|
|
||||||
if !skiptopkgdef(imp) {
|
|
||||||
yyerror("import %s: not a package file", file)
|
|
||||||
errorexit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check object header
|
// check object header
|
||||||
p, err := imp.ReadString('\n')
|
p, err := imp.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -992,6 +969,22 @@ func importfile(f *Val) *types.Pkg {
|
||||||
p = p[:len(p)-1]
|
p = p[:len(p)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p == "!<arch>" { // package archive
|
||||||
|
// package export block should be first
|
||||||
|
sz := arsize(imp, "__.PKGDEF")
|
||||||
|
if sz <= 0 {
|
||||||
|
yyerror("import %s: not a package file", file)
|
||||||
|
errorexit()
|
||||||
|
}
|
||||||
|
p, err = imp.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("reading input: %v", err)
|
||||||
|
}
|
||||||
|
if len(p) > 0 {
|
||||||
|
p = p[:len(p)-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if p != "empty archive" {
|
if p != "empty archive" {
|
||||||
if !strings.HasPrefix(p, "go object ") {
|
if !strings.HasPrefix(p, "go object ") {
|
||||||
yyerror("import %s: not a go object file: %s", file, p)
|
yyerror("import %s: not a go object file: %s", file, p)
|
||||||
|
|
@ -1030,7 +1023,7 @@ func importfile(f *Val) *types.Pkg {
|
||||||
Ctxt.AddImport(path_)
|
Ctxt.AddImport(path_)
|
||||||
} else {
|
} else {
|
||||||
// For file "/Users/foo/go/pkg/darwin_amd64/math.a" record "math.a".
|
// For file "/Users/foo/go/pkg/darwin_amd64/math.a" record "math.a".
|
||||||
Ctxt.AddImport(file[len(file)-len(path_)-len(pkgSuffix):])
|
Ctxt.AddImport(file[len(file)-len(path_)-len(".a"):])
|
||||||
}
|
}
|
||||||
|
|
||||||
// In the importfile, if we find:
|
// In the importfile, if we find:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue