mirror of
https://github.com/golang/go
synced 2024-11-26 14:56:47 -07:00
cmd/pprof: fix addr calculation for Windows
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>
This commit is contained in:
parent
28afa5b176
commit
8d57f4dcef
@ -31,13 +31,7 @@ func (f *peFile) symbols() ([]Sym, error) {
|
|||||||
// We infer the size of a symbol by looking at where the next symbol begins.
|
// We infer the size of a symbol by looking at where the next symbol begins.
|
||||||
var addrs []uint64
|
var addrs []uint64
|
||||||
|
|
||||||
var imageBase uint64
|
imageBase, _ := f.imageBase()
|
||||||
switch oh := f.pe.OptionalHeader.(type) {
|
|
||||||
case *pe.OptionalHeader32:
|
|
||||||
imageBase = uint64(oh.ImageBase)
|
|
||||||
case *pe.OptionalHeader64:
|
|
||||||
imageBase = oh.ImageBase
|
|
||||||
}
|
|
||||||
|
|
||||||
var syms []Sym
|
var syms []Sym
|
||||||
for _, s := range f.pe.Symbols {
|
for _, s := range f.pe.Symbols {
|
||||||
@ -96,15 +90,11 @@ func (f *peFile) symbols() ([]Sym, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *peFile) pcln() (textStart uint64, symtab, pclntab []byte, err error) {
|
func (f *peFile) pcln() (textStart uint64, symtab, pclntab []byte, err error) {
|
||||||
var imageBase uint64
|
imageBase, err := f.imageBase()
|
||||||
switch oh := f.pe.OptionalHeader.(type) {
|
if err != nil {
|
||||||
case *pe.OptionalHeader32:
|
return 0, nil, nil, err
|
||||||
imageBase = uint64(oh.ImageBase)
|
|
||||||
case *pe.OptionalHeader64:
|
|
||||||
imageBase = oh.ImageBase
|
|
||||||
default:
|
|
||||||
return 0, nil, nil, fmt.Errorf("pe file format not recognized")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if sect := f.pe.Section(".text"); sect != nil {
|
if sect := f.pe.Section(".text"); sect != nil {
|
||||||
textStart = imageBase + uint64(sect.VirtualAddress)
|
textStart = imageBase + uint64(sect.VirtualAddress)
|
||||||
}
|
}
|
||||||
@ -127,15 +117,11 @@ func (f *peFile) pcln() (textStart uint64, symtab, pclntab []byte, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *peFile) text() (textStart uint64, text []byte, err error) {
|
func (f *peFile) text() (textStart uint64, text []byte, err error) {
|
||||||
var imageBase uint64
|
imageBase, err := f.imageBase()
|
||||||
switch oh := f.pe.OptionalHeader.(type) {
|
if err != nil {
|
||||||
case *pe.OptionalHeader32:
|
return 0, nil, err
|
||||||
imageBase = uint64(oh.ImageBase)
|
|
||||||
case *pe.OptionalHeader64:
|
|
||||||
imageBase = oh.ImageBase
|
|
||||||
default:
|
|
||||||
return 0, nil, fmt.Errorf("pe file format not recognized")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sect := f.pe.Section(".text")
|
sect := f.pe.Section(".text")
|
||||||
if sect == nil {
|
if sect == nil {
|
||||||
return 0, nil, fmt.Errorf("text section not found")
|
return 0, nil, fmt.Errorf("text section not found")
|
||||||
@ -197,7 +183,18 @@ func (f *peFile) goarch() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *peFile) loadAddress() (uint64, error) {
|
func (f *peFile) loadAddress() (uint64, error) {
|
||||||
return 0, fmt.Errorf("unknown load address")
|
return f.imageBase()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *peFile) imageBase() (uint64, error) {
|
||||||
|
switch oh := f.pe.OptionalHeader.(type) {
|
||||||
|
case *pe.OptionalHeader32:
|
||||||
|
return uint64(oh.ImageBase), nil
|
||||||
|
case *pe.OptionalHeader64:
|
||||||
|
return oh.ImageBase, nil
|
||||||
|
default:
|
||||||
|
return 0, fmt.Errorf("pe file format not recognized")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *peFile) dwarf() (*dwarf.Data, error) {
|
func (f *peFile) dwarf() (*dwarf.Data, error) {
|
||||||
|
@ -233,8 +233,7 @@ func (f *file) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *file) ObjAddr(addr uint64) (uint64, error) {
|
func (f *file) ObjAddr(addr uint64) (uint64, error) {
|
||||||
// No support for shared libraries, so translation is a no-op.
|
return addr - f.offset, nil
|
||||||
return addr, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *file) BuildID() string {
|
func (f *file) BuildID() string {
|
||||||
|
@ -83,9 +83,6 @@ func mustHaveDisasm(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Skip PIE platforms, pprof can't disassemble PIE.
|
// Skip PIE platforms, pprof can't disassemble PIE.
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
t.Skipf("skipping on %s, issue 46639", runtime.GOOS)
|
|
||||||
}
|
|
||||||
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
|
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
|
||||||
t.Skipf("skipping on %s/%s, issue 46639", runtime.GOOS, runtime.GOARCH)
|
t.Skipf("skipping on %s/%s, issue 46639", runtime.GOOS, runtime.GOARCH)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user