Skip to content

Commit

Permalink
cmd/link: add loadelf support for riscv64
Browse files Browse the repository at this point in the history
Update #36641

Change-Id: I8618da30d8940a56d6cc86a37a2f54b31ee029e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/263601
Trust: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
TryBot-Result: Go Bot <gobot@golang.org>
  • Loading branch information
4a6f656c committed Oct 29, 2020
1 parent 2e6f500 commit 0b798c4
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions src/cmd/link/internal/loadelf/ldelf.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
return errorf("elf object but not ppc64")
}

case sys.RISCV64:
if mach != elf.EM_RISCV || class != elf.ELFCLASS64 {
return errorf("elf object but not riscv64")
}

case sys.S390X:
if mach != elf.EM_S390 || class != elf.ELFCLASS64 {
return errorf("elf object but not s390x")
Expand Down Expand Up @@ -946,14 +951,15 @@ func relSize(arch *sys.Arch, pn string, elftype uint32) (uint8, error) {
// performance.

const (
AMD64 = uint32(sys.AMD64)
ARM = uint32(sys.ARM)
ARM64 = uint32(sys.ARM64)
I386 = uint32(sys.I386)
PPC64 = uint32(sys.PPC64)
S390X = uint32(sys.S390X)
MIPS = uint32(sys.MIPS)
MIPS64 = uint32(sys.MIPS64)
AMD64 = uint32(sys.AMD64)
ARM = uint32(sys.ARM)
ARM64 = uint32(sys.ARM64)
I386 = uint32(sys.I386)
MIPS = uint32(sys.MIPS)
MIPS64 = uint32(sys.MIPS64)
PPC64 = uint32(sys.PPC64)
RISCV64 = uint32(sys.RISCV64)
S390X = uint32(sys.S390X)
)

switch uint32(arch.Family) | elftype<<16 {
Expand Down Expand Up @@ -1056,6 +1062,27 @@ func relSize(arch *sys.Arch, pn string, elftype uint32) (uint8, error) {
S390X | uint32(elf.R_390_GOT64)<<16,
S390X | uint32(elf.R_390_PLT64)<<16:
return 8, nil

case RISCV64 | uint32(elf.R_RISCV_RVC_BRANCH)<<16,
RISCV64 | uint32(elf.R_RISCV_RVC_JUMP)<<16:
return 2, nil

case RISCV64 | uint32(elf.R_RISCV_32)<<16,
RISCV64 | uint32(elf.R_RISCV_BRANCH)<<16,
RISCV64 | uint32(elf.R_RISCV_HI20)<<16,
RISCV64 | uint32(elf.R_RISCV_LO12_I)<<16,
RISCV64 | uint32(elf.R_RISCV_LO12_S)<<16,
RISCV64 | uint32(elf.R_RISCV_GOT_HI20)<<16,
RISCV64 | uint32(elf.R_RISCV_PCREL_HI20)<<16,
RISCV64 | uint32(elf.R_RISCV_PCREL_LO12_I)<<16,
RISCV64 | uint32(elf.R_RISCV_PCREL_LO12_S)<<16,
RISCV64 | uint32(elf.R_RISCV_RELAX)<<16:
return 4, nil

case RISCV64 | uint32(elf.R_RISCV_64)<<16,
RISCV64 | uint32(elf.R_RISCV_CALL)<<16,
RISCV64 | uint32(elf.R_RISCV_CALL_PLT)<<16:
return 8, nil
}
}

Expand Down

0 comments on commit 0b798c4

Please sign in to comment.