[compiler-rt] r212798 - [msan] Make one test case less brittle.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Fri Jul 11 01:47:51 PDT 2014
Author: eugenis
Date: Fri Jul 11 03:47:51 2014
New Revision: 212798
URL: http://llvm.org/viewvc/llvm-project?rev=212798&view=rev
Log:
[msan] Make one test case less brittle.
Modified:
compiler-rt/trunk/test/msan/wrap_indirect_calls_in_rtl.cc
Modified: compiler-rt/trunk/test/msan/wrap_indirect_calls_in_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/wrap_indirect_calls_in_rtl.cc?rev=212798&r1=212797&r2=212798&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/wrap_indirect_calls_in_rtl.cc (original)
+++ compiler-rt/trunk/test/msan/wrap_indirect_calls_in_rtl.cc Fri Jul 11 03:47:51 2014
@@ -1,8 +1,10 @@
// 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>
@@ -24,9 +26,6 @@ void *ThreadFn2(void *) {
return 0;
}
-bool in_gettimeofday;
-bool in_lgamma;
-
int my_gettimeofday(struct timeval *p, void *q) {
p->tv_sec = 1;
p->tv_usec = 2;
@@ -37,17 +36,20 @@ 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 (in_gettimeofday)
- return (uintptr_t)my_gettimeofday;
- if (in_lgamma)
- return (uintptr_t)my_lgamma;
+ 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
@@ -61,18 +63,14 @@ int main(void) {
// gettimeofday is intercepted in msan_interceptors.cc and the real one (from
// libc) is called indirectly.
struct timeval tv;
- in_gettimeofday = true;
int res = gettimeofday(&tv, NULL);
- in_gettimeofday = false;
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.
- in_lgamma = true;
double dres = lgamma(1.1);
- in_lgamma = false;
assert(dres == 1.1);
return 0;
More information about the llvm-commits
mailing list