@@ -109,6 +109,7 @@ static bool isSupportedRISCV(uint64_t Type) {
109
109
case ELF::R_RISCV_HI20:
110
110
case ELF::R_RISCV_LO12_I:
111
111
case ELF::R_RISCV_LO12_S:
112
+ case ELF::R_RISCV_64:
112
113
return true ;
113
114
}
114
115
}
@@ -209,6 +210,7 @@ static size_t getSizeForTypeRISCV(uint64_t Type) {
209
210
case ELF::R_RISCV_LO12_I:
210
211
case ELF::R_RISCV_LO12_S:
211
212
return 4 ;
213
+ case ELF::R_RISCV_64:
212
214
case ELF::R_RISCV_GOT_HI20:
213
215
// See extractValueRISCV for why this is necessary.
214
216
return 8 ;
@@ -364,6 +366,16 @@ static uint64_t encodeValueAArch64(uint64_t Type, uint64_t Value, uint64_t PC) {
364
366
return Value;
365
367
}
366
368
369
+ static uint64_t encodeValueRISCV (uint64_t Type, uint64_t Value, uint64_t PC) {
370
+ switch (Type) {
371
+ default :
372
+ llvm_unreachable (" unsupported relocation" );
373
+ case ELF::R_RISCV_64:
374
+ break ;
375
+ }
376
+ return Value;
377
+ }
378
+
367
379
static uint64_t extractValueX86 (uint64_t Type, uint64_t Contents, uint64_t PC) {
368
380
if (Type == ELF::R_X86_64_32S)
369
381
return SignExtend64<32 >(Contents);
@@ -539,6 +551,7 @@ static uint64_t extractValueRISCV(uint64_t Type, uint64_t Contents,
539
551
return SignExtend64<8 >(((Contents >> 2 ) & 0x1f ) | ((Contents >> 5 ) & 0xe0 ));
540
552
case ELF::R_RISCV_ADD32:
541
553
case ELF::R_RISCV_SUB32:
554
+ case ELF::R_RISCV_64:
542
555
return Contents;
543
556
}
544
557
}
@@ -704,6 +717,7 @@ static bool isPCRelativeRISCV(uint64_t Type) {
704
717
case ELF::R_RISCV_HI20:
705
718
case ELF::R_RISCV_LO12_I:
706
719
case ELF::R_RISCV_LO12_S:
720
+ case ELF::R_RISCV_64:
707
721
return false ;
708
722
case ELF::R_RISCV_JAL:
709
723
case ELF::R_RISCV_CALL:
@@ -756,7 +770,7 @@ uint64_t Relocation::encodeValue(uint64_t Type, uint64_t Value, uint64_t PC) {
756
770
if (Arch == Triple::aarch64)
757
771
return encodeValueAArch64 (Type, Value, PC);
758
772
if (Arch == Triple::riscv64)
759
- llvm_unreachable ( " not implemented " );
773
+ return encodeValueRISCV (Type, Value, PC );
760
774
return encodeValueX86 (Type, Value, PC);
761
775
}
762
776
@@ -844,6 +858,8 @@ bool Relocation::isPCRelative(uint64_t Type) {
844
858
uint64_t Relocation::getAbs64 () {
845
859
if (Arch == Triple::aarch64)
846
860
return ELF::R_AARCH64_ABS64;
861
+ if (Arch == Triple::riscv64)
862
+ return ELF::R_RISCV_64;
847
863
return ELF::R_X86_64_64;
848
864
}
849
865
0 commit comments