]> Cypherpunks repositories - gostls13.git/commitdiff
debug/elf: do not skip first symbol in the symbol table
authorJoel Sing <jsing@google.com>
Wed, 14 Nov 2012 15:24:14 +0000 (02:24 +1100)
committerJoel Sing <jsing@google.com>
Wed, 14 Nov 2012 15:24:14 +0000 (02:24 +1100)
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 #4107.

R=golang-dev, mikioh.mikioh, iant, iant
CC=golang-dev
https://golang.org/cl/6848044

doc/go1.1.html
src/pkg/debug/elf/file.go
src/pkg/debug/elf/file_test.go
src/pkg/debug/elf/testdata/gcc-amd64-openbsd-debug-with-rela.obj [new file with mode: 0644]

index 6eacc1f325d2d471906a30ab0ab47f5df4664fd4..3e0bd4f009105b29917f41a1c8342a10b7dc30d7 100644 (file)
@@ -62,4 +62,14 @@ to adjust frame pointer offsets.
 
 <h2 id="library">Changes to the standard library</h2>
 
+<h3 id="debug/elf">debug/elf</h3>
+<p>
+Previous versions of the debug/elf package intentionally skipped over the first
+symbol in the ELF symbol table, since it is always an empty symbol. This symbol
+is no longer skipped since indexes into the symbol table returned by debug/elf,
+will be different to indexes into the original ELF symbol table. Any code that
+calls the debug/elf functions Symbols or ImportedSymbols may need to be
+adjusted to account for the additional symbol and the change in symbol offsets.
+</p>
+
 TODO
index d38da4bf8e9125d56d0aff07b821a272da80aafd..25b04d79593533a91642a3604df16f5cb2f173c0 100644 (file)
@@ -417,10 +417,6 @@ func (f *File) getSymbols32(typ SectionType) ([]Symbol, []byte, error) {
                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 @@ func (f *File) getSymbols64(typ SectionType) ([]Symbol, []byte, error) {
                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 12036e816b4bdc766f59c8a106558fc661739187..810a2f9b9a36d5f932f01d0a6c46143c4beaa80f 100644 (file)
@@ -175,23 +175,41 @@ func TestOpen(t *testing.T) {
        }
 }
 
+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 @@ func TestDWARFRelocations(t *testing.T) {
                        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
+                       }
                }
        }
 }
diff --git a/src/pkg/debug/elf/testdata/gcc-amd64-openbsd-debug-with-rela.obj b/src/pkg/debug/elf/testdata/gcc-amd64-openbsd-debug-with-rela.obj
new file mode 100644 (file)
index 0000000..f62b1ea
Binary files /dev/null and b/src/pkg/debug/elf/testdata/gcc-amd64-openbsd-debug-with-rela.obj differ