@@ -1205,6 +1205,7 @@ void LowerTypeTestsModule::verifyTypeMDNode(GlobalObject *GO, MDNode *Type) {
1205
1205
1206
1206
static const unsigned kX86JumpTableEntrySize = 8 ;
1207
1207
static const unsigned kARMJumpTableEntrySize = 4 ;
1208
+ static const unsigned kARMBTIJumpTableEntrySize = 8 ;
1208
1209
1209
1210
unsigned LowerTypeTestsModule::getJumpTableEntrySize () {
1210
1211
switch (Arch) {
@@ -1213,7 +1214,12 @@ unsigned LowerTypeTestsModule::getJumpTableEntrySize() {
1213
1214
return kX86JumpTableEntrySize ;
1214
1215
case Triple::arm:
1215
1216
case Triple::thumb:
1217
+ return kARMJumpTableEntrySize ;
1216
1218
case Triple::aarch64:
1219
+ if (const auto *BTE = mdconst::extract_or_null<ConstantInt>(
1220
+ M.getModuleFlag (" branch-target-enforcement" )))
1221
+ if (BTE->getZExtValue ())
1222
+ return kARMBTIJumpTableEntrySize ;
1217
1223
return kARMJumpTableEntrySize ;
1218
1224
default :
1219
1225
report_fatal_error (" Unsupported architecture for jump tables" );
@@ -1232,7 +1238,13 @@ void LowerTypeTestsModule::createJumpTableEntry(
1232
1238
if (JumpTableArch == Triple::x86 || JumpTableArch == Triple::x86_64) {
1233
1239
AsmOS << " jmp ${" << ArgIndex << " :c}@plt\n " ;
1234
1240
AsmOS << " int3\n int3\n int3\n " ;
1235
- } else if (JumpTableArch == Triple::arm || JumpTableArch == Triple::aarch64) {
1241
+ } else if (JumpTableArch == Triple::arm) {
1242
+ AsmOS << " b $" << ArgIndex << " \n " ;
1243
+ } else if (JumpTableArch == Triple::aarch64) {
1244
+ if (const auto *BTE = mdconst::extract_or_null<ConstantInt>(
1245
+ Dest->getParent ()->getModuleFlag (" branch-target-enforcement" )))
1246
+ if (BTE->getZExtValue ())
1247
+ AsmOS << " bti c\n " ;
1236
1248
AsmOS << " b $" << ArgIndex << " \n " ;
1237
1249
} else if (JumpTableArch == Triple::thumb) {
1238
1250
AsmOS << " b.w $" << ArgIndex << " \n " ;
@@ -1394,6 +1406,10 @@ void LowerTypeTestsModule::createJumpTable(
1394
1406
// by Clang for -march=armv7.
1395
1407
F->addFnAttr (" target-cpu" , " cortex-a8" );
1396
1408
}
1409
+ if (JumpTableArch == Triple::aarch64) {
1410
+ F->addFnAttr (" branch-target-enforcement" , " false" );
1411
+ F->addFnAttr (" sign-return-address" , " none" );
1412
+ }
1397
1413
// Make sure we don't emit .eh_frame for this function.
1398
1414
F->addFnAttr (Attribute::NoUnwind);
1399
1415
0 commit comments