Commit 5a6f9735 authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: fail gracefully on export format skew

Import errors due to unexpected format are virtually
always due to version skew. Don't panic but report a
good error message (incl. hint that the imported package
needs to be reinstalled) if not in debugFormat mode.

Recognize export data format version and store it so
it can be used to automatically handle minor version
differences. We did this before, but not very well.

No export data format changes.

Manually tested with corrupted export data.

For #16881.

Change-Id: I53ba98ef747b1c81033a914bb61ee52991f35a90
Reviewed-on: https://go-review.googlesource.com/27814Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent 7c3fc4b8
......@@ -157,9 +157,8 @@ const debugFormat = false // default: false
// TODO(gri) disable and remove once there is only one export format again
const forceObjFileStability = true
// Current export format version.
// Must not start with 'c' or 'd' (initials of prior format).
const exportVersion = "version 1"
// Current export format version. Increase with each format change.
const exportVersion = 1
// exportInlined enables the export of inlined function bodies and related
// dependencies. The compiler should work w/o any loss of functionality with
......@@ -217,7 +216,10 @@ func export(out *bufio.Writer, trace bool) int {
}
// write version info
p.rawStringln(exportVersion)
// The version string must start with "version %d" where %d is the version
// number. Additional debugging information may follow after a blank; that
// text is ignored by the importer.
p.rawStringln(fmt.Sprintf("version %d", exportVersion))
var debug string
if debugFormat {
debug = "debug"
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment