295 lines · plain
1# REQUIRES: aarch642# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %s -o %t.o3# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu --defsym CANONICAL_PLT=1 %s -o %tcanon.o4# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu --defsym RELVTABLE_PLT=1 %s -o %trelvtable.o5# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-bti1.s -o %t1.o6# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func3.s -o %t2.o7# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func3-bti.s -o %t3.o8# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func2.s -o %tno.o9 10## We do not add BTI support when the inputs don't have the .note.gnu.property11## field.12 13# RUN: ld.lld %tno.o %t3.o --shared -o %tno.so14# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %tno.so | FileCheck --check-prefix=NOBTI %s15# RUN: llvm-readelf -x .got.plt %tno.so | FileCheck --check-prefix SOGOTPLT %s16# RUN: llvm-readelf --dynamic-table %tno.so | FileCheck --check-prefix NOBTIDYN %s17 18# NOBTIDYN-NOT: 0x0000000070000001 (AARCH64_BTI_PLT)19# NOBTIDYN-NOT: 0x0000000070000003 (AARCH64_PAC_PLT)20 21# NOBTI: 00000000000102b8 <func2>:22# NOBTI-NEXT: 102b8: bl 0x102f0 <func3@plt>23# NOBTI-NEXT: 102bc: ret24# NOBTI: Disassembly of section .plt:25# NOBTI: 00000000000102d0 <.plt>:26# NOBTI-NEXT: 102d0: stp x16, x30, [sp, #-16]!27# NOBTI-NEXT: 102d4: adrp x16, 0x3000028# NOBTI-NEXT: 102d8: ldr x17, [x16, #960]29# NOBTI-NEXT: 102dc: add x16, x16, #96030# NOBTI-NEXT: 102e0: br x1731# NOBTI-NEXT: 102e4: nop32# NOBTI-NEXT: 102e8: nop33# NOBTI-NEXT: 102ec: nop34# NOBTI: 00000000000102f0 <func3@plt>:35# NOBTI-NEXT: 102f0: adrp x16, 0x3000036# NOBTI-NEXT: 102f4: ldr x17, [x16, #968]37# NOBTI-NEXT: 102f8: add x16, x16, #96838# NOBTI-NEXT: 102fc: br x1739 40## The .got.plt should be identical between the BTI and no BTI DSO PLT.41# SOGOTPLT: Hex dump of section '.got.plt'42# SOGOTPLT-NEXT: 0x000303b0 00000000 00000000 00000000 0000000043# SOGOTPLT-NEXT: 0x000303c0 00000000 00000000 d0020100 0000000044 45## Expect a bti c at the start of plt[0], the plt entries do not need bti c as46## their address doesn't escape the shared object, so they can't be indirectly47## called. Expect no other difference.48 49# RUN: ld.lld %t1.o %t3.o --shared --soname=t.so -o %t.so50# RUN: llvm-readelf -n %t.so | FileCheck --check-prefix BTIPROP %s51# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %t.so | FileCheck --check-prefix BTISO %s52# RUN: llvm-readelf -x .got.plt %t.so | FileCheck --check-prefix SOGOTPLT2 %s53# RUN: llvm-readelf --dynamic-table %t.so | FileCheck --check-prefix BTIDYN %s54 55# BTIPROP: Properties: aarch64 feature: BTI56 57# BTIDYN: 0x0000000070000001 (AARCH64_BTI_PLT)58# BTIDYN-NOT: 0x0000000070000003 (AARCH64_PAC_PLT)59 60# BTISO: 0000000000010348 <func2>:61# BTISO-NEXT: 10348: bl 0x10380 <func3@plt>62# BTISO-NEXT: ret63# BTISO: 0000000000010350 <func3>:64# BTISO-NEXT: 10350: ret65# BTISO: Disassembly of section .plt:66# BTISO: 0000000000010360 <.plt>:67# BTISO-NEXT: 10360: bti c68# BTISO-NEXT: stp x16, x30, [sp, #-16]!69# BTISO-NEXT: adrp x16, 0x3000070# BTISO-NEXT: ldr x17, [x16, #1144]71# BTISO-NEXT: add x16, x16, #114472# BTISO-NEXT: br x1773# BTISO-NEXT: nop74# BTISO-NEXT: nop75# BTISO: 0000000000010380 <func3@plt>:76# BTISO-NEXT: 10380: adrp x16, 0x3000077# BTISO-NEXT: ldr x17, [x16, #1152]78# BTISO-NEXT: add x16, x16, #115279# BTISO-NEXT: br x1780 81# SOGOTPLT2: Hex dump of section '.got.plt'82# SOGOTPLT2-NEXT: 0x00030468 00000000 00000000 00000000 0000000083# SOGOTPLT2-NEXT: 0x00030478 00000000 00000000 60030100 0000000084 85## Build an executable with all relocatable inputs having the BTI86## .note.gnu.property.87 88# RUN: ld.lld %t2.o --shared --soname=t2.so -o %t2.so89 90# RUN: ld.lld %t.o %t.so %t2.so -o %t.exe91# RUN: llvm-readelf --dynamic-table -n %t.exe | FileCheck --check-prefix=BTIPROP %s92# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %t.exe | FileCheck --check-prefix=EXECBTI %s93 94# EXECBTI: Disassembly of section .text:95# EXECBTI: 0000000000210348 <func1>:96# EXECBTI-NEXT: 210348: bl 0x210370 <func2@plt>97# EXECBTI-NEXT: ret98# EXECBTI: Disassembly of section .plt:99# EXECBTI: 0000000000210350 <.plt>:100# EXECBTI-NEXT: 210350: bti c101# EXECBTI-NEXT: stp x16, x30, [sp, #-16]!102# EXECBTI-NEXT: adrp x16, 0x230000103# EXECBTI-NEXT: ldr x17, [x16, #1160]104# EXECBTI-NEXT: add x16, x16, #1160105# EXECBTI-NEXT: br x17106# EXECBTI-NEXT: nop107# EXECBTI-NEXT: nop108# EXECBTI: 0000000000210370 <func2@plt>:109# EXECBTI-NEXT: 210370: adrp x16, 0x230000110# EXECBTI-NEXT: ldr x17, [x16, #1168]111# EXECBTI-NEXT: add x16, x16, #1168112# EXECBTI-NEXT: br x17113# EXECBTI-NEXT: nop114# EXECBTI-NEXT: nop115 116## We expect a bti c in front of a canonical PLT entry because its address117## can escape the executable.118# RUN: ld.lld %tcanon.o %t.so %t2.so -o %t2.exe119# RUN: llvm-readelf --dynamic-table -n %t2.exe | FileCheck --check-prefix=BTIPROP %s120# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %t2.exe | FileCheck --check-prefix=EXECBTI2 %s121# EXECBTI2: 0000000000210380 <func2@plt>:122# EXECBTI2-NEXT: 210380: bti c123# EXECBTI2-NEXT: adrp x16, 0x230000124# EXECBTI2-NEXT: ldr x17, [x16, #1184]125# EXECBTI2-NEXT: add x16, x16, #1184126# EXECBTI2-NEXT: br x17127# EXECBTI2-NEXT: nop128 129 130## We expect the same for PIE, as the address of an ifunc can escape131# RUN: ld.lld --pie %t.o %t.so %t2.so -o %tpie.exe132# RUN: llvm-readelf -n %tpie.exe | FileCheck --check-prefix=BTIPROP %s133# RUN: llvm-readelf --dynamic-table -n %tpie.exe | FileCheck --check-prefix=BTIPROP %s134# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %tpie.exe | FileCheck --check-prefix=PIE %s135 136# PIE: Disassembly of section .text:137# PIE: 0000000000010348 <func1>:138# PIE-NEXT: 10348: bl 0x10370 <func2@plt>139# PIE-NEXT: ret140# PIE: Disassembly of section .plt:141# PIE: 0000000000010350 <.plt>:142# PIE-NEXT: 10350: bti c143# PIE-NEXT: stp x16, x30, [sp, #-16]!144# PIE-NEXT: adrp x16, 0x30000145# PIE-NEXT: ldr x17, [x16, #1176]146# PIE-NEXT: add x16, x16, #1176147# PIE-NEXT: br x17148# PIE-NEXT: nop149# PIE-NEXT: nop150# PIE: 0000000000010370 <func2@plt>:151# PIE-NEXT: 10370: adrp x16, 0x30000152# PIE-NEXT: ldr x17, [x16, #1184]153# PIE-NEXT: add x16, x16, #1184154# PIE-NEXT: br x17155# PIE-NEXT: nop156# PIE-NEXT: nop157 158## We expect the same for R_AARCH64_PLT32, as the address of an plt entry escapes159# RUN: ld.lld --shared %trelvtable.o -o %trelv.exe160# RUN: llvm-readelf -n %trelv.exe | FileCheck --check-prefix=BTIPROP %s161# RUN: llvm-readelf --dynamic-table -n %trelv.exe | FileCheck --check-prefix=BTIPROP %s162# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %trelv.exe | FileCheck --check-prefix=RELV %s163 164# RELV: Disassembly of section .text:165# RELV-LABEL: <func1>:166# RELV-NEXT: 10380: bl 0x103b0 <func2@plt>167# RELV-NEXT: bl 0x103c8 <funcRelVtable@plt>168# RELV-NEXT: ret169# RELV: Disassembly of section .plt:170# RELV-LABEL: <.plt>:171# RELV-NEXT: 10390: bti c172# RELV-NEXT: stp x16, x30, [sp, #-16]!173# RELV-NEXT: adrp x16, 0x30000174# RELV-NEXT: ldr x17, [x16, #1200]175# RELV-NEXT: add x16, x16, #1200176# RELV-NEXT: br x17177# RELV-NEXT: nop178# RELV-NEXT: nop179# RELV-LABEL: <func2@plt>:180# RELV-NEXT: 103b0: adrp x16, 0x30000181# RELV-NEXT: ldr x17, [x16, #1208]182# RELV-NEXT: add x16, x16, #1208183# RELV-NEXT: br x17184# RELV-NEXT: nop185# RELV-NEXT: nop186# RELV-LABEL: <funcRelVtable@plt>:187# RELV-NEXT: 103c8: bti c188# RELV-NEXT: adrp x16, 0x30000189# RELV-NEXT: ldr x17, [x16, #1216]190# RELV-NEXT: add x16, x16, #1216191# RELV-NEXT: br x17192# RELV-NEXT: nop193 194## Build and executable with not all relocatable inputs having the BTI195## .note.property, expect no bti c and no .note.gnu.property entry196 197# RUN: ld.lld %t.o %t2.o %t.so -o %tnobti.exe198# RUN: llvm-readelf --dynamic-table %tnobti.exe | FileCheck --check-prefix NOBTIDYN %s199# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %tnobti.exe | FileCheck --check-prefix=NOEX %s200 201# NOEX: Disassembly of section .text:202# NOEX: 00000000002102e0 <func1>:203# NOEX-NEXT: 2102e0: bl 0x210310 <func2@plt>204# NOEX-NEXT: ret205# NOEX: 00000000002102e8 <func3>:206# NOEX-NEXT: 2102e8: ret207# NOEX: Disassembly of section .plt:208# NOEX: 00000000002102f0 <.plt>:209# NOEX-NEXT: 2102f0: stp x16, x30, [sp, #-16]!210# NOEX-NEXT: adrp x16, 0x230000211# NOEX-NEXT: ldr x17, [x16, #1024]212# NOEX-NEXT: add x16, x16, #1024213# NOEX-NEXT: br x17214# NOEX-NEXT: nop215# NOEX-NEXT: nop216# NOEX-NEXT: nop217# NOEX: 0000000000210310 <func2@plt>:218# NOEX-NEXT: 210310: adrp x16, 0x230000219# NOEX-NEXT: ldr x17, [x16, #1032]220# NOEX-NEXT: add x16, x16, #1032221# NOEX-NEXT: br x17222 223## Force BTI entries with the -z force-bti command line option. Expect a warning224## from the file without the .note.gnu.property.225 226# RUN: ld.lld %t.o %t2.o -z force-bti %t.so -o %tforcebti.exe 2>&1 | FileCheck --check-prefix=FORCE-WARN %s227# RUN: not ld.lld %t.o %t2.o -z force-bti -z bti-report=error %t.so -o %tfailifnotbti.exe 2>&1 | FileCheck --check-prefix=BTI_REPORT-ERROR %s228 229# FORCE-WARN: aarch64-feature-bti.s.tmp2.o: -z force-bti: file does not have GNU_PROPERTY_AARCH64_FEATURE_1_BTI property230# BTI_REPORT-ERROR: aarch64-feature-bti.s.tmp2.o: -z bti-report: file does not have GNU_PROPERTY_AARCH64_FEATURE_1_BTI property231# BTI_REPORT-ERROR-EMPTY:232 233# RUN: llvm-readelf -n %tforcebti.exe | FileCheck --check-prefix=BTIPROP %s234# RUN: llvm-readelf --dynamic-table %tforcebti.exe | FileCheck --check-prefix BTIDYN %s235# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %tforcebti.exe | FileCheck --check-prefix=FORCE %s236 237# FORCE: Disassembly of section .text:238# FORCE: 0000000000210370 <func1>:239# FORCE-NEXT: 210370: bl 0x2103a0 <func2@plt>240# FORCE-NEXT: ret241# FORCE: 0000000000210378 <func3>:242# FORCE-NEXT: 210378: ret243# FORCE: Disassembly of section .plt:244# FORCE: 0000000000210380 <.plt>:245# FORCE-NEXT: 210380: bti c246# FORCE-NEXT: stp x16, x30, [sp, #-16]!247# FORCE-NEXT: adrp x16, 0x230000248# FORCE-NEXT: ldr x17, [x16, #1192]249# FORCE-NEXT: add x16, x16, #1192250# FORCE-NEXT: br x17251# FORCE-NEXT: nop252# FORCE-NEXT: nop253# FORCE: 00000000002103a0 <func2@plt>:254# FORCE-NEXT: 2103a0: adrp x16, 0x230000255# FORCE-NEXT: ldr x17, [x16, #1200]256# FORCE-NEXT: add x16, x16, #1200257# FORCE-NEXT: br x17258# FORCE-NEXT: nop259# FORCE-NEXT: nop260 261# RUN: not ld.lld %t.o -z bti-report=u -o /dev/null 2>&1 | FileCheck --check-prefix=REPORT-ERR %s262# REPORT-ERR: error: unknown -z bti-report= value: u{{$}}263# REPORT-EMPTY:264 265.section ".note.gnu.property", "a"266.long 4267.long 0x10268.long 0x5269.asciz "GNU"270 271.long 0xc0000000 // GNU_PROPERTY_AARCH64_FEATURE_1_AND272.long 4273.long 1 // GNU_PROPERTY_AARCH64_FEATURE_1_BTI274.long 0275 276.text277.globl _start278.type func1,%function279func1:280.ifdef CANONICAL_PLT281 adrp x0, func2282 add x0, x0, :lo12:func2283.else284 bl func2285.endif286.ifdef RELVTABLE_PLT287 bl funcRelVtable288.endif289 ret290 291.ifdef RELVTABLE_PLT292// R_AARCH64_PLT32293.word funcRelVtable@PLT - .294.endif295