@@ -1039,13 +1039,23 @@ AArch64BtiPac::AArch64BtiPac(Ctx &ctx) : AArch64(ctx) {
10391039
10401040void AArch64BtiPac::writePltHeader (uint8_t *buf) const {
10411041 const uint8_t btiData[] = { 0x5f , 0x24 , 0x03 , 0xd5 }; // bti c
1042+ const uint8_t signLR[] = {0x7f , 0x23 , 0x03 , 0xd5 }; // pacibsp
10421043 const uint8_t pltData[] = {
10431044 0xf0 , 0x7b , 0xbf , 0xa9 , // stp x16, x30, [sp,#-16]!
10441045 0x10 , 0x00 , 0x00 , 0x90 , // adrp x16, Page(&(.got.plt[2]))
10451046 0x11 , 0x02 , 0x40 , 0xf9 , // ldr x17, [x16, Offset(&(.got.plt[2]))]
10461047 0x10 , 0x02 , 0x00 , 0x91 , // add x16, x16, Offset(&(.got.plt[2]))
1047- 0x20 , 0x02 , 0x1f , 0xd6 , // br x17
1048- 0x1f , 0x20 , 0x03 , 0xd5 , // nop
1048+ };
1049+ const uint8_t pacHintBr[] = {
1050+ 0x9f , 0x21 , 0x03 , 0xd5 , // autia1716
1051+ 0x20 , 0x02 , 0x1f , 0xd6 // br x17
1052+ };
1053+ const uint8_t pacBr[] = {
1054+ 0x30 , 0x0a , 0x1f , 0xd7 , // braa x17, x16
1055+ 0x1f , 0x20 , 0x03 , 0xd5 // nop
1056+ };
1057+ const uint8_t stdBr[] = {
1058+ 0x20 , 0x02 , 0x1f , 0xd6 , // br x17
10491059 0x1f , 0x20 , 0x03 , 0xd5 // nop
10501060 };
10511061 const uint8_t nopData[] = { 0x1f , 0x20 , 0x03 , 0xd5 }; // nop
@@ -1060,15 +1070,30 @@ void AArch64BtiPac::writePltHeader(uint8_t *buf) const {
10601070 buf += sizeof (btiData);
10611071 plt += sizeof (btiData);
10621072 }
1073+ if (pacEntryKind != PEK_NoAuth) {
1074+ memcpy (buf, signLR, sizeof (signLR));
1075+ buf += sizeof (signLR);
1076+ plt += sizeof (signLR);
1077+ }
10631078 memcpy (buf, pltData, sizeof (pltData));
10641079
10651080 relocateNoSym (buf + 4 , R_AARCH64_ADR_PREL_PG_HI21,
10661081 getAArch64Page (got + 16 ) - getAArch64Page (plt + 4 ));
10671082 relocateNoSym (buf + 8 , R_AARCH64_LDST64_ABS_LO12_NC, got + 16 );
10681083 relocateNoSym (buf + 12 , R_AARCH64_ADD_ABS_LO12_NC, got + 16 );
1084+
1085+ if (pacEntryKind != PEK_NoAuth)
1086+ memcpy (buf + sizeof (pltData),
1087+ (pacEntryKind == PEK_AuthHint ? pacHintBr : pacBr),
1088+ sizeof (pacEntryKind == PEK_AuthHint ? pacHintBr : pacBr));
1089+ else
1090+ memcpy (buf + sizeof (pltData), stdBr, sizeof (stdBr));
10691091 if (!btiHeader)
10701092 // We didn't add the BTI c instruction so round out size with NOP.
1071- memcpy (buf + sizeof (pltData), nopData, sizeof (nopData));
1093+ memcpy (buf + sizeof (pltData) + sizeof (stdBr), nopData, sizeof (nopData));
1094+ if (pacEntryKind == PEK_NoAuth)
1095+ // We didn't add the PACIBSP instruction so round out size with NOP.
1096+ memcpy (buf + sizeof (pltData) + sizeof (stdBr), nopData, sizeof (nopData));
10721097}
10731098
10741099void AArch64BtiPac::writePlt (uint8_t *buf, const Symbol &sym,
0 commit comments