@@ -1040,13 +1040,23 @@ AArch64BtiPac::AArch64BtiPac(Ctx &ctx) : AArch64(ctx) {
1040
1040
1041
1041
void AArch64BtiPac::writePltHeader (uint8_t *buf) const {
1042
1042
const uint8_t btiData[] = { 0x5f , 0x24 , 0x03 , 0xd5 }; // bti c
1043
+ const uint8_t signLR[] = {0x7f , 0x23 , 0x03 , 0xd5 }; // pacibsp
1043
1044
const uint8_t pltData[] = {
1044
1045
0xf0 , 0x7b , 0xbf , 0xa9 , // stp x16, x30, [sp,#-16]!
1045
1046
0x10 , 0x00 , 0x00 , 0x90 , // adrp x16, Page(&(.got.plt[2]))
1046
1047
0x11 , 0x02 , 0x40 , 0xf9 , // ldr x17, [x16, Offset(&(.got.plt[2]))]
1047
1048
0x10 , 0x02 , 0x00 , 0x91 , // add x16, x16, Offset(&(.got.plt[2]))
1048
- 0x20 , 0x02 , 0x1f , 0xd6 , // br x17
1049
- 0x1f , 0x20 , 0x03 , 0xd5 , // nop
1049
+ };
1050
+ const uint8_t pacHintBr[] = {
1051
+ 0x9f , 0x21 , 0x03 , 0xd5 , // autia1716
1052
+ 0x20 , 0x02 , 0x1f , 0xd6 // br x17
1053
+ };
1054
+ const uint8_t pacBr[] = {
1055
+ 0x30 , 0x0a , 0x1f , 0xd7 , // braa x17, x16
1056
+ 0x1f , 0x20 , 0x03 , 0xd5 // nop
1057
+ };
1058
+ const uint8_t stdBr[] = {
1059
+ 0x20 , 0x02 , 0x1f , 0xd6 , // br x17
1050
1060
0x1f , 0x20 , 0x03 , 0xd5 // nop
1051
1061
};
1052
1062
const uint8_t nopData[] = { 0x1f , 0x20 , 0x03 , 0xd5 }; // nop
@@ -1061,15 +1071,30 @@ void AArch64BtiPac::writePltHeader(uint8_t *buf) const {
1061
1071
buf += sizeof (btiData);
1062
1072
plt += sizeof (btiData);
1063
1073
}
1074
+ if (pacEntryKind != PEK_NoAuth) {
1075
+ memcpy (buf, signLR, sizeof (signLR));
1076
+ buf += sizeof (signLR);
1077
+ plt += sizeof (signLR);
1078
+ }
1064
1079
memcpy (buf, pltData, sizeof (pltData));
1065
1080
1066
1081
relocateNoSym (buf + 4 , R_AARCH64_ADR_PREL_PG_HI21,
1067
1082
getAArch64Page (got + 16 ) - getAArch64Page (plt + 4 ));
1068
1083
relocateNoSym (buf + 8 , R_AARCH64_LDST64_ABS_LO12_NC, got + 16 );
1069
1084
relocateNoSym (buf + 12 , R_AARCH64_ADD_ABS_LO12_NC, got + 16 );
1085
+
1086
+ if (pacEntryKind != PEK_NoAuth)
1087
+ memcpy (buf + sizeof (pltData),
1088
+ (pacEntryKind == PEK_AuthHint ? pacHintBr : pacBr),
1089
+ sizeof (pacEntryKind == PEK_AuthHint ? pacHintBr : pacBr));
1090
+ else
1091
+ memcpy (buf + sizeof (pltData), stdBr, sizeof (stdBr));
1070
1092
if (!btiHeader)
1071
1093
// We didn't add the BTI c instruction so round out size with NOP.
1072
- memcpy (buf + sizeof (pltData), nopData, sizeof (nopData));
1094
+ memcpy (buf + sizeof (pltData) + sizeof (stdBr), nopData, sizeof (nopData));
1095
+ if (pacEntryKind == PEK_NoAuth)
1096
+ // We didn't add the PACIBSP instruction so round out size with NOP.
1097
+ memcpy (buf + sizeof (pltData) + sizeof (stdBr), nopData, sizeof (nopData));
1073
1098
}
1074
1099
1075
1100
void AArch64BtiPac::writePlt (uint8_t *buf, const Symbol &sym,
0 commit comments