From 407010ef0b858a7fa6e6e95abe652fdff923da9a Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sat, 27 Jul 2019 16:14:16 -0700 Subject: [PATCH] cmd/go: only pass -fsplit-stack to gccgo if supported Also add other gccgo options. This ports CL 45695 and CL 48592 from the gofrontend repo to the gc repo. CL 45695 (partial entry, other parts out of date and not ported): cmd/go: gccgo: consistent results Pass the -fdebug-prefix-map and -gno-record-gcc-switches compiler options to gccgo to generate consistent results. CL 48592: cmd/go: use gccSupportsFlag for -fsplit-stack Don't assume that all (or only) 386/amd64 compilers support -fsplit-stack. Fixes #33108 Change-Id: I61f9e5a67e4fb059f26750e97621d27afa566ec2 Reviewed-on: https://go-review.googlesource.com/c/go/+/187824 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills --- src/cmd/go/internal/work/exec.go | 3 +-- src/cmd/go/internal/work/gccgo.go | 14 +++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index 944b23f1d8..b68f902853 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -2532,8 +2532,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo } if cfg.BuildToolchainName == "gccgo" { - switch cfg.Goarch { - case "386", "amd64": + if b.gccSupportsFlag([]string{BuildToolchain.compiler()}, "-fsplit-stack") { cgoCFLAGS = append(cgoCFLAGS, "-fsplit-stack") } cgoflags = append(cgoflags, "-gccgo") diff --git a/src/cmd/go/internal/work/gccgo.go b/src/cmd/go/internal/work/gccgo.go index 36726d369b..24d856ca1e 100644 --- a/src/cmd/go/internal/work/gccgo.go +++ b/src/cmd/go/internal/work/gccgo.go @@ -67,6 +67,8 @@ func (tools gccgoToolchain) gc(b *Builder, a *Action, archive string, importcfg ofile = objdir + out gcargs := []string{"-g"} gcargs = append(gcargs, b.gccArchArgs()...) + gcargs = append(gcargs, "-fdebug-prefix-map="+b.WorkDir+"=/tmp/go-build") + gcargs = append(gcargs, "-gno-record-gcc-switches") if pkgpath := gccgoPkgpath(p); pkgpath != "" { gcargs = append(gcargs, "-fgo-pkgpath="+pkgpath) } @@ -528,12 +530,18 @@ func (tools gccgoToolchain) cc(b *Builder, a *Action, ofile, cfile string) error if pkgpath := gccgoCleanPkgpath(p); pkgpath != "" { defs = append(defs, `-D`, `GOPKGPATH="`+pkgpath+`"`) } - switch cfg.Goarch { - case "386", "amd64": + compiler := envList("CC", cfg.DefaultCC(cfg.Goos, cfg.Goarch)) + if b.gccSupportsFlag(compiler, "-fsplit-stack") { defs = append(defs, "-fsplit-stack") } defs = tools.maybePIC(defs) - return b.run(a, p.Dir, p.ImportPath, nil, envList("CC", cfg.DefaultCC(cfg.Goos, cfg.Goarch)), "-Wall", "-g", + if b.gccSupportsFlag(compiler, "-fdebug-prefix-map=a=b") { + defs = append(defs, "-fdebug-prefix-map="+b.WorkDir+"=/tmp/go-build") + } + if b.gccSupportsFlag(compiler, "-gno-record-gcc-switches") { + defs = append(defs, "-gno-record-gcc-switches") + } + return b.run(a, p.Dir, p.ImportPath, nil, compiler, "-Wall", "-g", "-I", a.Objdir, "-I", inc, "-o", ofile, defs, "-c", cfile) } -- 2.48.1