go/gcimporter15: update exportdata.go to match latest version from std lib

For golang/go#17281.

Change-Id: I7bed233368939719672eb331cca1d6aef01e807d
Reviewed-on: https://go-review.googlesource.com/30591
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Robert Griesemer 2016-10-06 11:03:39 -07:00
parent 03663480fa
commit b5358b5fee
1 changed files with 8 additions and 28 deletions

View File

@ -12,7 +12,6 @@ package gcimporter
import (
"bufio"
"errors"
"fmt"
"io"
"strconv"
@ -33,7 +32,7 @@ func readGopackHeader(r *bufio.Reader) (name string, size int, err error) {
s := strings.TrimSpace(string(hdr[16+12+6+6+8:][:10]))
size, err = strconv.Atoi(s)
if err != nil || hdr[len(hdr)-2] != '`' || hdr[len(hdr)-1] != '\n' {
err = errors.New("invalid archive header")
err = fmt.Errorf("invalid archive header")
return
}
name = strings.TrimSpace(string(hdr[:16]))
@ -50,47 +49,27 @@ func FindExportData(r *bufio.Reader) (hdr string, err error) {
// Read first line to make sure this is an object file.
line, err := r.ReadSlice('\n')
if err != nil {
err = fmt.Errorf("can't find export data (%v)", err)
return
}
if string(line) == "!<arch>\n" {
// Archive file. Scan to __.PKGDEF.
var name string
var size int
if name, size, err = readGopackHeader(r); err != nil {
if name, _, err = readGopackHeader(r); err != nil {
return
}
// 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 name, _, err = readGopackHeader(r); err != nil {
return
}
}
// First real entry should be __.PKGDEF.
// First entry should be __.PKGDEF.
if name != "__.PKGDEF" {
err = errors.New("go archive is missing __.PKGDEF")
err = fmt.Errorf("go archive is missing __.PKGDEF")
return
}
// Read first line of __.PKGDEF data, so that line
// is once again the first line of the input.
if line, err = r.ReadSlice('\n'); err != nil {
err = fmt.Errorf("can't find export data (%v)", err)
return
}
}
@ -98,7 +77,7 @@ func FindExportData(r *bufio.Reader) (hdr string, err error) {
// Now at __.PKGDEF in archive or still at beginning of file.
// Either way, line should begin with "go object ".
if !strings.HasPrefix(string(line), "go object ") {
err = errors.New("not a go object file")
err = fmt.Errorf("not a Go object file")
return
}
@ -106,6 +85,7 @@ func FindExportData(r *bufio.Reader) (hdr string, err error) {
// Begins after first line starting with $$.
for line[0] != '$' {
if line, err = r.ReadSlice('\n'); err != nil {
err = fmt.Errorf("can't find export data (%v)", err)
return
}
}