golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.04k stars 17.44k forks source link

cmd/cgo: arch list is not in sync with cmd/go and go/build arch list #45644

Open perillo opened 3 years ago

perillo commented 3 years ago

There are currently 3 places where supported architectures are enumerated:

The problem is that the list in cmd/cgo/main.go is out of sync with the other lists.

From cmd/cgo/main.go:

var ptrSizeMap = map[string]int64{
    "386":      4,
    "alpha":    8,
    "amd64":    8,
    "arm":      4,
    "arm64":    8,
    "m68k":     4,
    "mips":     4,
    "mipsle":   4,
    "mips64":   8,
    "mips64le": 8,
    "nios2":    4,
    "ppc":      4,
    "ppc64":    8,
    "ppc64le":  8,
    "riscv":    4,
    "riscv64":  8,
    "s390":     4,
    "s390x":    8,
    "sh":       4,
    "shbe":     4,
    "sparc":    4,
    "sparc64":  8,
}

From cmd/go/internal/imports/build.go:

var KnownArch = map[string]bool{
    "386":         true,
    "amd64":       true,
    "amd64p32":    true, // legacy; don't remove
    "arm":         true,
    "armbe":       true,
    "arm64":       true,
    "arm64be":     true,
    "ppc64":       true,
    "ppc64le":     true,
    "mips":        true,
    "mipsle":      true,
    "mips64":      true,
    "mips64le":    true,
    "mips64p32":   true,
    "mips64p32le": true,
    "ppc":         true,
    "riscv":       true,
    "riscv64":     true,
    "s390":        true,
    "s390x":       true,
    "sparc":       true,
    "sparc64":     true,
    "wasm":        true,
}

cgo have alpha, m68k nios2 sh and shbe, and is missing amd64p32, mips64p32 and mips64p32le. I don't know if there is a reason for the difference, but the problem is that the additional architectures known to cgo are used as a build tag in cmd/vendor/golang.org/x/sys/unix (in endian_big.go and endian_big.go), and since they are not known by go, they are probably ignored.

Another small issues is that the architecture list in cmd/go/internal/imports/build.go is not sorted correctly.

I'm not sure if this should be reported as an issue about cmd/cgo or about golang.org/x/sys/unix. Probably this is harmless.

perillo commented 3 years ago

This is the change for golang.org/x/sys: https://golang.org/cl/270317.

ianlancetaylor commented 3 years ago

The additional architectures in cmd/cgo and the build tags in golang.org/x/sys are supported by gccgo, and they are used when the package is built by gccgo. So I don't think that anything is actually broken.

But it would be better if all the architectures were reflected in all of those locations.

perillo commented 3 years ago

The problem is that, as far as I can understand, a tag like nios2 will simply be ignored by go build, since it is not a know GOARCH.

ianlancetaylor commented 3 years ago

gccgo has its own copy of the go command.