mirror of
https://github.com/golang/go
synced 2024-11-19 11:44:45 -07:00
cmd/go: don't crash on unknown GOARCH unless we actually care
For example, "GOARCH=sparc go build -compiler=gccgo" should not crash merely because the architecture character for sparc is not known. Change-Id: I18912c7f5d90ef8f586592235ec9d6e5053e4bef Reviewed-on: https://go-review.googlesource.com/7695 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
db96e6821a
commit
e14339d34c
@ -384,8 +384,10 @@ func runInstall(cmd *Command, args []string) {
|
|||||||
var (
|
var (
|
||||||
goarch string
|
goarch string
|
||||||
goos string
|
goos string
|
||||||
archChar string
|
|
||||||
exeSuffix string
|
exeSuffix string
|
||||||
|
|
||||||
|
archCharVal string
|
||||||
|
archCharErr error
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -394,16 +396,16 @@ func init() {
|
|||||||
if goos == "windows" {
|
if goos == "windows" {
|
||||||
exeSuffix = ".exe"
|
exeSuffix = ".exe"
|
||||||
}
|
}
|
||||||
var err error
|
archCharVal, archCharErr = build.ArchChar(goarch)
|
||||||
archChar, err = build.ArchChar(goarch)
|
|
||||||
if err != nil {
|
|
||||||
if _, isgc := buildToolchain.(gcToolchain); isgc {
|
|
||||||
fatalf("%s", err)
|
|
||||||
}
|
}
|
||||||
// archChar is only required for gcToolchain, if we're using
|
|
||||||
// another toolchain leave it blank.
|
// archChar returns the architecture character. This is only needed
|
||||||
archChar = ""
|
// for the gc toolchain, so only fail if we actually need it.
|
||||||
|
func archChar() string {
|
||||||
|
if archCharErr != nil {
|
||||||
|
fatalf("%s", archCharErr)
|
||||||
}
|
}
|
||||||
|
return archCharVal
|
||||||
}
|
}
|
||||||
|
|
||||||
// A builder holds global state about a build.
|
// A builder holds global state about a build.
|
||||||
@ -839,7 +841,7 @@ func (b *builder) build(a *action) (err error) {
|
|||||||
fmt.Fprintf(os.Stderr, "%s\n", a.p.ImportPath)
|
fmt.Fprintf(os.Stderr, "%s\n", a.p.ImportPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.p.Standard && a.p.ImportPath == "runtime" && buildContext.Compiler == "gc" &&
|
if a.p.Standard && a.p.ImportPath == "runtime" && buildContext.Compiler == "gc" && archChar() != "" &&
|
||||||
(!hasString(a.p.GoFiles, "zgoos_"+buildContext.GOOS+".go") ||
|
(!hasString(a.p.GoFiles, "zgoos_"+buildContext.GOOS+".go") ||
|
||||||
!hasString(a.p.GoFiles, "zgoarch_"+buildContext.GOARCH+".go")) {
|
!hasString(a.p.GoFiles, "zgoarch_"+buildContext.GOARCH+".go")) {
|
||||||
return fmt.Errorf("%s/%s must be bootstrapped using make%v", buildContext.GOOS, buildContext.GOARCH, defaultSuffix())
|
return fmt.Errorf("%s/%s must be bootstrapped using make%v", buildContext.GOOS, buildContext.GOARCH, defaultSuffix())
|
||||||
@ -1002,9 +1004,11 @@ func (b *builder) build(a *action) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
objExt := archChar
|
var objExt string
|
||||||
if _, ok := buildToolchain.(gccgoToolchain); ok {
|
if _, ok := buildToolchain.(gccgoToolchain); ok {
|
||||||
objExt = "o"
|
objExt = "o"
|
||||||
|
} else {
|
||||||
|
objExt = archChar()
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range cfiles {
|
for _, file := range cfiles {
|
||||||
@ -1637,18 +1641,18 @@ func (noToolchain) cc(b *builder, p *Package, objdir, ofile, cfile string) error
|
|||||||
type gcToolchain struct{}
|
type gcToolchain struct{}
|
||||||
|
|
||||||
func (gcToolchain) compiler() string {
|
func (gcToolchain) compiler() string {
|
||||||
return tool(archChar + "g")
|
return tool(archChar() + "g")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gcToolchain) linker() string {
|
func (gcToolchain) linker() string {
|
||||||
return tool(archChar + "l")
|
return tool(archChar() + "l")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gcToolchain) gc(b *builder, p *Package, archive, obj string, asmhdr bool, importArgs []string, gofiles []string) (ofile string, output []byte, err error) {
|
func (gcToolchain) gc(b *builder, p *Package, archive, obj string, asmhdr bool, importArgs []string, gofiles []string) (ofile string, output []byte, err error) {
|
||||||
if archive != "" {
|
if archive != "" {
|
||||||
ofile = archive
|
ofile = archive
|
||||||
} else {
|
} else {
|
||||||
out := "_go_." + archChar
|
out := "_go_." + archChar()
|
||||||
ofile = obj + out
|
ofile = obj + out
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1677,7 +1681,7 @@ func (gcToolchain) gc(b *builder, p *Package, archive, obj string, asmhdr bool,
|
|||||||
gcargs = append(gcargs, "-installsuffix", buildContext.InstallSuffix)
|
gcargs = append(gcargs, "-installsuffix", buildContext.InstallSuffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []interface{}{buildToolExec, tool(archChar + "g"), "-o", ofile, "-trimpath", b.work, buildGcflags, gcargs, "-D", p.localPrefix, importArgs}
|
args := []interface{}{buildToolExec, tool(archChar() + "g"), "-o", ofile, "-trimpath", b.work, buildGcflags, gcargs, "-D", p.localPrefix, importArgs}
|
||||||
if ofile == archive {
|
if ofile == archive {
|
||||||
args = append(args, "-pack")
|
args = append(args, "-pack")
|
||||||
}
|
}
|
||||||
@ -1706,7 +1710,7 @@ func (gcToolchain) asm(b *builder, p *Package, obj, ofile, sfile string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if verifyAsm && goarch != "arm64" {
|
if verifyAsm && goarch != "arm64" {
|
||||||
if err := toolVerify(b, p, "old"+archChar+"a", ofile, args); err != nil {
|
if err := toolVerify(b, p, "old"+archChar()+"a", ofile, args); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1882,7 +1886,7 @@ func (gcToolchain) ld(b *builder, p *Package, out string, allactions []*action,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ldflags = append(ldflags, buildLdflags...)
|
ldflags = append(ldflags, buildLdflags...)
|
||||||
return b.run(".", p.ImportPath, nil, buildToolExec, tool(archChar+"l"), "-o", out, importArgs, ldflags, mainpkg)
|
return b.run(".", p.ImportPath, nil, buildToolExec, tool(archChar()+"l"), "-o", out, importArgs, ldflags, mainpkg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gcToolchain) cc(b *builder, p *Package, objdir, ofile, cfile string) error {
|
func (gcToolchain) cc(b *builder, p *Package, objdir, ofile, cfile string) error {
|
||||||
@ -2175,12 +2179,12 @@ func (b *builder) ccompilerCmd(envvar, defcmd, objdir string) []string {
|
|||||||
|
|
||||||
// gccArchArgs returns arguments to pass to gcc based on the architecture.
|
// gccArchArgs returns arguments to pass to gcc based on the architecture.
|
||||||
func (b *builder) gccArchArgs() []string {
|
func (b *builder) gccArchArgs() []string {
|
||||||
switch archChar {
|
switch goarch {
|
||||||
case "8":
|
case "386":
|
||||||
return []string{"-m32"}
|
return []string{"-m32"}
|
||||||
case "6":
|
case "amd64", "amd64p32":
|
||||||
return []string{"-m64"}
|
return []string{"-m64"}
|
||||||
case "5":
|
case "arm":
|
||||||
return []string{"-marm"} // not thumb
|
return []string{"-marm"} // not thumb
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -2245,7 +2249,12 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, pcCFLAGS, pcLDFLAGS, cgofi
|
|||||||
cgoflags := []string{}
|
cgoflags := []string{}
|
||||||
// TODO: make cgo not depend on $GOARCH?
|
// TODO: make cgo not depend on $GOARCH?
|
||||||
|
|
||||||
objExt := archChar
|
var objExt string
|
||||||
|
if _, ok := buildToolchain.(gccgoToolchain); ok {
|
||||||
|
objExt = "o"
|
||||||
|
} else {
|
||||||
|
objExt = archChar()
|
||||||
|
}
|
||||||
|
|
||||||
if p.Standard && p.ImportPath == "runtime/cgo" {
|
if p.Standard && p.ImportPath == "runtime/cgo" {
|
||||||
cgoflags = append(cgoflags, "-import_runtime_cgo=false")
|
cgoflags = append(cgoflags, "-import_runtime_cgo=false")
|
||||||
@ -2269,7 +2278,6 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, pcCFLAGS, pcLDFLAGS, cgofi
|
|||||||
if pkgpath := gccgoPkgpath(p); pkgpath != "" {
|
if pkgpath := gccgoPkgpath(p); pkgpath != "" {
|
||||||
cgoflags = append(cgoflags, "-gccgopkgpath="+pkgpath)
|
cgoflags = append(cgoflags, "-gccgopkgpath="+pkgpath)
|
||||||
}
|
}
|
||||||
objExt = "o"
|
|
||||||
}
|
}
|
||||||
if err := b.run(p.Dir, p.ImportPath, cgoenv, buildToolExec, cgoExe, "-objdir", obj, cgoflags, "--", cgoCPPFLAGS, cgoexeCFLAGS, cgofiles); err != nil {
|
if err := b.run(p.Dir, p.ImportPath, cgoenv, buildToolExec, cgoExe, "-objdir", obj, cgoflags, "--", cgoCPPFLAGS, cgoexeCFLAGS, cgofiles); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -36,7 +36,6 @@ func mkEnv() []envVar {
|
|||||||
env := []envVar{
|
env := []envVar{
|
||||||
{"GOARCH", goarch},
|
{"GOARCH", goarch},
|
||||||
{"GOBIN", gobin},
|
{"GOBIN", gobin},
|
||||||
{"GOCHAR", archChar},
|
|
||||||
{"GOEXE", exeSuffix},
|
{"GOEXE", exeSuffix},
|
||||||
{"GOHOSTARCH", runtime.GOARCH},
|
{"GOHOSTARCH", runtime.GOARCH},
|
||||||
{"GOHOSTOS", runtime.GOOS},
|
{"GOHOSTOS", runtime.GOOS},
|
||||||
@ -50,6 +49,10 @@ func mkEnv() []envVar {
|
|||||||
{"TERM", "dumb"},
|
{"TERM", "dumb"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if archCharErr == nil {
|
||||||
|
env = append(env, envVar{"GOCHAR", archChar()})
|
||||||
|
}
|
||||||
|
|
||||||
if goos != "plan9" {
|
if goos != "plan9" {
|
||||||
cmd := b.gccCmd(".")
|
cmd := b.gccCmd(".")
|
||||||
env = append(env, envVar{"CC", cmd[0]})
|
env = append(env, envVar{"CC", cmd[0]})
|
||||||
|
Loading…
Reference in New Issue
Block a user