@@ -999,7 +999,9 @@ class AArch64BtiPac final : public AArch64 {
999999
10001000private:
10011001 bool btiHeader; // bti instruction needed in PLT Header and Entry
1002- bool pacEntry; // autia1716 instruction needed in PLT Entry
1002+ bool pacEntry; // Authenticated branch needed in PLT Entry
1003+ bool pacUseHint =
1004+ true ; // Use hint space instructions for authenticated branch in PLT entry
10031005};
10041006} // namespace
10051007
@@ -1016,6 +1018,10 @@ AArch64BtiPac::AArch64BtiPac(Ctx &ctx) : AArch64(ctx) {
10161018 // from properties in the objects, so we use the command line flag.
10171019 pacEntry = ctx.arg .zPacPlt ;
10181020
1021+ if (llvm::any_of (ctx.aarch64PauthAbiCoreInfo ,
1022+ [](uint8_t c) { return c != 0 ; }))
1023+ pacUseHint = false ;
1024+
10191025 if (btiHeader || pacEntry) {
10201026 pltEntrySize = 24 ;
10211027 ipltEntrySize = 24 ;
@@ -1066,9 +1072,13 @@ void AArch64BtiPac::writePlt(uint8_t *buf, const Symbol &sym,
10661072 0x11 , 0x02 , 0x40 , 0xf9 , // ldr x17, [x16, Offset(&(.got.plt[n]))]
10671073 0x10 , 0x02 , 0x00 , 0x91 // add x16, x16, Offset(&(.got.plt[n]))
10681074 };
1075+ const uint8_t pacHintBr[] = {
1076+ 0x9f , 0x21 , 0x03 , 0xd5 , // autia1716
1077+ 0x20 , 0x02 , 0x1f , 0xd6 // br x17
1078+ };
10691079 const uint8_t pacBr[] = {
1070- 0x9f , 0x21 , 0x03 , 0xd5 , // autia1716
1071- 0x20 , 0x02 , 0x1f , 0xd6 // br x17
1080+ 0x30 , 0x0a , 0x1f , 0xd7 , // braa x17, x16
1081+ 0x1f , 0x20 , 0x03 , 0xd5 // nop
10721082 };
10731083 const uint8_t stdBr[] = {
10741084 0x20 , 0x02 , 0x1f , 0xd6 , // br x17
@@ -1097,7 +1107,8 @@ void AArch64BtiPac::writePlt(uint8_t *buf, const Symbol &sym,
10971107 relocateNoSym (buf + 8 , R_AARCH64_ADD_ABS_LO12_NC, gotPltEntryAddr);
10981108
10991109 if (pacEntry)
1100- memcpy (buf + sizeof (addrInst), pacBr, sizeof (pacBr));
1110+ memcpy (buf + sizeof (addrInst), (pacUseHint ? pacHintBr : pacBr),
1111+ sizeof (pacUseHint ? pacHintBr : pacBr));
11011112 else
11021113 memcpy (buf + sizeof (addrInst), stdBr, sizeof (stdBr));
11031114 if (!hasBti)
0 commit comments