go: Use build CC when build cpu == target cpu

go compiler needs to run on the host machine. But go
build system does not differentiate between target tuples
e.g. x86_64-pc-linux-gnu and x86_64-cros-linux-gnu.

Since go binary needs to run on the host, it needs to be
built with BUILD CC, not TARGET CC. This fixes a build error
in glibc upgrade.

Go standard library will continue to be built with TARGET CC.

BUG=b/189265774
TEST=presubmit
RELEASE_NOTE=None

Change-Id: If8d1589ed91df67972477b02c53aa1070d178c73
Reviewed-on: https://cos-review.googlesource.com/c/third_party/overlays/chromiumos-overlay/+/17051
Reviewed-by: Roy Yang <royyang@google.com>
Tested-by: Cusky Presubmit Bot <presubmit@cos-infra-prod.iam.gserviceaccount.com>
diff --git a/dev-lang/go/go-1.15.7-r1.ebuild b/dev-lang/go/go-1.15.7-r2.ebuild
similarity index 100%
rename from dev-lang/go/go-1.15.7-r1.ebuild
rename to dev-lang/go/go-1.15.7-r2.ebuild
diff --git a/dev-lang/go/go-1.15.7.ebuild b/dev-lang/go/go-1.15.7.ebuild
index 849a9b5..d81562e 100644
--- a/dev-lang/go/go-1.15.7.ebuild
+++ b/dev-lang/go/go-1.15.7.ebuild
@@ -72,9 +72,15 @@
 
 	cd "${S}/src"
 	einfo "Building the cross compiler for ${CTARGET}."
-	GOOS="linux" GOARCH="$(get_goarch ${CTARGET})" CGO_ENABLED="1" \
-		CC_FOR_TARGET="$(tc-getTARGET_CC)" \
-		CXX_FOR_TARGET="$(tc-getTARGET_CXX)" \
+	local go_target_cc="$(tc-getTARGET_CC)"
+	local go_target_cxx="$(tc-getTARGET_CXX)"
+	if [[ "$(tc-arch "${CBUILD}")" == "$(tc-arch "${CTARGET}")" ]]; then
+		go_target_cc="$(tc-getBUILD_CC)"
+		go_target_cxx="$(tc-getBUILD_CXX)"
+	fi
+	GOOS="linux" GOARCH="$(get_goarch "${CTARGET}")" CGO_ENABLED="1" \
+		CC_FOR_TARGET="${go_target_cc}" \
+		CXX_FOR_TARGET="${go_target_cxx}" \
 		./make.bash || die
 
 	if is_cross ; then