aboutsummaryrefslogtreecommitdiff
path: root/src/debug/elf/file.go
diff options
context:
space:
mode:
authorYao Zhang <lunaria21@gmail.com>2015-09-10 09:15:19 -0400
committerMinux Ma <minux@golang.org>2015-11-12 04:50:32 +0000
commit7ff52e13cdc61af1f63ab27bd91c1f00cf11bd86 (patch)
tree5b9c687d79553fa2680389b06d6790ecff76dedd /src/debug/elf/file.go
parent559fb85af6e2ba723da0377d2c72cfadeb32768a (diff)
downloadgo-7ff52e13cdc61af1f63ab27bd91c1f00cf11bd86.tar.xz
debug/elf: added MIPS ELF relocations
Change-Id: I05352749a852095baae2f67fd71ffcf5f727538d Reviewed-on: https://go-review.googlesource.com/14453 Reviewed-by: Minux Ma <minux@golang.org>
Diffstat (limited to 'src/debug/elf/file.go')
-rw-r--r--src/debug/elf/file.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/debug/elf/file.go b/src/debug/elf/file.go
index 40625435fd..3e766afe15 100644
--- a/src/debug/elf/file.go
+++ b/src/debug/elf/file.go
@@ -537,6 +537,8 @@ func (f *File) applyRelocations(dst []byte, rels []byte) error {
return f.applyRelocationsPPC(dst, rels)
case f.Class == ELFCLASS64 && f.Machine == EM_PPC64:
return f.applyRelocationsPPC64(dst, rels)
+ case f.Class == ELFCLASS64 && f.Machine == EM_MIPS:
+ return f.applyRelocationsMIPS64(dst, rels)
default:
return errors.New("applyRelocations: not implemented")
}
@@ -800,6 +802,58 @@ func (f *File) applyRelocationsPPC64(dst []byte, rels []byte) error {
return nil
}
+func (f *File) applyRelocationsMIPS64(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)
+ var symNo uint64
+ var t R_MIPS
+ if f.ByteOrder == binary.BigEndian {
+ symNo = rela.Info >> 32
+ t = R_MIPS(rela.Info & 0xff)
+ } else {
+ symNo = rela.Info & 0xffffffff
+ t = R_MIPS(rela.Info >> 56)
+ }
+
+ 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_MIPS_64:
+ 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_MIPS_32:
+ 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) {
// sectionData gets the data for s, checks its size, and
// applies any applicable relations.