5
5
package main
6
6
7
7
import (
8
+ "flag"
8
9
"go/build"
9
10
"internal/testenv"
10
11
"io/ioutil"
@@ -49,6 +50,16 @@ var armNeed = []string{
49
50
"RET" ,
50
51
}
51
52
53
+ var ppcNeed = []string {
54
+ "fmthello.go:6" ,
55
+ "TEXT main.main(SB)" ,
56
+ "BR main.main(SB)" ,
57
+ "BL fmt.Println(SB)" ,
58
+ "RET" ,
59
+ }
60
+
61
+ var target = flag .String ("target" , "" , "test disassembly of `goos/goarch` binary" )
62
+
52
63
// objdump is fully cross platform: it can handle binaries
53
64
// from any known operating system and architecture.
54
65
// We could in principle add binaries to testdata and check
@@ -62,6 +73,19 @@ func testDisasm(t *testing.T, flags ...string) {
62
73
tmp , exe := buildObjdump (t )
63
74
defer os .RemoveAll (tmp )
64
75
76
+ goarch := runtime .GOARCH
77
+ if * target != "" {
78
+ f := strings .Split (* target , "/" )
79
+ if len (f ) != 2 {
80
+ t .Fatalf ("-target argument must be goos/goarch" )
81
+ }
82
+ defer os .Setenv ("GOOS" , os .Getenv ("GOOS" ))
83
+ defer os .Setenv ("GOARCH" , os .Getenv ("GOARCH" ))
84
+ os .Setenv ("GOOS" , f [0 ])
85
+ os .Setenv ("GOARCH" , f [1 ])
86
+ goarch = f [1 ]
87
+ }
88
+
65
89
hello := filepath .Join (tmp , "hello.exe" )
66
90
args := []string {"build" , "-o" , hello }
67
91
args = append (args , flags ... )
@@ -74,11 +98,13 @@ func testDisasm(t *testing.T, flags ...string) {
74
98
"fmthello.go:6" ,
75
99
"TEXT main.main(SB)" ,
76
100
}
77
- switch runtime . GOARCH {
101
+ switch goarch {
78
102
case "amd64" , "386" :
79
103
need = append (need , x86Need ... )
80
104
case "arm" :
81
105
need = append (need , armNeed ... )
106
+ case "ppc64" , "ppc64le" :
107
+ need = append (need , ppcNeed ... )
82
108
}
83
109
84
110
out , err = exec .Command (exe , "-s" , "main.main" , hello ).CombinedOutput ()
@@ -101,8 +127,6 @@ func testDisasm(t *testing.T, flags ...string) {
101
127
102
128
func TestDisasm (t * testing.T ) {
103
129
switch runtime .GOARCH {
104
- case "ppc64" , "ppc64le" :
105
- t .Skipf ("skipping on %s, issue 9039" , runtime .GOARCH )
106
130
case "arm64" :
107
131
t .Skipf ("skipping on %s, issue 10106" , runtime .GOARCH )
108
132
case "mips64" , "mips64le" :
0 commit comments