[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: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Than McIntosh 2019-10-16 12:31:33 -04:00
parent 6cbf37b30b
commit e5acb58c39
2 changed files with 11 additions and 4 deletions

View File

@ -502,12 +502,15 @@ func (r *objReader) parseObject(prefix []byte) error {
}
// TODO: extract OS + build ID if/when we need it
r.readFull(r.tmp[:8])
if bytes.Equal(r.tmp[:8], []byte("\x00go114LD")) {
r.offset -= 8
p, err := r.peek(8)
if err != nil {
return err
}
if bytes.Equal(p, []byte("\x00go114LD")) {
r.readNew()
return nil
}
r.readFull(r.tmp[:8])
if !bytes.Equal(r.tmp[:8], []byte("\x00go114ld")) {
return r.error(errCorruptObject)
}

View File

@ -15,7 +15,11 @@ import (
// the data to the current goobj API.
func (r *objReader) readNew() {
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 {
panic("cannot read object file")
}