1
0
mirror of https://github.com/golang/go synced 2024-11-11 22:40:22 -07:00

cmd/go: get -m options from GOARCH when using gccgo

R=golang-dev, bradfitz, minux.ma
CC=golang-dev
https://golang.org/cl/7057063
This commit is contained in:
Ian Lance Taylor 2013-01-09 14:45:03 -08:00
parent e0bf0374ca
commit 5ca4f5e483

View File

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