aboutsummaryrefslogtreecommitdiff
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
parent7c7aaa4156a280960749467dfd3651b8798d420e (diff)
downloadgo-6e8c7f5bb241852f052a9b4a2f20f3e33d0ec7b2.tar.gz
go-6e8c7f5bb241852f052a9b4a2f20f3e33d0ec7b2.zip
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
-rw-r--r--src/cmd/nm/pe.go14
-rw-r--r--src/pkg/runtime/arch_amd64.h6
-rw-r--r--src/pkg/runtime/runtime_test.go4
3 files changed, 19 insertions, 5 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
diff --git a/src/pkg/runtime/arch_amd64.h b/src/pkg/runtime/arch_amd64.h
index 060c4d4f53..c8a21847c4 100644
--- a/src/pkg/runtime/arch_amd64.h
+++ b/src/pkg/runtime/arch_amd64.h
@@ -9,8 +9,12 @@ enum {
#ifdef GOOS_solaris
RuntimeGogoBytes = 80,
#else
+#ifdef GOOS_windows
+ RuntimeGogoBytes = 80,
+#else
RuntimeGogoBytes = 64,
-#endif
+#endif // Windows
+#endif // Solaris
PhysPageSize = 4096,
PCQuantum = 1
};
diff --git a/src/pkg/runtime/runtime_test.go b/src/pkg/runtime/runtime_test.go
index a14e06e7ad..62e59c78db 100644
--- a/src/pkg/runtime/runtime_test.go
+++ b/src/pkg/runtime/runtime_test.go
@@ -95,10 +95,6 @@ func BenchmarkDeferMany(b *testing.B) {
// The value reported will include the padding between runtime.gogo and the
// next function in memory. That's fine.
func TestRuntimeGogoBytes(t *testing.T) {
- // TODO(brainman): delete when issue 6973 is fixed.
- if GOOS == "windows" {
- t.Skip("skipping broken test on windows")
- }
dir, err := ioutil.TempDir("", "go-build")
if err != nil {
t.Fatalf("failed to create temp directory: %v", err)