From: Ian Lance Taylor Date: Wed, 9 Jan 2013 22:45:03 +0000 (-0800) Subject: cmd/go: get -m options from GOARCH when using gccgo X-Git-Tag: go1.1rc2~1436 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5ca4f5e48384fa9c483d1ed40364940e6cb4e355;p=gostls13.git cmd/go: get -m options from GOARCH when using gccgo R=golang-dev, bradfitz, minux.ma CC=golang-dev https://golang.org/cl/7057063 --- diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go index 8db752bd91..776aa5e0df 100644 --- a/src/cmd/go/build.go +++ b/src/cmd/go/build.go @@ -1404,6 +1404,7 @@ func (gccgcToolchain) gc(b *builder, p *Package, obj string, importArgs []string out := p.Name + ".o" ofile = obj + out gcargs := []string{"-g"} + gcargs = append(gcargs, b.gccArchArgs()...) if pkgpath := gccgoPkgpath(p); pkgpath != "" { gcargs = append(gcargs, "-fgo-pkgpath="+pkgpath) } @@ -1423,6 +1424,7 @@ func (gccgcToolchain) asm(b *builder, p *Package, obj, ofile, sfile string) erro if pkgpath := gccgoCleanPkgpath(p); pkgpath != "" { defs = append(defs, `-D`, `GOPKGPATH="`+pkgpath+`"`) } + defs = append(defs, b.gccArchArgs()...) return b.run(p.Dir, p.ImportPath, "gccgo", "-I", obj, "-o", ofile, defs, sfile) } @@ -1446,7 +1448,7 @@ func (tools gccgcToolchain) ld(b *builder, p *Package, out string, allactions [] // and all LDFLAGS from cgo dependencies. afiles := make(map[*Package]string) sfiles := make(map[*Package][]string) - ldflags := []string{} + ldflags := b.gccArchArgs() cgoldflags := []string{} usesCgo := false for _, a := range allactions { @@ -1487,6 +1489,7 @@ func (gccgcToolchain) cc(b *builder, p *Package, objdir, ofile, cfile string) er inc := filepath.Join(goroot, "pkg", fmt.Sprintf("%s_%s", goos, goarch)) cfile = mkAbs(p.Dir, cfile) defs := []string{"-D", "GOOS_" + goos, "-D", "GOARCH_" + goarch} + defs = append(defs, b.gccArchArgs()...) if pkgpath := gccgoCleanPkgpath(p); pkgpath != "" { defs = append(defs, `-D`, `GOPKGPATH="`+pkgpath+`"`) } @@ -1547,14 +1550,7 @@ func (b *builder) gccCmd(objdir string) []string { if goos != "windows" { a = append(a, "-fPIC") } - switch archChar { - case "8": - a = append(a, "-m32") - case "6": - a = append(a, "-m64") - case "5": - a = append(a, "-marm") // not thumb - } + a = append(a, b.gccArchArgs()...) // gcc-4.5 and beyond require explicit "-pthread" flag // for multithreading with pthread library. if buildContext.CgoEnabled { @@ -1576,6 +1572,19 @@ func (b *builder) gccCmd(objdir string) []string { return a } +// gccArchArgs returns arguments to pass to gcc based on the architecture. +func (b *builder) gccArchArgs() []string { + switch archChar { + case "8": + return []string{"-m32"} + case "6": + return []string{"-m64"} + case "5": + return []string{"-marm"} // not thumb + } + return nil +} + func envList(key string) []string { return strings.Fields(os.Getenv(key)) }