aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/nm
diff options
context:
space:
mode:
authorAlex Brainman <alex.brainman@gmail.com>2014-04-19 14:47:20 +1000
committerAlex Brainman <alex.brainman@gmail.com>2014-04-19 14:47:20 +1000
commit6e8c7f5bb241852f052a9b4a2f20f3e33d0ec7b2 (patch)
tree08cad03e61d4daf785f8a711c650ac67e430b83d /src/cmd/nm
parent7c7aaa4156a280960749467dfd3651b8798d420e (diff)
downloadgo-6e8c7f5bb241852f052a9b4a2f20f3e33d0ec7b2.tar.xz
cmd/nm: print symbol sizes for windows pe executables
Fixes #6973 LGTM=r R=golang-codereviews, r CC=golang-codereviews https://golang.org/cl/88820043
Diffstat (limited to 'src/cmd/nm')
-rw-r--r--src/cmd/nm/pe.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/cmd/nm/pe.go b/src/cmd/nm/pe.go
index 7175e2295c..52d05e51d0 100644
--- a/src/cmd/nm/pe.go
+++ b/src/cmd/nm/pe.go
@@ -9,6 +9,7 @@ package main
import (
"debug/pe"
"os"
+ "sort"
)
func peSymbols(f *os.File) []Sym {
@@ -18,6 +19,10 @@ func peSymbols(f *os.File) []Sym {
return nil
}
+ // Build sorted list of addresses of all symbols.
+ // We infer the size of a symbol by looking at where the next symbol begins.
+ var addrs []uint64
+
var imageBase uint64
switch oh := p.OptionalHeader.(type) {
case *pe.OptionalHeader32:
@@ -78,6 +83,15 @@ func peSymbols(f *os.File) []Sym {
sym.Addr += imageBase + uint64(sect.VirtualAddress)
}
syms = append(syms, sym)
+ addrs = append(addrs, sym.Addr)
+ }
+
+ sort.Sort(uint64s(addrs))
+ for i := range syms {
+ j := sort.Search(len(addrs), func(x int) bool { return addrs[x] > syms[i].Addr })
+ if j < len(addrs) {
+ syms[i].Size = int64(addrs[j] - syms[i].Addr)
+ }
}
return syms