[compiler-rt] r198253 - Fix an ODR violation in the sanitizer runtimes.

Chandler Carruth chandlerc at gmail.com
Mon Dec 30 15:36:12 PST 2013


Author: chandlerc
Date: Mon Dec 30 17:36:11 2013
New Revision: 198253

URL: http://llvm.org/viewvc/llvm-project?rev=198253&view=rev
Log:
Fix an ODR violation in the sanitizer runtimes.

A helper function is a C++ function, and so even though one of the two
definitions is weak, it still technically triggers the ODR. Perhaps
these two definitions are ODR equivalent, but I'm not even confident in
that.

Instead, just define the function once, declare it as weak, and use
a wrapper that is clearly file-local. This avoids two definitions. Also
make the function extern "C" so that we can't even mess up the type
signature somehow or otherwise fail to match up the weak declaration
here with the interceptor defined elsewhere.

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=198253&r1=198252&r2=198253&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Mon Dec 30 17:36:11 2013
@@ -2586,7 +2586,8 @@ INTERCEPTOR(int, pthread_attr_getstack,
 // We may need to call the real pthread_attr_getstack from the run-time
 // in sanitizer_common, but we don't want to include the interception headers
 // there. So, just define this function here.
-int __sanitizer_pthread_attr_getstack(void *attr, void **addr, SIZE_T *size) {
+extern "C" int __sanitizer_pthread_attr_getstack(void *attr, void **addr,
+                                                 SIZE_T *size) {
   return REAL(pthread_attr_getstack)(attr, addr, size);
 }
 

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc?rev=198253&r1=198252&r2=198253&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc Mon Dec 30 17:36:11 2013
@@ -34,9 +34,15 @@
 #endif
 
 // This function is defined elsewhere if we intercepted pthread_attr_getstack.
-SANITIZER_WEAK_ATTRIBUTE
-int __sanitizer_pthread_attr_getstack(void *attr, void **addr, size_t *size) {
-  return pthread_attr_getstack((pthread_attr_t*)attr, addr, size);
+extern "C" SANITIZER_WEAK_ATTRIBUTE int
+__sanitizer_pthread_attr_getstack(void *attr, void **addr, size_t *size);
+
+static int my_pthread_attr_getstack(void *attr, void **addr, size_t *size) {
+  if (__sanitizer_pthread_attr_getstack)
+    return __sanitizer_pthread_attr_getstack((pthread_attr_t *)attr, addr,
+                                             size);
+
+  return pthread_attr_getstack((pthread_attr_t *)attr, addr, size);
 }
 
 namespace __sanitizer {
@@ -80,7 +86,7 @@ void GetThreadStackTopAndBottom(bool at_
   CHECK_EQ(pthread_getattr_np(pthread_self(), &attr), 0);
   uptr stacksize = 0;
   void *stackaddr = 0;
-  __sanitizer_pthread_attr_getstack(&attr, &stackaddr, (size_t*)&stacksize);
+  my_pthread_attr_getstack(&attr, &stackaddr, (size_t*)&stacksize);
   pthread_attr_destroy(&attr);
 
   CHECK_LE(stacksize, kMaxThreadStackSize);  // Sanity check.
@@ -276,7 +282,7 @@ void AdjustStackSizeLinux(void *attr_) {
   pthread_attr_t *attr = (pthread_attr_t *)attr_;
   uptr stackaddr = 0;
   size_t stacksize = 0;
-  __sanitizer_pthread_attr_getstack(attr, (void**)&stackaddr, &stacksize);
+  my_pthread_attr_getstack(attr, (void**)&stackaddr, &stacksize);
   // GLibC will return (0 - stacksize) as the stack address in the case when
   // stacksize is set, but stackaddr is not.
   bool stack_set = (stackaddr != 0) && (stackaddr + stacksize != 0);





More information about the llvm-commits mailing list