diff options
author | Ian Lance Taylor <iant@golang.org> | 2016-05-27 16:03:44 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2016-05-31 13:02:09 +0000 |
commit | 4223294eab3dee0f6c03fd57fc24be3dc3e2d53a (patch) | |
tree | 70f810ef844aee4ef2a974661de8f6fb347b97df /src/cmd/pprof | |
parent | 87ee12cece96ec5837fe89c37899d725e7e852d9 (diff) | |
download | go-4223294eab3dee0f6c03fd57fc24be3dc3e2d53a.tar.gz go-4223294eab3dee0f6c03fd57fc24be3dc3e2d53a.zip |
runtime/pprof, cmd/pprof: fix profiling for PIE
In order to support pprof for position independent executables, pprof
needs to adjust the PC addresses stored in the profile by the address at
which the program is loaded. The legacy profiling support which we use
already supports recording the GNU/Linux /proc/self/maps data
immediately after the CPU samples, so do that. Also change the pprof
symbolizer to use the information, if available, when looking up
addresses in the Go pcline data.
Fixes #15714.
Change-Id: I4bf679210ef7c51d85cf873c968ce82db8898e3e
Reviewed-on: https://go-review.googlesource.com/23525
Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
Diffstat (limited to 'src/cmd/pprof')
-rw-r--r-- | src/cmd/pprof/pprof.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/cmd/pprof/pprof.go b/src/cmd/pprof/pprof.go index bce37dcb97..0187045b4a 100644 --- a/src/cmd/pprof/pprof.go +++ b/src/cmd/pprof/pprof.go @@ -117,6 +117,9 @@ func (*objTool) Open(name string, start uint64) (plugin.ObjFile, error) { name: name, file: of, } + if load, err := of.LoadAddress(); err == nil { + f.offset = start - load + } return f, nil } @@ -169,10 +172,11 @@ func (*objTool) SetConfig(config string) { // (instead of invoking GNU binutils). // A file represents a single executable being analyzed. type file struct { - name string - sym []objfile.Sym - file *objfile.File - pcln *gosym.Table + name string + offset uint64 + sym []objfile.Sym + file *objfile.File + pcln *gosym.Table triedDwarf bool dwarf *dwarf.Data @@ -200,6 +204,7 @@ func (f *file) SourceLine(addr uint64) ([]plugin.Frame, error) { } f.pcln = pcln } + addr -= f.offset file, line, fn := f.pcln.PCToLine(addr) if fn != nil { frame := []plugin.Frame{ |