aboutsummaryrefslogtreecommitdiff
path: root/src/debug/elf/file.go
diff options
context:
space:
mode:
authorJames Clarke <jrtc27@jrtc27.com>2016-10-11 19:08:45 +0100
committerIan Lance Taylor <iant@golang.org>2016-10-11 21:52:37 +0000
commite1fc292500aa70c265937aebad00ac010031cbaf (patch)
tree63a9aec599c8e30fdb284de5c784d8b829428e7d /src/debug/elf/file.go
parent35220534d5edbbbcd0eed59133bcfae54d140287 (diff)
downloadgo-e1fc292500aa70c265937aebad00ac010031cbaf.tar.xz
debug/elf: add sparc64 relocations
Change-Id: I1a2504ad9ca8607588d2d366598115fe360435b5 Reviewed-on: https://go-review.googlesource.com/30870 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/debug/elf/file.go')
-rw-r--r--src/debug/elf/file.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/debug/elf/file.go b/src/debug/elf/file.go
index c173ea9331..c1cbfa6225 100644
--- a/src/debug/elf/file.go
+++ b/src/debug/elf/file.go
@@ -598,6 +598,8 @@ func (f *File) applyRelocations(dst []byte, rels []byte) error {
return f.applyRelocationsMIPS64(dst, rels)
case f.Class == ELFCLASS64 && f.Machine == EM_S390:
return f.applyRelocationss390x(dst, rels)
+ case f.Class == ELFCLASS64 && f.Machine == EM_SPARCV9:
+ return f.applyRelocationsSPARC64(dst, rels)
default:
return errors.New("applyRelocations: not implemented")
}
@@ -962,6 +964,51 @@ func (f *File) applyRelocationss390x(dst []byte, rels []byte) error {
return nil
}
+func (f *File) applyRelocationsSPARC64(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_SPARC(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_SPARC_64, R_SPARC_UA64:
+ 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_SPARC_32, R_SPARC_UA32:
+ 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.