]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/objdump: switch to using NewReaderFromBytes
authorThan McIntosh <thanm@google.com>
Wed, 16 Oct 2019 16:31:33 +0000 (12:31 -0400)
committerThan McIntosh <thanm@google.com>
Thu, 17 Oct 2019 14:20:08 +0000 (14:20 +0000)
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>
src/cmd/internal/goobj/read.go
src/cmd/internal/goobj/readnew.go

index 2a3afffeb071b20898ead36f2832bcca3231317c..e61e95dcc8ee926969153f979df8fc79edcd7a43 100644 (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)
        }
index e5dc652800952f06c517dad8ef867e1f9c077654..de05f37c3b6aef6e90c23e149a0a766449c55070 100644 (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")
        }