Skip to content

Commit f4f1b30

Browse files
committed
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 <[email protected]>
1 parent ed41054 commit f4f1b30

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/cmd/compile/internal/gc/main.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,24 @@ func loadsys() {
643643
iota_ = -1000000
644644
incannedimport = 1
645645

646-
importpkg = Runtimepkg
647-
parse_import(bufio.NewReader(strings.NewReader(runtimeimport)), nil)
648-
649-
importpkg = unsafepkg
650-
parse_import(bufio.NewReader(strings.NewReader(unsafeimport)), nil)
646+
// The first byte in the binary export format is a 'c' or 'd'
647+
// specifying the encoding format. We could just check that
648+
// byte, but this is a perhaps more robust. Also, it is not
649+
// speed-critical.
650+
// TODO(gri) simplify once textual export format has gone
651+
if strings.HasPrefix(runtimeimport, "package") {
652+
// textual export format
653+
importpkg = Runtimepkg
654+
parse_import(bufio.NewReader(strings.NewReader(runtimeimport)), nil)
655+
importpkg = unsafepkg
656+
parse_import(bufio.NewReader(strings.NewReader(unsafeimport)), nil)
657+
} else {
658+
// binary export format
659+
importpkg = Runtimepkg
660+
Import(bufio.NewReader(strings.NewReader(runtimeimport)))
661+
importpkg = unsafepkg
662+
Import(bufio.NewReader(strings.NewReader(unsafeimport)))
663+
}
651664

652665
importpkg = nil
653666
incannedimport = 0

0 commit comments

Comments
 (0)