diff options
author | Austin Clements <austin@google.com> | 2014-10-22 15:51:54 -0400 |
---|---|---|
committer | Austin Clements <austin@google.com> | 2014-10-22 15:51:54 -0400 |
commit | fc92f8a400cf3e4d053940e0b86b72d6de27d67a (patch) | |
tree | ad0b517f2a9cd798c909e59d982b9061f16c0348 /src/debug/elf/file.go | |
parent | 48b04a95e5f719cbef174124780dce00bb410c2c (diff) | |
parent | b8d4cd490ddd8ba298b5347d3e72316df768565c (diff) | |
download | go-fc92f8a400cf3e4d053940e0b86b72d6de27d67a.tar.gz |
[dev.power64] all: merge default into dev.power64
This brings dev.power64 up-to-date with the current tip of
default. go_bootstrap is still panicking with a bad defer
when initializing the runtime (even on amd64).
LGTM=rsc
R=rsc
CC=golang-codereviews
https://codereview.appspot.com/152570049
Diffstat (limited to 'src/debug/elf/file.go')
-rw-r--r-- | src/debug/elf/file.go | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/debug/elf/file.go b/src/debug/elf/file.go index de8a3a24f..74d1db306 100644 --- a/src/debug/elf/file.go +++ b/src/debug/elf/file.go @@ -532,6 +532,9 @@ func (f *File) applyRelocations(dst []byte, rels []byte) error { if f.Class == ELFCLASS64 && f.Machine == EM_AARCH64 { return f.applyRelocationsARM64(dst, rels) } + if f.Class == ELFCLASS64 && f.Machine == EM_PPC64 { + return f.applyRelocationsPPC64(dst, rels) + } return errors.New("not implemented") } @@ -671,6 +674,51 @@ func (f *File) applyRelocationsARM64(dst []byte, rels []byte) error { return nil } +func (f *File) applyRelocationsPPC64(dst []byte, rels []byte) error { + // 24 is the size of Rela64. + if len(rels)%24 != 0 { + return errors.New("length of relocation section is not a multiple of 24") + } + + symbols, _, err := f.getSymbols(SHT_SYMTAB) + if err != nil { + return err + } + + b := bytes.NewReader(rels) + var rela Rela64 + + for b.Len() > 0 { + binary.Read(b, f.ByteOrder, &rela) + symNo := rela.Info >> 32 + t := R_PPC64(rela.Info & 0xffff) + + if symNo == 0 || symNo > uint64(len(symbols)) { + continue + } + sym := &symbols[symNo-1] + if SymType(sym.Info&0xf) != STT_SECTION { + // We don't handle non-section relocations for now. + continue + } + + switch t { + case R_PPC64_ADDR64: + if rela.Off+8 >= uint64(len(dst)) || rela.Addend < 0 { + continue + } + f.ByteOrder.PutUint64(dst[rela.Off:rela.Off+8], uint64(rela.Addend)) + case R_PPC64_ADDR32: + if rela.Off+4 >= uint64(len(dst)) || rela.Addend < 0 { + continue + } + f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], uint32(rela.Addend)) + } + } + + return nil +} + func (f *File) DWARF() (*dwarf.Data, error) { // There are many other DWARF sections, but these // are the required ones, and the debug/dwarf package @@ -693,7 +741,7 @@ func (f *File) DWARF() (*dwarf.Data, error) { // If there's a relocation table for .debug_info, we have to process it // now otherwise the data in .debug_info is invalid for x86-64 objects. rela := f.Section(".rela.debug_info") - if rela != nil && rela.Type == SHT_RELA && (f.Machine == EM_X86_64 || f.Machine == EM_AARCH64) { + if rela != nil && rela.Type == SHT_RELA && (f.Machine == EM_X86_64 || f.Machine == EM_AARCH64 || f.Machine == EM_PPC64) { data, err := rela.Data() if err != nil { return nil, err |