summaryrefslogtreecommitdiff
path: root/src/cmd/nm
diff options
context:
space:
mode:
authorDavid du Colombier <0intro@gmail.com>2014-01-22 23:30:52 +0100
committerDavid du Colombier <0intro@gmail.com>2014-01-22 23:30:52 +0100
commit2756fd453aa5db96e356f18707fa37c34ecb6b64 (patch)
treee967494f7ee3377da736fe960f3fc7da74947722 /src/cmd/nm
parentdb923706b887eb4b185db5aae094770d5ef1fdf2 (diff)
downloadgo-2756fd453aa5db96e356f18707fa37c34ecb6b64.tar.gz
debug/plan9obj: implement parsing of Plan 9 a.out executables
It implements parsing of the header and symbol table for both 32-bit and 64-bit Plan 9 binaries. The nm tool was updated to use this package. R=rsc, aram CC=golang-codereviews https://codereview.appspot.com/49970044
Diffstat (limited to 'src/cmd/nm')
-rw-r--r--src/cmd/nm/nm.go4
-rw-r--r--src/cmd/nm/plan9obj.go48
2 files changed, 52 insertions, 0 deletions
diff --git a/src/cmd/nm/nm.go b/src/cmd/nm/nm.go
index fdf6ef673..a4036184e 100644
--- a/src/cmd/nm/nm.go
+++ b/src/cmd/nm/nm.go
@@ -105,6 +105,10 @@ var parsers = []struct {
{[]byte("\xCE\xFA\xED\xFE"), machoSymbols},
{[]byte("\xCF\xFA\xED\xFE"), machoSymbols},
{[]byte("MZ"), peSymbols},
+ {[]byte("\x00\x00\x01\xEB"), plan9Symbols}, // 386
+ {[]byte("\x00\x00\x04\x07"), plan9Symbols}, // mips
+ {[]byte("\x00\x00\x06\x47"), plan9Symbols}, // arm
+ {[]byte("\x00\x00\x8A\x97"), plan9Symbols}, // amd64
}
func nm(file string) {
diff --git a/src/cmd/nm/plan9obj.go b/src/cmd/nm/plan9obj.go
new file mode 100644
index 000000000..006c66ebf
--- /dev/null
+++ b/src/cmd/nm/plan9obj.go
@@ -0,0 +1,48 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Parsing of Plan 9 a.out executables.
+
+package main
+
+import (
+ "debug/plan9obj"
+ "os"
+ "sort"
+)
+
+func plan9Symbols(f *os.File) []Sym {
+ p, err := plan9obj.NewFile(f)
+ if err != nil {
+ errorf("parsing %s: %v", f.Name(), err)
+ return nil
+ }
+
+ plan9Syms, err := p.Symbols()
+ if err != nil {
+ errorf("parsing %s: %v", f.Name(), err)
+ 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
+ for _, s := range plan9Syms {
+ addrs = append(addrs, s.Value)
+ }
+ sort.Sort(uint64s(addrs))
+
+ var syms []Sym
+
+ for _, s := range plan9Syms {
+ sym := Sym{Addr: s.Value, Name: s.Name, Code: rune(s.Type)}
+ i := sort.Search(len(addrs), func(x int) bool { return addrs[x] > s.Value })
+ if i < len(addrs) {
+ sym.Size = int64(addrs[i] - s.Value)
+ }
+ syms = append(syms, sym)
+ }
+
+ return syms
+}