]> Cypherpunks repositories - gostls13.git/commitdiff
gopack: do not look for Go metadata in non-Go objects
authorRuss Cox <rsc@golang.org>
Thu, 3 Nov 2011 16:07:47 +0000 (12:07 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 3 Nov 2011 16:07:47 +0000 (12:07 -0400)
Fixes #2333.

R=r
CC=golang-dev
https://golang.org/cl/5316075

src/cmd/gopack/ar.c

index c02903bc7a123b8310acffbac13b840cce055d7d..9125f2987eb4eaa434402f2306239b6a6e9e0de3 100644 (file)
@@ -654,7 +654,7 @@ matchhdr(char *p, char **lastp)
 void
 scanobj(Biobuf *b, Arfile *ap, long size)
 {
-       int obj;
+       int obj, goobject;
        vlong offset, offset1;
        Dir *d;
        static int lastobj = -1;
@@ -695,9 +695,19 @@ scanobj(Biobuf *b, Arfile *ap, long size)
                return;
        }
 
+       goobject = 1;
        offset1 = Boffset(b);
        Bseek(b, offset, 0);
        p = Brdstr(b, '\n', 1);
+       
+       // After the go object header comes the Go metadata,
+       // followed by ! on a line by itself.  If this is not a Go object,
+       // the ! comes immediately.  Catch that so we can avoid
+       // the call to scanpkg below, since scanpkg assumes that the
+       // Go metadata is present.
+       if(Bgetc(b) == '!')
+               goobject = 0;
+
        Bseek(b, offset1, 0);
        if(p == nil || strncmp(p, "go object ", 10) != 0) {
                fprint(2, "gopack: malformed object file %s\n", file);
@@ -734,7 +744,7 @@ scanobj(Biobuf *b, Arfile *ap, long size)
        }
        Bseek(b, offset, 0);
        objtraverse(objsym, ap);
-       if (gflag) {
+       if (gflag && goobject) {
                scanpkg(b, size);
                Bseek(b, offset, 0);
        }