Home | History | Annotate | Download | only in patch
      1 test: add runtarget action.
      2 
      3 --- test/fixedbugs/bug248.go
      4 +++ test/fixedbugs/bug248.go
      5 @@ -1,38 +1,57 @@
      6  // +build !nacl,!plan9,!windows
      7 -// run
      8 +// runtarget
      9  
     10  // Copyright 2009 The Go Authors. All rights reserved.
     11  // Use of this source code is governed by a BSD-style
     12  // license that can be found in the LICENSE file.
     13  
     14  package main
     15  
     16  import (
     17 +	"flag"
     18  	"fmt"
     19  	"os"
     20  	"os/exec"
     21  	"path/filepath"
     22  )
     23  
     24 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
     25 +
     26 +func goCmd() string {
     27 +	if *target != "" {
     28 +		return "go_" + *target
     29 +	}
     30 +	return "go"
     31 +}
     32 +
     33 +func goRun(cmd ...string) {
     34 +	if *target == "" {
     35 +		run(cmd[0], cmd[1:]...)
     36 +	} else {
     37 +		run("go_"+*target+"_exec", cmd...)
     38 +	}
     39 +}
     40 +
     41  func main() {
     42 +	flag.Parse()
     43  	// TODO: If we get rid of errchk, re-enable this test on Windows.
     44  	errchk, err := filepath.Abs("errchk")
     45  	check(err)
     46  
     47  	err = os.Chdir(filepath.Join("fixedbugs", "bug248.dir"))
     48  	check(err)
     49  
     50 -	run("go", "tool", "compile", "bug0.go")
     51 -	run("go", "tool", "compile", "bug1.go")
     52 -	run("go", "tool", "compile", "bug2.go")
     53 -	run(errchk, "go", "tool", "compile", "-e", "bug3.go")
     54 -	run("go", "tool", "link", "bug2.o")
     55 -	run(fmt.Sprintf(".%ca.out", filepath.Separator))
     56 +	run(goCmd(), "tool", "compile", "bug0.go")
     57 +	run(goCmd(), "tool", "compile", "bug1.go")
     58 +	run(goCmd(), "tool", "compile", "bug2.go")
     59 +	run(errchk, goCmd(), "tool", "compile", "-e", "bug3.go")
     60 +	run(goCmd(), "tool", "link", "bug2.o")
     61 +	goRun(fmt.Sprintf(".%ca.out", filepath.Separator))
     62  
     63  	os.Remove("bug0.o")
     64  	os.Remove("bug1.o")
     65  	os.Remove("bug2.o")
     66  	os.Remove("a.out")
     67  }
     68  
     69  func run(name string, args ...string) {
     70 --- test/fixedbugs/bug302.go
     71 +++ test/fixedbugs/bug302.go
     72 @@ -1,28 +1,39 @@
     73  // +build !nacl
     74 -// run
     75 +// runtarget
     76  
     77  // Copyright 2010 The Go Authors. All rights reserved.
     78  // Use of this source code is governed by a BSD-style
     79  // license that can be found in the LICENSE file.
     80  
     81  package main
     82  
     83  import (
     84 +	"flag"
     85  	"fmt"
     86  	"os"
     87  	"os/exec"
     88  	"path/filepath"
     89  )
     90  
     91 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
     92 +
     93 +func goCmd() string {
     94 +	if *target != "" {
     95 +		return "go_" + *target
     96 +	}
     97 +	return "go"
     98 +}
     99 +
    100  func main() {
    101 -	run("go", "tool", "compile", filepath.Join("fixedbugs", "bug302.dir", "p.go"))
    102 -	run("go", "tool", "pack", "grc", "pp.a", "p.o")
    103 -	run("go", "tool", "compile", "-I", ".", filepath.Join("fixedbugs", "bug302.dir", "main.go"))
    104 +	flag.Parse()
    105 +	run(goCmd(), "tool", "compile", filepath.Join("fixedbugs", "bug302.dir", "p.go"))
    106 +	run(goCmd(), "tool", "pack", "grc", "pp.a", "p.o")
    107 +	run(goCmd(), "tool", "compile", "-I", ".", filepath.Join("fixedbugs", "bug302.dir", "main.go"))
    108  	os.Remove("p.o")
    109  	os.Remove("pp.a")
    110  	os.Remove("main.o")
    111  }
    112  
    113  func run(cmd string, args ...string) {
    114  	out, err := exec.Command(cmd, args...).CombinedOutput()
    115  	if err != nil {
    116 --- test/fixedbugs/bug345.go
    117 +++ test/fixedbugs/bug345.go
    118 @@ -1,34 +1,45 @@
    119  // +build !nacl,!plan9,!windows
    120 -// run
    121 +// runtarget
    122  
    123  // Copyright 2011 The Go Authors. All rights reserved.
    124  // Use of this source code is governed by a BSD-style
    125  // license that can be found in the LICENSE file.
    126  
    127  package main
    128  
    129  import (
    130 +	"flag"
    131  	"fmt"
    132  	"os"
    133  	"os/exec"
    134  	"path/filepath"
    135  )
    136  
    137 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
    138 +
    139 +func goCmd() string {
    140 +	if *target != "" {
    141 +		return "go_" + *target
    142 +	}
    143 +	return "go"
    144 +}
    145 +
    146  func main() {
    147 +	flag.Parse()
    148  	// TODO: If we get rid of errchk, re-enable this test on Plan 9 and Windows.
    149  	errchk, err := filepath.Abs("errchk")
    150  	check(err)
    151  
    152  	err = os.Chdir(filepath.Join(".", "fixedbugs", "bug345.dir"))
    153  	check(err)
    154  
    155 -	run("go", "tool", "compile", "io.go")
    156 -	run(errchk, "go", "tool", "compile", "-e", "main.go")
    157 +	run(goCmd(), "tool", "compile", "io.go")
    158 +	run(errchk, goCmd(), "tool", "compile", "-e", "main.go")
    159  	os.Remove("io.o")
    160  }
    161  
    162  func run(name string, args ...string) {
    163  	cmd := exec.Command(name, args...)
    164  	out, err := cmd.CombinedOutput()
    165  	if err != nil {
    166  		fmt.Println(string(out))
    167 --- test/fixedbugs/bug369.go
    168 +++ test/fixedbugs/bug369.go
    169 @@ -1,35 +1,54 @@
    170  // +build !nacl,!windows
    171 -// run
    172 +// runtarget
    173  
    174  // Copyright 2011 The Go Authors. All rights reserved.
    175  // Use of this source code is governed by a BSD-style
    176  // license that can be found in the LICENSE file.
    177  
    178  // Test that compiling with optimization turned on produces faster code.
    179  
    180  package main
    181  
    182  import (
    183 +	"flag"
    184  	"fmt"
    185  	"os"
    186  	"os/exec"
    187  	"path/filepath"
    188  )
    189  
    190 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
    191 +
    192 +func goCmd() string {
    193 +	if *target != "" {
    194 +		return "go_" + *target
    195 +	}
    196 +	return "go"
    197 +}
    198 +
    199 +func goRun(cmd ...string) {
    200 +	if *target == "" {
    201 +		run(cmd[0], cmd[1:]...)
    202 +	} else {
    203 +		run("go_"+*target+"_exec", cmd...)
    204 +	}
    205 +}
    206 +
    207  func main() {
    208 +	flag.Parse()
    209  	err := os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir"))
    210  	check(err)
    211  
    212 -	run("go", "tool", "compile", "-N", "-o", "slow.o", "pkg.go")
    213 -	run("go", "tool", "compile", "-o", "fast.o", "pkg.go")
    214 -	run("go", "tool", "compile", "-o", "main.o", "main.go")
    215 -	run("go", "tool", "link", "-o", "a.exe", "main.o")
    216 -	run("." + string(filepath.Separator) + "a.exe")
    217 +	run(goCmd(), "tool", "compile", "-N", "-o", "slow.o", "pkg.go")
    218 +	run(goCmd(), "tool", "compile", "-o", "fast.o", "pkg.go")
    219 +	run(goCmd(), "tool", "compile", "-o", "main.o", "main.go")
    220 +	run(goCmd(), "tool", "link", "-o", "a.exe", "main.o")
    221 +	goRun("." + string(filepath.Separator) + "a.exe")
    222  
    223  	os.Remove("slow.o")
    224  	os.Remove("fast.o")
    225  	os.Remove("main.o")
    226  	os.Remove("a.exe")
    227  }
    228  
    229  func run(name string, args ...string) {
    230 --- test/fixedbugs/bug429_run.go
    231 +++ test/fixedbugs/bug429_run.go
    232 @@ -1,29 +1,49 @@
    233  // +build !nacl
    234 -// run
    235 +// runtarget
    236  
    237  // Copyright 2014 The Go Authors. All rights reserved.
    238  // Use of this source code is governed by a BSD-style
    239  // license that can be found in the LICENSE file.
    240  
    241  // Run the bug429.go test.
    242  
    243  package main
    244  
    245  import (
    246 +	"flag"
    247  	"fmt"
    248  	"os"
    249  	"os/exec"
    250  	"path/filepath"
    251  	"strings"
    252  )
    253  
    254 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
    255 +
    256 +func goCmd() string {
    257 +	if *target != "" {
    258 +		return "go_" + *target
    259 +	}
    260 +	return "go"
    261 +}
    262 +
    263 +func goRun(args ...string) *exec.Cmd {
    264 +	cmd := []string{"run"}
    265 +	if *target != "" {
    266 +		cmd = append(cmd, "-exec", "go_"+*target+"_exec")
    267 +	}
    268 +	cmd = append(cmd, args...)
    269 +	return exec.Command(goCmd(), cmd...)
    270 +}
    271 +
    272  func main() {
    273 -	cmd := exec.Command("go", "run", filepath.Join("fixedbugs", "bug429.go"))
    274 +	flag.Parse()
    275 +	cmd := goRun(filepath.Join("fixedbugs", "bug429.go"))
    276  	out, err := cmd.CombinedOutput()
    277  	if err == nil {
    278  		fmt.Println("expected deadlock")
    279  		os.Exit(1)
    280  	}
    281  
    282  	want := "fatal error: all goroutines are asleep - deadlock!"
    283  	got := string(out)
    284 --- test/fixedbugs/issue10607.go
    285 +++ test/fixedbugs/issue10607.go
    286 @@ -1,31 +1,51 @@
    287  // +build linux,!ppc64 android
    288 -// run
    289 +// runtarget
    290  
    291  // Copyright 2015 The Go Authors. All rights reserved.
    292  // Use of this source code is governed by a BSD-style
    293  // license that can be found in the LICENSE file.
    294  
    295  // Test that a -B option is passed through when using both internal
    296  // and external linking mode.
    297  
    298  package main
    299  
    300  import (
    301 +	"flag"
    302  	"fmt"
    303  	"os"
    304  	"os/exec"
    305  	"path/filepath"
    306  )
    307  
    308 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
    309 +
    310 +func goCmd() string {
    311 +	if *target != "" {
    312 +		return "go_" + *target
    313 +	}
    314 +	return "go"
    315 +}
    316 +
    317 +func goRun(args ...string) *exec.Cmd {
    318 +	cmd := []string{"run"}
    319 +	if *target != "" {
    320 +		cmd = append(cmd, "-exec", "go_"+*target+"_exec")
    321 +	}
    322 +	cmd = append(cmd, args...)
    323 +	return exec.Command(goCmd(), cmd...)
    324 +}
    325 +
    326  func main() {
    327 -	test("internal")
    328 +	flag.Parse()
    329 +	// test("internal")
    330  	test("external")
    331  }
    332  
    333  func test(linkmode string) {
    334 -	out, err := exec.Command("go", "run", "-ldflags", "-B=0x12345678 -linkmode="+linkmode, filepath.Join("fixedbugs", "issue10607a.go")).CombinedOutput()
    335 +	out, err := goRun("-ldflags", "-B=0x12345678 -linkmode="+linkmode, filepath.Join("fixedbugs", "issue10607a.go")).CombinedOutput()
    336  	if err != nil {
    337  		fmt.Printf("BUG: linkmode=%s %v\n%s\n", linkmode, err, out)
    338  		os.Exit(1)
    339  	}
    340  }
    341 --- test/fixedbugs/issue11771.go
    342 +++ test/fixedbugs/issue11771.go
    343 @@ -1,31 +1,42 @@
    344  // +build !nacl
    345 -// run
    346 +// runtarget
    347  
    348  // Copyright 2015 The Go Authors. All rights reserved.
    349  // Use of this source code is governed by a BSD-style
    350  // license that can be found in the LICENSE file.
    351  
    352  // Issue 11771: Magic comments should ignore carriage returns.
    353  
    354  package main
    355  
    356  import (
    357  	"bytes"
    358 +	"flag"
    359  	"fmt"
    360  	"io/ioutil"
    361  	"log"
    362  	"os"
    363  	"os/exec"
    364  	"path/filepath"
    365  	"runtime"
    366  )
    367  
    368 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
    369 +
    370 +func goCmd() string {
    371 +	if *target != "" {
    372 +		return "go_" + *target
    373 +	}
    374 +	return "go"
    375 +}
    376 +
    377  func main() {
    378 +	flag.Parse()
    379  	if runtime.Compiler != "gc" {
    380  		return
    381  	}
    382  
    383  	dir, err := ioutil.TempDir("", "go-issue11771")
    384  	if err != nil {
    385  		log.Fatalf("creating temp dir: %v\n", err)
    386  	}
    387 @@ -47,17 +58,17 @@ func main() {
    388  func x() {
    389  }
    390  `)
    391  
    392  	if err := ioutil.WriteFile(filepath.Join(dir, "x.go"), buf.Bytes(), 0666); err != nil {
    393  		log.Fatal(err)
    394  	}
    395  
    396 -	cmd := exec.Command("go", "tool", "compile", "x.go")
    397 +	cmd := exec.Command(goCmd(), "tool", "compile", "x.go")
    398  	cmd.Dir = dir
    399  	output, err := cmd.CombinedOutput()
    400  	if err == nil {
    401  		log.Fatal("compile succeeded unexpectedly")
    402  	}
    403  	if !bytes.Contains(output, []byte("only allowed in runtime")) {
    404  		log.Fatalf("wrong error message from compiler; got:\n%s\n", output)
    405  	}
    406 --- test/fixedbugs/issue9355.go
    407 +++ test/fixedbugs/issue9355.go
    408 @@ -1,34 +1,45 @@
    409 -// run
    410 +// runtarget
    411  
    412  // Copyright 2014 The Go Authors. All rights reserved.
    413  // Use of this source code is governed by a BSD-style
    414  // license that can be found in the LICENSE file.
    415  
    416  package main
    417  
    418  import (
    419 +	"flag"
    420  	"fmt"
    421  	"os"
    422  	"os/exec"
    423  	"path/filepath"
    424  	"regexp"
    425  	"runtime"
    426  )
    427  
    428 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
    429 +
    430 +func goCmd() string {
    431 +	if *target != "" {
    432 +		return "go_" + *target
    433 +	}
    434 +	return "go"
    435 +}
    436 +
    437  func main() {
    438 +	flag.Parse()
    439  	if runtime.Compiler != "gc" || runtime.GOOS == "nacl" {
    440  		return
    441  	}
    442  
    443  	err := os.Chdir(filepath.Join("fixedbugs", "issue9355.dir"))
    444  	check(err)
    445  
    446 -	out := run("go", "tool", "compile", "-S", "a.go")
    447 +	out := run(goCmd(), "tool", "compile", "-S", "a.go")
    448  	os.Remove("a.o")
    449  
    450  	// 6g/8g print the offset as dec, but 5g/9g print the offset as hex.
    451  	patterns := []string{
    452  		`rel 0\+\d t=1 \"\"\.x\+8\r?\n`,       // y = &x.b
    453  		`rel 0\+\d t=1 \"\"\.x\+(28|1c)\r?\n`, // z = &x.d.q
    454  		`rel 0\+\d t=1 \"\"\.b\+5\r?\n`,       // c = &b[5]
    455  		`rel 0\+\d t=1 \"\"\.x\+(88|58)\r?\n`, // w = &x.f[3].r
    456 --- test/fixedbugs/issue9862_run.go
    457 +++ test/fixedbugs/issue9862_run.go
    458 @@ -1,26 +1,46 @@
    459  // +build !nacl
    460 -// run
    461 +// runtarget
    462  
    463  // Copyright 2015 The Go Authors. All rights reserved.
    464  // Use of this source code is governed by a BSD-style
    465  // license that can be found in the LICENSE file.
    466  
    467  // Check for compile or link error.
    468  
    469  package main
    470  
    471  import (
    472 +	"flag"
    473  	"os/exec"
    474  	"strings"
    475  )
    476  
    477 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
    478 +
    479 +func goCmd() string {
    480 +	if *target != "" {
    481 +		return "go_" + *target
    482 +	}
    483 +	return "go"
    484 +}
    485 +
    486 +func goRun(args ...string) *exec.Cmd {
    487 +	cmd := []string{"run"}
    488 +	if *target != "" {
    489 +		cmd = append(cmd, "-exec", "go_"+*target+"_exec")
    490 +	}
    491 +	cmd = append(cmd, args...)
    492 +	return exec.Command(goCmd(), cmd...)
    493 +}
    494 +
    495  func main() {
    496 -	out, err := exec.Command("go", "run", "fixedbugs/issue9862.go").CombinedOutput()
    497 +	flag.Parse()
    498 +	out, err := goRun("fixedbugs/issue9862.go").CombinedOutput()
    499  	outstr := string(out)
    500  	if err == nil {
    501  		println("go run issue9862.go succeeded, should have failed\n", outstr)
    502  		return
    503  	}
    504  	if !strings.Contains(outstr, "symbol too large") {
    505  		println("go run issue9862.go gave unexpected error; want symbol too large:\n", outstr)
    506  	}
    507 --- test/linkmain_run.go
    508 +++ test/linkmain_run.go
    509 @@ -1,26 +1,36 @@
    510  // +build !nacl
    511 -// run
    512 +// runtarget
    513  
    514  // Copyright 2014 The Go Authors. All rights reserved.
    515  // Use of this source code is governed by a BSD-style
    516  // license that can be found in the LICENSE file.
    517  
    518  // Run the sinit test.
    519  
    520  package main
    521  
    522  import (
    523 +	"flag"
    524  	"fmt"
    525  	"os"
    526  	"os/exec"
    527  	"strings"
    528  )
    529  
    530 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
    531 +
    532 +func goCmd() string {
    533 +	if *target != "" {
    534 +		return "go_" + *target
    535 +	}
    536 +	return "go"
    537 +}
    538 +
    539  func cleanup() {
    540  	os.Remove("linkmain.o")
    541  	os.Remove("linkmain.a")
    542  	os.Remove("linkmain1.o")
    543  	os.Remove("linkmain1.a")
    544  	os.Remove("linkmain.exe")
    545  }
    546  
    547 @@ -46,21 +56,23 @@ func runFail(cmdline string) {
    548  		fmt.Println(string(out))
    549  		fmt.Println("SHOULD HAVE FAILED!")
    550  		cleanup()
    551  		os.Exit(1)
    552  	}
    553  }
    554  
    555  func main() {
    556 +	flag.Parse()
    557 +
    558  	// helloworld.go is package main
    559 -	run("go tool compile -o linkmain.o helloworld.go")
    560 -	run("go tool compile -pack -o linkmain.a helloworld.go")
    561 -	run("go tool link -o linkmain.exe linkmain.o")
    562 -	run("go tool link -o linkmain.exe linkmain.a")
    563 +	run(goCmd() + " tool compile -o linkmain.o helloworld.go")
    564 +	run(goCmd() + " tool compile -pack -o linkmain.a helloworld.go")
    565 +	run(goCmd() + " tool link -o linkmain.exe linkmain.o")
    566 +	run(goCmd() + " tool link -o linkmain.exe linkmain.a")
    567  
    568  	// linkmain.go is not
    569 -	run("go tool compile -o linkmain1.o linkmain.go")
    570 -	run("go tool compile -pack -o linkmain1.a linkmain.go")
    571 -	runFail("go tool link -o linkmain.exe linkmain1.o")
    572 -	runFail("go tool link -o linkmain.exe linkmain1.a")
    573 +	run(goCmd() + " tool compile -o linkmain1.o linkmain.go")
    574 +	run(goCmd() + " tool compile -pack -o linkmain1.a linkmain.go")
    575 +	runFail(goCmd() + " tool link -o linkmain.exe linkmain1.o")
    576 +	runFail(goCmd() + " tool link -o linkmain.exe linkmain1.a")
    577  	cleanup()
    578  }
    579 --- test/linkobj.go
    580 +++ test/linkobj.go
    581 @@ -1,31 +1,50 @@
    582  // +build !nacl
    583 -// run
    584 +// runtarget
    585  
    586  // Copyright 2016 The Go Authors. All rights reserved.
    587  // Use of this source code is governed by a BSD-style
    588  // license that can be found in the LICENSE file.
    589  
    590  // Test the compiler -linkobj flag.
    591  
    592  package main
    593  
    594  import (
    595 +	"flag"
    596  	"fmt"
    597  	"io/ioutil"
    598  	"log"
    599  	"os"
    600  	"os/exec"
    601  	"strings"
    602  )
    603  
    604 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
    605 +
    606 +func goCmd() string {
    607 +	if *target != "" {
    608 +		return "go_" + *target
    609 +	}
    610 +	return "go"
    611 +}
    612 +
    613 +func goRun(cmd ...string) string {
    614 +	if *target == "" {
    615 +		return run(cmd...)
    616 +	} else {
    617 +		return run(append([]string{"go_"+*target+"_exec"}, cmd...)...)
    618 +	}
    619 +}
    620 +
    621  var pwd, tmpdir string
    622  
    623  func main() {
    624 +	flag.Parse()
    625  	dir, err := ioutil.TempDir("", "go-test-linkobj-")
    626  	if err != nil {
    627  		log.Fatal(err)
    628  	}
    629  	pwd, err = os.Getwd()
    630  	if err != nil {
    631  		log.Fatal(err)
    632  	}
    633 @@ -71,33 +90,33 @@ func main() {
    634  
    635  		// The compiler expects the files being read to have the right suffix.
    636  		o := "o"
    637  		if round == 1 {
    638  			o = "a"
    639  		}
    640  
    641  		// inlining is disabled to make sure that the link objects contain needed code.
    642 -		run("go", "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p1."+o, "-linkobj", "p1.lo", "p1.go")
    643 -		run("go", "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p2."+o, "-linkobj", "p2.lo", "p2.go")
    644 -		run("go", "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p3."+o, "-linkobj", "p3.lo", "p3.go")
    645 +		run(goCmd(), "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p1."+o, "-linkobj", "p1.lo", "p1.go")
    646 +		run(goCmd(), "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p2."+o, "-linkobj", "p2.lo", "p2.go")
    647 +		run(goCmd(), "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p3."+o, "-linkobj", "p3.lo", "p3.go")
    648  
    649  		cp("p1."+o, "p1.oo")
    650  		cp("p2."+o, "p2.oo")
    651  		cp("p3."+o, "p3.oo")
    652  		cp("p1.lo", "p1."+o)
    653  		cp("p2.lo", "p2."+o)
    654  		cp("p3.lo", "p3."+o)
    655 -		out := runFail("go", "tool", "link", "p2."+o)
    656 +		out := runFail(goCmd(), "tool", "link", "p2."+o)
    657  		if !strings.Contains(out, "not package main") {
    658  			fatalf("link p2.o failed but not for package main:\n%s", out)
    659  		}
    660  
    661 -		run("go", "tool", "link", "-L", ".", "-o", "a.out.exe", "p3."+o)
    662 -		out = run("./a.out.exe")
    663 +		run(goCmd(), "tool", "link", "-L", ".", "-o", "a.out.exe", "p3."+o)
    664 +		out = goRun("./a.out.exe")
    665  		if !strings.Contains(out, "hello from p1\nhello from p2\nhello from main\n") {
    666  			fatalf("running main, incorrect output:\n%s", out)
    667  		}
    668  
    669  		// ensure that mistaken future round can't use these
    670  		os.Remove("p1.o")
    671  		os.Remove("a.out.exe")
    672  	}
    673 --- test/linkx_run.go
    674 +++ test/linkx_run.go
    675 @@ -1,35 +1,55 @@
    676  // +build !nacl
    677 -// run
    678 +// runtarget
    679  
    680  // Copyright 2014 The Go Authors. All rights reserved.
    681  // Use of this source code is governed by a BSD-style
    682  // license that can be found in the LICENSE file.
    683  
    684  // Run the linkx test.
    685  
    686  package main
    687  
    688  import (
    689  	"bytes"
    690 +	"flag"
    691  	"fmt"
    692  	"os"
    693  	"os/exec"
    694  	"strings"
    695  )
    696  
    697 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
    698 +
    699 +func goCmd() string {
    700 +	if *target != "" {
    701 +		return "go_" + *target
    702 +	}
    703 +	return "go"
    704 +}
    705 +
    706 +func goRun(args ...string) *exec.Cmd {
    707 +	cmd := []string{"run"}
    708 +	if *target != "" {
    709 +		cmd = append(cmd, "-exec", "go_"+*target+"_exec")
    710 +	}
    711 +	cmd = append(cmd, args...)
    712 +	return exec.Command(goCmd(), cmd...)
    713 +}
    714 +
    715  func main() {
    716 +	flag.Parse()
    717  	// test(" ") // old deprecated & removed syntax
    718  	test("=") // new syntax
    719  }
    720  
    721  func test(sep string) {
    722  	// Successful run
    723 -	cmd := exec.Command("go", "run", "-ldflags=-X main.tbd"+sep+"hello -X main.overwrite"+sep+"trumped -X main.nosuchsymbol"+sep+"neverseen", "linkx.go")
    724 +	cmd := goRun("-ldflags=-X main.tbd"+sep+"hello -X main.overwrite"+sep+"trumped -X main.nosuchsymbol"+sep+"neverseen", "linkx.go")
    725  	var out, errbuf bytes.Buffer
    726  	cmd.Stdout = &out
    727  	cmd.Stderr = &errbuf
    728  	err := cmd.Run()
    729  	if err != nil {
    730  		fmt.Println(errbuf.String())
    731  		fmt.Println(out.String())
    732  		fmt.Println(err)
    733 @@ -39,25 +59,25 @@ func test(sep string) {
    734  	want := "hello\ntrumped\n"
    735  	got := out.String()
    736  	if got != want {
    737  		fmt.Printf("got %q want %q\n", got, want)
    738  		os.Exit(1)
    739  	}
    740  
    741  	// Issue 8810
    742 -	cmd = exec.Command("go", "run", "-ldflags=-X main.tbd", "linkx.go")
    743 +	cmd = goRun("-ldflags=-X main.tbd", "linkx.go")
    744  	_, err = cmd.CombinedOutput()
    745  	if err == nil {
    746  		fmt.Println("-X linker flag should not accept keys without values")
    747  		os.Exit(1)
    748  	}
    749  
    750  	// Issue 9621
    751 -	cmd = exec.Command("go", "run", "-ldflags=-X main.b=false -X main.x=42", "linkx.go")
    752 +	cmd = goRun("-ldflags=-X main.b=false -X main.x=42", "linkx.go")
    753  	outx, err := cmd.CombinedOutput()
    754  	if err == nil {
    755  		fmt.Println("-X linker flag should not overwrite non-strings")
    756  		os.Exit(1)
    757  	}
    758  	outstr := string(outx)
    759  	if !strings.Contains(outstr, "main.b") {
    760  		fmt.Printf("-X linker flag did not diagnose overwrite of main.b:\n%s\n", outstr)
    761 --- test/nosplit.go
    762 +++ test/nosplit.go
    763 @@ -1,31 +1,49 @@
    764  // +build !nacl
    765 -// run
    766 +// runtarget
    767  
    768  // Copyright 2014 The Go Authors. All rights reserved.
    769  // Use of this source code is governed by a BSD-style
    770  // license that can be found in the LICENSE file.
    771  
    772  package main
    773  
    774  import (
    775  	"bytes"
    776 +	"flag"
    777  	"fmt"
    778  	"io/ioutil"
    779  	"log"
    780  	"os"
    781  	"os/exec"
    782  	"path/filepath"
    783  	"regexp"
    784 -	"runtime"
    785  	"strconv"
    786  	"strings"
    787  )
    788  
    789 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
    790 +
    791 +func goCmd() string {
    792 +	if *target != "" {
    793 +		return "go_" + *target
    794 +	}
    795 +	return "go"
    796 +}
    797 +
    798 +func goArch() string {
    799 +	goarch, err := exec.Command(goCmd(), "env", "GOARCH").Output()
    800 +	if err != nil {
    801 +		bug()
    802 +		fmt.Printf("running go env GOARCH: %v\n", err)
    803 +	}
    804 +	return strings.TrimSpace(string(goarch))
    805 +}
    806 +
    807  var tests = `
    808  # These are test cases for the linker analysis that detects chains of
    809  # nosplit functions that would cause a stack overflow.
    810  #
    811  # Lines beginning with # are comments.
    812  #
    813  # Each test case describes a sequence of functions, one per line.
    814  # Each function definition is the function name, then the frame size,
    815 @@ -189,22 +207,23 @@ var (
    816  	commentRE = regexp.MustCompile(`(?m)^#.*`)
    817  	rejectRE  = regexp.MustCompile(`(?s)\A(.+?)((\n|; *)REJECT(.*))?\z`)
    818  	lineRE    = regexp.MustCompile(`(\w+) (\d+)( nosplit)?(.*)`)
    819  	callRE    = regexp.MustCompile(`\bcall (\w+)\b`)
    820  	callindRE = regexp.MustCompile(`\bcallind\b`)
    821  )
    822  
    823  func main() {
    824 -	goarch := os.Getenv("GOARCH")
    825 +	flag.Parse()
    826 +	goarch := goArch()
    827  	if goarch == "" {
    828 -		goarch = runtime.GOARCH
    829 +		return
    830  	}
    831  
    832 -	version, err := exec.Command("go", "tool", "compile", "-V").Output()
    833 +	version, err := exec.Command(goCmd(), "tool", "compile", "-V").Output()
    834  	if err != nil {
    835  		bug()
    836  		fmt.Printf("running go tool compile -V: %v\n", err)
    837  		return
    838  	}
    839  	if s := string(version); goarch == "amd64" && strings.Contains(s, "X:") && !strings.Contains(s, "framepointer") {
    840  		// Skip this test if framepointer is NOT enabled on AMD64
    841  		return
    842 @@ -340,17 +359,17 @@ TestCases:
    843  
    844  		if err := ioutil.WriteFile(filepath.Join(dir, "asm.s"), buf.Bytes(), 0666); err != nil {
    845  			log.Fatal(err)
    846  		}
    847  		if err := ioutil.WriteFile(filepath.Join(dir, "main.go"), gobuf.Bytes(), 0666); err != nil {
    848  			log.Fatal(err)
    849  		}
    850  
    851 -		cmd := exec.Command("go", "build")
    852 +		cmd := exec.Command(goCmd(), "build")
    853  		cmd.Dir = dir
    854  		output, err := cmd.CombinedOutput()
    855  		if err == nil {
    856  			nok++
    857  			if reject {
    858  				bug()
    859  				fmt.Printf("accepted incorrectly:\n\t%s\n", indent(strings.TrimSpace(stanza)))
    860  			}
    861 --- test/run.go
    862 +++ test/run.go
    863 @@ -222,16 +222,26 @@ func goRun(runcmd runCmd, flags []string, goname string, args ...string) (out []
    864  		cmd = append(cmd, findExecCmd()...)
    865  	}
    866  	cmd = append(cmd, flags...)
    867  	cmd = append(cmd, goname)
    868  	cmd = append(cmd, args...)
    869  	return runcmd(cmd...)
    870  }
    871  
    872 +func goRunTarget(runcmd runCmd, goname string, args ...string) (out []byte, err error) {
    873 +	cmd := []string{"go_local", "run"}
    874 +	cmd = append(cmd, goname)
    875 +	if *target != "" {
    876 +		cmd = append(cmd, "-target", *target)
    877 +	}
    878 +	cmd = append(cmd, args...)
    879 +	return runcmd(cmd...)
    880 +}
    881 +
    882  // skipError describes why a test was skipped.
    883  type skipError string
    884  
    885  func (s skipError) Error() string { return string(s) }
    886  
    887  func check(err error) {
    888  	if err != nil {
    889  		log.Fatal(err)
    890 @@ -484,17 +494,17 @@ func (t *test) run() {
    891  	}
    892  
    893  	// TODO: Clean up/simplify this switch statement.
    894  	switch action {
    895  	case "rundircmpout":
    896  		action = "rundir"
    897  	case "cmpout":
    898  		action = "run" // the run case already looks for <dir>/<test>.out files
    899 -	case "compile", "compiledir", "build", "builddir", "run", "buildrun", "runoutput", "rundir":
    900 +	case "compile", "compiledir", "build", "builddir", "run", "runtarget", "buildrun", "runoutput", "rundir":
    901  		// nothing to do
    902  	case "errorcheckandrundir":
    903  		wantError = false // should be no error if also will run
    904  	case "errorcheckwithauto":
    905  		action = "errorcheck"
    906  		wantAuto = true
    907  		wantError = true
    908  	case "errorcheck", "errorcheckdir", "errorcheckoutput":
    909 @@ -807,16 +817,27 @@ func (t *test) run() {
    910  		if err != nil {
    911  			t.err = err
    912  			return
    913  		}
    914  		if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
    915  			t.err = fmt.Errorf("incorrect output\n%s", out)
    916  		}
    917  
    918 +	case "runtarget":
    919 +		useTmp = false
    920 +		out, err := goRunTarget(runcmd, t.goFileName(), args...)
    921 +		if err != nil {
    922 +			t.err = err
    923 +			return
    924 +		}
    925 +		if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
    926 +			t.err = fmt.Errorf("incorrect output\n%s", out)
    927 +		}
    928 +
    929  	case "runoutput":
    930  		rungatec <- true
    931  		defer func() {
    932  			<-rungatec
    933  		}()
    934  		useTmp = false
    935  		out, err := goRun(runcmd, nil, t.goFileName(), args...)
    936  		if err != nil {
    937 --- test/sinit_run.go
    938 +++ test/sinit_run.go
    939 @@ -1,28 +1,39 @@
    940  // +build !nacl
    941 -// run
    942 +// runtarget
    943  
    944  // Copyright 2014 The Go Authors. All rights reserved.
    945  // Use of this source code is governed by a BSD-style
    946  // license that can be found in the LICENSE file.
    947  
    948  // Run the sinit test.
    949  
    950  package main
    951  
    952  import (
    953  	"bytes"
    954 +	"flag"
    955  	"fmt"
    956  	"os"
    957  	"os/exec"
    958  )
    959  
    960 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
    961 +
    962 +func goCmd() string {
    963 +	if *target != "" {
    964 +		return "go_" + *target
    965 +	}
    966 +	return "go"
    967 +}
    968 +
    969  func main() {
    970 -	cmd := exec.Command("go", "tool", "compile", "-S", "sinit.go")
    971 +	flag.Parse()
    972 +	cmd := exec.Command(goCmd(), "tool", "compile", "-S", "sinit.go")
    973  	out, err := cmd.CombinedOutput()
    974  	if err != nil {
    975  		fmt.Println(string(out))
    976  		fmt.Println(err)
    977  		os.Exit(1)
    978  	}
    979  	os.Remove("sinit.o")
    980  
    981