Skip to content

Commit 7a4f3b0

Browse files
timothy-kingGo LUCI
authored and
Go LUCI
committed
internal/gcimporter: require archive files
Proposal golang/go#68898 was accepted. gcexportdata.Read now supports tip and the latest two releases. FindExportData is needed only to support Read and can thus have the same support policy. Since go1.21, the only files the compiler produces with the header "go object " are either in archive files or do not contain exportdata (cmd/asm). It is therefore safe for FindExportData to require the files to be ar files. Updates golang/go#70651 Change-Id: Iec6703da6768198524e174824b0b05f95b96db90 Reviewed-on: https://go-review.googlesource.com/c/tools/+/633115 Reviewed-by: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]> Commit-Queue: Tim King <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 2f73c61 commit 7a4f3b0

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

internal/gcimporter/exportdata.go

+27-19
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ func readGopackHeader(r *bufio.Reader) (name string, size int64, err error) {
3939
}
4040

4141
// FindExportData positions the reader r at the beginning of the
42-
// export data section of an underlying GC-created object/archive
42+
// export data section of an underlying cmd/compile created archive
4343
// file by reading from it. The reader must be positioned at the
4444
// start of the file before calling this function. The hdr result
4545
// is the string before the export data, either "$$" or "$$B".
4646
// The size result is the length of the export data in bytes, or -1 if not known.
47+
//
48+
// This function is needed by [gcexportdata.Read], which must
49+
// accept inputs produced by the last two releases of cmd/compile,
50+
// plus tip.
4751
func FindExportData(r *bufio.Reader) (hdr string, size int64, err error) {
4852
// Read first line to make sure this is an object file.
4953
line, err := r.ReadSlice('\n')
@@ -52,27 +56,31 @@ func FindExportData(r *bufio.Reader) (hdr string, size int64, err error) {
5256
return
5357
}
5458

55-
if string(line) == "!<arch>\n" {
56-
// Archive file. Scan to __.PKGDEF.
57-
var name string
58-
if name, size, err = readGopackHeader(r); err != nil {
59-
return
60-
}
59+
// Is the first line an archive file signature?
60+
if string(line) != "!<arch>\n" {
61+
err = fmt.Errorf("not the start of an archive file (%q)", line)
62+
return
63+
}
6164

62-
// First entry should be __.PKGDEF.
63-
if name != "__.PKGDEF" {
64-
err = fmt.Errorf("go archive is missing __.PKGDEF")
65-
return
66-
}
65+
// Archive file. Scan to __.PKGDEF.
66+
var name string
67+
if name, size, err = readGopackHeader(r); err != nil {
68+
return
69+
}
6770

68-
// Read first line of __.PKGDEF data, so that line
69-
// is once again the first line of the input.
70-
if line, err = r.ReadSlice('\n'); err != nil {
71-
err = fmt.Errorf("can't find export data (%v)", err)
72-
return
73-
}
74-
size -= int64(len(line))
71+
// First entry should be __.PKGDEF.
72+
if name != "__.PKGDEF" {
73+
err = fmt.Errorf("go archive is missing __.PKGDEF")
74+
return
75+
}
76+
77+
// Read first line of __.PKGDEF data, so that line
78+
// is once again the first line of the input.
79+
if line, err = r.ReadSlice('\n'); err != nil {
80+
err = fmt.Errorf("can't find export data (%v)", err)
81+
return
7582
}
83+
size -= int64(len(line))
7684

7785
// Now at __.PKGDEF in archive or still at beginning of file.
7886
// Either way, line should begin with "go object ".

0 commit comments

Comments
 (0)