Commit e5acb58c authored by Than McIntosh's avatar Than McIntosh

[dev.link] cmd/objdump: switch to using NewReaderFromBytes

Convert the object file dumper to use NewReaderFromBytes when
reading new object files, as opposed to NewReader.

Change-Id: I9f5e0356bd21c16f545cdd70262e983a2ed38bfc
Reviewed-on: https://go-review.googlesource.com/c/go/+/201441
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent 6cbf37b3
...@@ -502,12 +502,15 @@ func (r *objReader) parseObject(prefix []byte) error { ...@@ -502,12 +502,15 @@ func (r *objReader) parseObject(prefix []byte) error {
} }
// TODO: extract OS + build ID if/when we need it // TODO: extract OS + build ID if/when we need it
r.readFull(r.tmp[:8]) p, err := r.peek(8)
if bytes.Equal(r.tmp[:8], []byte("\x00go114LD")) { if err != nil {
r.offset -= 8 return err
}
if bytes.Equal(p, []byte("\x00go114LD")) {
r.readNew() r.readNew()
return nil return nil
} }
r.readFull(r.tmp[:8])
if !bytes.Equal(r.tmp[:8], []byte("\x00go114ld")) { if !bytes.Equal(r.tmp[:8], []byte("\x00go114ld")) {
return r.error(errCorruptObject) return r.error(errCorruptObject)
} }
......
...@@ -15,7 +15,11 @@ import ( ...@@ -15,7 +15,11 @@ import (
// the data to the current goobj API. // the data to the current goobj API.
func (r *objReader) readNew() { func (r *objReader) readNew() {
start := uint32(r.offset) start := uint32(r.offset)
rr := goobj2.NewReader(r.f, start)
length := r.limit - r.offset
objbytes := make([]byte, length)
r.readFull(objbytes)
rr := goobj2.NewReaderFromBytes(objbytes, false)
if rr == nil { if rr == nil {
panic("cannot read object file") panic("cannot read object file")
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment