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/go: go test -c does still not respect all gcflags #48719

Closed
darkdragon-001 opened this issue Oct 1, 2021 · 6 comments
Closed

cmd/go: go test -c does still not respect all gcflags #48719

darkdragon-001 opened this issue Oct 1, 2021 · 6 comments
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@darkdragon-001
Copy link

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

$ go version
go version go1.17 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/USER/.cache/go-build"
GOENV="/home/USER/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/USER/go/pkg/mod"
GONOPROXY="gitlab.TLD"
GONOSUMDB="gitlab.TLD"
GOOS="linux"
GOPATH="/home/USER/go"
GOPRIVATE="gitlab.TLD"
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.17"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/tmp/pipes-test/go-pipeline-article/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-stdlib=libc++"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-stdlib=libc++ -lc++ -lc++abi"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1708645155=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Compile the following generics test code:

package main

import (
	"fmt"
)

func print[T any](s []T) {
	for _, v := range s {
		fmt.Print(v)
	}
}

func main() {
	print([]string{"Hello, ", "playground\n"})
}

func TestMain(_ *testing.T) {
	print([]string{"Hello, ", "playground\n"})
}
  • run: works go run -gcflags=-G=3 main.go
  • build: works go build -gcflags=-G=3 main.go
  • test: doesn't work go build -gcflags=-G=3 main.go

What did you expect to see?

No error.

What did you see instead?

$ go test -gcflags=-G=3 main.go
# command-line-arguments
vet: ./main.go:8:11: expected '(', found '['

Additional information

Related?

@bcmills
Copy link
Contributor

bcmills commented Oct 1, 2021

go version go1.17 linux/amd64

Generics are not fully supported in Go 1.17. Does this reproduce with a Go built from head?

What commands do you see if you add the -x flag?

@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Oct 1, 2021
@bcmills bcmills added this to the Backlog milestone Oct 1, 2021
@bcmills bcmills added the GoCommand cmd/go label Oct 1, 2021
@bcmills
Copy link
Contributor

bcmills commented Oct 1, 2021

This may be a duplicate of #47682.

@bcmills bcmills changed the title go test -c does still not respect all gcflags cmd/go: go test -c does still not respect all gcflags Oct 1, 2021
@bcmills bcmills added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Oct 1, 2021
@darkdragon-001
Copy link
Author

I tested with latest master (d55009c).

I can confirm that it works on master while it doesn't work with v1.17.1.

It only works when specifying the source file directly go build -gcflags=-G=3 main.go while it doesn't work when using current folder go build gcflags=-G=3 ..

Output with -x flag:

$ ./goroot/bin/go build -x -gcflags=-G=3 -v .
WORK=/tmp/go-build908583775
MOD/tmp_bin
mkdir -p $WORK/b001/
cat >$WORK/b001/_gomod_.go << 'EOF' # internal
package main
import _ "unsafe"
//go:linkname __debug_modinfo__ runtime.modinfo
var __debug_modinfo__ = "0w\xaf\f\x92t\b\x02A\xe1\xc1\a\xe6\xd6\x18\xe6path\tMOD/tmp_bin\nmod\tMOD\t(devel)\t\n\xf92C1\x86\x18 r\x00\x82B\x10A\x16\xd8\xf2"
EOF
cat >$WORK/b001/importcfg << 'EOF' # internal
# import config
packagefile fmt=GOROOT/pkg/linux_amd64/fmt.a
packagefile runtime=GOROOT/pkg/linux_amd64/runtime.a
EOF
cd DIR
GOROOT/pkg/tool/linux_amd64/compile -o $WORK/b001/_pkg_.a -trimpath "$WORK/b001=>" -p main -lang=go1.17 -complete -buildid z-sMC8R1MPGhU10yT-o1/z-sMC8R1MPGhU10yT-o1 -G=3 -importcfg $WORK/b001/importcfg -pack ./main.go $WORK/b001/_gomod_.go
# MOD/tmp_bin
./main.go:7:12: type parameters require go1.18 or later
./main.go:7:14: undeclared name: any (requires version go1.18 or later)
./main.go:14:7: implicit function instantiation requires go1.18 or later

@cuonglm
Copy link
Member

cuonglm commented Oct 5, 2021

@darkdragon-001 Seems that your go.mod specify go1.17? If that the case, then you need to overwrite it by passing -gcflags="-G=3 -lang=go1.18.

I would say this is duplicated of #47682, and was fixed at tip. We can close the issue then,

@bcmills bcmills closed this as completed Oct 5, 2021
@darkdragon-001
Copy link
Author

darkdragon-001 commented Oct 5, 2021

Thanks for your help! I can confirm it works! Will the fix be backported to 1.17.2?

@ianlancetaylor
Copy link
Contributor

The -G=3 option only partially works in Go 1.17, and is not documented to work there. We aren't going to backport anything related to -G=3 to the 1.17 release cycle.

@golang golang locked and limited conversation to collaborators Oct 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants