[compiler-rt] r176938 - [sanitizer] Move GetTlsSize code from TSan to sanitizer_common.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Wed Mar 13 01:19:54 PDT 2013
Author: eugenis
Date: Wed Mar 13 03:19:53 2013
New Revision: 176938
URL: http://llvm.org/viewvc/llvm-project?rev=176938&view=rev
Log:
[sanitizer] Move GetTlsSize code from TSan to sanitizer_common.
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h
compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=176938&r1=176937&r2=176938&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Wed Mar 13 03:19:53 2013
@@ -133,6 +133,9 @@ bool StackSizeIsUnlimited();
void SetStackSizeLimitInBytes(uptr limit);
void PrepareForSandboxing();
+void InitTlsSize();
+uptr GetTlsSize();
+
// Other
void SleepForSeconds(int seconds);
void SleepForMillis(int millis);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=176938&r1=176937&r2=176938&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Wed Mar 13 03:19:53 2013
@@ -22,6 +22,7 @@
#include "sanitizer_procmaps.h"
#include "sanitizer_stacktrace.h"
+#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
@@ -673,6 +674,34 @@ bool ThreadLister::GetDirectoryEntries()
return true;
}
+static uptr g_tls_size;
+
+#ifdef __i386__
+# define DL_INTERNAL_FUNCTION __attribute__((regparm(3), stdcall))
+#else
+# define DL_INTERNAL_FUNCTION
+#endif
+
+void InitTlsSize() {
+#ifndef SANITIZER_GO
+ typedef void (*get_tls_func)(size_t*, size_t*) DL_INTERNAL_FUNCTION;
+ get_tls_func get_tls;
+ void *get_tls_static_info_ptr = dlsym(RTLD_NEXT, "_dl_get_tls_static_info");
+ CHECK_EQ(sizeof(get_tls), sizeof(get_tls_static_info_ptr));
+ internal_memcpy(&get_tls, &get_tls_static_info_ptr,
+ sizeof(get_tls_static_info_ptr));
+ CHECK_NE(get_tls, 0);
+ size_t tls_size = 0;
+ size_t tls_align = 0;
+ get_tls(&tls_size, &tls_align);
+ g_tls_size = tls_size;
+#endif
+}
+
+uptr GetTlsSize() {
+ return g_tls_size;
+}
+
} // namespace __sanitizer
#endif // __linux__
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=176938&r1=176937&r2=176938&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Wed Mar 13 03:19:53 2013
@@ -326,6 +326,13 @@ void BlockingMutex::CheckLocked() {
CHECK_EQ((uptr)pthread_self(), owner_);
}
+uptr GetTlsSize() {
+ return 0;
+}
+
+void InitTlsSize() {
+}
+
} // namespace __sanitizer
#endif // __APPLE__
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=176938&r1=176937&r2=176938&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Wed Mar 13 03:19:53 2013
@@ -295,6 +295,13 @@ void BlockingMutex::CheckLocked() {
CHECK_EQ(owner_, GetThreadSelf());
}
+uptr GetTlsSize() {
+ return 0;
+}
+
+void InitTlsSize() {
+}
+
} // namespace __sanitizer
#endif // _WIN32
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt?rev=176938&r1=176937&r2=176938&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt Wed Mar 13 03:19:53 2013
@@ -56,7 +56,7 @@ macro(add_sanitizer_tests_for_arch arch)
-I${COMPILER_RT_SOURCE_DIR}/lib
-I${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common
-O2 -g -Wall -Werror ${TARGET_FLAGS})
- set(SANITIZER_TEST_LINK_FLAGS -lstdc++ -lpthread ${TARGET_FLAGS})
+ set(SANITIZER_TEST_LINK_FLAGS -lstdc++ -lpthread -ldl ${TARGET_FLAGS})
set(SANITIZER_TEST_OBJECTS)
foreach(source ${SANITIZER_TEST_SOURCES})
get_filename_component(basename ${source} NAME)
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h?rev=176938&r1=176937&r2=176938&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h Wed Mar 13 03:19:53 2013
@@ -148,7 +148,6 @@ void internal_start_thread(void(*func)(v
// Says whether the addr relates to a global var.
// Guesses with high probability, may yield both false positives and negatives.
bool IsGlobalVar(uptr addr);
-uptr GetTlsSize();
void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
uptr *tls_addr, uptr *tls_size);
int ExtractResolvFDs(void *state, int *fds, int nfd);
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc?rev=176938&r1=176937&r2=176938&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc Wed Mar 13 03:19:53 2013
@@ -167,27 +167,6 @@ static void InitDataSeg() {
CHECK_LT((uptr)&g_data_start, g_data_end);
}
-static uptr g_tls_size;
-
-#ifdef __i386__
-# define INTERNAL_FUNCTION __attribute__((regparm(3), stdcall))
-#else
-# define INTERNAL_FUNCTION
-#endif
-
-static int InitTlsSize() {
- typedef void (*get_tls_func)(size_t*, size_t*) INTERNAL_FUNCTION;
- get_tls_func get_tls;
- void *get_tls_static_info_ptr = dlsym(RTLD_NEXT, "_dl_get_tls_static_info");
- CHECK_EQ(sizeof(get_tls), sizeof(get_tls_static_info_ptr));
- internal_memcpy(&get_tls, &get_tls_static_info_ptr,
- sizeof(get_tls_static_info_ptr));
- CHECK_NE(get_tls, 0);
- size_t tls_size = 0;
- size_t tls_align = 0;
- get_tls(&tls_size, &tls_align);
- return tls_size;
-}
#endif // #ifndef TSAN_GO
static rlim_t getlim(int res) {
@@ -242,7 +221,7 @@ const char *InitializePlatform() {
#ifndef TSAN_GO
CheckPIE();
- g_tls_size = (uptr)InitTlsSize();
+ InitTlsSize();
InitDataSeg();
#endif
return GetEnv(kTsanOptionsEnv);
@@ -252,20 +231,12 @@ void FinalizePlatform() {
fflush(0);
}
-uptr GetTlsSize() {
-#ifndef TSAN_GO
- return g_tls_size;
-#else
- return 0;
-#endif
-}
-
void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
uptr *tls_addr, uptr *tls_size) {
#ifndef TSAN_GO
arch_prctl(ARCH_GET_FS, tls_addr);
- *tls_addr -= g_tls_size;
- *tls_size = g_tls_size;
+ *tls_size = GetTlsSize();
+ *tls_addr -= *tls_size;
uptr stack_top, stack_bottom;
GetThreadStackTopAndBottom(main, &stack_top, &stack_bottom);
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc?rev=176938&r1=176937&r2=176938&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc Wed Mar 13 03:19:53 2013
@@ -89,10 +89,6 @@ void FinalizePlatform() {
fflush(0);
}
-uptr GetTlsSize() {
- return 0;
-}
-
void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
uptr *tls_addr, uptr *tls_size) {
*stk_addr = 0;
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc?rev=176938&r1=176937&r2=176938&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc Wed Mar 13 03:19:53 2013
@@ -41,10 +41,6 @@ void FinalizePlatform() {
fflush(0);
}
-uptr GetTlsSize() {
- return 0;
-}
-
void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
uptr *tls_addr, uptr *tls_size) {
*stk_addr = 0;
More information about the llvm-commits
mailing list