Filipe Cabecinhas | 74ad311 | 2017-03-01 18:52:11 +0000 | [diff] [blame] | 1 | // RUN: %clangxx_asan %s -o %t |
| 2 | // RUN: not %run %t 0 2>&1 | FileCheck %s |
| 3 | // RUN: not %run %t n 2>&1 | FileCheck %s -check-prefix=CHECK -check-prefix=NON_EXEC |
| 4 | |
Kamil Rytarowski | d92f398 | 2017-08-30 23:02:36 +0000 | [diff] [blame] | 5 | // Not every OS lists every memory region in MemoryMappingLayout. |
| 6 | // REQUIRES: linux || freebsd || netbsd |
Filipe Cabecinhas | 74ad311 | 2017-03-01 18:52:11 +0000 | [diff] [blame] | 7 | |
Ulrich Weigand | f4556f6 | 2018-07-10 16:55:27 +0000 | [diff] [blame^] | 8 | // We don't have non-execute protection on s390 processors before z14. |
| 9 | // UNSUPPORTED: s390 |
| 10 | |
Filipe Cabecinhas | 74ad311 | 2017-03-01 18:52:11 +0000 | [diff] [blame] | 11 | #include <assert.h> |
| 12 | |
| 13 | typedef void void_f(); |
| 14 | int main(int argc, char **argv) { |
| 15 | char *array = new char[42]; |
| 16 | void_f *func; |
| 17 | assert(argc > 1); |
| 18 | if (argv[1][0] == '0') { |
| 19 | func = (void_f *)0x04; |
| 20 | } else { |
| 21 | assert(argv[1][0] == 'n'); |
| 22 | func = (void_f *)array; |
| 23 | } |
| 24 | |
| 25 | func(); |
| 26 | // x86 reports the SEGV with both address=X and pc=X. |
| 27 | // On PowerPC64 ELFv1, the pointer is taken to be a function-descriptor |
| 28 | // pointer out of which three 64-bit quantities are read. This will SEGV, but |
| 29 | // the compiler is free to choose the order. As a result, the address is |
| 30 | // either X, X+0x8 or X+0x10. The pc is still in main() because it has not |
| 31 | // actually made the call when the faulting access occurs. |
| 32 | // CHECK: DEADLYSIGNAL |
| 33 | // CHECK: {{AddressSanitizer: (SEGV|access-violation).*(address|pc) }} |
| 34 | // NON_EXEC: PC is at a non-executable region. Maybe a wild jump? |
| 35 | return 0; |
| 36 | } |