1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
# REQUIRES: aarch64
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %s -o %t.o
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu --defsym CANONICAL_PLT=1 %s -o %tcanon.o
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu --defsym RELVTABLE_PLT=1 %s -o %trelvtable.o
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-bti1.s -o %t1.o
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func3.s -o %t2.o
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func3-bti.s -o %t3.o
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func2.s -o %tno.o
## We do not add BTI support when the inputs don't have the .note.gnu.property
## field.
# RUN: ld.lld %tno.o %t3.o --shared -o %tno.so
# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %tno.so | FileCheck --check-prefix=NOBTI %s
# RUN: llvm-readelf -x .got.plt %tno.so | FileCheck --check-prefix SOGOTPLT %s
# RUN: llvm-readelf --dynamic-table %tno.so | FileCheck --check-prefix NOBTIDYN %s
# NOBTIDYN-NOT: 0x0000000070000001 (AARCH64_BTI_PLT)
# NOBTIDYN-NOT: 0x0000000070000003 (AARCH64_PAC_PLT)
# NOBTI: 00000000000102b8 <func2>:
# NOBTI-NEXT: 102b8: bl 0x102f0 <func3@plt>
# NOBTI-NEXT: 102bc: ret
# NOBTI: Disassembly of section .plt:
# NOBTI: 00000000000102d0 <.plt>:
# NOBTI-NEXT: 102d0: stp x16, x30, [sp, #-16]!
# NOBTI-NEXT: 102d4: adrp x16, 0x30000
# NOBTI-NEXT: 102d8: ldr x17, [x16, #960]
# NOBTI-NEXT: 102dc: add x16, x16, #960
# NOBTI-NEXT: 102e0: br x17
# NOBTI-NEXT: 102e4: nop
# NOBTI-NEXT: 102e8: nop
# NOBTI-NEXT: 102ec: nop
# NOBTI: 00000000000102f0 <func3@plt>:
# NOBTI-NEXT: 102f0: adrp x16, 0x30000
# NOBTI-NEXT: 102f4: ldr x17, [x16, #968]
# NOBTI-NEXT: 102f8: add x16, x16, #968
# NOBTI-NEXT: 102fc: br x17
## The .got.plt should be identical between the BTI and no BTI DSO PLT.
# SOGOTPLT: Hex dump of section '.got.plt'
# 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.
# 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
# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %t.so | FileCheck --check-prefix BTISO %s
# RUN: llvm-readelf -x .got.plt %t.so | FileCheck --check-prefix SOGOTPLT2 %s
# RUN: llvm-readelf --dynamic-table %t.so | FileCheck --check-prefix BTIDYN %s
# BTIPROP: Properties: aarch64 feature: BTI
# BTIDYN: 0x0000000070000001 (AARCH64_BTI_PLT)
# BTIDYN-NOT: 0x0000000070000003 (AARCH64_PAC_PLT)
# BTISO: 0000000000010348 <func2>:
# BTISO-NEXT: 10348: bl 0x10380 <func3@plt>
# BTISO-NEXT: ret
# BTISO: 0000000000010350 <func3>:
# BTISO-NEXT: 10350: ret
# BTISO: Disassembly of section .plt:
# BTISO: 0000000000010360 <.plt>:
# BTISO-NEXT: 10360: bti c
# BTISO-NEXT: stp x16, x30, [sp, #-16]!
# BTISO-NEXT: adrp x16, 0x30000
# BTISO-NEXT: ldr x17, [x16, #1144]
# BTISO-NEXT: add x16, x16, #1144
# BTISO-NEXT: br x17
# BTISO-NEXT: nop
# BTISO-NEXT: nop
# BTISO: 0000000000010380 <func3@plt>:
# BTISO-NEXT: 10380: adrp x16, 0x30000
# BTISO-NEXT: ldr x17, [x16, #1152]
# BTISO-NEXT: add x16, x16, #1152
# BTISO-NEXT: br x17
# SOGOTPLT2: Hex dump of section '.got.plt'
# SOGOTPLT2-NEXT: 0x00030468 00000000 00000000 00000000 00000000
# SOGOTPLT2-NEXT: 0x00030478 00000000 00000000 60030100 00000000
## Build an executable with all relocatable inputs having the BTI
## .note.gnu.property.
# RUN: ld.lld %t2.o --shared --soname=t2.so -o %t2.so
# RUN: ld.lld %t.o %t.so %t2.so -o %t.exe
# RUN: llvm-readelf --dynamic-table -n %t.exe | FileCheck --check-prefix=BTIPROP %s
# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %t.exe | FileCheck --check-prefix=EXECBTI %s
# EXECBTI: Disassembly of section .text:
# EXECBTI: 0000000000210348 <func1>:
# EXECBTI-NEXT: 210348: bl 0x210370 <func2@plt>
# EXECBTI-NEXT: ret
# EXECBTI: Disassembly of section .plt:
# EXECBTI: 0000000000210350 <.plt>:
# EXECBTI-NEXT: 210350: bti c
# EXECBTI-NEXT: stp x16, x30, [sp, #-16]!
# EXECBTI-NEXT: adrp x16, 0x230000
# EXECBTI-NEXT: ldr x17, [x16, #1160]
# EXECBTI-NEXT: add x16, x16, #1160
# EXECBTI-NEXT: br x17
# EXECBTI-NEXT: nop
# EXECBTI-NEXT: nop
# EXECBTI: 0000000000210370 <func2@plt>:
# EXECBTI-NEXT: 210370: 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.
# RUN: ld.lld %tcanon.o %t.so %t2.so -o %t2.exe
# RUN: llvm-readelf --dynamic-table -n %t2.exe | FileCheck --check-prefix=BTIPROP %s
# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %t2.exe | FileCheck --check-prefix=EXECBTI2 %s
# EXECBTI2: 0000000000210380 <func2@plt>:
# EXECBTI2-NEXT: 210380: bti c
# EXECBTI2-NEXT: adrp x16, 0x230000
# EXECBTI2-NEXT: ldr x17, [x16, #1184]
# EXECBTI2-NEXT: add x16, x16, #1184
# EXECBTI2-NEXT: br x17
# EXECBTI2-NEXT: nop
## We expect the same for PIE, as the address of an ifunc can escape
# RUN: ld.lld --pie %t.o %t.so %t2.so -o %tpie.exe
# RUN: llvm-readelf -n %tpie.exe | FileCheck --check-prefix=BTIPROP %s
# RUN: llvm-readelf --dynamic-table -n %tpie.exe | FileCheck --check-prefix=BTIPROP %s
# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %tpie.exe | FileCheck --check-prefix=PIE %s
# PIE: Disassembly of section .text:
# PIE: 0000000000010348 <func1>:
# PIE-NEXT: 10348: bl 0x10370 <func2@plt>
# PIE-NEXT: ret
# PIE: Disassembly of section .plt:
# PIE: 0000000000010350 <.plt>:
# PIE-NEXT: 10350: bti c
# PIE-NEXT: stp x16, x30, [sp, #-16]!
# PIE-NEXT: adrp x16, 0x30000
# PIE-NEXT: ldr x17, [x16, #1176]
# PIE-NEXT: add x16, x16, #1176
# PIE-NEXT: br x17
# PIE-NEXT: nop
# PIE-NEXT: nop
# PIE: 0000000000010370 <func2@plt>:
# PIE-NEXT: 10370: 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
## We expect the same for R_AARCH64_PLT32, as the address of an plt entry escapes
# RUN: ld.lld --shared %trelvtable.o -o %trelv.exe
# RUN: llvm-readelf -n %trelv.exe | FileCheck --check-prefix=BTIPROP %s
# RUN: llvm-readelf --dynamic-table -n %trelv.exe | FileCheck --check-prefix=BTIPROP %s
# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %trelv.exe | FileCheck --check-prefix=RELV %s
# RELV: Disassembly of section .text:
# RELV-LABEL: <func1>:
# RELV-NEXT: 10380: bl 0x103b0 <func2@plt>
# RELV-NEXT: bl 0x103c8 <funcRelVtable@plt>
# RELV-NEXT: ret
# RELV: Disassembly of section .plt:
# RELV-LABEL: <.plt>:
# RELV-NEXT: 10390: bti c
# RELV-NEXT: stp x16, x30, [sp, #-16]!
# RELV-NEXT: adrp x16, 0x30000
# RELV-NEXT: ldr x17, [x16, #1200]
# RELV-NEXT: add x16, x16, #1200
# RELV-NEXT: br x17
# RELV-NEXT: nop
# RELV-NEXT: nop
# RELV-LABEL: <func2@plt>:
# RELV-NEXT: 103b0: adrp x16, 0x30000
# RELV-NEXT: ldr x17, [x16, #1208]
# RELV-NEXT: add x16, x16, #1208
# RELV-NEXT: br x17
# RELV-NEXT: nop
# RELV-NEXT: nop
# RELV-LABEL: <funcRelVtable@plt>:
# RELV-NEXT: 103c8: bti c
# RELV-NEXT: adrp x16, 0x30000 <_DYNAMIC+0xfc20>
# RELV-NEXT: ldr x17, [x16, #1216]
# RELV-NEXT: add x16, x16, #1216
# RELV-NEXT: br x17
# RELV-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
# RUN: ld.lld %t.o %t2.o %t.so -o %tnobti.exe
# RUN: llvm-readelf --dynamic-table %tnobti.exe | FileCheck --check-prefix NOBTIDYN %s
# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %tnobti.exe | FileCheck --check-prefix=NOEX %s
# NOEX: Disassembly of section .text:
# NOEX: 00000000002102e0 <func1>:
# NOEX-NEXT: 2102e0: bl 0x210310 <func2@plt>
# NOEX-NEXT: ret
# NOEX: 00000000002102e8 <func3>:
# NOEX-NEXT: 2102e8: ret
# NOEX: Disassembly of section .plt:
# NOEX: 00000000002102f0 <.plt>:
# NOEX-NEXT: 2102f0: stp x16, x30, [sp, #-16]!
# NOEX-NEXT: adrp x16, 0x230000
# NOEX-NEXT: ldr x17, [x16, #1024]
# NOEX-NEXT: add x16, x16, #1024
# NOEX-NEXT: br x17
# NOEX-NEXT: nop
# NOEX-NEXT: nop
# NOEX-NEXT: nop
# NOEX: 0000000000210310 <func2@plt>:
# NOEX-NEXT: 210310: adrp x16, 0x230000
# NOEX-NEXT: ldr x17, [x16, #1032]
# NOEX-NEXT: add x16, x16, #1032
# NOEX-NEXT: br x17
## Force BTI entries with the -z force-bti command line option. Expect a warning
## from the file without the .note.gnu.property.
# RUN: ld.lld %t.o %t2.o -z force-bti %t.so -o %tforcebti.exe 2>&1 | FileCheck --check-prefix=FORCE-WARN %s
# 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 %s
# FORCE-WARN: aarch64-feature-bti.s.tmp2.o: -z force-bti: file does not have GNU_PROPERTY_AARCH64_FEATURE_1_BTI property
# BTI_REPORT-ERROR: aarch64-feature-bti.s.tmp2.o: -z bti-report: file does not have GNU_PROPERTY_AARCH64_FEATURE_1_BTI property
# BTI_REPORT-ERROR-EMPTY:
# RUN: llvm-readelf -n %tforcebti.exe | FileCheck --check-prefix=BTIPROP %s
# RUN: llvm-readelf --dynamic-table %tforcebti.exe | FileCheck --check-prefix BTIDYN %s
# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %tforcebti.exe | FileCheck --check-prefix=FORCE %s
# FORCE: Disassembly of section .text:
# FORCE: 0000000000210370 <func1>:
# FORCE-NEXT: 210370: bl 0x2103a0 <func2@plt>
# FORCE-NEXT: ret
# FORCE: 0000000000210378 <func3>:
# FORCE-NEXT: 210378: ret
# FORCE: Disassembly of section .plt:
# FORCE: 0000000000210380 <.plt>:
# FORCE-NEXT: 210380: bti c
# FORCE-NEXT: stp x16, x30, [sp, #-16]!
# FORCE-NEXT: adrp x16, 0x230000
# FORCE-NEXT: ldr x17, [x16, #1192]
# FORCE-NEXT: add x16, x16, #1192
# FORCE-NEXT: br x17
# FORCE-NEXT: nop
# FORCE-NEXT: nop
# FORCE: 00000000002103a0 <func2@plt>:
# FORCE-NEXT: 2103a0: 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
.long 0x10
.long 0x5
.asciz "GNU"
.long 0xc0000000 // GNU_PROPERTY_AARCH64_FEATURE_1_AND
.long 4
.long 1 // GNU_PROPERTY_AARCH64_FEATURE_1_BTI
.long 0
.text
.globl _start
.type func1,%function
func1:
.ifdef CANONICAL_PLT
adrp x0, func2
add x0, x0, :lo12:func2
.else
bl func2
.endif
.ifdef RELVTABLE_PLT
bl funcRelVtable
.endif
ret
.ifdef RELVTABLE_PLT
// R_AARCH64_PLT32
.word funcRelVtable@PLT - .
.endif
|