]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/nm: print symbol sizes for windows pe executables
authorAlex Brainman <alex.brainman@gmail.com>
Sat, 19 Apr 2014 04:47:20 +0000 (14:47 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Sat, 19 Apr 2014 04:47:20 +0000 (14:47 +1000)
Fixes #6973

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/88820043

src/cmd/nm/pe.go
src/pkg/runtime/arch_amd64.h
src/pkg/runtime/runtime_test.go

index 7175e2295c1063595b572bc844d4f62a2781faa6..52d05e51d05f76a436b0c06f5a3e331658b6d5db 100644 (file)
@@ -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
index 060c4d4f534f1315df8f6a330bc99d8bc1a41947..c8a21847c4fa3db2f64a47e3e81bb42ae025f364 100644 (file)
@@ -8,9 +8,13 @@ enum {
        CacheLineSize = 64,
 #ifdef GOOS_solaris
        RuntimeGogoBytes = 80,
+#else
+#ifdef GOOS_windows
+       RuntimeGogoBytes = 80,
 #else
        RuntimeGogoBytes = 64,
-#endif
+#endif // Windows
+#endif // Solaris
        PhysPageSize = 4096,
        PCQuantum = 1
 };
index a14e06e7ad38d5b40de239415a4eea594b01f951..62e59c78db692e93c4f0281e5a28d483a9446857 100644 (file)
@@ -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)