diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/msan/wrap_indirect_calls.cc | 64 | ||||
-rw-r--r-- | test/msan/wrap_indirect_calls/caller.cc | 51 | ||||
-rw-r--r-- | test/msan/wrap_indirect_calls/lit.local.cfg | 3 | ||||
-rw-r--r-- | test/msan/wrap_indirect_calls/one.cc | 3 | ||||
-rw-r--r-- | test/msan/wrap_indirect_calls/two.cc | 11 | ||||
-rw-r--r-- | test/msan/wrap_indirect_calls/wrapper.cc | 11 | ||||
-rw-r--r-- | test/msan/wrap_indirect_calls2.cc | 42 | ||||
-rw-r--r-- | test/msan/wrap_indirect_calls_in_rtl.cc | 77 |
8 files changed, 0 insertions, 262 deletions
diff --git a/test/msan/wrap_indirect_calls.cc b/test/msan/wrap_indirect_calls.cc deleted file mode 100644 index be17bd824..000000000 --- a/test/msan/wrap_indirect_calls.cc +++ /dev/null @@ -1,64 +0,0 @@ -// Test indirect call wrapping in MemorySanitizer. - -// RUN: %clangxx_msan -O0 %p/wrap_indirect_calls/two.cc -fPIC -shared -o %t-two-so.so -// RUN: %clangxx_msan -O0 %p/wrap_indirect_calls/wrapper.cc -fPIC -shared -o %t-wrapper-so.so - -// Disable fast path. - -// RUN: %clangxx_msan -O0 %p/wrap_indirect_calls/caller.cc %p/wrap_indirect_calls/one.cc %s \ -// RUN: %t-two-so.so %t-wrapper-so.so \ -// RUN: -mllvm -msan-wrap-indirect-calls=wrapper \ -// RUN: -mllvm -msan-wrap-indirect-calls-fast=0 \ -// RUN: -DSLOW=1 \ -// RUN: -Wl,--defsym=__executable_start=0 -o %t -// RUN: %run %t - -// Enable fast path, call from executable, -O0. - -// RUN: %clangxx_msan -O0 %p/wrap_indirect_calls/caller.cc %p/wrap_indirect_calls/one.cc %s \ -// RUN: %t-two-so.so %t-wrapper-so.so \ -// RUN: -mllvm -msan-wrap-indirect-calls=wrapper \ -// RUN: -mllvm -msan-wrap-indirect-calls-fast=1 \ -// RUN: -DSLOW=0 \ -// RUN: -Wl,--defsym=__executable_start=0 -o %t -// RUN: %run %t - -// Enable fast path, call from executable, -O3. - -// RUN: %clangxx_msan -O3 %p/wrap_indirect_calls/caller.cc %p/wrap_indirect_calls/one.cc %s \ -// RUN: %t-two-so.so %t-wrapper-so.so \ -// RUN: -mllvm -msan-wrap-indirect-calls=wrapper \ -// RUN: -mllvm -msan-wrap-indirect-calls-fast=1 \ -// RUN: -DSLOW=0 \ -// RUN: -Wl,--defsym=__executable_start=0 -o %t -// RUN: %run %t - -// Enable fast path, call from DSO, -O0. - -// RUN: %clangxx_msan -O0 %p/wrap_indirect_calls/caller.cc %p/wrap_indirect_calls/one.cc -shared \ -// RUN: %t-two-so.so %t-wrapper-so.so \ -// RUN: -mllvm -msan-wrap-indirect-calls=wrapper \ -// RUN: -mllvm -msan-wrap-indirect-calls-fast=1 \ -// RUN: -DSLOW=0 \ -// RUN: -Wl,--defsym=__executable_start=0 -o %t-caller-so.so -// RUN: %clangxx_msan -O0 %s %t-caller-so.so %t-two-so.so %t-wrapper-so.so -o %t -// RUN: %run %t - -// Enable fast path, call from DSO, -O3. - -// RUN: %clangxx_msan -O3 %p/wrap_indirect_calls/caller.cc %p/wrap_indirect_calls/one.cc -shared \ -// RUN: %t-two-so.so %t-wrapper-so.so \ -// RUN: -mllvm -msan-wrap-indirect-calls=wrapper \ -// RUN: -mllvm -msan-wrap-indirect-calls-fast=1 \ -// RUN: -DSLOW=0 \ -// RUN: -Wl,--defsym=__executable_start=0 -o %t-caller-so.so -// RUN: %clangxx_msan -O3 %s %t-caller-so.so %t-two-so.so %t-wrapper-so.so -o %t -// RUN: %run %t - -// The actual test is in multiple files in wrap_indirect_calls/ directory. -void run_test(); - -int main() { - run_test(); - return 0; -} diff --git a/test/msan/wrap_indirect_calls/caller.cc b/test/msan/wrap_indirect_calls/caller.cc deleted file mode 100644 index a0af8b7bb..000000000 --- a/test/msan/wrap_indirect_calls/caller.cc +++ /dev/null @@ -1,51 +0,0 @@ -// Indirectly call a bunch of functions. - -#include <assert.h> - -extern int cnt; - -typedef int (*F)(int, int); - -// A function in the same object. -int f_local(int x, int y) { - return x + y; -} - -// A function in another object. -int f_other_object(int x, int y); - -// A function in another DSO. -int f_dso(int x, int y); - -// A function in another DSO that is replaced by the wrapper. -int f_replaced(int x, int y); - -void run_test(void) { - int x; - int expected_cnt = 0; - volatile F f; - - if (SLOW) ++expected_cnt; - f = &f_local; - x = f(1, 2); - assert(x == 3); - assert(cnt == expected_cnt); - - if (SLOW) ++expected_cnt; - f = &f_other_object; - x = f(2, 3); - assert(x == 6); - assert(cnt == expected_cnt); - - ++expected_cnt; - f = &f_dso; - x = f(2, 3); - assert(x == 7); - assert(cnt == expected_cnt); - - ++expected_cnt; - f = &f_replaced; - x = f(2, 3); - assert(x == 11); - assert(cnt == expected_cnt); -} diff --git a/test/msan/wrap_indirect_calls/lit.local.cfg b/test/msan/wrap_indirect_calls/lit.local.cfg deleted file mode 100644 index 5e01230c0..000000000 --- a/test/msan/wrap_indirect_calls/lit.local.cfg +++ /dev/null @@ -1,3 +0,0 @@ -# Sources in this directory are used by tests in parent directory. - -config.suffixes = [] diff --git a/test/msan/wrap_indirect_calls/one.cc b/test/msan/wrap_indirect_calls/one.cc deleted file mode 100644 index ab7bf4125..000000000 --- a/test/msan/wrap_indirect_calls/one.cc +++ /dev/null @@ -1,3 +0,0 @@ -int f_other_object(int x, int y) { - return x * y; -} diff --git a/test/msan/wrap_indirect_calls/two.cc b/test/msan/wrap_indirect_calls/two.cc deleted file mode 100644 index c939a993b..000000000 --- a/test/msan/wrap_indirect_calls/two.cc +++ /dev/null @@ -1,11 +0,0 @@ -int f_dso(int x, int y) { - return 2 * x + y; -} - -int f_replaced(int x, int y) { - return x + y + 5; -} - -int f_replacement(int x, int y) { - return x + y + 6; -} diff --git a/test/msan/wrap_indirect_calls/wrapper.cc b/test/msan/wrap_indirect_calls/wrapper.cc deleted file mode 100644 index 8fcd0c635..000000000 --- a/test/msan/wrap_indirect_calls/wrapper.cc +++ /dev/null @@ -1,11 +0,0 @@ -int f_replaced(int x, int y); -int f_replacement(int x, int y); - -int cnt; - -extern "C" void *wrapper(void *p) { - ++cnt; - if (p == (void *)f_replaced) - return (void *)f_replacement; - return p; -} diff --git a/test/msan/wrap_indirect_calls2.cc b/test/msan/wrap_indirect_calls2.cc deleted file mode 100644 index fb4e6c798..000000000 --- a/test/msan/wrap_indirect_calls2.cc +++ /dev/null @@ -1,42 +0,0 @@ -// Test __msan_set_indirect_call_wrapper. - -// RUN: %clangxx_msan -mllvm -msan-wrap-indirect-calls=__msan_wrap_indirect_call \ -// RUN: -mllvm -msan-wrap-indirect-calls-fast=0 \ -// RUN: -O0 -g -rdynamic -Wl,--defsym=__executable_start=0 %s -o %t && %run %t - -// This test disables -msan-wrap-indirect-calls-fast, otherwise indirect calls -// inside the same module are short-circuited and are never seen by the wrapper. - -#include <assert.h> -#include <pthread.h> -#include <stdio.h> -#include <stdint.h> - -extern "C" void __msan_set_indirect_call_wrapper(uintptr_t); - -bool done_f, done_g; - -void f(void) { - assert(!done_g); - done_f = true; -} - -void g(void) { - assert(done_f); - done_g = true; -} - -typedef void (*Fn)(void); -extern "C" Fn my_wrapper(Fn target) { - if (target == f) return g; - return target; -} - -int main(void) { - volatile Fn fp; - fp = &f; - fp(); - __msan_set_indirect_call_wrapper((uintptr_t)my_wrapper); - fp(); - return !(done_f && done_g); -} diff --git a/test/msan/wrap_indirect_calls_in_rtl.cc b/test/msan/wrap_indirect_calls_in_rtl.cc deleted file mode 100644 index 58e80045e..000000000 --- a/test/msan/wrap_indirect_calls_in_rtl.cc +++ /dev/null @@ -1,77 +0,0 @@ -// Test indirect call wrapping in MemorySanitizer runtime. - -// RUN: %clangxx_msan -O0 -g -rdynamic %s -o %t && %run %t -// RUN: %clangxx_msan -O2 -g -rdynamic %s -o %t && %run %t - -#include <assert.h> -#include <dlfcn.h> -#include <math.h> -#include <pthread.h> -#include <stdio.h> -#include <stdint.h> -#include <sys/time.h> - -extern "C" void __msan_set_indirect_call_wrapper(uintptr_t); - -bool pthread_create_done; - -void *ThreadFn(void *) { - printf("bad threadfn\n"); - return 0; -} - -void *ThreadFn2(void *) { - printf("good threadfn\n"); - pthread_create_done = true; - return 0; -} - -int my_gettimeofday(struct timeval *p, void *q) { - p->tv_sec = 1; - p->tv_usec = 2; - return 42; -} - -double my_lgamma(double x) { - return x; -} - -uintptr_t real_gettimeofday; -uintptr_t real_lgamma; - -extern "C" uintptr_t my_wrapper(uintptr_t f) { - if (f == (uintptr_t)ThreadFn) return (uintptr_t)&ThreadFn2; - if (f == real_gettimeofday) return (uintptr_t)my_gettimeofday; - if (f == real_lgamma) return (uintptr_t)my_lgamma; - return f; -} - -int main(void) { - real_gettimeofday = (uintptr_t)dlsym(RTLD_NEXT, "gettimeofday"); - real_lgamma = (uintptr_t)dlsym(RTLD_NEXT, "lgamma"); - - __msan_set_indirect_call_wrapper((uintptr_t)my_wrapper); - - // ThreadFn is called indirectly from a wrapper function in MSan rtl and - // is subject to indirect call wrapping (it could be an native-to-translated - // edge). - pthread_t t; - pthread_create(&t, 0, ThreadFn, 0); - pthread_join(t, 0); - assert(pthread_create_done); - - // gettimeofday is intercepted in msan_interceptors.cc and the real one (from - // libc) is called indirectly. - struct timeval tv; - int res = gettimeofday(&tv, NULL); - assert(tv.tv_sec == 1); - assert(tv.tv_usec == 2); - assert(res == 42); - - // lgamma is intercepted in sanitizer_common_interceptors.inc and is also - // called indirectly. - double dres = lgamma(1.1); - assert(dres == 1.1); - - return 0; -} |