diff --git a/src/cmd/nm/doc.go b/src/cmd/nm/doc.go index 619c2d12dd4..12b079d25f2 100644 --- a/src/cmd/nm/doc.go +++ b/src/cmd/nm/doc.go @@ -13,6 +13,8 @@ // // T text (code) segment symbol // t static text segment symbol +// R read-only data segment symbol +// r static read-only data segment symbol // D data segment symbol // d static data segment symbol // B bss segment symbol diff --git a/src/cmd/nm/elf.go b/src/cmd/nm/elf.go index 6dc8d442b48..58a4b556f38 100644 --- a/src/cmd/nm/elf.go +++ b/src/cmd/nm/elf.go @@ -47,6 +47,9 @@ func elfSymbols(f *os.File) []Sym { sym.Code = 'D' } } + if elf.ST_BIND(s.Info) == elf.STB_LOCAL { + sym.Code += 'a' - 'A' + } syms = append(syms, sym) } diff --git a/src/cmd/nm/goobj.go b/src/cmd/nm/goobj.go index 1ceefff9c08..b0de51db9c0 100644 --- a/src/cmd/nm/goobj.go +++ b/src/cmd/nm/goobj.go @@ -42,7 +42,7 @@ func goobjSymbols(f *os.File) []Sym { case goobj.SBSS, goobj.SNOPTRBSS, goobj.STLSBSS: sym.Code = 'B' case goobj.SXREF, goobj.SMACHOSYMSTR, goobj.SMACHOSYMTAB, goobj.SMACHOINDIRECTPLT, goobj.SMACHOINDIRECTGOT, goobj.SFILE, goobj.SFILEPATH, goobj.SCONST, goobj.SDYNIMPORT, goobj.SHOSTOBJ: - sym.Code = 'X' + sym.Code = 'X' // should not see } if s.Version != 0 { sym.Code += 'a' - 'A' diff --git a/src/cmd/nm/nm.go b/src/cmd/nm/nm.go index c37d1cc0076..d369a4ab54d 100644 --- a/src/cmd/nm/nm.go +++ b/src/cmd/nm/nm.go @@ -24,6 +24,8 @@ var ( sortOrder = flag.String("sort", "name", "") printSize = flag.Bool("size", false, "") printType = flag.Bool("type", false, "") + + filePrefix = false ) func init() { @@ -64,6 +66,7 @@ func main() { } args := flag.Args() + filePrefix = len(args) > 1 if len(args) == 0 { flag.Usage() } @@ -136,6 +139,9 @@ HaveSyms: w := bufio.NewWriter(os.Stdout) for _, sym := range syms { + if filePrefix { + fmt.Fprintf(w, "%s:\t", file) + } if sym.Code == 'U' { fmt.Fprintf(w, "%8s", "") } else { @@ -153,16 +159,6 @@ HaveSyms: w.Flush() } -func filter(syms []Sym, ok func(Sym) bool) []Sym { - out := syms[:0] - for _, sym := range syms { - if ok(sym) { - out = append(out, sym) - } - } - return out -} - type byAddr []Sym func (x byAddr) Len() int { return len(x) }