]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/nm, cmd/objdump: fix elf symbol types
authorRuss Cox <rsc@golang.org>
Thu, 15 May 2014 00:45:13 +0000 (17:45 -0700)
committerRuss Cox <rsc@golang.org>
Thu, 15 May 2014 00:45:13 +0000 (17:45 -0700)
Turns out elf.File.Sections is indexed by the actual
section number, not the number minus one.
I don't know why I thought the -1 was necessary.

Fixes objdump test (and therefore build) on ELF systems.

While we're here, fix bounds on gnuDump so that we
don't crash when asked to disassemble outside
the text segment. May fix Windows build or at least
make the failure more interesting.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/92390043

src/cmd/nm/elf.go
src/cmd/objdump/elf.go
src/cmd/objdump/main.go

index 58a4b556f38b73d9e742aa0a38298473aaf8abc7..5aaa194dd1ee789c6730e116257d7c31d981c21a 100644 (file)
@@ -34,10 +34,10 @@ func elfSymbols(f *os.File) []Sym {
                        sym.Code = 'B'
                default:
                        i := int(s.Section)
-                       if i <= 0 || i > len(p.Sections) {
+                       if i < 0 || i >= len(p.Sections) {
                                break
                        }
-                       sect := p.Sections[i-1]
+                       sect := p.Sections[i]
                        switch sect.Flags & (elf.SHF_WRITE | elf.SHF_ALLOC | elf.SHF_EXECINSTR) {
                        case elf.SHF_ALLOC | elf.SHF_EXECINSTR:
                                sym.Code = 'T'
index 017c2034e5c97ffa2c0064d9564fd471081848c5..906e903532cfe8d6ed104c730d0364858a3b865e 100644 (file)
@@ -42,10 +42,10 @@ func elfSymbols(f *os.File) (syms []Sym, goarch string) {
                        sym.Code = 'B'
                default:
                        i := int(s.Section)
-                       if i <= 0 || i > len(p.Sections) {
+                       if i < 0 || i >= len(p.Sections) {
                                break
                        }
-                       sect := p.Sections[i-1]
+                       sect := p.Sections[i]
                        switch sect.Flags & (elf.SHF_WRITE | elf.SHF_ALLOC | elf.SHF_EXECINSTR) {
                        case elf.SHF_ALLOC | elf.SHF_EXECINSTR:
                                sym.Code = 'T'
index 62cbdec90d9c796a6fc2939b6972a8c0410a5d56..1b6b3d0fc4406e0289f916f52c540b035b887dcf 100644 (file)
@@ -235,6 +235,15 @@ func gnuDump(tab *gosym.Table, lookup lookupFunc, disasm disasmFunc, textData []
        if err != nil {
                log.Fatalf("invalid end PC: %v", err)
        }
+       if start < textStart {
+               start = textStart
+       }
+       if end < start {
+               end = start
+       }
+       if end > textStart+uint64(len(textData)) {
+               end = textStart + uint64(len(textData))
+       }
 
        stdout := bufio.NewWriter(os.Stdout)
        defer stdout.Flush()