From: Robert Griesemer Date: Wed, 20 Apr 2016 23:41:43 +0000 (-0700) Subject: cmd/compile: accept old and new import format for builtin declarations X-Git-Tag: go1.7beta1~573 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f4f1b30749be167b7c5ecb7c775c2acd8d32ae9e;p=gostls13.git cmd/compile: accept old and new import format for builtin declarations Test with forceNewExport set to true (but continues to be disabled by default for now). Fixes #15322. Change-Id: I3b893db2206cbb79e66339284f22f4a0b20bf137 Reviewed-on: https://go-review.googlesource.com/22328 Reviewed-by: Matthew Dempsky --- diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index 2afd262fed..f6de58462e 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -643,11 +643,24 @@ func loadsys() { iota_ = -1000000 incannedimport = 1 - importpkg = Runtimepkg - parse_import(bufio.NewReader(strings.NewReader(runtimeimport)), nil) - - importpkg = unsafepkg - parse_import(bufio.NewReader(strings.NewReader(unsafeimport)), nil) + // The first byte in the binary export format is a 'c' or 'd' + // specifying the encoding format. We could just check that + // byte, but this is a perhaps more robust. Also, it is not + // speed-critical. + // TODO(gri) simplify once textual export format has gone + if strings.HasPrefix(runtimeimport, "package") { + // textual export format + importpkg = Runtimepkg + parse_import(bufio.NewReader(strings.NewReader(runtimeimport)), nil) + importpkg = unsafepkg + parse_import(bufio.NewReader(strings.NewReader(unsafeimport)), nil) + } else { + // binary export format + importpkg = Runtimepkg + Import(bufio.NewReader(strings.NewReader(runtimeimport))) + importpkg = unsafepkg + Import(bufio.NewReader(strings.NewReader(unsafeimport))) + } importpkg = nil incannedimport = 0