summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2017-09-29 14:35:58 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2017-09-29 14:35:58 +0000
commita8acc388ac3395eb44ddaebe47717b13b7bfc925 (patch)
tree28b5d1ee27484b0b28463ab62b38b9cf33fa8088
parent47e8a478fd9ba3848b6206349c2205919d180d00 (diff)
downloadgcc-a8acc388ac3395eb44ddaebe47717b13b7bfc925.tar.gz
debug/elf: support 32-bit SPARC relocs
Patch by Rainer Orth. Reviewed-on: https://go-review.googlesource.com/67111 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253292 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--libgo/go/debug/elf/file.go42
2 files changed, 43 insertions, 1 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 56ede0d4c9b..07cde8979cc 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-9a9d526a4c0a7f5b3635034b3e1dc3bbe6380dd2
+5989ef1cd0add98f107839759a5bc57f34354d39
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
diff --git a/libgo/go/debug/elf/file.go b/libgo/go/debug/elf/file.go
index c493f2a0562..b415bb1bbc9 100644
--- a/libgo/go/debug/elf/file.go
+++ b/libgo/go/debug/elf/file.go
@@ -600,6 +600,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 == ELFCLASS32 && (f.Machine == EM_SPARC || f.Machine == EM_SPARC32PLUS):
+ return f.applyRelocationsSPARC(dst, rels)
case f.Class == ELFCLASS64 && f.Machine == EM_SPARCV9:
return f.applyRelocationsSPARC64(dst, rels)
case f.Class == ELFCLASS64 && f.Machine == EM_ALPHA:
@@ -1006,6 +1008,46 @@ func (f *File) applyRelocationss390x(dst []byte, rels []byte) error {
return nil
}
+func (f *File) applyRelocationsSPARC(dst []byte, rels []byte) error {
+ // 12 is the size of Rela32.
+ if len(rels)%12 != 0 {
+ return errors.New("length of relocation section is not a multiple of 12")
+ }
+
+ symbols, _, err := f.getSymbols(SHT_SYMTAB)
+ if err != nil {
+ return err
+ }
+
+ b := bytes.NewReader(rels)
+ var rela Rela32
+
+ for b.Len() > 0 {
+ binary.Read(b, f.ByteOrder, &rela)
+ symNo := rela.Info >> 32
+ t := R_SPARC(rela.Info & 0xff)
+
+ if symNo == 0 || symNo > uint32(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_32, R_SPARC_UA32:
+ if rela.Off+4 >= uint32(len(dst)) || rela.Addend < 0 {
+ continue
+ }
+ f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], uint32(rela.Addend))
+ }
+ }
+
+ return nil
+}
+
func (f *File) applyRelocationsSPARC64(dst []byte, rels []byte) error {
// 24 is the size of Rela64.
if len(rels)%24 != 0 {