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 5 // Only Linux and FreeBSD list every memory region in MemoryMappingLayout, for now. 6 // REQUIRES: linux || freebsd 7 8 #include <assert.h> 9 10 typedef void void_f(); 11 int main(int argc, char **argv) { 12 char *array = new char[42]; 13 void_f *func; 14 assert(argc > 1); 15 if (argv[1][0] == '0') { 16 func = (void_f *)0x04; 17 } else { 18 assert(argv[1][0] == 'n'); 19 func = (void_f *)array; 20 } 21 22 func(); 23 // x86 reports the SEGV with both address=X and pc=X. 24 // On PowerPC64 ELFv1, the pointer is taken to be a function-descriptor 25 // pointer out of which three 64-bit quantities are read. This will SEGV, but 26 // the compiler is free to choose the order. As a result, the address is 27 // either X, X+0x8 or X+0x10. The pc is still in main() because it has not 28 // actually made the call when the faulting access occurs. 29 // CHECK: DEADLYSIGNAL 30 // CHECK: {{AddressSanitizer: (SEGV|access-violation).*(address|pc) }} 31 // NON_EXEC: PC is at a non-executable region. Maybe a wild jump? 32 return 0; 33 } 34