Commit 3c1914fc authored by Russ Cox's avatar Russ Cox

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: default avatarIan Lance Taylor <iant@golang.org>
parent 4f2269ed
......@@ -750,21 +750,6 @@ func arsize(b *bufio.Reader, name string) int {
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
func addidir(dir string) {
......@@ -975,14 +960,6 @@ func importfile(f *Val) *types.Pkg {
defer impf.Close()
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
p, err := imp.ReadString('\n')
if err != nil {
......@@ -992,6 +969,22 @@ func importfile(f *Val) *types.Pkg {
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 !strings.HasPrefix(p, "go object ") {
yyerror("import %s: not a go object file: %s", file, p)
......@@ -1030,7 +1023,7 @@ func importfile(f *Val) *types.Pkg {
Ctxt.AddImport(path_)
} else {
// 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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment