1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
17 func buildObjdump(t *testing.T) (tmp, exe string) {
19 case "android", "nacl":
20 t.Skipf("skipping on %s", runtime.GOOS)
23 tmp, err := ioutil.TempDir("", "TestObjDump")
25 t.Fatal("TempDir failed: ", err)
28 exe = filepath.Join(tmp, "testobjdump.exe")
29 out, err := exec.Command("go", "build", "-o", exe, "cmd/objdump").CombinedOutput()
32 t.Fatalf("go build -o %v cmd/objdump: %v\n%s", exe, err, string(out))
37 var x86Need = []string{
41 "CALL fmt.Println(SB)",
45 var armNeed = []string{
48 //"B.LS main.main(SB)", // TODO(rsc): restore; golang.org/issue/9021
53 // objdump is fully cross platform: it can handle binaries
54 // from any known operating system and architecture.
55 // We could in principle add binaries to testdata and check
56 // all the supported systems during this test. However, the
57 // binaries would be about 1 MB each, and we don't want to
58 // add that much junk to the hg repository. Instead, build a
59 // binary for the current system (only) and test that objdump
60 // can handle that one.
62 func testDisasm(t *testing.T, flags ...string) {
63 tmp, exe := buildObjdump(t)
64 defer os.RemoveAll(tmp)
66 hello := filepath.Join(tmp, "hello.exe")
67 args := []string{"build", "-o", hello}
68 args = append(args, flags...)
69 args = append(args, "testdata/fmthello.go")
70 out, err := exec.Command("go", args...).CombinedOutput()
72 t.Fatalf("go build fmthello.go: %v\n%s", err, out)
78 switch runtime.GOARCH {
80 need = append(need, x86Need...)
82 need = append(need, armNeed...)
85 out, err = exec.Command(exe, "-s", "main.main", hello).CombinedOutput()
87 t.Fatalf("objdump fmthello.exe: %v\n%s", err, out)
92 for _, s := range need {
93 if !strings.Contains(text, s) {
94 t.Errorf("disassembly missing '%s'", s)
99 t.Logf("full disassembly:\n%s", text)
103 func TestDisasm(t *testing.T) {
104 switch runtime.GOARCH {
105 case "power64", "power64le":
106 t.Skipf("skipping on %s, issue 9039", runtime.GOARCH)
111 func TestDisasmExtld(t *testing.T) {
112 switch runtime.GOOS {
113 case "plan9", "windows":
114 t.Skipf("skipping on %s", runtime.GOOS)
116 switch runtime.GOARCH {
117 case "power64", "power64le":
118 t.Skipf("skipping on %s, no support for external linking, issue 9038", runtime.GOARCH)
120 testDisasm(t, "-ldflags=-linkmode=external")