@@ -549,15 +549,15 @@ void Thunk::setOffset(uint64_t newOffset) {
549
549
}
550
550
551
551
// AArch64 Thunk base class.
552
- static uint64_t getAArch64ThunkDestVA (const Symbol &s, int64_t a) {
552
+ static uint64_t getAArch64ThunkDestVA (Ctx &ctx, const Symbol &s, int64_t a) {
553
553
uint64_t v = s.isInPlt (ctx) ? s.getPltVA (ctx) : s.getVA (a);
554
554
return v;
555
555
}
556
556
557
557
bool AArch64Thunk::getMayUseShortThunk () {
558
558
if (!mayUseShortThunk)
559
559
return false ;
560
- uint64_t s = getAArch64ThunkDestVA (destination, addend);
560
+ uint64_t s = getAArch64ThunkDestVA (ctx, destination, addend);
561
561
uint64_t p = getThunkTargetSym ()->getVA ();
562
562
mayUseShortThunk = llvm::isInt<28 >(s - p);
563
563
return mayUseShortThunk;
@@ -568,7 +568,7 @@ void AArch64Thunk::writeTo(uint8_t *buf) {
568
568
writeLong (buf);
569
569
return ;
570
570
}
571
- uint64_t s = getAArch64ThunkDestVA (destination, addend);
571
+ uint64_t s = getAArch64ThunkDestVA (ctx, destination, addend);
572
572
uint64_t p = getThunkTargetSym ()->getVA ();
573
573
write32 (buf, 0x14000000 ); // b S
574
574
ctx.target ->relocateNoSym (buf, R_AARCH64_CALL26, s - p);
@@ -591,8 +591,9 @@ void AArch64ABSLongThunk::writeLong(uint8_t *buf) {
591
591
// If mayNeedLandingPad is true then destination is an
592
592
// AArch64BTILandingPadThunk that defines landingPad.
593
593
assert (!mayNeedLandingPad || landingPad != nullptr );
594
- uint64_t s = mayNeedLandingPad ? landingPad->getVA (0 )
595
- : getAArch64ThunkDestVA (destination, addend);
594
+ uint64_t s = mayNeedLandingPad
595
+ ? landingPad->getVA (0 )
596
+ : getAArch64ThunkDestVA (ctx, destination, addend);
596
597
memcpy (buf, data, sizeof (data));
597
598
ctx.target ->relocateNoSym (buf + 8 , R_AARCH64_ABS64, s);
598
599
}
@@ -619,8 +620,9 @@ void AArch64ADRPThunk::writeLong(uint8_t *buf) {
619
620
// if mayNeedLandingPad is true then destination is an
620
621
// AArch64BTILandingPadThunk that defines landingPad.
621
622
assert (!mayNeedLandingPad || landingPad != nullptr );
622
- uint64_t s = mayNeedLandingPad ? landingPad->getVA (0 )
623
- : getAArch64ThunkDestVA (destination, addend);
623
+ uint64_t s = mayNeedLandingPad
624
+ ? landingPad->getVA (0 )
625
+ : getAArch64ThunkDestVA (ctx, destination, addend);
624
626
uint64_t p = getThunkTargetSym ()->getVA ();
625
627
memcpy (buf, data, sizeof (data));
626
628
ctx.target ->relocateNoSym (buf, R_AARCH64_ADR_PREL_PG_HI21,
@@ -676,7 +678,7 @@ void AArch64BTILandingPadThunk::writeLong(uint8_t *buf) {
676
678
}
677
679
678
680
// ARM Target Thunks
679
- static uint64_t getARMThunkDestVA (const Symbol &s) {
681
+ static uint64_t getARMThunkDestVA (Ctx &ctx, const Symbol &s) {
680
682
uint64_t v = s.isInPlt (ctx) ? s.getPltVA (ctx) : s.getVA ();
681
683
return SignExtend64<32 >(v);
682
684
}
@@ -686,7 +688,7 @@ static uint64_t getARMThunkDestVA(const Symbol &s) {
686
688
bool ARMThunk::getMayUseShortThunk () {
687
689
if (!mayUseShortThunk)
688
690
return false ;
689
- uint64_t s = getARMThunkDestVA (destination);
691
+ uint64_t s = getARMThunkDestVA (ctx, destination);
690
692
if (s & 1 ) {
691
693
mayUseShortThunk = false ;
692
694
return false ;
@@ -703,7 +705,7 @@ void ARMThunk::writeTo(uint8_t *buf) {
703
705
return ;
704
706
}
705
707
706
- uint64_t s = getARMThunkDestVA (destination);
708
+ uint64_t s = getARMThunkDestVA (ctx, destination);
707
709
uint64_t p = getThunkTargetSym ()->getVA ();
708
710
int64_t offset = s - p - 8 ;
709
711
write32 (buf, 0xea000000 ); // b S
@@ -729,7 +731,7 @@ bool ARMThunk::isCompatibleWith(const InputSection &isec,
729
731
bool ThumbThunk::getMayUseShortThunk () {
730
732
if (!mayUseShortThunk || !ctx.arg .armJ1J2BranchEncoding )
731
733
return false ;
732
- uint64_t s = getARMThunkDestVA (destination);
734
+ uint64_t s = getARMThunkDestVA (ctx, destination);
733
735
if ((s & 1 ) == 0 ) {
734
736
mayUseShortThunk = false ;
735
737
return false ;
@@ -746,7 +748,7 @@ void ThumbThunk::writeTo(uint8_t *buf) {
746
748
return ;
747
749
}
748
750
749
- uint64_t s = getARMThunkDestVA (destination);
751
+ uint64_t s = getARMThunkDestVA (ctx, destination);
750
752
uint64_t p = getThunkTargetSym ()->getVA ();
751
753
int64_t offset = s - p - 4 ;
752
754
write16 (buf + 0 , 0xf000 ); // b.w S
@@ -768,7 +770,7 @@ void ARMV7ABSLongThunk::writeLong(uint8_t *buf) {
768
770
write32 (buf + 0 , 0xe300c000 ); // movw ip,:lower16:S
769
771
write32 (buf + 4 , 0xe340c000 ); // movt ip,:upper16:S
770
772
write32 (buf + 8 , 0xe12fff1c ); // bx ip
771
- uint64_t s = getARMThunkDestVA (destination);
773
+ uint64_t s = getARMThunkDestVA (ctx, destination);
772
774
ctx.target ->relocateNoSym (buf, R_ARM_MOVW_ABS_NC, s);
773
775
ctx.target ->relocateNoSym (buf + 4 , R_ARM_MOVT_ABS, s);
774
776
}
@@ -785,7 +787,7 @@ void ThumbV7ABSLongThunk::writeLong(uint8_t *buf) {
785
787
write16 (buf + 4 , 0xf2c0 ); // movt ip, :upper16:S
786
788
write16 (buf + 6 , 0x0c00 );
787
789
write16 (buf + 8 , 0x4760 ); // bx ip
788
- uint64_t s = getARMThunkDestVA (destination);
790
+ uint64_t s = getARMThunkDestVA (ctx, destination);
789
791
ctx.target ->relocateNoSym (buf, R_ARM_THM_MOVW_ABS_NC, s);
790
792
ctx.target ->relocateNoSym (buf + 4 , R_ARM_THM_MOVT_ABS, s);
791
793
}
@@ -801,7 +803,7 @@ void ARMV7PILongThunk::writeLong(uint8_t *buf) {
801
803
write32 (buf + 4 , 0xe340c000 ); // movt ip,:upper16:S - (P + (L1-P) + 8)
802
804
write32 (buf + 8 , 0xe08cc00f ); // L1: add ip, ip, pc
803
805
write32 (buf + 12 , 0xe12fff1c ); // bx ip
804
- uint64_t s = getARMThunkDestVA (destination);
806
+ uint64_t s = getARMThunkDestVA (ctx, destination);
805
807
uint64_t p = getThunkTargetSym ()->getVA ();
806
808
int64_t offset = s - p - 16 ;
807
809
ctx.target ->relocateNoSym (buf, R_ARM_MOVW_PREL_NC, offset);
@@ -821,7 +823,7 @@ void ThumbV7PILongThunk::writeLong(uint8_t *buf) {
821
823
write16 (buf + 6 , 0x0c00 );
822
824
write16 (buf + 8 , 0x44fc ); // L1: add ip, pc
823
825
write16 (buf + 10 , 0x4760 ); // bx ip
824
- uint64_t s = getARMThunkDestVA (destination);
826
+ uint64_t s = getARMThunkDestVA (ctx, destination);
825
827
uint64_t p = getThunkTargetSym ()->getVA () & ~0x1 ;
826
828
int64_t offset = s - p - 12 ;
827
829
ctx.target ->relocateNoSym (buf, R_ARM_THM_MOVW_PREL_NC, offset);
@@ -844,7 +846,7 @@ void ThumbV6MABSLongThunk::writeLong(uint8_t *buf) {
844
846
write16 (buf + 4 , 0x9001 ); // str r0, [sp, #4] ; SP + 4 = S
845
847
write16 (buf + 6 , 0xbd01 ); // pop {r0, pc} ; restore r0 and branch to dest
846
848
write32 (buf + 8 , 0x00000000 ); // L1: .word S
847
- uint64_t s = getARMThunkDestVA (destination);
849
+ uint64_t s = getARMThunkDestVA (ctx, destination);
848
850
ctx.target ->relocateNoSym (buf + 8 , R_ARM_ABS32, s);
849
851
}
850
852
@@ -871,7 +873,7 @@ void ThumbV6MABSXOLongThunk::writeLong(uint8_t *buf) {
871
873
write16 (buf + 14 , 0x3000 ); // adds r0, :lower0_7:S
872
874
write16 (buf + 16 , 0x9001 ); // str r0, [sp, #4] ; SP + 4 = S
873
875
write16 (buf + 18 , 0xbd01 ); // pop {r0, pc} ; restore r0 and branch to dest
874
- uint64_t s = getARMThunkDestVA (destination);
876
+ uint64_t s = getARMThunkDestVA (ctx, destination);
875
877
ctx.target ->relocateNoSym (buf + 2 , R_ARM_THM_ALU_ABS_G3, s);
876
878
ctx.target ->relocateNoSym (buf + 6 , R_ARM_THM_ALU_ABS_G2_NC, s);
877
879
ctx.target ->relocateNoSym (buf + 10 , R_ARM_THM_ALU_ABS_G1_NC, s);
@@ -895,7 +897,7 @@ void ThumbV6MPILongThunk::writeLong(uint8_t *buf) {
895
897
write16 (buf + 8 , 0x44e7 ); // L1: add pc, ip ; transfer control
896
898
write16 (buf + 10 , 0x46c0 ); // nop ; pad to 4-byte boundary
897
899
write32 (buf + 12 , 0x00000000 ); // L2: .word S - (P + (L1 - P) + 4)
898
- uint64_t s = getARMThunkDestVA (destination);
900
+ uint64_t s = getARMThunkDestVA (ctx, destination);
899
901
uint64_t p = getThunkTargetSym ()->getVA () & ~0x1 ;
900
902
ctx.target ->relocateNoSym (buf + 12 , R_ARM_REL32, s - p - 12 );
901
903
}
@@ -912,7 +914,7 @@ void ARMV5LongLdrPcThunk::writeLong(uint8_t *buf) {
912
914
write32 (buf + 0 , 0xe51ff004 ); // ldr pc, [pc,#-4] ; L1
913
915
write32 (buf + 4 , 0x00000000 ); // L1: .word S
914
916
ctx.target ->relocateNoSym (buf + 4 , R_ARM_ABS32,
915
- getARMThunkDestVA (destination));
917
+ getARMThunkDestVA (ctx, destination));
916
918
}
917
919
918
920
void ARMV5LongLdrPcThunk::addSymbols (ThunkSection &isec) {
@@ -928,7 +930,7 @@ void ARMV4ABSLongBXThunk::writeLong(uint8_t *buf) {
928
930
write32 (buf + 4 , 0xe12fff1c ); // bx r12
929
931
write32 (buf + 8 , 0x00000000 ); // L1: .word S
930
932
ctx.target ->relocateNoSym (buf + 8 , R_ARM_ABS32,
931
- getARMThunkDestVA (destination));
933
+ getARMThunkDestVA (ctx, destination));
932
934
}
933
935
934
936
void ARMV4ABSLongBXThunk::addSymbols (ThunkSection &isec) {
@@ -945,7 +947,7 @@ void ThumbV4ABSLongBXThunk::writeLong(uint8_t *buf) {
945
947
write32 (buf + 4 , 0xe51ff004 ); // ldr pc, [pc, #-4] ; L1
946
948
write32 (buf + 8 , 0x00000000 ); // L1: .word S
947
949
ctx.target ->relocateNoSym (buf + 8 , R_ARM_ABS32,
948
- getARMThunkDestVA (destination));
950
+ getARMThunkDestVA (ctx, destination));
949
951
}
950
952
951
953
void ThumbV4ABSLongBXThunk::addSymbols (ThunkSection &isec) {
@@ -964,7 +966,7 @@ void ThumbV4ABSLongThunk::writeLong(uint8_t *buf) {
964
966
write32 (buf + 8 , 0xe12fff1c ); // bx r12
965
967
write32 (buf + 12 , 0x00000000 ); // L1: .word S
966
968
ctx.target ->relocateNoSym (buf + 12 , R_ARM_ABS32,
967
- getARMThunkDestVA (destination));
969
+ getARMThunkDestVA (ctx, destination));
968
970
}
969
971
970
972
void ThumbV4ABSLongThunk::addSymbols (ThunkSection &isec) {
@@ -981,7 +983,7 @@ void ARMV4PILongBXThunk::writeLong(uint8_t *buf) {
981
983
write32 (buf + 4 , 0xe08fc00c ); // L1: add ip, pc, ip
982
984
write32 (buf + 8 , 0xe12fff1c ); // bx ip
983
985
write32 (buf + 12 , 0x00000000 ); // L2: .word S - (P + (L1 - P) + 8)
984
- uint64_t s = getARMThunkDestVA (destination);
986
+ uint64_t s = getARMThunkDestVA (ctx, destination);
985
987
uint64_t p = getThunkTargetSym ()->getVA () & ~0x1 ;
986
988
ctx.target ->relocateNoSym (buf + 12 , R_ARM_REL32, s - p - 12 );
987
989
}
@@ -998,7 +1000,7 @@ void ARMV4PILongThunk::writeLong(uint8_t *buf) {
998
1000
write32 (buf + 0 , 0xe59fc000 ); // P: ldr ip, [pc] ; L2
999
1001
write32 (buf + 4 , 0xe08ff00c ); // L1: add pc, pc, r12
1000
1002
write32 (buf + 8 , 0x00000000 ); // L2: .word S - (P + (L1 - P) + 8)
1001
- uint64_t s = getARMThunkDestVA (destination);
1003
+ uint64_t s = getARMThunkDestVA (ctx, destination);
1002
1004
uint64_t p = getThunkTargetSym ()->getVA () & ~0x1 ;
1003
1005
ctx.target ->relocateNoSym (buf + 8 , R_ARM_REL32, s - p - 12 );
1004
1006
}
@@ -1017,7 +1019,7 @@ void ThumbV4PILongBXThunk::writeLong(uint8_t *buf) {
1017
1019
write32 (buf + 4 , 0xe59fc000 ); // ldr r12, [pc] ; L2
1018
1020
write32 (buf + 8 , 0xe08cf00f ); // L1: add pc, r12, pc
1019
1021
write32 (buf + 12 , 0x00000000 ); // L2: .word S - (P + (L1 - P) + 8)
1020
- uint64_t s = getARMThunkDestVA (destination);
1022
+ uint64_t s = getARMThunkDestVA (ctx, destination);
1021
1023
uint64_t p = getThunkTargetSym ()->getVA () & ~0x1 ;
1022
1024
ctx.target ->relocateNoSym (buf + 12 , R_ARM_REL32, s - p - 16 );
1023
1025
}
@@ -1038,7 +1040,7 @@ void ThumbV4PILongThunk::writeLong(uint8_t *buf) {
1038
1040
write32 (buf + 8 , 0xe08fc00c ); // L1: add ip, pc, ip
1039
1041
write32 (buf + 12 , 0xe12fff1c ); // bx ip
1040
1042
write32 (buf + 16 , 0x00000000 ); // L2: .word S - (P + (L1 - P) + 8)
1041
- uint64_t s = getARMThunkDestVA (destination);
1043
+ uint64_t s = getARMThunkDestVA (ctx, destination);
1042
1044
uint64_t p = getThunkTargetSym ()->getVA () & ~0x1 ;
1043
1045
ctx.target ->relocateNoSym (buf + 16 , R_ARM_REL32, s - p - 16 );
1044
1046
}
@@ -1366,7 +1368,7 @@ static Thunk *addThunkAArch64(Ctx &ctx, RelType type, Symbol &s, int64_t a) {
1366
1368
fatal (" unrecognized relocation type" );
1367
1369
bool mayNeedLandingPad =
1368
1370
(ctx.arg .andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) &&
1369
- !isAArch64BTILandingPad (s, a);
1371
+ !isAArch64BTILandingPad (ctx, s, a);
1370
1372
if (ctx.arg .picThunk )
1371
1373
return make<AArch64ADRPThunk>(ctx, s, a, mayNeedLandingPad);
1372
1374
return make<AArch64ABSLongThunk>(ctx, s, a, mayNeedLandingPad);
0 commit comments