Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / lib / asan_abi / asan_abi_shim.cpp
blobbf3cba3178efbdfb7fa2b18079af2be42590eef9
1 //===-asan_abi_shim.cpp - ASan Stable ABI Shim-----------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "../asan/asan_interface_internal.h"
10 #include "asan_abi.h"
11 #include <assert.h>
13 extern "C" {
14 // Functions concerning instrumented global variables
15 void __asan_register_image_globals(uptr *flag) {
16 __asan_abi_register_image_globals();
18 void __asan_unregister_image_globals(uptr *flag) {
19 __asan_abi_unregister_image_globals();
21 void __asan_register_elf_globals(uptr *flag, void *start, void *stop) {
22 bool bFlag = *flag;
23 __asan_abi_register_elf_globals(&bFlag, start, stop);
24 *flag = bFlag;
26 void __asan_unregister_elf_globals(uptr *flag, void *start, void *stop) {
27 bool bFlag = *flag;
28 __asan_abi_unregister_elf_globals(&bFlag, start, stop);
29 *flag = bFlag;
31 void __asan_register_globals(__asan_global *globals, uptr n) {
32 __asan_abi_register_globals(globals, n);
34 void __asan_unregister_globals(__asan_global *globals, uptr n) {
35 __asan_abi_unregister_globals(globals, n);
38 // Functions concerning dynamic library initialization
39 void __asan_before_dynamic_init(const char *module_name) {
40 __asan_abi_before_dynamic_init(module_name);
42 void __asan_after_dynamic_init(void) { __asan_abi_after_dynamic_init(); }
44 // Functions concerning block memory destinations
45 void *__asan_memcpy(void *dst, const void *src, uptr size) {
46 return __asan_abi_memcpy(dst, src, size);
48 void *__asan_memset(void *s, int c, uptr n) {
49 return __asan_abi_memset(s, c, n);
51 void *__asan_memmove(void *dest, const void *src, uptr n) {
52 return __asan_abi_memmove(dest, src, n);
55 // Functions concerning RTL startup and initialization
56 void __asan_init(void) {
57 static_assert(sizeof(uptr) == 8);
58 static_assert(sizeof(u64) == 8);
59 static_assert(sizeof(u32) == 4);
61 __asan_abi_init();
64 void __asan_handle_no_return(void) { __asan_abi_handle_no_return(); }
66 // Variables concerning RTL state. These provisionally exist for completeness
67 // but will likely move into the Stable ABI implementation and not in the shim.
68 uptr __asan_shadow_memory_dynamic_address = (uptr)0xdeaddeaddeadbeaf;
69 int __asan_option_detect_stack_use_after_return = 0;
71 // Functions concerning memory load and store reporting
72 void __asan_report_load1(uptr addr) {
73 __asan_abi_report_load_n((void *)addr, 1, true);
75 void __asan_report_load2(uptr addr) {
76 __asan_abi_report_load_n((void *)addr, 2, true);
78 void __asan_report_load4(uptr addr) {
79 __asan_abi_report_load_n((void *)addr, 4, true);
81 void __asan_report_load8(uptr addr) {
82 __asan_abi_report_load_n((void *)addr, 8, true);
84 void __asan_report_load16(uptr addr) {
85 __asan_abi_report_load_n((void *)addr, 16, true);
87 void __asan_report_load_n(uptr addr, uptr size) {
88 __asan_abi_report_load_n((void *)addr, size, true);
90 void __asan_report_store1(uptr addr) {
91 __asan_abi_report_store_n((void *)addr, 1, true);
93 void __asan_report_store2(uptr addr) {
94 __asan_abi_report_store_n((void *)addr, 2, true);
96 void __asan_report_store4(uptr addr) {
97 __asan_abi_report_store_n((void *)addr, 4, true);
99 void __asan_report_store8(uptr addr) {
100 __asan_abi_report_store_n((void *)addr, 8, true);
102 void __asan_report_store16(uptr addr) {
103 __asan_abi_report_store_n((void *)addr, 16, true);
105 void __asan_report_store_n(uptr addr, uptr size) {
106 __asan_abi_report_store_n((void *)addr, size, true);
109 // Functions concerning memory load and store reporting (experimental variants)
110 void __asan_report_exp_load1(uptr addr, u32 exp) {
111 __asan_abi_report_exp_load_n((void *)addr, exp, 1, true);
113 void __asan_report_exp_load2(uptr addr, u32 exp) {
114 __asan_abi_report_exp_load_n((void *)addr, exp, 2, true);
116 void __asan_report_exp_load4(uptr addr, u32 exp) {
117 __asan_abi_report_exp_load_n((void *)addr, exp, 4, true);
119 void __asan_report_exp_load8(uptr addr, u32 exp) {
120 __asan_abi_report_exp_load_n((void *)addr, exp, 8, true);
122 void __asan_report_exp_load16(uptr addr, u32 exp) {
123 __asan_abi_report_exp_load_n((void *)addr, exp, 16, true);
125 void __asan_report_exp_load_n(uptr addr, uptr size, u32 exp) {
126 __asan_abi_report_exp_load_n((void *)addr, size, exp, true);
128 void __asan_report_exp_store1(uptr addr, u32 exp) {
129 __asan_abi_report_exp_store_n((void *)addr, exp, 1, true);
131 void __asan_report_exp_store2(uptr addr, u32 exp) {
132 __asan_abi_report_exp_store_n((void *)addr, exp, 2, true);
134 void __asan_report_exp_store4(uptr addr, u32 exp) {
135 __asan_abi_report_exp_store_n((void *)addr, exp, 4, true);
137 void __asan_report_exp_store8(uptr addr, u32 exp) {
138 __asan_abi_report_exp_store_n((void *)addr, exp, 8, true);
140 void __asan_report_exp_store16(uptr addr, u32 exp) {
141 __asan_abi_report_exp_store_n((void *)addr, exp, 16, true);
143 void __asan_report_exp_store_n(uptr addr, uptr size, u32 exp) {
144 __asan_abi_report_exp_store_n((void *)addr, size, exp, true);
147 // Functions concerning memory load and store reporting (noabort variants)
148 void __asan_report_load1_noabort(uptr addr) {
149 __asan_abi_report_load_n((void *)addr, 1, false);
151 void __asan_report_load2_noabort(uptr addr) {
152 __asan_abi_report_load_n((void *)addr, 2, false);
154 void __asan_report_load4_noabort(uptr addr) {
155 __asan_abi_report_load_n((void *)addr, 4, false);
157 void __asan_report_load8_noabort(uptr addr) {
158 __asan_abi_report_load_n((void *)addr, 8, false);
160 void __asan_report_load16_noabort(uptr addr) {
161 __asan_abi_report_load_n((void *)addr, 16, false);
163 void __asan_report_load_n_noabort(uptr addr, uptr size) {
164 __asan_abi_report_load_n((void *)addr, size, false);
166 void __asan_report_store1_noabort(uptr addr) {
167 __asan_abi_report_store_n((void *)addr, 1, false);
169 void __asan_report_store2_noabort(uptr addr) {
170 __asan_abi_report_store_n((void *)addr, 2, false);
172 void __asan_report_store4_noabort(uptr addr) {
173 __asan_abi_report_store_n((void *)addr, 4, false);
175 void __asan_report_store8_noabort(uptr addr) {
176 __asan_abi_report_store_n((void *)addr, 8, false);
178 void __asan_report_store16_noabort(uptr addr) {
179 __asan_abi_report_store_n((void *)addr, 16, false);
181 void __asan_report_store_n_noabort(uptr addr, uptr size) {
182 __asan_abi_report_store_n((void *)addr, size, false);
185 // Functions concerning memory load and store
186 void __asan_load1(uptr addr) { __asan_abi_load_n((void *)addr, 1, true); }
187 void __asan_load2(uptr addr) { __asan_abi_load_n((void *)addr, 2, true); }
188 void __asan_load4(uptr addr) { __asan_abi_load_n((void *)addr, 4, true); }
189 void __asan_load8(uptr addr) { __asan_abi_load_n((void *)addr, 8, true); }
190 void __asan_load16(uptr addr) { __asan_abi_load_n((void *)addr, 16, true); }
191 void __asan_loadN(uptr addr, uptr size) {
192 __asan_abi_load_n((void *)addr, size, true);
194 void __asan_store1(uptr addr) { __asan_abi_store_n((void *)addr, 1, true); }
195 void __asan_store2(uptr addr) { __asan_abi_store_n((void *)addr, 2, true); }
196 void __asan_store4(uptr addr) { __asan_abi_store_n((void *)addr, 4, true); }
197 void __asan_store8(uptr addr) { __asan_abi_store_n((void *)addr, 8, true); }
198 void __asan_store16(uptr addr) { __asan_abi_store_n((void *)addr, 16, true); }
199 void __asan_storeN(uptr addr, uptr size) {
200 __asan_abi_store_n((void *)addr, size, true);
203 // Functions concerning memory load and store (experimental variants)
204 void __asan_exp_load1(uptr addr, u32 exp) {
205 __asan_abi_exp_load_n((void *)addr, 1, exp, true);
207 void __asan_exp_load2(uptr addr, u32 exp) {
208 __asan_abi_exp_load_n((void *)addr, 2, exp, true);
210 void __asan_exp_load4(uptr addr, u32 exp) {
211 __asan_abi_exp_load_n((void *)addr, 4, exp, true);
213 void __asan_exp_load8(uptr addr, u32 exp) {
214 __asan_abi_exp_load_n((void *)addr, 8, exp, true);
216 void __asan_exp_load16(uptr addr, u32 exp) {
217 __asan_abi_exp_load_n((void *)addr, 16, exp, true);
219 void __asan_exp_loadN(uptr addr, uptr size, u32 exp) {
220 __asan_abi_exp_load_n((void *)addr, size, exp, true);
222 void __asan_exp_store1(uptr addr, u32 exp) {
223 __asan_abi_exp_store_n((void *)addr, 1, exp, true);
225 void __asan_exp_store2(uptr addr, u32 exp) {
226 __asan_abi_exp_store_n((void *)addr, 2, exp, true);
228 void __asan_exp_store4(uptr addr, u32 exp) {
229 __asan_abi_exp_store_n((void *)addr, 4, exp, true);
231 void __asan_exp_store8(uptr addr, u32 exp) {
232 __asan_abi_exp_store_n((void *)addr, 8, exp, true);
234 void __asan_exp_store16(uptr addr, u32 exp) {
235 __asan_abi_exp_store_n((void *)addr, 16, exp, true);
237 void __asan_exp_storeN(uptr addr, uptr size, u32 exp) {
238 __asan_abi_exp_store_n((void *)addr, size, exp, true);
241 // Functions concerning memory load and store (noabort variants)
242 void __asan_load1_noabort(uptr addr) {
243 __asan_abi_load_n((void *)addr, 1, false);
245 void __asan_load2_noabort(uptr addr) {
246 __asan_abi_load_n((void *)addr, 2, false);
248 void __asan_load4_noabort(uptr addr) {
249 __asan_abi_load_n((void *)addr, 4, false);
251 void __asan_load8_noabort(uptr addr) {
252 __asan_abi_load_n((void *)addr, 8, false);
254 void __asan_load16_noabort(uptr addr) {
255 __asan_abi_load_n((void *)addr, 16, false);
257 void __asan_loadN_noabort(uptr addr, uptr size) {
258 __asan_abi_load_n((void *)addr, size, false);
260 void __asan_store1_noabort(uptr addr) {
261 __asan_abi_store_n((void *)addr, 1, false);
263 void __asan_store2_noabort(uptr addr) {
264 __asan_abi_store_n((void *)addr, 2, false);
266 void __asan_store4_noabort(uptr addr) {
267 __asan_abi_store_n((void *)addr, 4, false);
269 void __asan_store8_noabort(uptr addr) {
270 __asan_abi_store_n((void *)addr, 8, false);
272 void __asan_store16_noabort(uptr addr) {
273 __asan_abi_store_n((void *)addr, 16, false);
275 void __asan_storeN_noabort(uptr addr, uptr size) {
276 __asan_abi_store_n((void *)addr, size, false);
279 // Functions concerning query about whether memory is poisoned
280 int __asan_address_is_poisoned(void const volatile *addr) {
281 return __asan_abi_address_is_poisoned(addr);
283 uptr __asan_region_is_poisoned(uptr beg, uptr size) {
284 return (uptr)__asan_abi_region_is_poisoned((void *)beg, size);
287 // Functions concerning the poisoning of memory
288 void __asan_poison_memory_region(void const volatile *addr, uptr size) {
289 __asan_abi_poison_memory_region(addr, size);
291 void __asan_unpoison_memory_region(void const volatile *addr, uptr size) {
292 __asan_abi_unpoison_memory_region(addr, size);
295 // Functions concerning the partial poisoning of memory
296 void __asan_set_shadow_00(uptr addr, uptr size) {
297 __asan_abi_set_shadow_xx_n((void *)addr, 0x00, size);
299 void __asan_set_shadow_01(uptr addr, uptr size) {
300 __asan_abi_set_shadow_xx_n((void *)addr, 0x01, size);
302 void __asan_set_shadow_02(uptr addr, uptr size) {
303 __asan_abi_set_shadow_xx_n((void *)addr, 0x02, size);
305 void __asan_set_shadow_03(uptr addr, uptr size) {
306 __asan_abi_set_shadow_xx_n((void *)addr, 0x03, size);
308 void __asan_set_shadow_04(uptr addr, uptr size) {
309 __asan_abi_set_shadow_xx_n((void *)addr, 0x04, size);
311 void __asan_set_shadow_05(uptr addr, uptr size) {
312 __asan_abi_set_shadow_xx_n((void *)addr, 0x05, size);
314 void __asan_set_shadow_06(uptr addr, uptr size) {
315 __asan_abi_set_shadow_xx_n((void *)addr, 0x06, size);
317 void __asan_set_shadow_07(uptr addr, uptr size) {
318 __asan_abi_set_shadow_xx_n((void *)addr, 0x07, size);
320 void __asan_set_shadow_f1(uptr addr, uptr size) {
321 __asan_abi_set_shadow_xx_n((void *)addr, 0xf1, size);
323 void __asan_set_shadow_f2(uptr addr, uptr size) {
324 __asan_abi_set_shadow_xx_n((void *)addr, 0xf2, size);
326 void __asan_set_shadow_f3(uptr addr, uptr size) {
327 __asan_abi_set_shadow_xx_n((void *)addr, 0xf3, size);
329 void __asan_set_shadow_f5(uptr addr, uptr size) {
330 __asan_abi_set_shadow_xx_n((void *)addr, 0xf5, size);
332 void __asan_set_shadow_f8(uptr addr, uptr size) {
333 __asan_abi_set_shadow_xx_n((void *)addr, 0xf8, size);
336 // Functions concerning stack poisoning
337 void __asan_poison_stack_memory(uptr addr, uptr size) {
338 __asan_abi_poison_stack_memory((void *)addr, size);
340 void __asan_unpoison_stack_memory(uptr addr, uptr size) {
341 __asan_abi_unpoison_stack_memory((void *)addr, size);
344 // Functions concerning redzone poisoning
345 void __asan_poison_intra_object_redzone(uptr p, uptr size) {
346 __asan_abi_poison_intra_object_redzone((void *)p, size);
348 void __asan_unpoison_intra_object_redzone(uptr p, uptr size) {
349 __asan_abi_unpoison_intra_object_redzone((void *)p, size);
352 // Functions concerning array cookie poisoning
353 void __asan_poison_cxx_array_cookie(uptr p) {
354 __asan_abi_poison_cxx_array_cookie((void *)p);
356 uptr __asan_load_cxx_array_cookie(uptr *p) {
357 return (uptr)__asan_abi_load_cxx_array_cookie((void **)p);
360 // Functions concerning fake stacks
361 void *__asan_get_current_fake_stack(void) {
362 return __asan_abi_get_current_fake_stack();
364 void *__asan_addr_is_in_fake_stack(void *fake_stack, void *addr, void **beg,
365 void **end) {
366 return __asan_abi_addr_is_in_fake_stack(fake_stack, addr, beg, end);
369 // Functions concerning poisoning and unpoisoning fake stack alloca
370 void __asan_alloca_poison(uptr addr, uptr size) {
371 __asan_abi_alloca_poison((void *)addr, size);
373 void __asan_allocas_unpoison(uptr top, uptr bottom) {
374 __asan_abi_allocas_unpoison((void *)top, (void *)bottom);
377 // Functions concerning fake stack malloc
378 uptr __asan_stack_malloc_0(uptr size) {
379 return (uptr)__asan_abi_stack_malloc_n(0, size);
381 uptr __asan_stack_malloc_1(uptr size) {
382 return (uptr)__asan_abi_stack_malloc_n(1, size);
384 uptr __asan_stack_malloc_2(uptr size) {
385 return (uptr)__asan_abi_stack_malloc_n(2, size);
387 uptr __asan_stack_malloc_3(uptr size) {
388 return (uptr)__asan_abi_stack_malloc_n(3, size);
390 uptr __asan_stack_malloc_4(uptr size) {
391 return (uptr)__asan_abi_stack_malloc_n(4, size);
393 uptr __asan_stack_malloc_5(uptr size) {
394 return (uptr)__asan_abi_stack_malloc_n(5, size);
396 uptr __asan_stack_malloc_6(uptr size) {
397 return (uptr)__asan_abi_stack_malloc_n(6, size);
399 uptr __asan_stack_malloc_7(uptr size) {
400 return (uptr)__asan_abi_stack_malloc_n(7, size);
402 uptr __asan_stack_malloc_8(uptr size) {
403 return (uptr)__asan_abi_stack_malloc_n(8, size);
405 uptr __asan_stack_malloc_9(uptr size) {
406 return (uptr)__asan_abi_stack_malloc_n(9, size);
408 uptr __asan_stack_malloc_10(uptr size) {
409 return (uptr)__asan_abi_stack_malloc_n(10, size);
412 // Functions concerning fake stack malloc (always variants)
413 uptr __asan_stack_malloc_always_0(uptr size) {
414 return (uptr)__asan_abi_stack_malloc_always_n(0, size);
416 uptr __asan_stack_malloc_always_1(uptr size) {
417 return (uptr)__asan_abi_stack_malloc_always_n(1, size);
419 uptr __asan_stack_malloc_always_2(uptr size) {
420 return (uptr)__asan_abi_stack_malloc_always_n(2, size);
422 uptr __asan_stack_malloc_always_3(uptr size) {
423 return (uptr)__asan_abi_stack_malloc_always_n(3, size);
425 uptr __asan_stack_malloc_always_4(uptr size) {
426 return (uptr)__asan_abi_stack_malloc_always_n(4, size);
428 uptr __asan_stack_malloc_always_5(uptr size) {
429 return (uptr)__asan_abi_stack_malloc_always_n(5, size);
431 uptr __asan_stack_malloc_always_6(uptr size) {
432 return (uptr)__asan_abi_stack_malloc_always_n(6, size);
434 uptr __asan_stack_malloc_always_7(uptr size) {
435 return (uptr)__asan_abi_stack_malloc_always_n(7, size);
437 uptr __asan_stack_malloc_always_8(uptr size) {
438 return (uptr)__asan_abi_stack_malloc_always_n(8, size);
440 uptr __asan_stack_malloc_always_9(uptr size) {
441 return (uptr)__asan_abi_stack_malloc_always_n(9, size);
443 uptr __asan_stack_malloc_always_10(uptr size) {
444 return (uptr)__asan_abi_stack_malloc_always_n(10, size);
447 // Functions concerning fake stack free
448 void __asan_stack_free_0(uptr ptr, uptr size) {
449 __asan_abi_stack_free_n(0, (void *)ptr, size);
451 void __asan_stack_free_1(uptr ptr, uptr size) {
452 __asan_abi_stack_free_n(1, (void *)ptr, size);
454 void __asan_stack_free_2(uptr ptr, uptr size) {
455 __asan_abi_stack_free_n(2, (void *)ptr, size);
457 void __asan_stack_free_3(uptr ptr, uptr size) {
458 __asan_abi_stack_free_n(3, (void *)ptr, size);
460 void __asan_stack_free_4(uptr ptr, uptr size) {
461 __asan_abi_stack_free_n(4, (void *)ptr, size);
463 void __asan_stack_free_5(uptr ptr, uptr size) {
464 __asan_abi_stack_free_n(5, (void *)ptr, size);
466 void __asan_stack_free_6(uptr ptr, uptr size) {
467 __asan_abi_stack_free_n(6, (void *)ptr, size);
469 void __asan_stack_free_7(uptr ptr, uptr size) {
470 __asan_abi_stack_free_n(7, (void *)ptr, size);
472 void __asan_stack_free_8(uptr ptr, uptr size) {
473 __asan_abi_stack_free_n(8, (void *)ptr, size);
475 void __asan_stack_free_9(uptr ptr, uptr size) {
476 __asan_abi_stack_free_n(9, (void *)ptr, size);
478 void __asan_stack_free_10(uptr ptr, uptr size) {
479 __asan_abi_stack_free_n(10, (void *)ptr, size);