d40cd88
diff -up go/src/cmd/dist/buildtool.go.bootstrap go/src/cmd/dist/buildtool.go
5767354
--- go/src/cmd/dist/buildtool.go.bootstrap	2017-07-11 12:05:00.041373419 +0200
5767354
+++ go/src/cmd/dist/buildtool.go	2017-07-11 12:07:27.141775914 +0200
5767354
@@ -153,18 +153,26 @@ func bootstrapBuildTools() {
d36359a
 	defer os.Setenv("GOBIN", os.Getenv("GOBIN"))
8d165df
 	os.Setenv("GOBIN", "")
8d165df
 
5767354
+    hostos := os.Getenv("GOHOSTOS")
5767354
+    hostarch := os.Getenv("GOHOSTARCH")
d36359a
+
d36359a
 	os.Setenv("GOOS", "")
d36359a
 	os.Setenv("GOHOSTOS", "")
d36359a
 	os.Setenv("GOARCH", "")
8d165df
 	os.Setenv("GOHOSTARCH", "")
8d165df
 
5767354
+    bingopath := pathf("%s/bin/%s_%s/go", goroot_bootstrap, hostos, hostarch)
5767354
+    if _, err := os.Stat(bingopath); os.IsNotExist(err) {
5767354
+       bingopath = pathf("%s/bin/go", goroot_bootstrap)
5767354
+    }
8d165df
+
d36359a
 	// Run Go 1.4 to build binaries. Use -gcflags=-l to disable inlining to
d36359a
 	// workaround bugs in Go 1.4's compiler. See discussion thread:
d36359a
 	// https://groups.google.com/d/msg/golang-dev/Ss7mCKsvk8w/Gsq7VYI0AwAJ
100fcef
 	// Use the math_big_pure_go build tag to disable the assembly in math/big
100fcef
 	// which may contain unsupported instructions.
5767354
 	cmd := []string{
5767354
-		pathf("%s/bin/go", goroot_bootstrap),
5767354
+		bingopath,
5767354
 		"install",
5767354
 		"-gcflags=-l",
5767354
 		"-tags=math_big_pure_go",
d40cd88
diff -up go/src/make.bash.bootstrap go/src/make.bash
5767354
--- go/src/make.bash.bootstrap	2017-07-11 12:05:00.036373439 +0200
5767354
+++ go/src/make.bash	2017-07-11 12:05:00.041373419 +0200
100fcef
@@ -120,8 +120,15 @@ echo '##### Building Go bootstrap tool.'
8d165df
 echo cmd/dist
8d165df
 export GOROOT="$(cd .. && pwd)"
8d165df
 GOROOT_BOOTSTRAP=${GOROOT_BOOTSTRAP:-$HOME/go1.4}
8d165df
-if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then
8d165df
-	echo "ERROR: Cannot find $GOROOT_BOOTSTRAP/bin/go." >&2
8d165df
+if [ -x "$GOROOT_BOOTSTRAP/bin/${GOHOSTOS}_${GOHOSTARCH}/go" ]; then
8d165df
+	rm -f cmd/dist/dist
8d165df
+	GOROOT="$GOROOT_BOOTSTRAP" GOOS="" GOARCH="" "$GOROOT_BOOTSTRAP/bin/${GOHOSTOS}_${GOHOSTARCH}/go" build -o cmd/dist/dist ./cmd/dist
8d165df
+elif [ -x "$GOROOT_BOOTSTRAP/bin/go" ]; then
8d165df
+	rm -f cmd/dist/dist
8d165df
+	GOROOT="$GOROOT_BOOTSTRAP" GOOS="" GOARCH="" "$GOROOT_BOOTSTRAP/bin/go" build -o cmd/dist/dist ./cmd/dist
8d165df
+else
8d165df
+	echo "ERROR: Cannot find $GOROOT_BOOTSTRAP/bin/${GOHOSTOS}_${GOHOSTARCH}/go." >&2
8d165df
+	echo "ERROR: or $GOROOT_BOOTSTRAP/bin/${GOHOSTOS}_${GOHOSTARCH}/go." >&2
8d165df
 	echo "Set \$GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4." >&2
d40cd88
 	exit 1
8d165df
 fi
5767354
@@ -130,8 +137,6 @@ if [ "$GOROOT_BOOTSTRAP" = "$GOROOT" ];
d36359a
 	echo "Set \$GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4." >&2
d36359a
 	exit 1
d36359a
 fi
d36359a
-rm -f cmd/dist/dist
d36359a
-GOROOT="$GOROOT_BOOTSTRAP" GOOS="" GOARCH="" "$GOROOT_BOOTSTRAP/bin/go" build -o cmd/dist/dist ./cmd/dist
d36359a
 
d36359a
 # -e doesn't propagate out of eval, so check success by hand.
d36359a
 eval $(./cmd/dist/dist env -p || echo FAIL=true)