aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2021-11-23 18:03:47 -0500
committerCherry Mui <cherryyz@google.com>2021-11-24 16:01:55 +0000
commitb38ab0ac5f78ac03a38052018ff629c03e36b864 (patch)
treed957a4316bf63808950295b17784a12dad235788 /src/cmd/internal
parent14f2b2a4c55b707828be2890b8c750cb849203f6 (diff)
downloadgo-b38ab0ac5f78ac03a38052018ff629c03e36b864.tar.gz
go-b38ab0ac5f78ac03a38052018ff629c03e36b864.zip
cmd/internal/objfile, debug/gosym: use the address of runtime.text as textStart
Tools like objdump uses the pcln table to find the line number of a given PC. For a PIE binary, at least in some cases such as on macOS 12 with ld64-711, the table contains unrelocated address, which does not match the address in the symbol table, causing the lookup to fail. In Go 1.18 the pcln table is essentually position independent, except the start PC. Instead of reading the static content from the table, use the PC of runtime.text from the symbol table. While here, change the type of textStart to uint64. What matters here is the word size of the target program, not the host, so it shouldn't be uintptr. Fixes #49700. Change-Id: I517d79be7ba02dd4dd0275e75a11a136b08d76cd Reviewed-on: https://go-review.googlesource.com/c/go/+/366695 Trust: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src/cmd/internal')
-rw-r--r--src/cmd/internal/objfile/objfile.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/cmd/internal/objfile/objfile.go b/src/cmd/internal/objfile/objfile.go
index dcfd158ec2..d890a0b756 100644
--- a/src/cmd/internal/objfile/objfile.go
+++ b/src/cmd/internal/objfile/objfile.go
@@ -152,6 +152,15 @@ func (e *Entry) PCLineTable() (Liner, error) {
if err != nil {
return nil, err
}
+ syms, err := e.raw.symbols()
+ if err == nil {
+ for _, s := range syms {
+ if s.Name == "runtime.text" {
+ textStart = s.Addr
+ break
+ }
+ }
+ }
return gosym.NewTable(symtab, gosym.NewLineTable(pclntab, textStart))
}