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

cmd/go: have go run, go list respect -buildmode/-linkshared

Change-Id: I749fd91cd3c7581cdcc97a15e8eeee0c20f0b259
Reviewed-on: https://go-review.googlesource.com/8805
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Michael Hudson-Doyle 2015-04-01 15:53:52 +13:00 committed by Ian Lance Taylor
parent e8b7133e9b
commit 62353ff876
3 changed files with 6 additions and 4 deletions

View File

@ -159,6 +159,7 @@ var buildLinkshared bool // -linkshared flag
var buildContext = build.Default var buildContext = build.Default
var buildToolchain toolchain = noToolchain{} var buildToolchain toolchain = noToolchain{}
var ldBuildmode string
// buildCompiler implements flag.Var. // buildCompiler implements flag.Var.
// It implements Set by updating both // It implements Set by updating both
@ -307,7 +308,7 @@ func pkgsNotMain(pkgs []*Package) (res []*Package) {
var pkgsFilter = func(pkgs []*Package) []*Package { return pkgs } var pkgsFilter = func(pkgs []*Package) []*Package { return pkgs }
func buildModeInit() { func buildModeInit() {
var codegenArg, ldBuildmode string var codegenArg string
platform := goos + "/" + goarch platform := goos + "/" + goarch
switch buildBuildmode { switch buildBuildmode {
case "archive": case "archive":
@ -362,9 +363,6 @@ func buildModeInit() {
// TODO(mwhudson): remove -w when that gets fixed in linker. // TODO(mwhudson): remove -w when that gets fixed in linker.
buildLdflags = append(buildLdflags, "-linkshared", "-w") buildLdflags = append(buildLdflags, "-linkshared", "-w")
} }
if ldBuildmode != "" {
buildLdflags = append(buildLdflags, "-buildmode="+ldBuildmode)
}
if codegenArg != "" { if codegenArg != "" {
buildAsmflags = append(buildAsmflags, codegenArg) buildAsmflags = append(buildAsmflags, codegenArg)
buildGcflags = append(buildGcflags, codegenArg) buildGcflags = append(buildGcflags, codegenArg)
@ -1286,6 +1284,7 @@ func (b *builder) linkShared(a *action) (err error) {
importArgs := b.includeArgs("-L", allactions[:len(allactions)-1]) importArgs := b.includeArgs("-L", allactions[:len(allactions)-1])
// TODO(mwhudson): this does not check for cxx-ness, extldflags etc // TODO(mwhudson): this does not check for cxx-ness, extldflags etc
ldflags := []string{"-installsuffix", buildContext.InstallSuffix} ldflags := []string{"-installsuffix", buildContext.InstallSuffix}
ldflags = append(ldflags, "-buildmode="+ldBuildmode)
ldflags = append(ldflags, buildLdflags...) ldflags = append(ldflags, buildLdflags...)
for _, d := range a.deps { for _, d := range a.deps {
if d.target != "" { // omit unsafe etc if d.target != "" { // omit unsafe etc
@ -2082,6 +2081,7 @@ func (gcToolchain) ld(b *builder, p *Package, out string, allactions []*action,
} }
} }
} }
ldflags = append(ldflags, "-buildmode="+ldBuildmode)
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)
} }

View File

@ -126,6 +126,7 @@ var listJson = cmdList.Flag.Bool("json", false, "")
var nl = []byte{'\n'} var nl = []byte{'\n'}
func runList(cmd *Command, args []string) { func runList(cmd *Command, args []string) {
buildModeInit()
out := newTrackingWriter(os.Stdout) out := newTrackingWriter(os.Stdout)
defer out.w.Flush() defer out.w.Flush()

View File

@ -64,6 +64,7 @@ func printStderr(args ...interface{}) (int, error) {
func runRun(cmd *Command, args []string) { func runRun(cmd *Command, args []string) {
raceInit() raceInit()
buildModeInit()
var b builder var b builder
b.init() b.init()
b.print = printStderr b.print = printStderr