aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/objdump
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-05-14 17:45:13 -0700
committerRuss Cox <rsc@golang.org>2014-05-14 17:45:13 -0700
commit8e22903b46aadd6eda937417cba86b528cba92e2 (patch)
tree4191024da4129525a65e80f28bd2f1e84cef7ca1 /src/cmd/objdump
parentbf1d400d1c75985354f52f7969ba15fb228aacb2 (diff)
downloadgo-8e22903b46aadd6eda937417cba86b528cba92e2.tar.xz
cmd/nm, cmd/objdump: fix elf symbol types
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
Diffstat (limited to 'src/cmd/objdump')
-rw-r--r--src/cmd/objdump/elf.go4
-rw-r--r--src/cmd/objdump/main.go9
2 files changed, 11 insertions, 2 deletions
diff --git a/src/cmd/objdump/elf.go b/src/cmd/objdump/elf.go
index 017c2034e5..906e903532 100644
--- a/src/cmd/objdump/elf.go
+++ b/src/cmd/objdump/elf.go
@@ -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'
diff --git a/src/cmd/objdump/main.go b/src/cmd/objdump/main.go
index 62cbdec90d..1b6b3d0fc4 100644
--- a/src/cmd/objdump/main.go
+++ b/src/cmd/objdump/main.go
@@ -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()