aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go
diff options
context:
space:
mode:
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.go27
1 files changed, 21 insertions, 6 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 9a82cb8e92..390f952feb 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
@@ -175,20 +175,35 @@ func (bu *Binutils) Open(name string, start, limit, offset uint64) (plugin.ObjFi
func (b *binrep) openMachO(name string, start, limit, offset uint64) (plugin.ObjFile, error) {
of, err := macho.Open(name)
if err != nil {
- return nil, fmt.Errorf("Parsing %s: %v", name, err)
+ return nil, fmt.Errorf("error parsing %s: %v", name, err)
}
defer of.Close()
+ // Subtract the load address of the __TEXT section. Usually 0 for shared
+ // libraries or 0x100000000 for executables. You can check this value by
+ // running `objdump -private-headers <file>`.
+
+ textSegment := of.Segment("__TEXT")
+ if textSegment == nil {
+ return nil, fmt.Errorf("could not identify base for %s: no __TEXT segment", name)
+ }
+ if textSegment.Addr > start {
+ return nil, fmt.Errorf("could not identify base for %s: __TEXT segment address (0x%x) > mapping start address (0x%x)",
+ name, textSegment.Addr, start)
+ }
+
+ base := start - textSegment.Addr
+
if b.fast || (!b.addr2lineFound && !b.llvmSymbolizerFound) {
- return &fileNM{file: file{b: b, name: name}}, nil
+ return &fileNM{file: file{b: b, name: name, base: base}}, nil
}
- return &fileAddr2Line{file: file{b: b, name: name}}, nil
+ return &fileAddr2Line{file: file{b: b, name: name, base: base}}, nil
}
func (b *binrep) openELF(name string, start, limit, offset uint64) (plugin.ObjFile, error) {
ef, err := elf.Open(name)
if err != nil {
- return nil, fmt.Errorf("Parsing %s: %v", name, err)
+ return nil, fmt.Errorf("error parsing %s: %v", name, err)
}
defer ef.Close()
@@ -215,9 +230,9 @@ func (b *binrep) openELF(name string, start, limit, offset uint64) (plugin.ObjFi
}
}
- base, err := elfexec.GetBase(&ef.FileHeader, nil, stextOffset, start, limit, offset)
+ base, err := elfexec.GetBase(&ef.FileHeader, elfexec.FindTextProgHeader(ef), stextOffset, start, limit, offset)
if err != nil {
- return nil, fmt.Errorf("Could not identify base for %s: %v", name, err)
+ return nil, fmt.Errorf("could not identify base for %s: %v", name, err)
}
buildID := ""