[clang-tidy][modernize-use-starts-ends-with] Fix operator rewriting false negative...
[llvm-project.git] / lld / test / ELF / aarch64-feature-btipac.s
blob3b3c174437036238023001078f7ac795b5cd0a62
1 # REQUIRES: aarch64
2 # RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %s -o %t.o
3 # RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-btipac1.s -o %t1.o
4 # RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func3.s -o %t3.o
5 # RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func3-btipac.s -o %t3btipac.o
7 ## Build shared library with all inputs having BTI and PAC, expect PLT
8 ## entries supporting both PAC and BTI. For a shared library this means:
9 ## PLT[0] has bti c at start
10 ## PLT[n] has autia1716 before br x17
12 # RUN: ld.lld %t1.o %t3btipac.o --shared --soname=t.so -o %t.so
13 # RUN: llvm-readelf -n %t.so | FileCheck --check-prefix BTIPACPROP %s
14 # RUN: llvm-objdump --no-print-imm-hex -d --mattr=+v8.5a --no-show-raw-insn %t.so | FileCheck --check-prefix BTIPACSO %s
15 # RUN: llvm-readelf --dynamic-table %t.so | FileCheck --check-prefix BTIPACDYN %s
17 # BTIPACSO: Disassembly of section .text:
18 # BTIPACSO: 0000000000010348 <func2>:
19 # BTIPACSO-NEXT: 10348: bl 0x10380 <func3@plt>
20 # BTIPACSO-NEXT: ret
21 # BTIPACSO: 0000000000010350 <func3>:
22 # BTIPACSO-NEXT: 10350: ret
23 # BTIPACSO: Disassembly of section .plt:
24 # BTIPACSO: 0000000000010360 <.plt>:
25 # BTIPACSO-NEXT: 10360: bti c
26 # BTIPACSO-NEXT: stp x16, x30, [sp, #-16]!
27 # BTIPACSO-NEXT: adrp x16, 0x30000
28 # BTIPACSO-NEXT: ldr x17, [x16, #1144]
29 # BTIPACSO-NEXT: add x16, x16, #1144
30 # BTIPACSO-NEXT: br x17
31 # BTIPACSO-NEXT: nop
32 # BTIPACSO-NEXT: nop
33 # BTIPACSO: 0000000000010380 <func3@plt>:
34 # BTIPACSO-NEXT: 10380: adrp x16, 0x30000
35 # BTIPACSO-NEXT: ldr x17, [x16, #1152]
36 # BTIPACSO-NEXT: add x16, x16, #1152
37 # BTIPACSO-NEXT: br x17
39 # BTIPACPROP: Properties: aarch64 feature: BTI, PAC
41 # BTIPACDYN: 0x0000000070000001 (AARCH64_BTI_PLT)
42 # BTIPACDYN-NOT: 0x0000000070000003 (AARCH64_PAC_PLT)
44 ## Make an executable with both BTI and PAC properties. Expect:
45 ## PLT[0] bti c as first instruction
46 ## PLT[n] bti n as first instruction
48 # RUN: ld.lld %t.o %t3btipac.o %t.so -o %t.exe
49 # RUN: llvm-readelf -n %t.exe | FileCheck --check-prefix=BTIPACPROP %s
50 # RUN: llvm-objdump --no-print-imm-hex -d --mattr=+v8.5a --no-show-raw-insn %t.exe | FileCheck --check-prefix BTIPACEX %s
51 # RUN: llvm-readelf --dynamic-table %t.exe | FileCheck --check-prefix BTIPACDYNEX %s
53 # BTIPACEX: Disassembly of section .text:
54 # BTIPACEX: 0000000000210370 <func1>:
55 # BTIPACEX-NEXT: 210370: bl 0x2103a0 <func2@plt>
56 # BTIPACEX-NEXT: ret
57 # BTIPACEX-NEXT: ret
58 # BTIPACEX: 000000000021037c <func3>:
59 # BTIPACEX-NEXT: 21037c: ret
60 # BTIPACEX: Disassembly of section .plt:
61 # BTIPACEX: 0000000000210380 <.plt>:
62 # BTIPACEX-NEXT: 210380: bti c
63 # BTIPACEX-NEXT: stp x16, x30, [sp, #-16]!
64 # BTIPACEX-NEXT: adrp x16, 0x230000
65 # BTIPACEX-NEXT: ldr x17, [x16, #1192]
66 # BTIPACEX-NEXT: add x16, x16, #1192
67 # BTIPACEX-NEXT: br x17
68 # BTIPACEX-NEXT: nop
69 # BTIPACEX-NEXT: nop
70 # BTIPACEX: 00000000002103a0 <func2@plt>:
71 # BTIPACEX-NEXT: 2103a0: adrp x16, 0x230000
72 # BTIPACEX-NEXT: ldr x17, [x16, #1200]
73 # BTIPACEX-NEXT: add x16, x16, #1200
74 # BTIPACEX-NEXT: br x17
75 # BTIPACEX-NEXT: nop
76 # BTIPACEX-NEXT: nop
78 # BTIPACDYNEX: 0x0000000070000001 (AARCH64_BTI_PLT)
79 # BTIPACDYNEX-NOT: 0x0000000070000003 (AARCH64_PAC_PLT)
81 ## Check that combinations of BTI+PAC with 0 properties results in standard PLT
83 # RUN: ld.lld %t.o %t3.o %t.so -o %t.exe
84 # RUN: llvm-objdump --no-print-imm-hex -d --mattr=+v8.5a --no-show-raw-insn %t.exe | FileCheck --check-prefix EX %s
85 # RUN: llvm-readelf --dynamic-table %t.exe | FileCheck --check-prefix=NODYN %s
87 # EX: Disassembly of section .text:
88 # EX: 00000000002102e0 <func1>:
89 # EX-NEXT: 2102e0: bl 0x210310 <func2@plt>
90 # EX-NEXT: ret
91 # EX-NEXT: ret
92 # EX: 00000000002102ec <func3>:
93 # EX-NEXT: 2102ec: ret
94 # EX: Disassembly of section .plt:
95 # EX: 00000000002102f0 <.plt>:
96 # EX-NEXT: 2102f0: stp x16, x30, [sp, #-16]!
97 # EX-NEXT: adrp x16, 0x230000
98 # EX-NEXT: ldr x17, [x16, #1024]
99 # EX-NEXT: add x16, x16, #1024
100 # EX-NEXT: br x17
101 # EX-NEXT: nop
102 # EX-NEXT: nop
103 # EX-NEXT: nop
104 # EX: 0000000000210310 <func2@plt>:
105 # EX: 210310: adrp x16, 0x230000
106 # EX-NEXT: ldr x17, [x16, #1032]
107 # EX-NEXT: add x16, x16, #1032
108 # EX-NEXT: br x17
110 # NODYN-NOT: 0x0000000070000001 (AARCH64_BTI_PLT)
111 # NODYN-NOT: 0x0000000070000003 (AARCH64_PAC_PLT)
113 ## Check that combination of -z pac-plt and -z force-bti warns for the file that
114 ## doesn't contain the BTI property, but generates PAC and BTI PLT sequences.
115 ## The -z pac-plt doesn't warn as it is not required for correctness.
116 ## Expect:
117 ## PLT[0] bti c as first instruction
118 ## PLT[n] bti n as first instruction, autia1716 before br x17
120 # RUN: ld.lld %t.o %t3.o %t.so -z pac-plt -z force-bti -o %t.exe 2>&1 | FileCheck --check-prefix=FORCE-WARN %s
122 # FORCE-WARN: aarch64-feature-btipac.s.tmp3.o: -z force-bti: file does not have GNU_PROPERTY_AARCH64_FEATURE_1_BTI property
124 # RUN: llvm-readelf -n %t.exe | FileCheck --check-prefix=BTIPACPROP %s
125 # RUN: llvm-objdump --no-print-imm-hex -d --mattr=+v8.5a --no-show-raw-insn %t.exe | FileCheck --check-prefix BTIPACEX2 %s
126 # RUN: llvm-readelf --dynamic-table %t.exe | FileCheck --check-prefix BTIPACDYN2 %s
127 .section ".note.gnu.property", "a"
128 .long 4
129 .long 0x10
130 .long 0x5
131 .asciz "GNU"
133 .long 0xc0000000 // GNU_PROPERTY_AARCH64_FEATURE_1_AND
134 .long 4
135 .long 3 // GNU_PROPERTY_AARCH64_FEATURE_1_BTI and PAC
136 .long 0
138 .text
139 .globl _start
140 .type func1,%function
141 func1:
142 bl func2
144 .globl func3
145 .type func3,%function
148 # BTIPACEX2: Disassembly of section .text:
149 # BTIPACEX2: 0000000000210370 <func1>:
150 # BTIPACEX2-NEXT: 210370: bl 0x2103a0 <func2@plt>
151 # BTIPACEX2-NEXT: ret
152 # BTIPACEX2-NEXT: ret
153 # BTIPACEX2: 000000000021037c <func3>:
154 # BTIPACEX2-NEXT: 21037c: ret
155 # BTIPACEX2: Disassembly of section .plt:
156 # BTIPACEX2: 0000000000210380 <.plt>:
157 # BTIPACEX2-NEXT: 210380: bti c
158 # BTIPACEX2-NEXT: stp x16, x30, [sp, #-16]!
159 # BTIPACEX2-NEXT: adrp x16, 0x230000
160 # BTIPACEX2-NEXT: ldr x17, [x16, #1208]
161 # BTIPACEX2-NEXT: add x16, x16, #1208
162 # BTIPACEX2-NEXT: br x17
163 # BTIPACEX2-NEXT: nop
164 # BTIPACEX2-NEXT: nop
165 # BTIPACEX2: 00000000002103a0 <func2@plt>:
166 # BTIPACEX2-NEXT: 2103a0: adrp x16, 0x230000
167 # BTIPACEX2-NEXT: ldr x17, [x16, #1216]
168 # BTIPACEX2-NEXT: add x16, x16, #1216
169 # BTIPACEX2-NEXT: autia1716
170 # BTIPACEX2-NEXT: br x17
171 # BTIPACEX2-NEXT: nop
173 # BTIPACDYN2: 0x0000000070000001 (AARCH64_BTI_PLT)
174 # BTIPACDYN2-NEXT: 0x0000000070000003 (AARCH64_PAC_PLT)