[PATCH] A fix for sanitizers' TLS support on FreeBSD

Viktor Kutuzov vkutuzov at accesssoftek.com
Tue Mar 18 05:24:54 PDT 2014


  Updated.

Hi kcc, samsonov,

http://llvm-reviews.chandlerc.com/D3099

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D3099?vs=7887&id=7910#toc

Files:
  lib/sanitizer_common/sanitizer_linux_libcdep.cc

Index: lib/sanitizer_common/sanitizer_linux_libcdep.cc
===================================================================
--- lib/sanitizer_common/sanitizer_linux_libcdep.cc
+++ lib/sanitizer_common/sanitizer_linux_libcdep.cc
@@ -105,6 +105,7 @@
     return;
   }
   pthread_attr_t attr;
+  pthread_attr_init(&attr);
   CHECK_EQ(pthread_getattr_np(pthread_self(), &attr), 0);
   uptr stacksize = 0;
   void *stackaddr = 0;
@@ -269,34 +270,16 @@
     trace[size++] = frames[i].absolute_pc + 2;
 }
 
+#if !SANITIZER_FREEBSD
 static uptr g_tls_size;
+#endif
 
 #ifdef __i386__
 # define DL_INTERNAL_FUNCTION __attribute__((regparm(3), stdcall))
 #else
 # define DL_INTERNAL_FUNCTION
 #endif
 
-void InitTlsSize() {
-#if !SANITIZER_ANDROID
-  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;
-  IndirectExternCall(get_tls)(&tls_size, &tls_align);
-  g_tls_size = tls_size;
-#endif
-}
-
-uptr GetTlsSize() {
-  return g_tls_size;
-}
-
 #if (defined(__x86_64__) || defined(__i386__)) && SANITIZER_LINUX
 // sizeof(struct thread) from glibc.
 static atomic_uintptr_t kThreadDescriptorSize;
@@ -405,6 +388,32 @@
 #endif
 }
 
+void InitTlsSize() {
+#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID
+  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;
+  IndirectExternCall(get_tls)(&tls_size, &tls_align);
+  g_tls_size = tls_size;
+#endif  // !SANITIZER_FREEBSD && !SANITIZER_ANDROID
+}
+
+uptr GetTlsSize() {
+#if SANITIZER_FREEBSD
+  uptr addr, size;
+  GetTls(&addr, &size);
+  return size;
+#else
+  return g_tls_size;
+#endif
+}
+
 void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
                           uptr *tls_addr, uptr *tls_size) {
   GetTls(tls_addr, tls_size);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3099.2.patch
Type: text/x-patch
Size: 2426 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140318/befa92be/attachment.bin>


More information about the llvm-commits mailing list