xref: /llvm-project/compiler-rt/test/asan/TestCases/Darwin/linked-only.cpp (revision b316c30269c35559dd99b1902a97f873c44ac413)
1 // Main executable is uninstrumented, but linked to ASan runtime.
2 // Regression test for https://code.google.com/p/address-sanitizer/issues/detail?id=357.
3 
4 // RUN: %clangxx -g -O0 %s -c -o %t.o
5 // RUN: %clangxx_asan -g -O0 %t.o -o %t
6 // RUN: %run %t 2>&1 | FileCheck %s
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 
12 #include "sanitizer/asan_interface.h"
13 #if __has_feature(ptrauth_calls)
14 #  include <ptrauth.h>
15 #endif
16 
test_shadow(char * p,size_t size)17 void test_shadow(char *p, size_t size) {
18   fprintf(stderr, "p = %p\n", p);
19   char *q = (char *)__asan_region_is_poisoned(p, size);
20   fprintf(stderr, "=%zd=\n", q ? q - p : -1);
21 }
22 
main(int argc,char * argv[])23 int main(int argc, char *argv[]) {
24   char *p = (char *)malloc(10000);
25   test_shadow(p, 100);
26   free(p);
27   // CHECK: =-1=
28 
29   char *mainptr;
30 #if __has_feature(ptrauth_calls)
31   mainptr = (char *)ptrauth_strip((void *)&main, ptrauth_key_return_address);
32 #else
33   mainptr = (char *)&main;
34 #endif
35   test_shadow(mainptr, 1);
36   // CHECK: =-1=
37 
38   test_shadow((char *)&p, 1);
39   // CHECK: =-1=
40 
41   return 0;
42 }
43