]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: add loadelf support for riscv64
authorJoel Sing <joel@sing.id.au>
Tue, 20 Oct 2020 11:04:55 +0000 (22:04 +1100)
committerJoel Sing <joel@sing.id.au>
Thu, 29 Oct 2020 18:26:42 +0000 (18:26 +0000)
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>

src/cmd/link/internal/loadelf/ldelf.go

index 5a39856a3b6c19f963b7901b9b6feb128f083330..5260c6bdcb111dbd25b9a7c763c8c860a45b156c 100644 (file)
@@ -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")
@@ -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 {
@@ -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
        }
 }