[memprof] Remove an unused using directive (#117004)
[llvm-project.git] / lld / test / ELF / aarch64-memtag-globals.s
blobb109c1d2c2e9c7485982a2e5a57fd8eaf7282043
1 # REQUIRES: aarch64
3 # RUN: rm -rf %t
5 ## Ensure MTE globals doesn't work with REL (only RELA).
6 # RUN: yaml2obj %s -o %t.rel.o
7 # RUN: not ld.lld -shared --android-memtag-mode=sync %t.rel.o -o %t1.so 2>&1 | FileCheck %s --check-prefix=CHECK-RELA
8 # CHECK-RELA: non-RELA relocations are not allowed with memtag globals
9 --- !ELF
10 FileHeader:
11 Class: ELFCLASS64
12 Data: ELFDATA2LSB
13 Type: ET_REL
14 Machine: EM_AARCH64
15 SectionHeaderStringTable: .strtab
16 Sections:
17 - Name: .text
18 Type: SHT_PROGBITS
19 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
20 AddressAlign: 0x4
21 Content: '00'
22 - Name: .data
23 Type: SHT_PROGBITS
24 Flags: [ SHF_WRITE, SHF_ALLOC ]
25 AddressAlign: 0x10
26 Content: '00'
27 - Name: .memtag.globals.static
28 Type: SHT_AARCH64_MEMTAG_GLOBALS_STATIC
29 AddressAlign: 0x1
30 - Name: .rel.memtag.globals.static
31 Type: SHT_REL
32 Flags: [ SHF_INFO_LINK ]
33 Link: .symtab
34 AddressAlign: 0x8
35 Info: .memtag.globals.static
36 Relocations:
37 - Symbol: four
38 Type: R_AARCH64_NONE
39 - Type: SectionHeaderTable
40 Sections:
41 - Name: .strtab
42 - Name: .text
43 - Name: .data
44 - Name: .memtag.globals.static
45 - Name: .rel.memtag.globals.static
46 - Name: .symtab
47 Symbols:
48 - Name: four
49 Type: STT_OBJECT
50 Section: .data
51 Binding: STB_GLOBAL
52 Value: 0x0
53 Size: 0x10
55 ## Functional testing for MTE globals.
56 # RUN: split-file %S/Inputs/aarch64-memtag-globals.s %t
57 # RUN: llvm-mc --filetype=obj -triple=aarch64-linux-android \
58 # RUN: %t/input_1.s -o %t1.o
59 # RUN: llvm-mc --filetype=obj -triple=aarch64-linux-android \
60 # RUN: %t/input_2.s -o %t2.o
61 # RUN: ld.lld -shared --android-memtag-mode=sync %t1.o %t2.o -o %t.so
63 ## Normally relocations are printed before the symbol tables, so reorder it a
64 ## bit to make it easier on matching addresses of relocations up with the
65 ## symbols.
66 # RUN: llvm-readelf %t.so -s > %t.out
67 # RUN: llvm-readelf %t.so --section-headers --relocs --memtag >> %t.out
68 # RUN: FileCheck %s < %t.out
69 # RUN: llvm-objdump -Dz %t.so | FileCheck %s --check-prefix=CHECK-SPECIAL-RELOCS
71 ## And ensure that --apply-dynamic-relocs is banned.
72 # RUN: not ld.lld --apply-dynamic-relocs -shared --android-memtag-mode=sync \
73 # RUN: %t1.o %t2.o -o %t1.so 2>&1 | FileCheck %s --check-prefix=CHECK-DYNRELOC
74 # CHECK-DYNRELOC: --apply-dynamic-relocs cannot be used with MTE globals
76 ## Ensure that fully statically linked executables just simply drop the MTE
77 ## globals stuff: special relocations, data in the place to be relocated,
78 ## dynamic entries, etc.
79 # RUN: llvm-mc --filetype=obj -triple=aarch64-linux-android \
80 # RUN: %t/input_3.s -o %t3.o
81 # RUN: ld.lld -static --android-memtag-mode=sync %t1.o %t2.o %t3.o -o %t.static.so
82 # RUN: llvm-readelf -s --section-headers --relocs --memtag %t.static.so | \
83 # RUN: FileCheck %s --check-prefix=CHECK-STATIC
84 # CHECK-STATIC-NOT: .memtag.globals.static
85 # CHECK-STATIC-NOT: DT_AARCH64_MEMTAG_
87 # CHECK-STATIC: There are no relocations in this file
88 # CHECK-STATIC: Memtag Dynamic Entries:
89 # CHECK-STATIC-NEXT: < none found >
91 # RUN: llvm-objdump -tDz %t.static.so | FileCheck %s --check-prefix=CHECK-STATIC-SPECIAL-RELOCS
92 # CHECK-STATIC-SPECIAL-RELOCS: [[#%x,HIDDEN_GLOBAL_ADDR:]] {{.*}} .bss {{0*}}10 hidden_global
93 # CHECK-STATIC-SPECIAL-RELOCS: <pointer_to_hidden_global_end>:
94 # CHECK-STATIC-SPECIAL-RELOCS-NEXT: .word 0x{{0*}}[[#HIDDEN_GLOBAL_ADDR + 12]]
95 # CHECK-STATIC-SPECIAL-RELOCS-NEXT: .word 0x00000000
96 # CHECK-STATIC-SPECIAL-RELOCS-NEXT: .word 0x00000000
97 # CHECK-STATIC-SPECIAL-RELOCS-NEXT: .word 0x00000000
98 # CHECK-STATIC-SPECIAL-RELOCS: <pointer_past_hidden_global_end>:
99 # CHECK-STATIC-SPECIAL-RELOCS-NEXT: .word 0x{{0*}}[[#HIDDEN_GLOBAL_ADDR + 16]]
100 # CHECK-STATIC-SPECIAL-RELOCS-NEXT: .word 0x00000000
101 # CHECK-STATIC-SPECIAL-RELOCS-NEXT: .word 0x00000000
102 # CHECK-STATIC-SPECIAL-RELOCS-NEXT: .word 0x00000000
104 # CHECK: Symbol table '.dynsym' contains
105 # CHECK-DAG: [[#%x,GLOBAL:]] 32 OBJECT GLOBAL DEFAULT [[#]] global{{$}}
106 # CHECK-DAG: [[#%x,GLOBAL_UNTAGGED:]] 4 OBJECT GLOBAL DEFAULT [[#]] global_untagged{{$}}
107 # CHECK-DAG: [[#%x,CONST_GLOBAL:]] 4 OBJECT GLOBAL DEFAULT [[#]] const_global{{$}}
108 # CHECK-DAG: [[#%x,GLOBAL_EXTERN:]] 16 OBJECT GLOBAL DEFAULT [[#]] global_extern{{$}}
109 # CHECK-DAG: [[#%x,GLOBAL_EXTERN_UNTAGGED:]] 4 OBJECT GLOBAL DEFAULT [[#]] global_extern_untagged{{$}}
110 # CHECK-DAG: 0 NOTYPE GLOBAL DEFAULT UND global_extern_outside_this_dso{{$}}
111 # CHECK-DAG: [[#%x,GLOBAL_EXTERN_CONST_DEFINITION_BUT_NONCONST_IMPORT:]] 4 OBJECT GLOBAL DEFAULT [[#]] global_extern_untagged_definition_but_tagged_import{{$}}
112 # CHECK-DAG: [[#%x,GLOBAL_EXTERN_UNTAGGED_DEFINITION_BUT_TAGGED_IMPORT:]] 4 OBJECT GLOBAL DEFAULT [[#]] global_extern_const_definition_but_nonconst_import{{$}}
113 # CHECK-DAG: [[#%x,POINTER_TO_GLOBAL:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global{{$}}
114 # CHECK-DAG: [[#%x,POINTER_INSIDE_GLOBAL:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_inside_global{{$}}
115 # CHECK-DAG: [[#%x,POINTER_TO_GLOBAL_END:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global_end{{$}}
116 # CHECK-DAG: [[#%x,POINTER_PAST_GLOBAL_END:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_past_global_end{{$}}
117 # CHECK-DAG: [[#%x,POINTER_TO_GLOBAL_UNTAGGED:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global_untagged{{$}}
118 # CHECK-DAG: [[#%x,POINTER_TO_CONST_GLOBAL:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_const_global{{$}}
119 # CHECK-DAG: [[#%x,POINTER_TO_HIDDEN_CONST_GLOBAL:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_hidden_const_global{{$}}
120 # CHECK-DAG: [[#%x,POINTER_TO_HIDDEN_GLOBAL:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_hidden_global{{$}}
121 # CHECK-DAG: [[#%x,POINTER_TO_HIDDEN_GLOBAL_END:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_hidden_global_end{{$}}
122 # CHECK-DAG: [[#%x,POINTER_PAST_HIDDEN_GLOBAL_END:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_past_hidden_global_end{{$}}
123 # CHECK-DAG: [[#%x,POINTER_TO_HIDDEN_ATTR_GLOBAL:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_hidden_attr_global{{$}}
124 # CHECK-DAG: [[#%x,POINTER_TO_HIDDEN_ATTR_CONST_GLOBAL:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_hidden_attr_const_global{{$}}
125 # CHECK-DAG: [[#%x,POINTER_TO_GLOBAL_EXTERN:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global_extern{{$}}
126 # CHECK-DAG: [[#%x,POINTER_TO_GLOBAL_EXTERN_UNTAGGED:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global_extern_untagged{{$}}
127 # CHECK-DAG: [[#%x,POINTER_TO_GLOBAL_EXTERN_OUTSIDE_THIS_DSO:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global_extern_outside_this_dso{{$}}
128 # CHECK-DAG: [[#%x,POINTER_TO_GLOBAL_EXTERN_CONST_DEFINITION_BUT_NONCONST_IMPORT:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global_extern_const_definition_but_nonconst_import{{$}}
129 # CHECK-DAG: [[#%x,POINTER_TO_GLOBAL_EXTERN_UNTAGGED_DEFINITION_BUT_TAGGED_IMPORT:]] 16 OBJECT GLOBAL DEFAULT [[#]] pointer_to_global_extern_untagged_definition_but_tagged_import{{$}}
131 # CHECK: Symbol table '.symtab' contains
132 # CHECK-DAG: [[#%x,HIDDEN_CONST_GLOBAL:]] 4 OBJECT LOCAL DEFAULT [[#]] hidden_const_global{{$}}
133 # CHECK-DAG: [[#%x,HIDDEN_GLOBAL:]] 16 OBJECT LOCAL DEFAULT [[#]] hidden_global{{$}}
134 # CHECK-DAG: [[#%x,HIDDEN_ATTR_GLOBAL:]] 16 OBJECT LOCAL HIDDEN [[#]] hidden_attr_global{{$}}
135 # CHECK-DAG: [[#%x,HIDDEN_ATTR_CONST_GLOBAL:]] 4 OBJECT LOCAL HIDDEN [[#]] hidden_attr_const_global{{$}}
137 # CHECK: Section Headers:
138 # CHECK: .memtag.globals.dynamic AARCH64_MEMTAG_GLOBALS_DYNAMIC
139 # CHECK-NOT: .memtag.globals.static
140 # CHECK-NOT: AARCH64_MEMTAG_GLOBALS_STATIC
142 # CHECK: Relocation section '.rela.dyn'
143 # CHECK-DAG: [[#POINTER_TO_GLOBAL]] {{.*}} R_AARCH64_ABS64 {{.*}} global + 0
144 # CHECK-DAG: [[#POINTER_INSIDE_GLOBAL]] {{.*}} R_AARCH64_ABS64 {{.*}} global + 11
145 # CHECK-DAG: [[#POINTER_TO_GLOBAL_END]] {{.*}} R_AARCH64_ABS64 {{.*}} global + 1e
146 # CHECK-DAG: [[#POINTER_PAST_GLOBAL_END]] {{.*}} R_AARCH64_ABS64 {{.*}} global + 30
147 # CHECK-DAG: [[#POINTER_TO_GLOBAL_UNTAGGED]] {{.*}} R_AARCH64_ABS64 {{.*}} global_untagged + 0
148 # CHECK-DAG: [[#POINTER_TO_CONST_GLOBAL]] {{.*}} R_AARCH64_ABS64 {{.*}} const_global + 0
150 ## RELATIVE relocations.
151 # CHECK-DAG: [[#POINTER_TO_HIDDEN_CONST_GLOBAL]] {{.*}} R_AARCH64_RELATIVE {{0*}}[[#HIDDEN_CONST_GLOBAL]]
152 # CHECK-DAG: [[#POINTER_TO_HIDDEN_GLOBAL]] {{.*}} R_AARCH64_RELATIVE {{0*}}[[#HIDDEN_GLOBAL]]
154 ## AArch64 MemtagABI special RELATIVE relocation semantics, where the offset is encoded in the place.
155 # CHECK-DAG: [[#POINTER_TO_HIDDEN_GLOBAL_END]] {{.*}} R_AARCH64_RELATIVE {{0*}}[[#HIDDEN_GLOBAL + 12]]
156 # CHECK-SPECIAL-RELOCS: <pointer_to_hidden_global_end>:
157 # CHECK-SPECIAL-RELOCS-NEXT: .word 0x00000000
158 # CHECK-SPECIAL-RELOCS-NEXT: .word 0x00000000
159 # CHECK-DAG: [[#POINTER_PAST_HIDDEN_GLOBAL_END]] {{.*}} R_AARCH64_RELATIVE {{0*}}[[#HIDDEN_GLOBAL + 16]]
160 # CHECK-SPECIAL-RELOCS: <pointer_past_hidden_global_end>:
161 # CHECK-SPECIAL-RELOCS-NEXT: .word 0xfffffff0
162 # CHECK-SPECIAL-RELOCS-NEXT: .word 0xffffffff
164 ## More ABS64 relocations.
165 # CHECK-DAG: [[#POINTER_TO_GLOBAL_EXTERN]] {{[0-9a-f]+}} R_AARCH64_ABS64 {{[0-9a-f]+}} global_extern + 0
166 # CHECK-DAG: [[#POINTER_TO_GLOBAL_EXTERN_UNTAGGED]] {{[0-9a-f]+}} R_AARCH64_ABS64 {{[0-9a-f]+}} global_extern_untagged + 0
167 # CHECK-DAG: [[#POINTER_TO_GLOBAL_EXTERN_OUTSIDE_THIS_DSO]] {{[0-9a-f]+}} R_AARCH64_ABS64 {{[0-9a-f]+}} global_extern_outside_this_dso + 0
168 # CHECK-DAG: [[#POINTER_TO_GLOBAL_EXTERN_CONST_DEFINITION_BUT_NONCONST_IMPORT]] {{[0-9a-f]+}} R_AARCH64_ABS64 {{[0-9a-f]+}} global_extern_const_definition_but_nonconst_import + 0
169 # CHECK-DAG: [[#POINTER_TO_GLOBAL_EXTERN_UNTAGGED_DEFINITION_BUT_TAGGED_IMPORT]] {{[0-9a-f]+}} R_AARCH64_ABS64 {{[0-9a-f]+}} global_extern_untagged_definition_but_tagged_import + 0
171 # CHECK: Memtag Dynamic Entries
172 # CHECK-NEXT: AARCH64_MEMTAG_MODE: Synchronous (0)
173 # CHECK-NEXT: AARCH64_MEMTAG_HEAP: Disabled (0)
174 # CHECK-NEXT: AARCH64_MEMTAG_STACK: Disabled (0)
175 # CHECK-NEXT: AARCH64_MEMTAG_GLOBALS: 0x{{[0-9a-f]+}}
176 # CHECK-NEXT: AARCH64_MEMTAG_GLOBALSSZ: 23
178 # CHECK: Memtag Android Note
179 # CHECK-NEXT: Tagging Mode: SYNC
180 # CHECK-NEXT: Heap: Disabled
181 # CHECK-NEXT: Stack: Disabled
183 ## Global variable order hopefully isn't too brittle of a test here, but this allows us to make sure
184 ## that we have all the global variables we expect, and no more.
185 # CHECK: Memtag Global Descriptors:
186 # CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL]]: 0x10
187 # CHECK-NEXT: 0x[[#POINTER_INSIDE_GLOBAL]]: 0x10
188 # CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL_END]]: 0x10
189 # CHECK-NEXT: 0x[[#POINTER_PAST_GLOBAL_END]]: 0x10
190 # CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL_UNTAGGED]]: 0x10
191 # CHECK-NEXT: 0x[[#POINTER_TO_CONST_GLOBAL]]: 0x10
192 # CHECK-NEXT: 0x[[#POINTER_TO_HIDDEN_CONST_GLOBAL]]: 0x10
193 # CHECK-NEXT: 0x[[#POINTER_TO_HIDDEN_GLOBAL]]: 0x10
194 # CHECK-NEXT: 0x[[#POINTER_TO_HIDDEN_ATTR_GLOBAL]]: 0x10
195 # CHECK-NEXT: 0x[[#POINTER_TO_HIDDEN_ATTR_CONST_GLOBAL]]: 0x10
196 # CHECK-NEXT: 0x[[#POINTER_TO_HIDDEN_GLOBAL_END]]: 0x10
197 # CHECK-NEXT: 0x[[#POINTER_PAST_HIDDEN_GLOBAL_END]]: 0x10
198 # CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL_EXTERN]]: 0x10
199 # CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL_EXTERN_UNTAGGED]]: 0x10
200 # CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL_EXTERN_OUTSIDE_THIS_DSO]]: 0x10
201 # CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL_EXTERN_CONST_DEFINITION_BUT_NONCONST_IMPORT]]: 0x10
202 # CHECK-NEXT: 0x[[#POINTER_TO_GLOBAL_EXTERN_UNTAGGED_DEFINITION_BUT_TAGGED_IMPORT]]: 0x10
203 # CHECK-NEXT: 0x[[#GLOBAL]]: 0x20
204 # CHECK-NEXT: 0x[[#HIDDEN_ATTR_GLOBAL]]: 0x10
205 # CHECK-NEXT: 0x[[#HIDDEN_GLOBAL]]: 0x10
206 # CHECK-NEXT: 0x[[#GLOBAL_EXTERN]]: 0x10
207 # CHECK-NOT: 0x