// for compatibility with other nm commands
// -size
// print symbol size in decimal between address and type
-// -sort {address,name,none}
+// -sort {address,name,none,size}
// sort output in the given order (default name)
+// size orders from largest to smallest
// -type
// print symbol type after name
//
flag.Parse()
switch *sortOrder {
- case "address", "name", "none":
+ case "address", "name", "none", "size":
// ok
default:
fmt.Fprintf(os.Stderr, "nm: unknown sort order %q\n", *sortOrder)
sort.Sort(byAddr(syms))
case "name":
sort.Sort(byName(syms))
+ case "size":
+ sort.Sort(bySize(syms))
}
w := bufio.NewWriter(os.Stdout)
func (x byName) Len() int { return len(x) }
func (x byName) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
func (x byName) Less(i, j int) bool { return x[i].Name < x[j].Name }
+
+type bySize []Sym
+
+func (x bySize) Len() int { return len(x) }
+func (x bySize) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
+func (x bySize) Less(i, j int) bool { return x[i].Size > x[j].Size }