From 4e3127283a86b0f12bb86e6939f0ad34cd93b1d0 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 18 Dec 2013 10:53:59 -0800 Subject: [PATCH] go.tools/go/gcimporter: adjust for new .a file format R=rsc, r CC=golang-dev https://golang.org/cl/41510044 --- go/gcimporter/exportdata.go | 41 +++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/go/gcimporter/exportdata.go b/go/gcimporter/exportdata.go index c53d18cbb72..657742bb6d7 100644 --- a/go/gcimporter/exportdata.go +++ b/go/gcimporter/exportdata.go @@ -48,38 +48,35 @@ func FindExportData(r *bufio.Reader) (err error) { return } if string(line) == "!\n" { - // Archive file. Scan to __.PKGDEF, which should - // be second archive entry. + // Archive file. Scan to __.PKGDEF. var name string var size int - - // First entry should be __.GOSYMDEF. - // Older archives used __.SYMDEF, so allow that too. - // Read and discard. if name, size, err = readGopackHeader(r); err != nil { return } - if name != "__.SYMDEF" && name != "__.GOSYMDEF" { - err = errors.New("go archive does not begin with __.SYMDEF or __.GOSYMDEF") - return - } - const block = 4096 - tmp := make([]byte, block) - for size > 0 { - n := size - if n > block { - n = block + + // Optional leading __.GOSYMDEF or __.SYMDEF. + // Read and discard. + if name == "__.SYMDEF" || name == "__.GOSYMDEF" { + const block = 4096 + tmp := make([]byte, block) + for size > 0 { + n := size + if n > block { + n = block + } + if _, err = io.ReadFull(r, tmp[:n]); err != nil { + return + } + size -= n } - if _, err = io.ReadFull(r, tmp[:n]); err != nil { + + if name, size, err = readGopackHeader(r); err != nil { return } - size -= n } - // Second entry should be __.PKGDEF. - if name, size, err = readGopackHeader(r); err != nil { - return - } + // First real entry should be __.PKGDEF. if name != "__.PKGDEF" { err = errors.New("go archive is missing __.PKGDEF") return