| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target hwaddress_exec } */ |
| 3 |
/* { dg-shouldfail "hwasan" } */ |
| 4 |
/* Don't really need this option since there are no vararray/alloca objects in |
| 5 |
the interesting function, however it never hurts to make doubly sure and |
| 6 |
make it explicit that we're checking the alternate approach to deallocation. |
| 7 |
*/ |
| 8 |
/* { dg-additional-options "--param hwasan-instrument-allocas=0" } */ |
| 9 |
|
| 10 |
/* Handling large aligned variables. |
| 11 |
Large aligned variables take a different code-path through expand_stack_vars |
| 12 |
in cfgexpand.c. This testcase is just to exercise that code-path. |
| 13 |
|
| 14 |
The alternate code-path produces a second base-pointer through some |
| 15 |
instructions emitted in the prologue. |
| 16 |
|
| 17 |
This eventually follows a different code path for untagging when not tagging |
| 18 |
allocas. The untagging needs to work at the top of the frame, and this |
| 19 |
should account for this different base when large aligned variables are |
| 20 |
around. */ |
| 21 |
__attribute__ ((noinline)) |
| 22 |
void * Ident (void * argument) |
| 23 |
{ |
| 24 |
return argument; |
| 25 |
} |
| 26 |
|
| 27 |
#ifndef ALIGNMENT |
| 28 |
#define ALIGNMENT |
| 29 |
#endif |
| 30 |
void __attribute__ ((noinline)) |
| 31 |
large_alignment_untagging (int num, int *retval, int **big, int **other) |
| 32 |
{ |
| 33 |
int other_array[100] ALIGNMENT; |
| 34 |
int big_array[100] __attribute__ ((aligned (32))); |
| 35 |
*retval = big_array[num] + other_array[num]; |
| 36 |
*big = (int*)Ident(big_array); |
| 37 |
*other = (int*)Ident(other_array); |
| 38 |
} |
| 39 |
|
| 40 |
#ifndef ARG |
| 41 |
#define ARG 0 |
| 42 |
#endif |
| 43 |
|
| 44 |
int global; |
| 45 |
|
| 46 |
int __attribute__ ((noinline)) |
| 47 |
main () |
| 48 |
{ |
| 49 |
int retval; |
| 50 |
int *big, *other; |
| 51 |
large_alignment_untagging (0, &retval, &big, &other); |
| 52 |
/* Want to test that both ends of both variables are untagged. */ |
| 53 |
switch (ARG) { |
| 54 |
case 0: |
| 55 |
global += big[0]; |
| 56 |
break; |
| 57 |
case 1: |
| 58 |
global += big[99]; |
| 59 |
break; |
| 60 |
case 2: |
| 61 |
global += other[0]; |
| 62 |
break; |
| 63 |
case 3: |
| 64 |
global += other[99]; |
| 65 |
break; |
| 66 |
} |
| 67 |
return 0; |
| 68 |
} |
| 69 |
|
| 70 |
/* { dg-output "HWAddressSanitizer: tag-mismatch on address 0x\[0-9a-f\]*.*" } */ |
| 71 |
/* NOTE: This assumes the current tagging mechanism (one at a time from the |
| 72 |
base and large aligned variables being handled first). */ |
| 73 |
/* { dg-output "READ of size 4 at 0x\[0-9a-f\]* tags: \[\[:xdigit:\]\]\[\[:xdigit:\]\]/\[\[:xdigit:\]\]\[\[:xdigit:\]\] \\(ptr/mem\\) in thread T0.*" } */ |
| 74 |
/* { dg-output "Address 0x\[0-9a-f\]* is located in stack of thread T0.*" } */ |
| 75 |
/* { dg-output "SUMMARY: HWAddressSanitizer: tag-mismatch \[^\n\]*.*" } */ |