From c6f280584c61835c0cc9f15222e842d68f500d8d Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Thu, 3 Sep 2015 12:33:06 +1200 Subject: [PATCH] cmd/go: implicitly include math in a shared library on arm In the same manner in which runtime/cgo is included on other architectures. Change-Id: I90a5ad8585248b2566d763d33994a600508d89cb Reviewed-on: https://go-review.googlesource.com/14221 Reviewed-by: Ian Lance Taylor --- src/cmd/go/build.go | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go index 30af02e401..c87cedc571 100644 --- a/src/cmd/go/build.go +++ b/src/cmd/go/build.go @@ -982,7 +982,11 @@ func (b *builder) action1(mode buildMode, depMode buildMode, p *Package, looksha func (b *builder) libaction(libname string, pkgs []*Package, mode, depMode buildMode) *action { a := &action{} - if mode == modeBuild { + switch mode { + default: + fatalf("unrecognized mode %v", mode) + + case modeBuild: a.f = (*builder).linkShared a.target = filepath.Join(b.work, libname) for _, p := range pkgs { @@ -991,14 +995,15 @@ func (b *builder) libaction(libname string, pkgs []*Package, mode, depMode build } a.deps = append(a.deps, b.action(depMode, depMode, p)) } - } else if mode == modeInstall { + + case modeInstall: // Currently build mode shared forces external linking mode, and - // external linking mode forces an import of runtime/cgo. So if it - // was not passed on the command line and it is not present in - // another shared library, add it here. - seencgo := false + // external linking mode forces an import of runtime/cgo (and + // math on arm). So if it was not passed on the command line and + // it is not present in another shared library, add it here. _, gccgo := buildToolchain.(gccgoToolchain) if !gccgo { + seencgo := false for _, p := range pkgs { seencgo = seencgo || (p.Standard && p.ImportPath == "runtime/cgo") } @@ -1018,6 +1023,28 @@ func (b *builder) libaction(libname string, pkgs []*Package, mode, depMode build pkgs = append(pkgs, p) } } + if goarch == "arm" { + seenmath := false + for _, p := range pkgs { + seenmath = seenmath || (p.Standard && p.ImportPath == "math") + } + if !seenmath { + var stk importStack + p := loadPackage("math", &stk) + if p.Error != nil { + fatalf("load math: %v", p.Error) + } + computeStale(p) + // If math is in another shared library, then that's + // also the shared library that contains runtime, so + // something will depend on it and so math's staleness + // will be checked when processing that library. + if p.Shlib == "" || p.Shlib == libname { + pkgs = append([]*Package{}, pkgs...) + pkgs = append(pkgs, p) + } + } + } } // Figure out where the library will go. @@ -1068,8 +1095,6 @@ func (b *builder) libaction(libname string, pkgs []*Package, mode, depMode build shlibnameaction.deps = append(shlibnameaction.deps, buildAction) } } - } else { - fatalf("unregonized mode %v", mode) } return a } -- 2.48.1