// Copyright 2011 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.// This file is a copy of $GOROOT/src/go/internal/gcimporter/exportdata.go.// This file implements FindExportData.package gcimporterimport ()func ( *bufio.Reader) ( string, int64, error) {// See $GOROOT/include/ar.h. := make([]byte, 16+12+6+6+8+10+2) _, = io.ReadFull(, )if != nil {return }// leave for debuggingiffalse {fmt.Printf("header: %s", ) } := strings.TrimSpace(string([16+12+6+6+8:][:10])) , := strconv.Atoi() = int64()if != nil || [len()-2] != '`' || [len()-1] != '\n' { = fmt.Errorf("invalid archive header")return } = strings.TrimSpace(string([:16]))return}// FindExportData positions the reader r at the beginning of the// export data section of an underlying GC-created object/archive// file by reading from it. The reader must be positioned at the// start of the file before calling this function. The hdr result// is the string before the export data, either "$$" or "$$B".// The size result is the length of the export data in bytes, or -1 if not known.func ( *bufio.Reader) ( string, int64, error) {// Read first line to make sure this is an object file. , := .ReadSlice('\n')if != nil { = fmt.Errorf("can't find export data (%v)", )return }ifstring() == "!<arch>\n" {// Archive file. Scan to __.PKGDEF.varstringif , , = readGopackHeader(); != nil {return }// First entry should be __.PKGDEF.if != "__.PKGDEF" { = 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 , = .ReadSlice('\n'); != nil { = fmt.Errorf("can't find export data (%v)", )return } -= int64(len()) }// Now at __.PKGDEF in archive or still at beginning of file. // Either way, line should begin with "go object ".if !strings.HasPrefix(string(), "go object ") { = fmt.Errorf("not a Go object file")return }// Skip over object header to export data. // Begins after first line starting with $$.for [0] != '$' {if , = .ReadSlice('\n'); != nil { = fmt.Errorf("can't find export data (%v)", )return } -= int64(len()) } = string()if < 0 { = -1 }return}
The pages are generated with Goldsv0.4.9. (GOOS=linux GOARCH=amd64)