Reviewers: golang-dev_googlegroups.com,
Message:
Hello [email protected],
I'd like you to review this change to
https://go.googlecode.com/hg/
Description:
debug/elf: do not skip first symbol in the symbol table
Do not skip the first symbol in the symbol table. Any other indexes
into the symbol table (for example, indexes in relocation entries)
will now refer to the symbol following the one that was intended.
Add an object that contains debug relocations, which debug/dwarf
failed to decode correctly. Extend the relocation tests to cover
this case.
Note that the existing tests passed since the symbol following the
symbol that required relocation is also of type STT_SECTION.
Fixes issue 4107.
Please review this at http://codereview.appspot.com/6848044/
Affected files:
M src/pkg/debug/elf/file.go
M src/pkg/debug/elf/file_test.go
A src/pkg/debug/elf/testdata/gcc-amd64-openbsd-debug-with-rela.obj
Index: src/pkg/debug/elf/file.go
===================================================================
--- a/src/pkg/debug/elf/file.go
+++ b/src/pkg/debug/elf/file.go
@@ -417,10 +417,6 @@
return nil, nil, errors.New("cannot load string table section")
}
- // The first entry is all zeros.
- var skip [Sym32Size]byte
- symtab.Read(skip[0:])
-
symbols := make([]Symbol, symtab.Len()/Sym32Size)
i := 0
@@ -460,10 +456,6 @@
return nil, nil, errors.New("cannot load string table section")
}
- // The first entry is all zeros.
- var skip [Sym64Size]byte
- symtab.Read(skip[0:])
-
symbols := make([]Symbol, symtab.Len()/Sym64Size)
i := 0
Index: src/pkg/debug/elf/file_test.go
===================================================================
--- a/src/pkg/debug/elf/file_test.go
+++ b/src/pkg/debug/elf/file_test.go
@@ -175,23 +175,41 @@
}
}
+type relocationTestEntry struct {
+ entryNumber int
+ entry *dwarf.Entry
+}
+
type relocationTest struct {
- file string
- firstEntry *dwarf.Entry
+ file string
+ entries []relocationTestEntry
}
var relocationTests = []relocationTest{
{
"testdata/go-relocation-test-gcc441-x86-64.obj",
- &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)}}},
+ []relocationTestEntry{
+ {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)}}}},
+ },
},
{
"testdata/go-relocation-test-gcc441-x86.obj",
- &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)}}},
+ []relocationTestEntry{
+ {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)}}}},
+ },
},
{
"testdata/go-relocation-test-gcc424-x86-64.obj",
- &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)}}},
+ []relocationTestEntry{
+ {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)}}}},
+ },
+ },
+ {
+ "testdata/gcc-amd64-openbsd-debug-with-rela.obj",
+ []relocationTestEntry{
+ {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}}}}},
+ {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}}}}},
+ },
},
}
@@ -207,20 +225,24 @@
t.Error(err)
continue
}
- reader := dwarf.Reader()
- // Checking only the first entry is sufficient since it has
- // many different strings. If the relocation had failed, all
- // the string offsets would be zero and all the strings would
- // end up being the same.
- firstEntry, err := reader.Next()
- if err != nil {
- t.Error(err)
- continue
- }
-
- if !reflect.DeepEqual(test.firstEntry, firstEntry) {
- t.Errorf("#%d: mismatch: got:%#v want:%#v", i, firstEntry,
test.firstEntry)
- continue
+ for _, testEntry := range test.entries {
+ reader := dwarf.Reader()
+ for j := 0; j < testEntry.entryNumber; j++ {
+ entry, err := reader.Next()
+ if entry == nil || err != nil {
+ t.Errorf("Failed to skip to entry %d: %v", testEntry.entryNumber, err)
+ continue
+ }
+ }
+ entry, err := reader.Next()
+ if err != nil {
+ t.Error(err)
+ continue
+ }
+ if !reflect.DeepEqual(testEntry.entry, entry) {
+ t.Errorf("#%d/%d: mismatch: got:%#v want:%#v", i,
testEntry.entryNumber, entry, testEntry.entry)
+ continue
+ }
}
}
}
Index: src/pkg/debug/elf/testdata/gcc-amd64-openbsd-debug-with-rela.obj
===================================================================
new file mode 100644
index
0000000000000000000000000000000000000000..f62b1ea1cada83530e45320cc58394933753dddb
GIT binary patch
literal 6544
zc$}44YmD4h6}}$ZV~=Mav)NDzjl`CKT4=M6Bu%#2ZIY&sJeo#*kfuVFEYFN*##xU&
zu|2cd^pUhlq0OTYAeHz50xDIAKdn%t2!2or_)+?!LPA2I{-~(<)fTCRQcw#G=iGCz
z$Lq`xu(IQOzVp22o_p?{$?-e(-&s%;CLe`uXML*w?3wJ3cZ$z3R=!M5>M9e;m(9uY
zHRgn}[email protected]^0x9qSpiGxC{s-&_D;@QjA`Sn3`55BFTr4YSv46eUX_Y4W+=+u
zNmMkiWqT)Qz-@^n8M7u8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