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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Ian Lance Taylor 2019-07-27 16:14:16 -07:00
parent e81b731592
commit 407010ef0b
2 changed files with 12 additions and 5 deletions

View File

@ -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")

View File

@ -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)
}