]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use file content, not suffix, to distinguish .a and .o files
authorRuss Cox <rsc@golang.org>
Thu, 1 Jun 2017 18:26:55 +0000 (14:26 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 6 Jun 2017 19:50:00 +0000 (19:50 +0000)
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>
src/cmd/compile/internal/gc/main.go

index e123648d7f2a690f54c10e5d8fff164af5c2883f..8c3878e354521910c9f689eea0c28a8b340d0946 100644 (file)
@@ -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: