Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -841,10 +841,23 @@ AC_DEFINE(HAVE_VFP2, 1, [Whether we have VFP2 or above]) AC_MSG_RESULT(yes) ], [ AC_MSG_RESULT(no) ]) + ;; +aarch64* | arm64*) + AC_MSG_CHECKING(for bti) + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([], [ + __asm__ __volatile__ ("bti jc"); + ]) + ], [ + AC_DEFINE(HAVE_BTI, 1, [Whether we have bti]) + AC_MSG_RESULT(yes) + ], [ + AC_MSG_RESULT(no) + ]) ;; i?86) AC_MSG_CHECKING(for endbr32) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([], [ Index: src/forwarding/apple-forwarding-arm64.S ================================================================== --- src/forwarding/apple-forwarding-arm64.S +++ src/forwarding/apple-forwarding-arm64.S @@ -31,10 +31,14 @@ .section __TEXT, __text, regular, pure_instructions .align 2 _OFForward: _OFForward_stret: +#ifdef HAVE_BTI + bti jc +#endif + stp fp, lr, [sp, #-208]! mov fp, sp sub sp, sp, #208 /* Save all arguments, x8 and x19 */ Index: src/forwarding/forwarding-arm64-elf.S ================================================================== --- src/forwarding/forwarding-arm64-elf.S +++ src/forwarding/forwarding-arm64-elf.S @@ -21,10 +21,14 @@ .globl OFForward_stret .section .text OFForward: OFForward_stret: +#ifdef HAVE_BTI + bti jc +#endif + stp fp, lr, [sp, #-208]! mov fp, sp sub sp, sp, #208 /* Save all arguments, x8 and x19 */ @@ -101,10 +105,14 @@ .size OFForward, .-OFForward .type OFForward_stret, %function .size OFForward_stret, .-OFForward_stret init: +#ifdef HAVE_BTI + bti c +#endif + adrp x0, module add x0, x0, :lo12:module b __objc_exec_class .section .init_array, "aw", %init_array Index: src/runtime/lookup-asm/lookup-asm-arm64-elf.S ================================================================== --- src/runtime/lookup-asm/lookup-asm-arm64-elf.S +++ src/runtime/lookup-asm/lookup-asm-arm64-elf.S @@ -23,10 +23,14 @@ .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: +#ifdef HAVE_BTI + bti jc +#endif + cbz x0, returnNilMethod tst x0, #1 b.ne .LtaggedPointer_\name @@ -66,10 +70,14 @@ .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: +#ifdef HAVE_BTI + bti jc +#endif + mov x2, x0 ldr x0, [x0] cbz x0, returnNilMethod ldr x2, [x2, #8]