Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
perillo opened this issue Apr 20, 2021 · 4 comments
Open

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

perillo opened this issue Apr 20, 2021 · 4 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@perillo
Copy link
Contributor

perillo commented Apr 20, 2021

There are currently 3 places where supported architectures are enumerated:

  • cmd/cgo/main.go
  • cmd/go/internal/imports/build.go
  • go/build/syslist.go

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
Copy link
Contributor Author

perillo commented Apr 20, 2021

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

@ianlancetaylor
Copy link
Contributor

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
Copy link
Contributor Author

perillo commented Apr 20, 2021

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
Copy link
Contributor

gccgo has its own copy of the go command.

@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 20, 2021
@toothrot toothrot added this to the Backlog milestone Apr 20, 2021
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: Triage Backlog
Development

No branches or pull requests

4 participants