Repository: go
Issue: cmd/pprof: disassembly support for PIE binaries / shared libraries
Labels: NeedsFix,compiler/runtime

`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](https://github.com/google/pprof/blob/a2663126120b7b9a8462cbdf75017f0e51f1917e/internal/binutils/binutils.go#L627) to handle position independent code, but [our implementation](https://github.com/golang/go/blob/68327e1aa11457cd570bc7eaf03a0260950f27d9/src/cmd/pprof/pprof.go#L235) 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