Skip to content

Commit 0b798c4

Browse files
committed
cmd/link: add loadelf support for riscv64
Update #36641 Change-Id: I8618da30d8940a56d6cc86a37a2f54b31ee029e5 Reviewed-on: https://go-review.googlesource.com/c/go/+/263601 Trust: Joel Sing <[email protected]> Reviewed-by: Cherry Zhang <[email protected]> Run-TryBot: Joel Sing <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 2e6f500 commit 0b798c4

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

Diff for: src/cmd/link/internal/loadelf/ldelf.go

+35-8
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,11 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
372372
return errorf("elf object but not ppc64")
373373
}
374374

375+
case sys.RISCV64:
376+
if mach != elf.EM_RISCV || class != elf.ELFCLASS64 {
377+
return errorf("elf object but not riscv64")
378+
}
379+
375380
case sys.S390X:
376381
if mach != elf.EM_S390 || class != elf.ELFCLASS64 {
377382
return errorf("elf object but not s390x")
@@ -946,14 +951,15 @@ func relSize(arch *sys.Arch, pn string, elftype uint32) (uint8, error) {
946951
// performance.
947952

948953
const (
949-
AMD64 = uint32(sys.AMD64)
950-
ARM = uint32(sys.ARM)
951-
ARM64 = uint32(sys.ARM64)
952-
I386 = uint32(sys.I386)
953-
PPC64 = uint32(sys.PPC64)
954-
S390X = uint32(sys.S390X)
955-
MIPS = uint32(sys.MIPS)
956-
MIPS64 = uint32(sys.MIPS64)
954+
AMD64 = uint32(sys.AMD64)
955+
ARM = uint32(sys.ARM)
956+
ARM64 = uint32(sys.ARM64)
957+
I386 = uint32(sys.I386)
958+
MIPS = uint32(sys.MIPS)
959+
MIPS64 = uint32(sys.MIPS64)
960+
PPC64 = uint32(sys.PPC64)
961+
RISCV64 = uint32(sys.RISCV64)
962+
S390X = uint32(sys.S390X)
957963
)
958964

959965
switch uint32(arch.Family) | elftype<<16 {
@@ -1056,6 +1062,27 @@ func relSize(arch *sys.Arch, pn string, elftype uint32) (uint8, error) {
10561062
S390X | uint32(elf.R_390_GOT64)<<16,
10571063
S390X | uint32(elf.R_390_PLT64)<<16:
10581064
return 8, nil
1065+
1066+
case RISCV64 | uint32(elf.R_RISCV_RVC_BRANCH)<<16,
1067+
RISCV64 | uint32(elf.R_RISCV_RVC_JUMP)<<16:
1068+
return 2, nil
1069+
1070+
case RISCV64 | uint32(elf.R_RISCV_32)<<16,
1071+
RISCV64 | uint32(elf.R_RISCV_BRANCH)<<16,
1072+
RISCV64 | uint32(elf.R_RISCV_HI20)<<16,
1073+
RISCV64 | uint32(elf.R_RISCV_LO12_I)<<16,
1074+
RISCV64 | uint32(elf.R_RISCV_LO12_S)<<16,
1075+
RISCV64 | uint32(elf.R_RISCV_GOT_HI20)<<16,
1076+
RISCV64 | uint32(elf.R_RISCV_PCREL_HI20)<<16,
1077+
RISCV64 | uint32(elf.R_RISCV_PCREL_LO12_I)<<16,
1078+
RISCV64 | uint32(elf.R_RISCV_PCREL_LO12_S)<<16,
1079+
RISCV64 | uint32(elf.R_RISCV_RELAX)<<16:
1080+
return 4, nil
1081+
1082+
case RISCV64 | uint32(elf.R_RISCV_64)<<16,
1083+
RISCV64 | uint32(elf.R_RISCV_CALL)<<16,
1084+
RISCV64 | uint32(elf.R_RISCV_CALL_PLT)<<16:
1085+
return 8, nil
10591086
}
10601087
}
10611088

0 commit comments

Comments
 (0)