diff options
| author | Lynn Boger <laboger@linux.vnet.ibm.com> | 2020-03-25 13:47:43 -0400 |
|---|---|---|
| committer | Lynn Boger <laboger@linux.vnet.ibm.com> | 2020-03-30 14:30:49 +0000 |
| commit | 5a312288799c0a433e2061550ff92689b627e080 (patch) | |
| tree | 6d80f1c3bbdc98622747391ae237ebe68cf0b42a /src/cmd/objdump/objdump_test.go | |
| parent | 89e13c88e4f9f3a3eea7bf105e5af475727a4c33 (diff) | |
| download | go-5a312288799c0a433e2061550ff92689b627e080.tar.xz | |
cmd/objdump: add support for -gnu option on Go objdump
This adds support for the -gnu option on Go objdump. When
this option is used, then output will include gnu
assembly in comments alongside the Go assembly.
The objdump test was updated to test this new option.
This option is supported for the arches found in
golang.org/x that provide the GNUsyntax function.
Updates #34372
Change-Id: I9e60e1691526607dda3c857c4564dcef408b8391
Reviewed-on: https://go-review.googlesource.com/c/go/+/225459
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/cmd/objdump/objdump_test.go')
| -rw-r--r-- | src/cmd/objdump/objdump_test.go | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/src/cmd/objdump/objdump_test.go b/src/cmd/objdump/objdump_test.go index 7ed32cf3c2..5030ec65d2 100644 --- a/src/cmd/objdump/objdump_test.go +++ b/src/cmd/objdump/objdump_test.go @@ -64,18 +64,42 @@ var x86Need = []string{ "RET", } +var amd64GnuNeed = []string{ + "movq", + "callq", + "cmpb", +} + +var i386GnuNeed = []string{ + "mov", + "call", + "cmp", +} + var armNeed = []string{ "B main.main(SB)", "BL main.Println(SB)", "RET", } +var arm64GnuNeed = []string{ + "ldr", + "bl", + "cmp", +} + var ppcNeed = []string{ "BR main.main(SB)", "CALL main.Println(SB)", "RET", } +var ppcGnuNeed = []string{ + "mflr", + "lbz", + "cmpw", +} + var target = flag.String("target", "", "test disassembly of `goos/goarch` binary") // objdump is fully cross platform: it can handle binaries @@ -87,7 +111,7 @@ var target = flag.String("target", "", "test disassembly of `goos/goarch` binary // binary for the current system (only) and test that objdump // can handle that one. -func testDisasm(t *testing.T, printCode bool, flags ...string) { +func testDisasm(t *testing.T, printCode bool, printGnuAsm bool, flags ...string) { t.Parallel() goarch := runtime.GOARCH if *target != "" { @@ -102,7 +126,7 @@ func testDisasm(t *testing.T, printCode bool, flags ...string) { goarch = f[1] } - hash := md5.Sum([]byte(fmt.Sprintf("%v-%v", flags, printCode))) + hash := md5.Sum([]byte(fmt.Sprintf("%v-%v-%v", flags, printCode, printGnuAsm))) hello := filepath.Join(tmp, fmt.Sprintf("hello-%x.exe", hash)) args := []string{"build", "-o", hello} args = append(args, flags...) @@ -133,6 +157,18 @@ func testDisasm(t *testing.T, printCode bool, flags ...string) { need = append(need, ppcNeed...) } + if printGnuAsm { + switch goarch { + case "amd64": + need = append(need, amd64GnuNeed...) + case "386": + need = append(need, i386GnuNeed...) + case "arm64": + need = append(need, arm64GnuNeed...) + case "ppc64", "ppc64le": + need = append(need, ppcGnuNeed...) + } + } args = []string{ "-s", "main.main", hello, @@ -142,6 +178,9 @@ func testDisasm(t *testing.T, printCode bool, flags ...string) { args = append([]string{"-S"}, args...) } + if printGnuAsm { + args = append([]string{"-gnu"}, args...) + } cmd = exec.Command(exe, args...) cmd.Dir = "testdata" // "Bad line" bug #36683 is sensitive to being run in the source directory out, err = cmd.CombinedOutput() @@ -180,7 +219,7 @@ func TestDisasm(t *testing.T) { case "s390x": t.Skipf("skipping on %s, issue 15255", runtime.GOARCH) } - testDisasm(t, false) + testDisasm(t, false, false) } func TestDisasmCode(t *testing.T) { @@ -188,7 +227,17 @@ func TestDisasmCode(t *testing.T) { case "mips", "mipsle", "mips64", "mips64le", "riscv64", "s390x": t.Skipf("skipping on %s, issue 19160", runtime.GOARCH) } - testDisasm(t, true) + testDisasm(t, true, false) +} + +func TestDisasmGnuAsm(t *testing.T) { + switch runtime.GOARCH { + case "mips", "mipsle", "mips64", "mips64le", "riscv64", "s390x": + t.Skipf("skipping on %s, issue 19160", runtime.GOARCH) + case "arm": + t.Skipf("skipping gnuAsm test on %s", runtime.GOARCH) + } + testDisasm(t, false, true) } func TestDisasmExtld(t *testing.T) { @@ -209,7 +258,7 @@ func TestDisasmExtld(t *testing.T) { if !build.Default.CgoEnabled { t.Skip("skipping because cgo is not enabled") } - testDisasm(t, false, "-ldflags=-linkmode=external") + testDisasm(t, false, false, "-ldflags=-linkmode=external") } func TestDisasmGoobj(t *testing.T) { |
