aboutsummaryrefslogtreecommitdiff
path: root/go/patch/go-1.10.3/go3.patch
blob: 223ccb8515c07b0f04e4f42f3c89d48b365e4780 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
diff --git test/fixedbugs/bug302.go test/fixedbugs/bug302.go
index e4de25d5d0..ea566e6e44 100644
--- test/fixedbugs/bug302.go
+++ test/fixedbugs/bug302.go
@@ -1,5 +1,5 @@
 // +build !nacl
-// run
+// runtarget
 
 // Copyright 2010 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -8,16 +8,27 @@
 package main
 
 import (
+	"flag"
 	"fmt"
 	"os"
 	"os/exec"
 	"path/filepath"
 )
 
+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
+
+func goCmd() string {
+        if *target != "" {
+                return "go_" + *target
+        }
+        return "go"
+}
+
 func main() {
-	run("go", "tool", "compile", filepath.Join("fixedbugs", "bug302.dir", "p.go"))
-	run("go", "tool", "pack", "grc", "pp.a", "p.o")
-	run("go", "tool", "compile", "-I", ".", filepath.Join("fixedbugs", "bug302.dir", "main.go"))
+	flag.Parse()
+	run(goCmd(), "tool", "compile", filepath.Join("fixedbugs", "bug302.dir", "p.go"))
+	run(goCmd(), "tool", "pack", "grc", "pp.a", "p.o")
+	run(goCmd(), "tool", "compile", "-I", ".", filepath.Join("fixedbugs", "bug302.dir", "main.go"))
 	os.Remove("p.o")
 	os.Remove("pp.a")
 	os.Remove("main.o")
diff --git test/fixedbugs/bug369.go test/fixedbugs/bug369.go
index 60162ab1cb..4470d5a076 100644
--- test/fixedbugs/bug369.go
+++ test/fixedbugs/bug369.go
@@ -1,5 +1,5 @@
 // +build !nacl,!windows
-// run
+// runtarget
 
 // Copyright 2011 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -10,21 +10,40 @@
 package main
 
 import (
+	"flag"
 	"fmt"
 	"os"
 	"os/exec"
 	"path/filepath"
 )
 
+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
+
+func goCmd() string {
+       if *target != "" {
+               return "go_" + *target
+       }
+       return "go"
+}
+
+func goRun(cmd ...string) {
+       if *target == "" {
+               run(cmd[0], cmd[1:]...)
+       } else {
+               run("go_"+*target+"_exec", cmd...)
+       }
+}
+
 func main() {
+	flag.Parse()
 	err := os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir"))
 	check(err)
 
-	run("go", "tool", "compile", "-N", "-o", "slow.o", "pkg.go")
-	run("go", "tool", "compile", "-o", "fast.o", "pkg.go")
-	run("go", "tool", "compile", "-o", "main.o", "main.go")
-	run("go", "tool", "link", "-o", "a.exe", "main.o")
-	run("." + string(filepath.Separator) + "a.exe")
+	run(goCmd(), "tool", "compile", "-N", "-o", "slow.o", "pkg.go")
+	run(goCmd(), "tool", "compile", "-o", "fast.o", "pkg.go")
+	run(goCmd(), "tool", "compile", "-o", "main.o", "main.go")
+	run(goCmd(), "tool", "link", "-o", "a.exe", "main.o")
+	goRun("." + string(filepath.Separator) + "a.exe")
 
 	os.Remove("slow.o")
 	os.Remove("fast.o")
diff --git test/fixedbugs/bug429_run.go test/fixedbugs/bug429_run.go
index 284033d1f7..e8d18b13e8 100644
--- test/fixedbugs/bug429_run.go
+++ test/fixedbugs/bug429_run.go
@@ -1,5 +1,5 @@
 // +build !nacl
-// run
+// runtarget
 
 // Copyright 2014 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -10,6 +10,7 @@
 package main
 
 import (
+	"flag"
 	"fmt"
 	"os"
 	"os/exec"
@@ -17,8 +18,27 @@ import (
 	"strings"
 )
 
+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
+
+func goCmd() string {
+       if *target != "" {
+               return "go_" + *target
+       }
+       return "go"
+}
+
+func goRun(args ...string) *exec.Cmd {
+       cmd := []string{"run"}
+       if *target != "" {
+               cmd = append(cmd, "-exec", "go_"+*target+"_exec")
+       }
+       cmd = append(cmd, args...)
+       return exec.Command(goCmd(), cmd...)
+}
+
 func main() {
-	cmd := exec.Command("go", "run", filepath.Join("fixedbugs", "bug429.go"))
+	flag.Parse()
+	cmd := goRun(filepath.Join("fixedbugs", "bug429.go"))
 	out, err := cmd.CombinedOutput()
 	if err == nil {
 		fmt.Println("expected deadlock")
diff --git test/fixedbugs/issue10607.go test/fixedbugs/issue10607.go
index 9ee6c72bc6..e819a3085a 100644
--- test/fixedbugs/issue10607.go
+++ test/fixedbugs/issue10607.go
@@ -1,5 +1,5 @@
 // +build linux,!ppc64 android
-// run
+// runtarget
 
 // Copyright 2015 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -11,19 +11,39 @@
 package main
 
 import (
+	"flag"
 	"fmt"
 	"os"
 	"os/exec"
 	"path/filepath"
 )
 
+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
+
+func goCmd() string {
+       if *target != "" {
+               return "go_" + *target
+       }
+       return "go"
+}
+
+func goRun(args ...string) *exec.Cmd {
+       cmd := []string{"run"}
+       if *target != "" {
+               cmd = append(cmd, "-exec", "go_"+*target+"_exec")
+       }
+       cmd = append(cmd, args...)
+       return exec.Command(goCmd(), cmd...)
+}
+
 func main() {
-	test("internal")
+	flag.Parse()
+	//test("internal")
 	test("external")
 }
 
 func test(linkmode string) {
-	out, err := exec.Command("go", "run", "-ldflags", "-B=0x12345678 -linkmode="+linkmode, filepath.Join("fixedbugs", "issue10607a.go")).CombinedOutput()
+	out, err := goRun("-ldflags", "-B=0x12345678 -linkmode="+linkmode, filepath.Join("fixedbugs", "issue10607a.go")).CombinedOutput()
 	if err != nil {
 		fmt.Printf("BUG: linkmode=%s %v\n%s\n", linkmode, err, out)
 		os.Exit(1)
diff --git test/fixedbugs/issue11771.go test/fixedbugs/issue11771.go
index d91fc5d966..4f55ce6982 100644
--- test/fixedbugs/issue11771.go
+++ test/fixedbugs/issue11771.go
@@ -1,5 +1,5 @@
 // +build !nacl
-// run
+// runtarget
 
 // Copyright 2015 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -11,6 +11,7 @@ package main
 
 import (
 	"bytes"
+	"flag"
 	"fmt"
 	"io/ioutil"
 	"log"
@@ -20,7 +21,17 @@ import (
 	"runtime"
 )
 
+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
+
+func goCmd() string {
+       if *target != "" {
+               return "go_" + *target
+       }
+       return "go"
+}
+
 func main() {
+	flag.Parse()
 	if runtime.Compiler != "gc" {
 		return
 	}
@@ -52,7 +63,7 @@ func x() {
 		log.Fatal(err)
 	}
 
-	cmd := exec.Command("go", "tool", "compile", "x.go")
+	cmd := exec.Command(goCmd(), "tool", "compile", "x.go")
 	cmd.Dir = dir
 	output, err := cmd.CombinedOutput()
 	if err == nil {
diff --git test/fixedbugs/issue9355.go test/fixedbugs/issue9355.go
index 10f8c73069..87356c7402 100644
--- test/fixedbugs/issue9355.go
+++ test/fixedbugs/issue9355.go
@@ -1,4 +1,4 @@
-// run
+// runtarget
 
 // Copyright 2014 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -7,6 +7,7 @@
 package main
 
 import (
+	"flag"
 	"fmt"
 	"os"
 	"os/exec"
@@ -15,7 +16,17 @@ import (
 	"runtime"
 )
 
+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
+
+func goCmd() string {
+        if *target != "" {
+                return "go_" + *target
+        }
+        return "go"
+}
+
 func main() {
+	flag.Parse()
 	if runtime.Compiler != "gc" || runtime.GOOS == "nacl" {
 		return
 	}
@@ -23,7 +34,7 @@ func main() {
 	err := os.Chdir(filepath.Join("fixedbugs", "issue9355.dir"))
 	check(err)
 
-	out := run("go", "tool", "compile", "-S", "a.go")
+	out := run(goCmd(), "tool", "compile", "-S", "a.go")
 	os.Remove("a.o")
 
 	// 6g/8g print the offset as dec, but 5g/9g print the offset as hex.
diff --git test/fixedbugs/issue9862_run.go test/fixedbugs/issue9862_run.go
index be22f40580..a72a59fda2 100644
--- test/fixedbugs/issue9862_run.go
+++ test/fixedbugs/issue9862_run.go
@@ -1,5 +1,5 @@
 // +build !nacl
-// run
+// runtarget
 
 // Copyright 2015 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -10,12 +10,32 @@
 package main
 
 import (
+	"flag"
 	"os/exec"
 	"strings"
 )
 
+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
+
+func goCmd() string {
+        if *target != "" {
+                return "go_" + *target
+        }
+        return "go"
+}
+
+func goRun(args ...string) *exec.Cmd {
+        cmd := []string{"run"}
+        if *target != "" {
+                cmd = append(cmd, "-exec", "go_"+*target+"_exec")
+        }
+        cmd = append(cmd, args...)
+        return exec.Command(goCmd(), cmd...)
+}
+
 func main() {
-	out, err := exec.Command("go", "run", "fixedbugs/issue9862.go").CombinedOutput()
+	flag.Parse()
+	out, err := goRun("fixedbugs/issue9862.go").CombinedOutput()
 	outstr := string(out)
 	if err == nil {
 		println("go run issue9862.go succeeded, should have failed\n", outstr)
diff --git test/linkmain_run.go test/linkmain_run.go
index 55de481a81..03666e6b29 100644
--- test/linkmain_run.go
+++ test/linkmain_run.go
@@ -1,5 +1,5 @@
 // +build !nacl
-// run
+// runtarget
 
 // Copyright 2014 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -10,12 +10,22 @@
 package main
 
 import (
+	"flag"
 	"fmt"
 	"os"
 	"os/exec"
 	"strings"
 )
 
+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
+
+func goCmd() string {
+        if *target != "" {
+                return "go_" + *target
+        }
+        return "go"
+}
+
 func cleanup() {
 	os.Remove("linkmain.o")
 	os.Remove("linkmain.a")
@@ -51,16 +61,17 @@ func runFail(cmdline string) {
 }
 
 func main() {
+	flag.Parse()
 	// helloworld.go is package main
-	run("go tool compile -o linkmain.o helloworld.go")
-	run("go tool compile -pack -o linkmain.a helloworld.go")
-	run("go tool link -o linkmain.exe linkmain.o")
-	run("go tool link -o linkmain.exe linkmain.a")
+	run(goCmd() + " tool compile -o linkmain.o helloworld.go")
+	run(goCmd() + " tool compile -pack -o linkmain.a helloworld.go")
+	run(goCmd() + " tool link -o linkmain.exe linkmain.o")
+	run(goCmd() + " tool link -o linkmain.exe linkmain.a")
 
 	// linkmain.go is not
-	run("go tool compile -o linkmain1.o linkmain.go")
-	run("go tool compile -pack -o linkmain1.a linkmain.go")
-	runFail("go tool link -o linkmain.exe linkmain1.o")
-	runFail("go tool link -o linkmain.exe linkmain1.a")
+	run(goCmd() + " tool compile -o linkmain1.o linkmain.go")
+	run(goCmd() + " tool compile -pack -o linkmain1.a linkmain.go")
+	runFail(goCmd() + " tool link -o linkmain.exe linkmain1.o")
+	runFail(goCmd() + " tool link -o linkmain.exe linkmain1.a")
 	cleanup()
 }
diff --git test/linkobj.go test/linkobj.go
index 8a86aa872f..0d1964e7fb 100644
--- test/linkobj.go
+++ test/linkobj.go
@@ -1,5 +1,5 @@
 // +build !nacl
-// run
+// runtarget
 
 // Copyright 2016 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -10,6 +10,7 @@
 package main
 
 import (
+	"flag"
 	"fmt"
 	"io/ioutil"
 	"log"
@@ -18,9 +19,27 @@ import (
 	"strings"
 )
 
+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
+
+func goCmd() string {
+        if *target != "" {
+                return "go_" + *target
+        }
+        return "go"
+}
+
+func goRun(cmd ...string) string {
+        if *target == "" {
+                return run(cmd...)
+        } else {
+                return run(append([]string{"go_"+*target+"_exec"}, cmd...)...)
+        }
+}
+
 var pwd, tmpdir string
 
 func main() {
+	flag.Parse()
 	dir, err := ioutil.TempDir("", "go-test-linkobj-")
 	if err != nil {
 		log.Fatal(err)
@@ -37,28 +56,28 @@ func main() {
 
 	writeFile("p1.go", `
 		package p1
-		
+
 		func F() {
 			println("hello from p1")
 		}
 	`)
 	writeFile("p2.go", `
 		package p2
-		
+
 		import "./p1"
 
 		func F() {
 			p1.F()
 			println("hello from p2")
 		}
-		
+
 		func main() {}
 	`)
 	writeFile("p3.go", `
 		package main
 
 		import "./p2"
-		
+
 		func main() {
 			p2.F()
 			println("hello from main")
@@ -76,9 +95,9 @@ func main() {
 		}
 
 		// inlining is disabled to make sure that the link objects contain needed code.
-		run("go", "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p1."+o, "-linkobj", "p1.lo", "p1.go")
-		run("go", "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p2."+o, "-linkobj", "p2.lo", "p2.go")
-		run("go", "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p3."+o, "-linkobj", "p3.lo", "p3.go")
+		run(goCmd(), "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p1."+o, "-linkobj", "p1.lo", "p1.go")
+		run(goCmd(), "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p2."+o, "-linkobj", "p2.lo", "p2.go")
+		run(goCmd(), "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p3."+o, "-linkobj", "p3.lo", "p3.go")
 
 		cp("p1."+o, "p1.oo")
 		cp("p2."+o, "p2.oo")
@@ -86,13 +105,13 @@ func main() {
 		cp("p1.lo", "p1."+o)
 		cp("p2.lo", "p2."+o)
 		cp("p3.lo", "p3."+o)
-		out := runFail("go", "tool", "link", "p2."+o)
+		out := runFail(goCmd(), "tool", "link", "p2."+o)
 		if !strings.Contains(out, "not package main") {
 			fatalf("link p2.o failed but not for package main:\n%s", out)
 		}
 
-		run("go", "tool", "link", "-L", ".", "-o", "a.out.exe", "p3."+o)
-		out = run("./a.out.exe")
+		run(goCmd(), "tool", "link", "-L", ".", "-o", "a.out.exe", "p3."+o)
+		out = goRun("./a.out.exe")
 		if !strings.Contains(out, "hello from p1\nhello from p2\nhello from main\n") {
 			fatalf("running main, incorrect output:\n%s", out)
 		}
diff --git test/linkx_run.go test/linkx_run.go
index cc249c9cfc..530159ab9d 100644
--- test/linkx_run.go
+++ test/linkx_run.go
@@ -1,5 +1,5 @@
 // +build !nacl
-// run
+// runtarget
 
 // Copyright 2014 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -11,20 +11,40 @@ package main
 
 import (
 	"bytes"
+	"flag"
 	"fmt"
 	"os"
 	"os/exec"
 	"strings"
 )
 
+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
+
+func goCmd() string {
+        if *target != "" {
+                return "go_" + *target
+        }
+        return "go"
+}
+
+func goRun(args ...string) *exec.Cmd {
+        cmd := []string{"run"}
+        if *target != "" {
+                cmd = append(cmd, "-exec", "go_"+*target+"_exec")
+        }
+        cmd = append(cmd, args...)
+        return exec.Command(goCmd(), cmd...)
+}
+
 func main() {
+	flag.Parse()
 	// test(" ") // old deprecated & removed syntax
 	test("=") // new syntax
 }
 
 func test(sep string) {
 	// Successful run
-	cmd := exec.Command("go", "run", "-ldflags=-X main.tbd"+sep+"hello -X main.overwrite"+sep+"trumped -X main.nosuchsymbol"+sep+"neverseen", "linkx.go")
+	cmd := goRun("-ldflags=-X main.tbd"+sep+"hello -X main.overwrite"+sep+"trumped -X main.nosuchsymbol"+sep+"neverseen", "linkx.go")
 	var out, errbuf bytes.Buffer
 	cmd.Stdout = &out
 	cmd.Stderr = &errbuf
@@ -44,7 +64,7 @@ func test(sep string) {
 	}
 
 	// Issue 8810
-	cmd = exec.Command("go", "run", "-ldflags=-X main.tbd", "linkx.go")
+	cmd = goRun("-ldflags=-X main.tbd", "linkx.go")
 	_, err = cmd.CombinedOutput()
 	if err == nil {
 		fmt.Println("-X linker flag should not accept keys without values")
@@ -52,7 +72,7 @@ func test(sep string) {
 	}
 
 	// Issue 9621
-	cmd = exec.Command("go", "run", "-ldflags=-X main.b=false -X main.x=42", "linkx.go")
+	cmd = goRun("-ldflags=-X main.b=false -X main.x=42", "linkx.go")
 	outx, err := cmd.CombinedOutput()
 	if err == nil {
 		fmt.Println("-X linker flag should not overwrite non-strings")
diff --git test/nosplit.go test/nosplit.go
index e6cecebde3..fed1c0e510 100644
--- test/nosplit.go
+++ test/nosplit.go
@@ -1,5 +1,5 @@
 // +build !nacl
-// run
+// runtarget
 
 // Copyright 2014 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -9,6 +9,7 @@ package main
 
 import (
 	"bytes"
+	"flag"
 	"fmt"
 	"io/ioutil"
 	"log"
@@ -21,6 +22,24 @@ import (
 	"strings"
 )
 
+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
+
+func goCmd() string {
+        if *target != "" {
+                return "go_" + *target
+        }
+        return "go"
+}
+
+func goArch() string {
+        goarch, err := exec.Command(goCmd(), "env", "GOARCH").Output()
+        if err != nil {
+                bug()
+                fmt.Printf("running go env GOARCH: %v\n", err)
+        }
+        return strings.TrimSpace(string(goarch))
+}
+
 var tests = `
 # These are test cases for the linker analysis that detects chains of
 # nosplit functions that would cause a stack overflow.
@@ -194,12 +213,13 @@ var (
 )
 
 func main() {
-	goarch := os.Getenv("GOARCH")
+	flag.Parse()
+	goarch := goArch()
 	if goarch == "" {
-		goarch = runtime.GOARCH
+		return
 	}
 
-	version, err := exec.Command("go", "tool", "compile", "-V").Output()
+	version, err := exec.Command(goCmd(), "tool", "compile", "-V").Output()
 	if err != nil {
 		bug()
 		fmt.Printf("running go tool compile -V: %v\n", err)
@@ -345,7 +365,7 @@ TestCases:
 			log.Fatal(err)
 		}
 
-		cmd := exec.Command("go", "build")
+		cmd := exec.Command(goCmd(), "build")
 		cmd.Dir = dir
 		output, err := cmd.CombinedOutput()
 		if err == nil {
diff --git test/run.go test/run.go
index ac5d3c3e8d..62041226b0 100644
--- test/run.go
+++ test/run.go
@@ -229,6 +229,16 @@ func goRun(runcmd runCmd, flags []string, goname string, args ...string) (out []
         return runcmd(cmd...)
 }
 
+func goRunTarget(runcmd runCmd, goname string, args ...string) (out []byte, err error) {
+        cmd := []string{"go_local", "run"}
+        cmd = append(cmd, goname)
+        if *target != "" {
+                cmd = append(cmd, "-target", *target)
+        }
+        cmd = append(cmd, args...)
+        return runcmd(cmd...)
+}
+
 // skipError describes why a test was skipped.
 type skipError string
 
@@ -491,7 +501,7 @@ func (t *test) run() {
 		action = "rundir"
 	case "cmpout":
 		action = "run" // the run case already looks for <dir>/<test>.out files
-	case "compile", "compiledir", "build", "builddir", "run", "buildrun", "runoutput", "rundir":
+	case "compile", "compiledir", "build", "builddir", "run", "runtarget", "buildrun", "runoutput", "rundir":
 		// nothing to do
 	case "errorcheckandrundir":
 		wantError = false // should be no error if also will run
@@ -816,6 +826,17 @@ func (t *test) run() {
 			t.err = fmt.Errorf("incorrect output\n%s", out)
 		}
 
+       case "runtarget":
+                useTmp = false
+                out, err := goRunTarget(runcmd, t.goFileName(), args...)
+                if err != nil {
+                        t.err = err
+                        return
+                }
+                if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
+                        t.err = fmt.Errorf("incorrect output\n%s", out)
+                }
+
 	case "runoutput":
 		rungatec <- true
 		defer func() {
diff --git test/sinit_run.go test/sinit_run.go
index c9afd3b777..dc885ecffd 100644
--- test/sinit_run.go
+++ test/sinit_run.go
@@ -1,5 +1,5 @@
 // +build !nacl
-// run
+// runtarget
 
 // Copyright 2014 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -11,13 +11,24 @@ package main
 
 import (
 	"bytes"
+	"flag"
 	"fmt"
 	"os"
 	"os/exec"
 )
 
+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
+
+func goCmd() string {
+       if *target != "" {
+               return "go_" + *target
+       }
+       return "go"
+}
+
 func main() {
-	cmd := exec.Command("go", "tool", "compile", "-S", "sinit.go")
+	flag.Parse()
+	cmd := exec.Command(goCmd(), "tool", "compile", "-S", "sinit.go")
 	out, err := cmd.CombinedOutput()
 	if err != nil {
 		fmt.Println(string(out))