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

internal/cpu: confusing file names in the format <name_$(GOARCH)_$(GOOS).*> #45647

Closed
perillo opened this issue Apr 20, 2021 · 1 comment
Closed

Comments

@perillo
Copy link
Contributor

perillo commented Apr 20, 2021

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

$ go version
go version go1.17-fe26dfadc3 Tue Apr 20 02:42:23 2021 +0000 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="on"
GOARCH="amd64"
GOBIN="/home/manlio/.local/bin"
GOCACHE="/home/manlio/.cache/go-build"
GOENV="/home/manlio/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE="*.local"
GOMODCACHE="/home/manlio/.local/lib/go/pkg/mod"
GONOPROXY=""
GONOSUMDB="*.local"
GOOS="linux"
GOPATH="/home/manlio/.local/lib/go:/home/manlio/src/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/manlio/src/contrib/go/go.googlesource.com/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/manlio/src/contrib/go/go.googlesource.com/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2214149710=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version devel go1.17-fe26dfadc3 Tue Apr 20 02:42:23 2021 +0000 linux/amd64
GOROOT/bin/go tool compile -V: compile version devel go1.17-fe26dfadc3 Tue Apr 20 02:42:23 2021 +0000
uname -sr: Linux 5.11.15-arch1-2
/usr/lib/libc.so.6: GNU C Library (GNU libc) release release version 2.33.
gdb --version: GNU gdb (GDB) 10.1

What did you do?

The .go file names in the internal/cpu package have the format name_$(GOARCH)_$(GOOS).*, instead of name_$(GOOS)_$(GOARCH).*.
This is not only confusing, but the source code has to explicitly add the tag for GOARCH.

As an example for cpu_arm64_freebsd.go, the file declares:

//go:build arm64
// +build arm64
@martisch
Copy link
Contributor

martisch commented Apr 20, 2021

This is intentional. internal/cpu is special in that it shares common code along OSes in a CPU specific file (e.g. 'cpu_ppc64x.go') and there are some differences in OSes where the os specific code is called from the top level CPU specific file. As such files are grouped by GOARCH first and GOOS second.

While it might be confusing there is not much change in internal/cpu and changes are made by hand full of people and its a very internal part of the go library and not exposed outside. When forgetting to set the build tags the compilation on builders will fail so this is not silently introducing bugs if forgotten. There is a reason to keep grouping this CPU specific package in a special way. If the request is to make some linter happy I would suggest to ignore the linter.

@golang golang locked and limited conversation to collaborators Apr 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants