Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/pprof: disassembly support for PIE binaries / shared libraries #46639

Open
prattmic opened this issue Jun 7, 2021 · 3 comments
Open

cmd/pprof: disassembly support for PIE binaries / shared libraries #46639

prattmic opened this issue Jun 7, 2021 · 3 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@prattmic
Copy link
Member

prattmic commented Jun 7, 2021

go tool pprof does not support disassembly of position independent code (PIE binaries or shared libraries). Notably, on Windows PIE is default, so disassembly doesn't work by default:

gopher@SERVER-2016-V7- c:\workdir>go\bin\go build cpu.go                                                                        
                                                                                                                                             
gopher@SERVER-2016-V7- c:\workdir>cpu.exe -output cpu.pprof                                                                      
                                                                                                                                             
gopher@SERVER-2016-V7- c:\workdir>pprof.exe -top cpu.exe cpu.pprof                                                               
File: cpu.exe                                                                                                                   
Type: cpu                                                                                                                       
Time: Jun 7, 2021 at 9:19pm (GMT)                                                                                               
Duration: 1.11s, Total samples = 990ms (89.48%)                                                                                  
Showing nodes accounting for 990ms, 100% of 990ms total                                                                         
      flat  flat%   sum%        cum   cum%                                                                                      
     330ms 33.33% 33.33%      840ms 84.85%  time.Since                                                                           
     280ms 28.28% 61.62%      280ms 28.28%  time.Time.Sub                                                                        
     150ms 15.15% 76.77%      990ms   100%  main.main                                                                            
     130ms 13.13% 89.90%      130ms 13.13%  runtime.nanotime1                                                                   
     100ms 10.10%   100%      230ms 23.23%  runtime.nanotime                                                                     
         0     0%   100%      990ms   100%  runtime.main                                                                         
                                                                                                                                             
gopher@SERVER-2016-V7- c:\workdir>pprof.exe -disasm . cpu.exe cpu.pprof     
Total: 990ms   

Without PIE:

gopher@SERVER-2016-V7- c:\workdir>go\bin\go build -buildmode=exe cpu.go                                                                        
                                                                                                                                             
gopher@SERVER-2016-V7- c:\workdir>cpu.exe -output cpu.pprof                                                                      
                                                                                                                                             
gopher@SERVER-2016-V7- c:\workdir>pprof.exe -disasm . cpu.exe cpu.pprof    
Total: 990ms      
ROUTINE ======================== time.Time.Sub                                                                                   
     310ms      310ms (flat, cum) 31.31% of Total                                                                               
...

Upstream pprof's binutils backend supports base address computation to handle position independent code, but our implementation skips that entirely.

The "binutils" implementation doesn't actually seem particularly specific to binutils, so it would likely not be too difficult to support in our implementation.

cc @cherrymui @mknyszek

@prattmic prattmic added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 7, 2021
@prattmic prattmic added this to the Backlog milestone Jun 7, 2021
@ianlancetaylor
Copy link
Contributor

See also #17883.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 7, 2022
@gopherbot
Copy link

Change https://go.dev/cl/416976 mentions this issue: cmd/pprof: fix addr calculation for Windows

gopherbot pushed a commit that referenced this issue Aug 20, 2022
This makes it possible to use `disasm` with ASLR windows binaries.

For #46639

Change-Id: I08aff38dc0b33fdfb07e0206766db066e33207d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/416976
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@gopherbot
Copy link

Change https://go.dev/cl/227483 mentions this issue: cmd/internal/objfile: read file/line information for ELF PIE binaries

gopherbot pushed a commit that referenced this issue Sep 22, 2022
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
Development

No branches or pull requests

3 participants