[compiler-rt] r194699 - [msan] A test for r194697.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Thu Nov 14 04:31:19 PST 2013


Author: eugenis
Date: Thu Nov 14 06:31:18 2013
New Revision: 194699

URL: http://llvm.org/viewvc/llvm-project?rev=194699&view=rev
Log:
[msan] A test for r194697.

Added:
    compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/
    compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls.cc   (with props)
    compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/caller.cc   (with props)
    compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/lit.local.cfg
    compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/one.cc   (with props)
    compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/two.cc   (with props)
    compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/wrapper.cc   (with props)

Added: compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls.cc?rev=194699&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls.cc (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls.cc Thu Nov 14 06:31:18 2013
@@ -0,0 +1,64 @@
+// 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: %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: %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: %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: %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: %t
+
+// The actual test is in multiple files in wrap_indirect_calls/ directory.
+void run_test();
+
+int main() {
+  run_test();
+  return 0;
+}

Propchange: compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls.cc
------------------------------------------------------------------------------
    svn:eol-style = LF

Added: compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/caller.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/caller.cc?rev=194699&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/caller.cc (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/caller.cc Thu Nov 14 06:31:18 2013
@@ -0,0 +1,51 @@
+// 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);
+}

Propchange: compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/caller.cc
------------------------------------------------------------------------------
    svn:eol-style = LF

Added: compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/lit.local.cfg?rev=194699&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/lit.local.cfg (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/lit.local.cfg Thu Nov 14 06:31:18 2013
@@ -0,0 +1,3 @@
+# Sources in this directory are used by tests in parent directory.
+
+config.suffixes = []

Added: compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/one.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/one.cc?rev=194699&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/one.cc (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/one.cc Thu Nov 14 06:31:18 2013
@@ -0,0 +1,3 @@
+int f_other_object(int x, int y) {
+  return x * y;
+}

Propchange: compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/one.cc
------------------------------------------------------------------------------
    svn:eol-style = LF

Added: compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/two.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/two.cc?rev=194699&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/two.cc (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/two.cc Thu Nov 14 06:31:18 2013
@@ -0,0 +1,11 @@
+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;
+}

Propchange: compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/two.cc
------------------------------------------------------------------------------
    svn:eol-style = LF

Added: compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/wrapper.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/wrapper.cc?rev=194699&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/wrapper.cc (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/wrapper.cc Thu Nov 14 06:31:18 2013
@@ -0,0 +1,11 @@
+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;
+}

Propchange: compiler-rt/trunk/lib/msan/lit_tests/wrap_indirect_calls/wrapper.cc
------------------------------------------------------------------------------
    svn:eol-style = LF





More information about the llvm-commits mailing list