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: !android
14
15#if BUILD_SO
16char dummy;
17void do_access(const void *p) {
18 // CHECK: AddressSanitizer: heap-buffer-overflow
19 dummy = ((const char *)p)[1];
20}
21#else
22#include <stdlib.h>
23extern void do_access(const void *p);
24int main(int argc, char **argv) {
25 void *p = malloc(size: 1);
26 do_access(p);
27 free(ptr: p);
28 return 0;
29}
30#endif
31

source code of compiler-rt/test/asan/TestCases/Linux/asan_preload_test-1.cpp