From eec8fb5ef3a60fae575f18ec05e7c21f5589f05f Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 1 May 2018 12:42:11 -0700 Subject: [PATCH] cmd/compile: explicitly disallow mixing -iexport={false,true} flagiexport currently controls not just whether to use the indexed export format when writing out package data, but also how symbol import logic works. In particular, it enables lazy loading logic that currently doesn't work with packages imported via bimport. We could change the import logic to base decisions on the export data format used by the packages that individual symbols were loaded from, but since we expect to deprecate and remove bimport anyway and there's no need for mixing bimport and iimport, it's simpler to just disallow mixing them. Change-Id: I02dbac45062e9dd85a1a647ee46bfa0efbb67e9d Reviewed-on: https://go-review.googlesource.com/110715 Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/gc/main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index 809910d7b2a..203903d10e9 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -1115,10 +1115,21 @@ func importfile(f *Val) *types.Pkg { errorexit() } + // New indexed format is distinguished by an 'i' byte, + // whereas old export format always starts with 'c', 'd', or 'v'. if c == 'i' { + if !flagiexport { + yyerror("import %s: cannot import package compiled with -iexport=true", file) + errorexit() + } + iimport(importpkg, imp) } else { - // Old export format always starts with 'c', 'd', or 'v'. + if flagiexport { + yyerror("import %s: cannot import package compiled with -iexport=false", file) + errorexit() + } + imp.UnreadByte() Import(importpkg, imp.Reader) }