aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/cgo
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2021-01-14 12:29:16 -0500
committerCherry Zhang <cherryyz@google.com>2021-01-14 21:55:29 +0000
commiteb330020dc42930e99d9a8c8ea3cc0972cbd230f (patch)
treeeea9c771ab7efbece0131b9a6e2070cdff2b8e90 /src/cmd/cgo
parent84e8a06f62e47bf3f126e6c7e5f39dd7ca82f421 (diff)
downloadgo-eb330020dc42930e99d9a8c8ea3cc0972cbd230f.tar.gz
go-eb330020dc42930e99d9a8c8ea3cc0972cbd230f.zip
cmd/dist, cmd/go: pass -arch for C compilation on Darwin
On Apple Silicon Mac, the C compiler has an annoying default target selection, depending on the ancestor processes' architecture. In particular, if the shell or IDE is x86, when running "go build" even with a native ARM64 Go toolchain, the C compiler defaults to x86, causing build failures. We pass "-arch" flag explicitly to avoid this situation. Fixes #43692. Fixes #43476. Updates golang/vscode-go#1087. Change-Id: I80b6a116a114e11e273c6886e377a1cc969fa3f6 Reviewed-on: https://go-review.googlesource.com/c/go/+/283812 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/cgo')
-rw-r--r--src/cmd/cgo/gcc.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go
index 111a309eb5..b5e28e3254 100644
--- a/src/cmd/cgo/gcc.go
+++ b/src/cmd/cgo/gcc.go
@@ -1549,7 +1549,14 @@ func (p *Package) gccBaseCmd() []string {
func (p *Package) gccMachine() []string {
switch goarch {
case "amd64":
+ if goos == "darwin" {
+ return []string{"-arch", "x86_64", "-m64"}
+ }
return []string{"-m64"}
+ case "arm64":
+ if goos == "darwin" {
+ return []string{"-arch", "arm64"}
+ }
case "386":
return []string{"-m32"}
case "arm":