aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go
diff options
context:
space:
mode:
authorEmmanuel T Odeke <emmanuel@orijtech.com>2021-02-26 02:27:24 -0800
committerEmmanuel Odeke <emmanuel@orijtech.com>2021-03-15 19:02:39 +0000
commit2d4042d4ab3a2021819dce91eb228daf8fa5e557 (patch)
tree0a0b71f4bc2859a19320760f54be55f891b5e07a /src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go
parenta8d9fb2fcd1fc11b41651e0ea608b3a3e90755b7 (diff)
downloadgo-2d4042d4ab3a2021819dce91eb228daf8fa5e557.tar.xz
all: update golang.org/x/* dependencies
Updates src/ and src/cmd/* dependencies, using go mod vendor as well as updatestd -branch=master -goroot=$GOROOT This change was ran in anticipation of bringing in x/net/http2 CL 237957. For #32112. For #36905. Change-Id: If8cefc348463b6d82d85020b57db411213720ef8 Reviewed-on: https://go-review.googlesource.com/c/go/+/296789 Trust: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Dmitri Shuralyov <dmitshur@golang.org> Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Alexander Rakoczy <alex@golang.org>
Diffstat (limited to 'src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go')
-rw-r--r--src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go65
1 files changed, 60 insertions, 5 deletions
diff --git a/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go b/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go
index 4b67cc4ab0..576a6ee66a 100644
--- a/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go
+++ b/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go
@@ -18,6 +18,7 @@ package binutils
import (
"debug/elf"
"debug/macho"
+ "debug/pe"
"encoding/binary"
"errors"
"fmt"
@@ -255,7 +256,7 @@ func (bu *Binutils) Disasm(file string, start, end uint64, intelSyntax bool) ([]
if !b.objdumpFound {
return nil, errors.New("cannot disasm: no objdump tool available")
}
- args := []string{"--disassemble-all", "--demangle", "--no-show-raw-insn",
+ args := []string{"--disassemble", "--demangle", "--no-show-raw-insn",
"--line-numbers", fmt.Sprintf("--start-address=%#x", start),
fmt.Sprintf("--stop-address=%#x", end)}
@@ -337,6 +338,15 @@ func (bu *Binutils) Open(name string, start, limit, offset uint64) (plugin.ObjFi
return f, nil
}
+ peMagic := string(header[:2])
+ if peMagic == "MZ" {
+ f, err := b.openPE(name, start, limit, offset)
+ if err != nil {
+ return nil, fmt.Errorf("error reading PE file %s: %v", name, err)
+ }
+ return f, nil
+ }
+
return nil, fmt.Errorf("unrecognized binary format: %s", name)
}
@@ -440,7 +450,23 @@ func (b *binrep) openELF(name string, start, limit, offset uint64) (plugin.ObjFi
}
}
- base, err := elfexec.GetBase(&ef.FileHeader, elfexec.FindTextProgHeader(ef), stextOffset, start, limit, offset)
+ var ph *elf.ProgHeader
+ // For user space executables, find the actual program segment that is
+ // associated with the given mapping. Skip this search if limit <= start.
+ // We cannot use just a check on the start address of the mapping to tell if
+ // it's a kernel / .ko module mapping, because with quipper address remapping
+ // enabled, the address would be in the lower half of the address space.
+ if stextOffset == nil && start < limit && limit < (uint64(1)<<63) {
+ ph, err = elfexec.FindProgHeaderForMapping(ef, offset, limit-start)
+ if err != nil {
+ return nil, fmt.Errorf("failed to find program header for file %q, mapping pgoff %x, memsz=%x: %v", name, offset, limit-start, err)
+ }
+ } else {
+ // For the kernel, find the program segment that includes the .text section.
+ ph = elfexec.FindTextProgHeader(ef)
+ }
+
+ base, err := elfexec.GetBase(&ef.FileHeader, ph, stextOffset, start, limit, offset)
if err != nil {
return nil, fmt.Errorf("could not identify base for %s: %v", name, err)
}
@@ -451,10 +477,38 @@ func (b *binrep) openELF(name string, start, limit, offset uint64) (plugin.ObjFi
buildID = fmt.Sprintf("%x", id)
}
}
+ isData := ph != nil && ph.Flags&elf.PF_X == 0
+ if b.fast || (!b.addr2lineFound && !b.llvmSymbolizerFound) {
+ return &fileNM{file: file{b, name, base, buildID, isData}}, nil
+ }
+ return &fileAddr2Line{file: file{b, name, base, buildID, isData}}, nil
+}
+
+func (b *binrep) openPE(name string, start, limit, offset uint64) (plugin.ObjFile, error) {
+ pf, err := pe.Open(name)
+ if err != nil {
+ return nil, fmt.Errorf("error parsing %s: %v", name, err)
+ }
+ defer pf.Close()
+
+ var imageBase uint64
+ switch h := pf.OptionalHeader.(type) {
+ case *pe.OptionalHeader32:
+ imageBase = uint64(h.ImageBase)
+ case *pe.OptionalHeader64:
+ imageBase = uint64(h.ImageBase)
+ default:
+ return nil, fmt.Errorf("unknown OptionalHeader %T", pf.OptionalHeader)
+ }
+
+ var base uint64
+ if start > 0 {
+ base = start - imageBase
+ }
if b.fast || (!b.addr2lineFound && !b.llvmSymbolizerFound) {
- return &fileNM{file: file{b, name, base, buildID}}, nil
+ return &fileNM{file: file{b: b, name: name, base: base}}, nil
}
- return &fileAddr2Line{file: file{b, name, base, buildID}}, nil
+ return &fileAddr2Line{file: file{b: b, name: name, base: base}}, nil
}
// file implements the binutils.ObjFile interface.
@@ -463,6 +517,7 @@ type file struct {
name string
base uint64
buildID string
+ isData bool
}
func (f *file) Name() string {
@@ -538,7 +593,7 @@ func (f *fileAddr2Line) SourceLine(addr uint64) ([]plugin.Frame, error) {
}
func (f *fileAddr2Line) init() {
- if llvmSymbolizer, err := newLLVMSymbolizer(f.b.llvmSymbolizer, f.name, f.base); err == nil {
+ if llvmSymbolizer, err := newLLVMSymbolizer(f.b.llvmSymbolizer, f.name, f.base, f.isData); err == nil {
f.llvmSymbolizer = llvmSymbolizer
return
}