Commit 62353ff8 authored by Michael Hudson-Doyle's avatar Michael Hudson-Doyle Committed by Ian Lance Taylor

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

Change-Id: I749fd91cd3c7581cdcc97a15e8eeee0c20f0b259
Reviewed-on: https://go-review.googlesource.com/8805Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
parent e8b7133e
...@@ -159,6 +159,7 @@ var buildLinkshared bool // -linkshared flag ...@@ -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) { ...@@ -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() { ...@@ -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) { ...@@ -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, ...@@ -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)
} }
......
...@@ -126,6 +126,7 @@ var listJson = cmdList.Flag.Bool("json", false, "") ...@@ -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()
......
...@@ -64,6 +64,7 @@ func printStderr(args ...interface{}) (int, error) { ...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment