From: Hiroshi Ioka Date: Tue, 26 Sep 2017 23:46:08 +0000 (+0900) Subject: debug/macho: fill Rpath.LoadBytes in NewFile X-Git-Tag: go1.10beta1~967 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0d0c1132f68b2f4c879a2ef21c3df58f3e47c8bc;p=gostls13.git debug/macho: fill Rpath.LoadBytes in NewFile Also, fix some error messages. Fixes #22065 Change-Id: Iac05c24b7bb128be3f43b8f2aa180b3957d5ee72 Reviewed-on: https://go-review.googlesource.com/66390 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/debug/macho/file.go b/src/debug/macho/file.go index 082c6b816a..7b9e83e5a8 100644 --- a/src/debug/macho/file.go +++ b/src/debug/macho/file.go @@ -290,6 +290,7 @@ func NewFile(r io.ReaderAt) (*File, error) { return nil, &FormatError{offset, "invalid path in rpath command", hdr.Path} } l.Path = cstring(cmddat[hdr.Path:]) + l.LoadBytes = LoadBytes(cmddat) f.Loads[i] = l case LoadCmdDylib: diff --git a/src/debug/macho/file_test.go b/src/debug/macho/file_test.go index b9d88c1bad..003c14e69b 100644 --- a/src/debug/macho/file_test.go +++ b/src/debug/macho/file_test.go @@ -234,6 +234,11 @@ func TestOpen(t *testing.T) { t.Errorf("open %s:\n\thave %#v\n\twant %#v\n", tt.file, f.FileHeader, tt.hdr) continue } + for i, l := range f.Loads { + if len(l.Raw()) < 8 { + t.Errorf("open %s, command %d:\n\tload command %T don't have enough data\n", tt.file, i, l) + } + } if tt.loads != nil { for i, l := range f.Loads { if i >= len(tt.loads) { @@ -249,22 +254,22 @@ func TestOpen(t *testing.T) { case *Segment: have := &l.SegmentHeader if !reflect.DeepEqual(have, want) { - t.Errorf("open %s, segment %d:\n\thave %#v\n\twant %#v\n", tt.file, i, have, want) + t.Errorf("open %s, command %d:\n\thave %#v\n\twant %#v\n", tt.file, i, have, want) } case *Dylib: have := l have.LoadBytes = nil if !reflect.DeepEqual(have, want) { - t.Errorf("open %s, segment %d:\n\thave %#v\n\twant %#v\n", tt.file, i, have, want) + t.Errorf("open %s, command %d:\n\thave %#v\n\twant %#v\n", tt.file, i, have, want) } case *Rpath: have := l have.LoadBytes = nil if !reflect.DeepEqual(have, want) { - t.Errorf("open %s, segment %d:\n\thave %#v\n\twant %#v\n", tt.file, i, have, want) + t.Errorf("open %s, command %d:\n\thave %#v\n\twant %#v\n", tt.file, i, have, want) } default: - t.Errorf("open %s, section %d: unknown load command\n\thave %#v\n\twant %#v\n", tt.file, i, l, want) + t.Errorf("open %s, command %d: unknown load command\n\thave %#v\n\twant %#v\n", tt.file, i, l, want) } } tn := len(tt.loads)