]> Cypherpunks repositories - gostls13.git/commitdiff
debug/macho: fill Rpath.LoadBytes in NewFile
authorHiroshi Ioka <hirochachacha@gmail.com>
Tue, 26 Sep 2017 23:46:08 +0000 (08:46 +0900)
committerIan Lance Taylor <iant@golang.org>
Wed, 27 Sep 2017 04:01:40 +0000 (04:01 +0000)
Also, fix some error messages.

Fixes #22065

Change-Id: Iac05c24b7bb128be3f43b8f2aa180b3957d5ee72
Reviewed-on: https://go-review.googlesource.com/66390
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/debug/macho/file.go
src/debug/macho/file_test.go

index 082c6b816ad70a8afe7a87d231bc780e42120d1c..7b9e83e5a878f553f4231f00a303dc30b7c91c1a 100644 (file)
@@ -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:
index b9d88c1bad46c55fbc69ef2b64d6d9a1e081b18b..003c14e69b1dcfaa06626dab5d2496d86fa0f42b 100644 (file)
@@ -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)