diff options
| author | Cherry Mui <cherryyz@google.com> | 2022-09-16 19:41:55 -0400 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2022-09-22 23:46:28 +0000 |
| commit | ddaf68200a485ae9605a397372b5d59f4dfba759 (patch) | |
| tree | 67c050f0743bfae40061dfba29793b312f1a7ccf /src/cmd/objdump/objdump_test.go | |
| parent | 533cd80315904661e3d644a140bdf52c8ac7aad6 (diff) | |
| download | go-ddaf68200a485ae9605a397372b5d59f4dfba759.tar.xz | |
cmd/internal/objfile: read file/line information for ELF PIE binaries
For PIE binaries, the .gopclntab section doesn't have the usual
name, but .data.rel.ro.gopclntab. Try the relro version as well.
If both failed (e.g. for externally linked PIE binaries), try
runtime.pclntab symbol.
This should make cmd/objdump able to print the file/line
information for PIE binaries.
I attempted to do this a few years ago, but that wasn't enough,
because the pclntab itself contains dynamic relocations which are
not applied by the tool. As of Go 1.18 the pclntab is mostly
position independent and does not contain dynamic relocations, so
this should be possible now.
Fixes #17883.
Updates #46639.
Change-Id: I85dc3d50ffcc1a4b187a349479a6a162de1ab2b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/227483
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Joel Sing <joel@sing.id.au>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/objdump/objdump_test.go')
| -rw-r--r-- | src/cmd/objdump/objdump_test.go | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/cmd/objdump/objdump_test.go b/src/cmd/objdump/objdump_test.go index e984ef279e..86e904dcd5 100644 --- a/src/cmd/objdump/objdump_test.go +++ b/src/cmd/objdump/objdump_test.go @@ -6,6 +6,7 @@ package main import ( "cmd/internal/notsha256" + "cmd/internal/sys" "flag" "fmt" "go/build" @@ -99,6 +100,12 @@ var ppcNeed = []string{ "RET", } +var ppcPIENeed = []string{ + "BR", + "CALL", + "RET", +} + var ppcGnuNeed = []string{ "mflr", "lbz", @@ -178,7 +185,21 @@ func testDisasm(t *testing.T, srcfname string, printCode bool, printGnuAsm bool, case "arm64": need = append(need, arm64Need...) case "ppc64", "ppc64le": - need = append(need, ppcNeed...) + var pie bool + for _, flag := range flags { + if flag == "-buildmode=pie" { + pie = true + break + } + } + if pie { + // In PPC64 PIE binaries we use a "local entry point" which is + // function symbol address + 8. Currently we don't symbolize that. + // Expect a different output. + need = append(need, ppcPIENeed...) + } else { + need = append(need, ppcNeed...) + } } if printGnuAsm { @@ -265,6 +286,14 @@ func TestDisasmExtld(t *testing.T) { testDisasm(t, "fmthello.go", false, false, "-ldflags=-linkmode=external") } +func TestDisasmPIE(t *testing.T) { + if !sys.BuildModeSupported("gc", "pie", runtime.GOOS, runtime.GOARCH) { + t.Skipf("skipping on %s/%s, PIE buildmode not supported", runtime.GOOS, runtime.GOARCH) + } + t.Parallel() + testDisasm(t, "fmthello.go", false, false, "-buildmode=pie") +} + func TestDisasmGoobj(t *testing.T) { mustHaveDisasm(t) |
