Index: lld/ELF/Arch/AArch64.cpp =================================================================== --- lld/ELF/Arch/AArch64.cpp +++ lld/ELF/Arch/AArch64.cpp @@ -912,8 +912,8 @@ // escape to shared objects. isInIplt indicates a non-preemptible ifunc. Its // address may escape if referenced by a direct relocation. The condition is // conservative. - bool hasBti = btiHeader && - (sym.hasFlag(NEEDS_COPY) || sym.isInIplt || sym.thunkAccessed); + bool hasBti = btiHeader && (sym.hasFlag(NEEDS_COPY) || sym.isInIplt || + sym.thunkAccessed || sym.exportDynamic); if (hasBti) { memcpy(buf, btiData, sizeof(btiData)); buf += sizeof(btiData); Index: lld/test/ELF/aarch64-feature-bti.s =================================================================== --- lld/test/ELF/aarch64-feature-bti.s +++ lld/test/ELF/aarch64-feature-bti.s @@ -41,9 +41,9 @@ # SOGOTPLT-NEXT: 0x000303b0 00000000 00000000 00000000 00000000 # SOGOTPLT-NEXT: 0x000303c0 00000000 00000000 d0020100 00000000 -## Expect a bti c at the start of plt[0], the plt entries do not need bti c as -## their address doesn't escape the shared object, so they can't be indirectly -## called. Expect no other difference. +## Expect a bti c at the start of plt[0], the plt entries do need bti c as +## their address may escape the shared object, so they can be indirectly +## called e.g. with relative vtables. Expect no other difference. # RUN: ld.lld %t1.o %t3.o --shared --soname=t.so -o %t.so # RUN: llvm-readelf -n %t.so | FileCheck --check-prefix BTIPROP %s @@ -72,7 +72,8 @@ # BTISO-NEXT: nop # BTISO-NEXT: nop # BTISO: 0000000000010380 : -# BTISO-NEXT: 10380: adrp x16, 0x30000 +# BTISO-NEXT: 10380: bti c +# BTISO-NEXT: adrp x16, 0x30000 # BTISO-NEXT: ldr x17, [x16, #1152] # BTISO-NEXT: add x16, x16, #1152 # BTISO-NEXT: br x17 @@ -105,12 +106,12 @@ # EXECBTI-NEXT: nop # EXECBTI-NEXT: nop # EXECBTI: 0000000000210370 : -# EXECBTI-NEXT: 210370: adrp x16, 0x230000 +# EXECBTI-NEXT: 210370: bti c +# EXECBTI-NEXT: adrp x16, 0x230000 # EXECBTI-NEXT: ldr x17, [x16, #1168] # EXECBTI-NEXT: add x16, x16, #1168 # EXECBTI-NEXT: br x17 # EXECBTI-NEXT: nop -# EXECBTI-NEXT: nop ## We expect a bti c in front of a canonical PLT entry because its address ## can escape the executable. @@ -147,12 +148,12 @@ # PIE-NEXT: nop # PIE-NEXT: nop # PIE: 0000000000010370 : -# PIE-NEXT: 10370: adrp x16, 0x30000 +# PIE-NEXT: 10370: bti c +# PIE-NEXT: adrp x16, 0x30000 # PIE-NEXT: ldr x17, [x16, #1184] # PIE-NEXT: add x16, x16, #1184 # PIE-NEXT: br x17 # PIE-NEXT: nop -# PIE-NEXT: nop ## Build and executable with not all relocatable inputs having the BTI ## .note.property, expect no bti c and no .note.gnu.property entry @@ -214,12 +215,12 @@ # FORCE-NEXT: nop # FORCE-NEXT: nop # FORCE: 00000000002103a0 : -# FORCE-NEXT: 2103a0: adrp x16, 0x230000 +# FORCE-NEXT: 2103a0: bti c +# FORCE-NEXT: adrp x16, 0x230000 # FORCE-NEXT: ldr x17, [x16, #1200] # FORCE-NEXT: add x16, x16, #1200 # FORCE-NEXT: br x17 # FORCE-NEXT: nop -# FORCE-NEXT: nop .section ".note.gnu.property", "a" .long 4 Index: lld/test/ELF/aarch64-feature-btipac.s =================================================================== --- lld/test/ELF/aarch64-feature-btipac.s +++ lld/test/ELF/aarch64-feature-btipac.s @@ -31,7 +31,8 @@ # BTIPACSO-NEXT: nop # BTIPACSO-NEXT: nop # BTIPACSO: 0000000000010380 : -# BTIPACSO-NEXT: 10380: adrp x16, 0x30000 +# BTIPACSO-NEXT: 10380: bti c +# BTIPACSO-NEXT: adrp x16, 0x30000 # BTIPACSO-NEXT: ldr x17, [x16, #1152] # BTIPACSO-NEXT: add x16, x16, #1152 # BTIPACSO-NEXT: br x17 @@ -68,12 +69,13 @@ # BTIPACEX-NEXT: nop # BTIPACEX-NEXT: nop # BTIPACEX: 00000000002103a0 : -# BTIPACEX-NEXT: 2103a0: adrp x16, 0x230000 +# BTIPACEX-NEXT: 2103a0: bti c +# BTIPACEX-NEXT: adrp x16, 0x230000 # BTIPACEX-NEXT: ldr x17, [x16, #1200] # BTIPACEX-NEXT: add x16, x16, #1200 # BTIPACEX-NEXT: br x17 # BTIPACEX-NEXT: nop -# BTIPACEX-NEXT: nop + # BTIPACDYNEX: 0x0000000070000001 (AARCH64_BTI_PLT) # BTIPACDYNEX-NOT: 0x0000000070000003 (AARCH64_PAC_PLT) @@ -163,12 +165,12 @@ # BTIPACEX2-NEXT: nop # BTIPACEX2-NEXT: nop # BTIPACEX2: 00000000002103a0 : -# BTIPACEX2-NEXT: 2103a0: adrp x16, 0x230000 +# BTIPACEX2-NEXT: 2103a0: bti c +# BTIPACEX2-NEXT: adrp x16, 0x230000 # BTIPACEX2-NEXT: ldr x17, [x16, #1216] # BTIPACEX2-NEXT: add x16, x16, #1216 # BTIPACEX2-NEXT: autia1716 # BTIPACEX2-NEXT: br x17 -# BTIPACEX2-NEXT: nop # BTIPACDYN2: 0x0000000070000001 (AARCH64_BTI_PLT) # BTIPACDYN2-NEXT: 0x0000000070000003 (AARCH64_PAC_PLT) Index: lld/test/ELF/aarch64-ifunc-bti.s =================================================================== --- lld/test/ELF/aarch64-ifunc-bti.s +++ lld/test/ELF/aarch64-ifunc-bti.s @@ -24,12 +24,12 @@ # CHECK-NEXT: nop # CHECK-NEXT: nop # CHECK: 00000000000103c0 : -# CHECK-NEXT: 103c0: adrp x16, 0x30000 +# CHECK-NEXT: 103c0: bti c +# CHECK-NEXT: adrp x16, 0x30000 # CHECK-NEXT: ldr x17, [x16, #1352] # CHECK-NEXT: add x16, x16, #1352 # CHECK-NEXT: br x17 # CHECK-NEXT: nop -# CHECK-NEXT: nop # CHECK-EMPTY: # CHECK: Disassembly of section .iplt: # CHECK-EMPTY: