Home | History | Annotate | Download | only in Linux
      1 // Test that non-sanitized executables work with sanitized shared libs
      2 // and preloaded runtime.
      3 //
      4 // RUN: %clangxx -DBUILD_SO=1 -fPIC -shared %s -o %t.so
      5 // RUN: %clangxx %s %t.so -o %t
      6 //
      7 // RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so
      8 // RUN: env LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
      9 
     10 // REQUIRES: asan-dynamic-runtime
     11 
     12 // This way of setting LD_PRELOAD does not work with Android test runner.
     13 // REQUIRES: not-android
     14 
     15 #if BUILD_SO
     16 char dummy;
     17 void do_access(const void *p) {
     18   // CHECK: AddressSanitizer: heap-buffer-overflow
     19   dummy = ((const char *)p)[1];
     20 }
     21 #else
     22 #include <stdlib.h>
     23 extern void do_access(const void *p);
     24 int main(int argc, char **argv) {
     25   void *p = malloc(1);
     26   do_access(p);
     27   free(p);
     28   return 0;
     29 }
     30 #endif
     31