From a989fb5ce7cfbb99342fe3360ed51975a57ca398 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 30 Dec 2013 23:36:11 +0000 Subject: [PATCH] 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. llvm-svn: 198253 --- .../sanitizer_common/sanitizer_common_interceptors.inc | 3 ++- .../lib/sanitizer_common/sanitizer_linux_libcdep.cc | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index becf67c..05ed8cf 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -2586,7 +2586,8 @@ INTERCEPTOR(int, pthread_attr_getstack, void *attr, void **addr, SIZE_T *size) { // 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); } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc index cd256e9..9a6dfe2 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -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_initialization, uptr *stack_top, 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); -- 2.7.4