From: Lynn Boger Date: Mon, 3 Dec 2018 22:02:20 +0000 (-0500) Subject: cmd/go: add missing gccgo checks for buildmodeInit X-Git-Tag: go1.12beta1~179 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ffac3d5a88352d4f6e8e47b9a2990352960eb5ca;p=gostls13.git cmd/go: add missing gccgo checks for buildmodeInit Some recent failures in gccgo on linux/ppc64 identified an error in buildmodeInit when buildmode=c-archive. A fix went into gofrontend, and this is the corresponding change for master. This change also includes two other updates related to gccgo in this function that were in the file from gofrontend but missing from master. Updates #29046 Change-Id: I9a894e7d728e31fb9e9344cd61d50408df7faf4a Reviewed-on: https://go-review.googlesource.com/c/152160 Run-TryBot: Lynn Boger TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/cmd/go/internal/work/init.go b/src/cmd/go/internal/work/init.go index 8d2fd10524..693a53e9ab 100644 --- a/src/cmd/go/internal/work/init.go +++ b/src/cmd/go/internal/work/init.go @@ -82,19 +82,23 @@ func buildModeInit() { pkgsFilter = pkgsNotMain case "c-archive": pkgsFilter = oneMainPkg - switch platform { - case "darwin/arm", "darwin/arm64": - codegenArg = "-shared" - default: - switch cfg.Goos { - case "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris": - if platform == "linux/ppc64" { - base.Fatalf("-buildmode=c-archive not supported on %s\n", platform) - } - // Use -shared so that the result is - // suitable for inclusion in a PIE or - // shared library. + if gccgo { + codegenArg = "-fPIC" + } else { + switch platform { + case "darwin/arm", "darwin/arm64": codegenArg = "-shared" + default: + switch cfg.Goos { + case "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris": + if platform == "linux/ppc64" { + base.Fatalf("-buildmode=c-archive not supported on %s\n", platform) + } + // Use -shared so that the result is + // suitable for inclusion in a PIE or + // shared library. + codegenArg = "-shared" + } } } cfg.ExeSuffix = ".a" @@ -129,6 +133,9 @@ func buildModeInit() { default: ldBuildmode = "exe" } + if gccgo { + codegenArg = "" + } case "exe": pkgsFilter = pkgsMain ldBuildmode = "exe" @@ -143,7 +150,7 @@ func buildModeInit() { base.Fatalf("-buildmode=pie not supported when -race is enabled") } if gccgo { - base.Fatalf("-buildmode=pie not supported by gccgo") + codegenArg = "-fPIE" } else { switch platform { case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x",