summaryrefslogtreecommitdiff
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
commitcac7e092097d6177d8a04710932ffcdcfe11fa80 (patch)
tree27a0f2521ed7d31ab16ca5961259644fa6ccfa95 /src/cmd/nm
parent636daa3aaf242364e7e72d0cf43d003bac7dac30 (diff)
downloadgo-cac7e092097d6177d8a04710932ffcdcfe11fa80.tar.gz
cmd/nm: print symbol sizes for windows pe executables
Fixes issue 6973 LGTM=r R=golang-codereviews, r CC=golang-codereviews https://codereview.appspot.com/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 7175e2295..52d05e51d 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