diff options
author | Michael Stapelberg <michael@stapelberg.de> | 2013-03-23 11:28:53 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-23 11:28:53 +0100 |
commit | b39e15dde5ec7b96c15da9faf4ab5892501c1aae (patch) | |
tree | 718cede1f6ca97d082c6c40b7dc3f4f6148253c0 /src/pkg/debug/elf/file.go | |
parent | 04b08da9af0c450d645ab7389d1467308cfc2db8 (diff) | |
download | golang-upstream/1.1_hg20130323.tar.gz |
Imported Upstream version 1.1~hg20130323upstream/1.1_hg20130323
Diffstat (limited to 'src/pkg/debug/elf/file.go')
-rw-r--r-- | src/pkg/debug/elf/file.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/pkg/debug/elf/file.go b/src/pkg/debug/elf/file.go index acb9817af..a55c37ea9 100644 --- a/src/pkg/debug/elf/file.go +++ b/src/pkg/debug/elf/file.go @@ -422,6 +422,10 @@ 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[:]) + symbols := make([]Symbol, symtab.Len()/Sym32Size) i := 0 @@ -461,6 +465,10 @@ 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[:]) + symbols := make([]Symbol, symtab.Len()/Sym64Size) i := 0 @@ -533,10 +541,10 @@ func (f *File) applyRelocationsAMD64(dst []byte, rels []byte) error { symNo := rela.Info >> 32 t := R_X86_64(rela.Info & 0xffff) - if symNo >= uint64(len(symbols)) { + if symNo == 0 || symNo > uint64(len(symbols)) { continue } - sym := &symbols[symNo] + sym := &symbols[symNo-1] if SymType(sym.Info&0xf) != STT_SECTION { // We don't handle non-section relocations for now. continue @@ -597,6 +605,10 @@ func (f *File) DWARF() (*dwarf.Data, error) { } // Symbols returns the symbol table for f. +// +// For compatibility with Go 1.0, Symbols omits the null symbol at index 0. +// After retrieving the symbols as symtab, an externally supplied index x +// corresponds to symtab[x-1], not symtab[x]. func (f *File) Symbols() ([]Symbol, error) { sym, _, err := f.getSymbols(SHT_SYMTAB) return sym, err @@ -706,7 +718,7 @@ func (f *File) gnuVersionInit(str []byte) { // which came from offset i of the symbol table. func (f *File) gnuVersion(i int, sym *ImportedSymbol) { // Each entry is two bytes. - i = i * 2 + i = (i + 1) * 2 if i >= len(f.gnuVersym) { return } |