Skip to content

cmd/go: should not require -arch flag for cross compiling to Darwin with cgo #59544

Closed as not planned
@scott-cotton

Description

@scott-cotton

What version of Go are you using (go version)?

$ go version
go version go1.20.3 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ubuntu/.cache/go-build"
GOENV="/home/ubuntu/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ubuntu/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ubuntu/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/ubuntu/tmp/repro/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3333528793=/tmp/go-build -gno-record-gcc-switches"

What did you do?

here is a repro:

package main

import "fmt"

/*
int number() {
    return 20;
}
*/
import "C"

func main() {
	fmt.Printf("%d\n", C.number())
}

Then on any run of the mill linux run

ubuntu@ip-172-31-33-216:~/tmp/repro$ CGO_ENABLED=1 GOOS=darwin go build .
# runtime/cgo
gcc: error: unrecognized command-line option '-arch'

What did you expect to see?

The program compile without error

What did you see instead?

see above. It seems to me the commit https://go-review.googlesource.com/c/go/+/283812 caused this, and that the flag -arch should be added when runtime.GOOS is Darwin, not when the env var GOOS is Darwin. I also tried installing clang on linux to get around this, thinking it was clang that accepted -arch, but that flag appears to be specific to Darwin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions