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: allow -buildmode=pie with -race on macOS #62318

Closed
danielslee opened this issue Aug 28, 2023 · 2 comments
Closed

cmd/go: allow -buildmode=pie with -race on macOS #62318

danielslee opened this issue Aug 28, 2023 · 2 comments
Assignees
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done. OS-Darwin
Milestone

Comments

@danielslee
Copy link

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

$ go version
go version go1.21.0 darwin/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='/Users/daniel/Library/Caches/go-build'
GOENV='/Users/daniel/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/daniel/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/daniel/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/daniel/Downloads/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/daniel/Downloads/go/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/f_/bzx32trj6ld4gd6_dcqlp1jh0000gn/T/go-build2514726154=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

go build -buildmode=pie -race something.go

What did you expect to see?

The command to work without issues.

What did you see instead?

-buildmode=pie not supported when -race is enabled

Some more context:

On darwin/arm64 -buildmode=pie is fact required and is used by default. This means that even if I do go build -race something.go I still get a PIE binary. (see the code here: https://github.com/golang/go/blob/master/src/internal/platform/supported.go#L236)

It used to be that on macOS/amd64 I would not get a PIE binary, but as of 3 weeks ago that is not the case anymore: f7b4f02

This means that you always get a PIE binary when targeting macOS, even with the -race flag, yet if you explicitly specify that you want a PIE binary, it prints out an error. This is very confusing and should be fixed.

I suggest doing something like:

index cd99a33a21..a017b20e6b 100644
--- a/src/cmd/go/internal/work/init.go
+++ b/src/cmd/go/internal/work/init.go
@@ -264,8 +264,8 @@ func buildModeInit() {
 			pkgsFilter = oneMainPkg
 		}
 	case "pie":
-		if cfg.BuildRace {
-			base.Fatalf("-buildmode=pie not supported when -race is enabled")
+		if cfg.BuildRace && cfg.Goos != "darwin" {
+			base.Fatalf("-buildmode=pie not supported when -race is enabled (except on macOS)")
 		}
 		if gccgo {
 			codegenArg = "-fPIE"

(note that the patch above is for Go 1.20 so it may be slightly different for the latest version)

@seankhliao seankhliao changed the title affected/package: go build (allow -buildmode=pie with -race on macOS) cmd/go: allow -buildmode=pie with -race on macOS Aug 28, 2023
@seankhliao
Copy link
Member

cc @golang/compiler

@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 28, 2023
@gopherbot
Copy link

Change https://go.dev/cl/523475 mentions this issue: cmd/go: allow -buildmode=pie with -race on darwin

@bcmills bcmills added this to the Go1.22 milestone Aug 28, 2023
@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 28, 2023
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 28, 2023
@panjf2000 panjf2000 self-assigned this Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done. OS-Darwin
Projects
None yet
Development

No branches or pull requests

5 participants