[compiler-rt] r185342 - [ASan] Properly disable strict init-order checking when pthread_create is called
Alexey Samsonov
samsonov at google.com
Mon Jul 1 09:16:41 PDT 2013
Author: samsonov
Date: Mon Jul 1 11:16:41 2013
New Revision: 185342
URL: http://llvm.org/viewvc/llvm-project?rev=185342&view=rev
Log:
[ASan] Properly disable strict init-order checking when pthread_create is called
Added:
compiler-rt/trunk/lib/asan/lit_tests/TestCases/Helpers/init-order-pthread-create-extra.cc
compiler-rt/trunk/lib/asan/lit_tests/TestCases/init-order-pthread-create.cc
Modified:
compiler-rt/trunk/lib/asan/asan_interceptors.cc
Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=185342&r1=185341&r2=185342&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Mon Jul 1 11:16:41 2013
@@ -94,11 +94,6 @@ void SetThreadName(const char *name) {
asanThreadRegistry().SetThreadName(t->tid(), name);
}
-static void DisableStrictInitOrderChecker() {
- if (flags()->strict_init_order)
- flags()->check_initialization_order = false;
-}
-
} // namespace __asan
// ---------------------- Wrappers ---------------- {{{1
@@ -144,7 +139,8 @@ extern "C" int pthread_attr_getdetachsta
INTERCEPTOR(int, pthread_create, void *thread,
void *attr, void *(*start_routine)(void*), void *arg) {
// Strict init-order checking in thread-hostile.
- DisableStrictInitOrderChecker();
+ if (flags()->strict_init_order)
+ StopInitOrderChecking();
GET_STACK_TRACE_THREAD;
int detached = 0;
if (attr != 0)
@@ -667,7 +663,8 @@ INTERCEPTOR_WINAPI(DWORD, CreateThread,
DWORD (__stdcall *start_routine)(void*), void* arg,
DWORD flags, void* tid) {
// Strict init-order checking in thread-hostile.
- DisableStrictInitOrderChecker();
+ if (flags()->strict_init_order)
+ StopInitOrderChecking();
GET_STACK_TRACE_THREAD;
u32 current_tid = GetCurrentTidOrInvalid();
AsanThread *t = AsanThread::Create(start_routine, arg);
Added: compiler-rt/trunk/lib/asan/lit_tests/TestCases/Helpers/init-order-pthread-create-extra.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/Helpers/init-order-pthread-create-extra.cc?rev=185342&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/Helpers/init-order-pthread-create-extra.cc (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/Helpers/init-order-pthread-create-extra.cc Mon Jul 1 11:16:41 2013
@@ -0,0 +1,2 @@
+void *bar(void *input);
+void *glob2 = bar((void*)0x2345);
Added: compiler-rt/trunk/lib/asan/lit_tests/TestCases/init-order-pthread-create.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/init-order-pthread-create.cc?rev=185342&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/init-order-pthread-create.cc (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/init-order-pthread-create.cc Mon Jul 1 11:16:41 2013
@@ -0,0 +1,32 @@
+// Check that init-order checking is properly disabled if pthread_create is
+// called.
+
+// RUN: %clangxx_asan %s %p/Helpers/init-order-pthread-create-extra.cc -o %t
+// RUN: ASAN_OPTIONS=check_initialization_order=true:strict_init_order=true %t
+
+#include <stdio.h>
+#include <pthread.h>
+
+void *run(void *arg) {
+ return arg;
+}
+
+void *foo(void *input) {
+ pthread_t t;
+ pthread_create(&t, 0, run, input);
+ void *res;
+ pthread_join(t, &res);
+ return res;
+}
+
+void *bar(void *input) {
+ return input;
+}
+
+void *glob = foo((void*)0x1234);
+extern void *glob2;
+
+int main() {
+ printf("%p %p\n", glob, glob2);
+ return 0;
+}
More information about the llvm-commits
mailing list