@@ -175,23 +175,41 @@ func TestOpen(t *testing.T) {
175
175
}
176
176
}
177
177
178
+ type relocationTestEntry struct {
179
+ entryNumber int
180
+ entry * dwarf.Entry
181
+ }
182
+
178
183
type relocationTest struct {
179
- file string
180
- firstEntry * dwarf. Entry
184
+ file string
185
+ entries [] relocationTestEntry
181
186
}
182
187
183
188
var relocationTests = []relocationTest {
184
189
{
185
190
"testdata/go-relocation-test-gcc441-x86-64.obj" ,
186
- & dwarf.Entry {Offset : 0xb , Tag : dwarf .TagCompileUnit , Children : true , Field : []dwarf.Field {{Attr : dwarf .AttrProducer , Val : "GNU C 4.4.1" }, {Attr : dwarf .AttrLanguage , Val : int64 (1 )}, {Attr : dwarf .AttrName , Val : "go-relocation-test.c" }, {Attr : dwarf .AttrCompDir , Val : "/tmp" }, {Attr : dwarf .AttrLowpc , Val : uint64 (0x0 )}, {Attr : dwarf .AttrHighpc , Val : uint64 (0x6 )}, {Attr : dwarf .AttrStmtList , Val : int64 (0 )}}},
191
+ []relocationTestEntry {
192
+ {0 , & dwarf.Entry {Offset : 0xb , Tag : dwarf .TagCompileUnit , Children : true , Field : []dwarf.Field {{Attr : dwarf .AttrProducer , Val : "GNU C 4.4.1" }, {Attr : dwarf .AttrLanguage , Val : int64 (1 )}, {Attr : dwarf .AttrName , Val : "go-relocation-test.c" }, {Attr : dwarf .AttrCompDir , Val : "/tmp" }, {Attr : dwarf .AttrLowpc , Val : uint64 (0x0 )}, {Attr : dwarf .AttrHighpc , Val : uint64 (0x6 )}, {Attr : dwarf .AttrStmtList , Val : int64 (0 )}}}},
193
+ },
187
194
},
188
195
{
189
196
"testdata/go-relocation-test-gcc441-x86.obj" ,
190
- & dwarf.Entry {Offset : 0xb , Tag : dwarf .TagCompileUnit , Children : true , Field : []dwarf.Field {{Attr : dwarf .AttrProducer , Val : "GNU C 4.4.1" }, {Attr : dwarf .AttrLanguage , Val : int64 (1 )}, {Attr : dwarf .AttrName , Val : "t.c" }, {Attr : dwarf .AttrCompDir , Val : "/tmp" }, {Attr : dwarf .AttrLowpc , Val : uint64 (0x0 )}, {Attr : dwarf .AttrHighpc , Val : uint64 (0x5 )}, {Attr : dwarf .AttrStmtList , Val : int64 (0 )}}},
197
+ []relocationTestEntry {
198
+ {0 , & dwarf.Entry {Offset : 0xb , Tag : dwarf .TagCompileUnit , Children : true , Field : []dwarf.Field {{Attr : dwarf .AttrProducer , Val : "GNU C 4.4.1" }, {Attr : dwarf .AttrLanguage , Val : int64 (1 )}, {Attr : dwarf .AttrName , Val : "t.c" }, {Attr : dwarf .AttrCompDir , Val : "/tmp" }, {Attr : dwarf .AttrLowpc , Val : uint64 (0x0 )}, {Attr : dwarf .AttrHighpc , Val : uint64 (0x5 )}, {Attr : dwarf .AttrStmtList , Val : int64 (0 )}}}},
199
+ },
191
200
},
192
201
{
193
202
"testdata/go-relocation-test-gcc424-x86-64.obj" ,
194
- & dwarf.Entry {Offset : 0xb , Tag : dwarf .TagCompileUnit , Children : true , Field : []dwarf.Field {{Attr : dwarf .AttrProducer , Val : "GNU C 4.2.4 (Ubuntu 4.2.4-1ubuntu4)" }, {Attr : dwarf .AttrLanguage , Val : int64 (1 )}, {Attr : dwarf .AttrName , Val : "go-relocation-test-gcc424.c" }, {Attr : dwarf .AttrCompDir , Val : "/tmp" }, {Attr : dwarf .AttrLowpc , Val : uint64 (0x0 )}, {Attr : dwarf .AttrHighpc , Val : uint64 (0x6 )}, {Attr : dwarf .AttrStmtList , Val : int64 (0 )}}},
203
+ []relocationTestEntry {
204
+ {0 , & dwarf.Entry {Offset : 0xb , Tag : dwarf .TagCompileUnit , Children : true , Field : []dwarf.Field {{Attr : dwarf .AttrProducer , Val : "GNU C 4.2.4 (Ubuntu 4.2.4-1ubuntu4)" }, {Attr : dwarf .AttrLanguage , Val : int64 (1 )}, {Attr : dwarf .AttrName , Val : "go-relocation-test-gcc424.c" }, {Attr : dwarf .AttrCompDir , Val : "/tmp" }, {Attr : dwarf .AttrLowpc , Val : uint64 (0x0 )}, {Attr : dwarf .AttrHighpc , Val : uint64 (0x6 )}, {Attr : dwarf .AttrStmtList , Val : int64 (0 )}}}},
205
+ },
206
+ },
207
+ {
208
+ "testdata/gcc-amd64-openbsd-debug-with-rela.obj" ,
209
+ []relocationTestEntry {
210
+ {203 , & dwarf.Entry {Offset : 0xc62 , Tag : dwarf .TagMember , Children : false , Field : []dwarf.Field {{Attr : dwarf .AttrName , Val : "it_interval" }, {Attr : dwarf .AttrDeclFile , Val : int64 (7 )}, {Attr : dwarf .AttrDeclLine , Val : int64 (236 )}, {Attr : dwarf .AttrType , Val : dwarf .Offset (0xb7f )}, {Attr : dwarf .AttrDataMemberLoc , Val : []byte {0x23 , 0x0 }}}}},
211
+ {204 , & dwarf.Entry {Offset : 0xc70 , Tag : dwarf .TagMember , Children : false , Field : []dwarf.Field {{Attr : dwarf .AttrName , Val : "it_value" }, {Attr : dwarf .AttrDeclFile , Val : int64 (7 )}, {Attr : dwarf .AttrDeclLine , Val : int64 (237 )}, {Attr : dwarf .AttrType , Val : dwarf .Offset (0xb7f )}, {Attr : dwarf .AttrDataMemberLoc , Val : []byte {0x23 , 0x10 }}}}},
212
+ },
195
213
},
196
214
}
197
215
@@ -207,20 +225,24 @@ func TestDWARFRelocations(t *testing.T) {
207
225
t .Error (err )
208
226
continue
209
227
}
210
- reader := dwarf .Reader ()
211
- // Checking only the first entry is sufficient since it has
212
- // many different strings. If the relocation had failed, all
213
- // the string offsets would be zero and all the strings would
214
- // end up being the same.
215
- firstEntry , err := reader .Next ()
216
- if err != nil {
217
- t .Error (err )
218
- continue
219
- }
220
-
221
- if ! reflect .DeepEqual (test .firstEntry , firstEntry ) {
222
- t .Errorf ("#%d: mismatch: got:%#v want:%#v" , i , firstEntry , test .firstEntry )
223
- continue
228
+ for _ , testEntry := range test .entries {
229
+ reader := dwarf .Reader ()
230
+ for j := 0 ; j < testEntry .entryNumber ; j ++ {
231
+ entry , err := reader .Next ()
232
+ if entry == nil || err != nil {
233
+ t .Errorf ("Failed to skip to entry %d: %v" , testEntry .entryNumber , err )
234
+ continue
235
+ }
236
+ }
237
+ entry , err := reader .Next ()
238
+ if err != nil {
239
+ t .Error (err )
240
+ continue
241
+ }
242
+ if ! reflect .DeepEqual (testEntry .entry , entry ) {
243
+ t .Errorf ("#%d/%d: mismatch: got:%#v want:%#v" , i , testEntry .entryNumber , entry , testEntry .entry )
244
+ continue
245
+ }
224
246
}
225
247
}
226
248
}
0 commit comments