aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/debug
diff options
context:
space:
mode:
authorMaciej W. Rozycki <macro@wdc.com>2020-08-28 16:05:56 +0100
committerIan Lance Taylor <iant@golang.org>2020-09-30 19:47:48 -0700
commit2c5499b57cf4a68ebc8decce90d3eb1e281c31a9 (patch)
treea53f1214796df28a6c081cdcd556c5bdd1bda5c9 /libgo/go/debug
parent2dd7b93778d551b6981c8086ecb38e26f677bd2b (diff)
downloadgcc-2c5499b57cf4a68ebc8decce90d3eb1e281c31a9.zip
gcc-2c5499b57cf4a68ebc8decce90d3eb1e281c31a9.tar.gz
gcc-2c5499b57cf4a68ebc8decce90d3eb1e281c31a9.tar.bz2
libgo: add 32-bit RISC-V (RV32) support
Add support for the 32-bit RISC-V (RV32) ISA matching the 64-bit RISC-V (RV64) port except for async preemption added as a stub only. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/251179
Diffstat (limited to 'libgo/go/debug')
-rw-r--r--libgo/go/debug/elf/file.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/libgo/go/debug/elf/file.go b/libgo/go/debug/elf/file.go
index b9a8b1e..48178d4 100644
--- a/libgo/go/debug/elf/file.go
+++ b/libgo/go/debug/elf/file.go
@@ -617,6 +617,8 @@ func (f *File) applyRelocations(dst []byte, rels []byte) error {
return f.applyRelocationsMIPS(dst, rels)
case f.Class == ELFCLASS64 && f.Machine == EM_MIPS:
return f.applyRelocationsMIPS64(dst, rels)
+ case f.Class == ELFCLASS32 && f.Machine == EM_RISCV:
+ return f.applyRelocationsRISCV(dst, rels)
case f.Class == ELFCLASS64 && f.Machine == EM_RISCV:
return f.applyRelocationsRISCV64(dst, rels)
case f.Class == ELFCLASS64 && f.Machine == EM_S390:
@@ -1008,6 +1010,47 @@ func (f *File) applyRelocationsMIPS64(dst []byte, rels []byte) error {
return nil
}
+func (f *File) applyRelocationsRISCV(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 >> 8
+ t := R_RISCV(rela.Info & 0xff)
+
+ if symNo == 0 || symNo > uint32(len(symbols)) {
+ continue
+ }
+ sym := &symbols[symNo-1]
+ needed, val := relocSymbolTargetOK(sym)
+ if !needed {
+ continue
+ }
+
+ switch t {
+ case R_RISCV_32:
+ if rela.Off+4 >= uint32(len(dst)) || rela.Addend < 0 {
+ continue
+ }
+ val32 := uint32(val) + uint32(rela.Addend)
+ f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], val32)
+ }
+ }
+
+ return nil
+}
+
func (f *File) applyRelocationsRISCV64(dst []byte, rels []byte) error {
// 24 is the size of Rela64.
if len(rels)%24 != 0 {