From 20819440fc65d28fabe8f7410ea8fe193cdc53c6 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Thu, 15 Oct 2020 18:04:08 -0400 Subject: cmd/internal/objfile: correct file table reading for Go object file Apparently I never actually understood the new file table in Go object files. The PC value stream actually encodes the file index in the per-CU table. I thought it was indexing into a per-function table, which then contains index to the per-CU table. Remove the extra indirection. Change-Id: I0aea5629f7b3888ebe3a04fea437aa15ce89519e Reviewed-on: https://go-review.googlesource.com/c/go/+/262779 Trust: Cherry Zhang Run-TryBot: Cherry Zhang TryBot-Result: Go Bot Reviewed-by: Than McIntosh Reviewed-by: Jeremy Faller --- src/cmd/objdump/objdump_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/cmd/objdump/objdump_test.go') diff --git a/src/cmd/objdump/objdump_test.go b/src/cmd/objdump/objdump_test.go index 85d1a2efb0..d136e2e6c3 100644 --- a/src/cmd/objdump/objdump_test.go +++ b/src/cmd/objdump/objdump_test.go @@ -333,3 +333,41 @@ func TestDisasmGoobj(t *testing.T) { t.Logf("full disassembly:\n%s", text) } } + +func TestGoobjFileNumber(t *testing.T) { + // Test that file table in Go object file is parsed correctly. + testenv.MustHaveGoBuild(t) + + t.Parallel() + + tmpdir, err := ioutil.TempDir("", "TestGoobjFileNumber") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpdir) + + obj := filepath.Join(tmpdir, "p.a") + cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", obj) + cmd.Dir = filepath.Join("testdata/testfilenum") + out, err := cmd.CombinedOutput() + if err != nil { + t.Fatalf("build failed: %v\n%s", err, out) + } + + cmd = exec.Command(exe, obj) + out, err = cmd.CombinedOutput() + if err != nil { + t.Fatalf("objdump failed: %v\n%s", err, out) + } + + text := string(out) + for _, s := range []string{"a.go", "b.go", "c.go"} { + if !strings.Contains(text, s) { + t.Errorf("output missing '%s'", s) + } + } + + if t.Failed() { + t.Logf("output:\n%s", text) + } +} -- cgit v1.2.1 From e7259c07d4e479d9f83899a4c8b2f58b7b4ff63e Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Fri, 16 Oct 2020 12:11:02 -0400 Subject: cmd/objdump: skip tests on unsupported platforms Should fix mips(64)(le) and s390x builds. Change-Id: I2c80339ce22b0ce5dceb595e504740e74bc840cd Reviewed-on: https://go-review.googlesource.com/c/go/+/263137 Trust: Cherry Zhang Run-TryBot: Cherry Zhang Reviewed-by: Than McIntosh Reviewed-by: Jeremy Faller --- src/cmd/objdump/objdump_test.go | 54 ++++++++++++----------------------------- 1 file changed, 16 insertions(+), 38 deletions(-) (limited to 'src/cmd/objdump/objdump_test.go') diff --git a/src/cmd/objdump/objdump_test.go b/src/cmd/objdump/objdump_test.go index d136e2e6c3..02a8b71385 100644 --- a/src/cmd/objdump/objdump_test.go +++ b/src/cmd/objdump/objdump_test.go @@ -106,6 +106,17 @@ var ppcGnuNeed = []string{ "cmpw", } +func mustHaveDisasm(t *testing.T) { + switch runtime.GOARCH { + case "mips", "mipsle", "mips64", "mips64le": + t.Skipf("skipping on %s, issue 12559", runtime.GOARCH) + case "riscv64": + t.Skipf("skipping on %s, issue 36738", runtime.GOARCH) + case "s390x": + t.Skipf("skipping on %s, issue 15255", runtime.GOARCH) + } +} + var target = flag.String("target", "", "test disassembly of `goos/goarch` binary") // objdump is fully cross platform: it can handle binaries @@ -118,6 +129,7 @@ var target = flag.String("target", "", "test disassembly of `goos/goarch` binary // can handle that one. func testDisasm(t *testing.T, srcfname string, printCode bool, printGnuAsm bool, flags ...string) { + mustHaveDisasm(t) goarch := runtime.GOARCH if *target != "" { f := strings.Split(*target, "/") @@ -227,71 +239,36 @@ func testGoAndCgoDisasm(t *testing.T, printCode bool, printGnuAsm bool) { testDisasm(t, "fmthello.go", printCode, printGnuAsm) if build.Default.CgoEnabled { if runtime.GOOS == "aix" { - t.Skipf("skipping on %s, issue 40972", runtime.GOOS) + return // issue 40972 } testDisasm(t, "fmthellocgo.go", printCode, printGnuAsm) } } func TestDisasm(t *testing.T) { - switch runtime.GOARCH { - case "mips", "mipsle", "mips64", "mips64le": - t.Skipf("skipping on %s, issue 12559", runtime.GOARCH) - case "riscv64": - t.Skipf("skipping on %s, issue 36738", runtime.GOARCH) - case "s390x": - t.Skipf("skipping on %s, issue 15255", runtime.GOARCH) - } testGoAndCgoDisasm(t, false, false) } func TestDisasmCode(t *testing.T) { - switch runtime.GOARCH { - case "mips", "mipsle", "mips64", "mips64le", "riscv64", "s390x": - t.Skipf("skipping on %s, issue 19160", runtime.GOARCH) - } testGoAndCgoDisasm(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) - } testGoAndCgoDisasm(t, false, true) } func TestDisasmExtld(t *testing.T) { + testenv.MustHaveCGO(t) switch runtime.GOOS { case "plan9", "windows": t.Skipf("skipping on %s", runtime.GOOS) } - switch runtime.GOARCH { - case "ppc64": - t.Skipf("skipping on %s, no support for external linking, issue 9038", runtime.GOARCH) - case "mips64", "mips64le", "mips", "mipsle": - t.Skipf("skipping on %s, issue 12559 and 12560", runtime.GOARCH) - case "riscv64": - t.Skipf("skipping on %s, no support for external linking, issue 36739", runtime.GOARCH) - case "s390x": - t.Skipf("skipping on %s, issue 15255", runtime.GOARCH) - } - if !build.Default.CgoEnabled { - t.Skip("skipping because cgo is not enabled") - } t.Parallel() testDisasm(t, "fmthello.go", false, false, "-ldflags=-linkmode=external") } func TestDisasmGoobj(t *testing.T) { - switch runtime.GOARCH { - case "mips", "mipsle", "mips64", "mips64le": - t.Skipf("skipping on %s, issue 12559", runtime.GOARCH) - case "riscv64": - t.Skipf("skipping on %s, issue 36738", runtime.GOARCH) - case "s390x": - t.Skipf("skipping on %s, issue 15255", runtime.GOARCH) - } + mustHaveDisasm(t) hello := filepath.Join(tmp, "hello.o") args := []string{"tool", "compile", "-o", hello} @@ -337,6 +314,7 @@ func TestDisasmGoobj(t *testing.T) { func TestGoobjFileNumber(t *testing.T) { // Test that file table in Go object file is parsed correctly. testenv.MustHaveGoBuild(t) + mustHaveDisasm(t) t.Parallel() -- cgit v1.2.1 From 3eae1a905854fd9f4ebeeae406c4ebb88cbd779b Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Fri, 16 Oct 2020 15:29:25 -0400 Subject: cmd/objdump: skip TestDisasmExtld on AIX Fixes #42025. Change-Id: I34bed3364902e37df24ed6f56cddf163c7a4dc52 Reviewed-on: https://go-review.googlesource.com/c/go/+/263147 Trust: Cherry Zhang Reviewed-by: Jeremy Faller Reviewed-by: Than McIntosh Run-TryBot: Cherry Zhang TryBot-Result: Go Bot --- src/cmd/objdump/objdump_test.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/cmd/objdump/objdump_test.go') diff --git a/src/cmd/objdump/objdump_test.go b/src/cmd/objdump/objdump_test.go index 02a8b71385..cb692e7a81 100644 --- a/src/cmd/objdump/objdump_test.go +++ b/src/cmd/objdump/objdump_test.go @@ -262,6 +262,8 @@ func TestDisasmExtld(t *testing.T) { switch runtime.GOOS { case "plan9", "windows": t.Skipf("skipping on %s", runtime.GOOS) + case "aix": + t.Skipf("skipping on AIX, see issue 40972") } t.Parallel() testDisasm(t, "fmthello.go", false, false, "-ldflags=-linkmode=external") -- cgit v1.2.1