summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2013-12-30 23:36:11 +0000
committerChandler Carruth <chandlerc@gmail.com>2013-12-30 23:36:11 +0000
commita989fb5ce7cfbb99342fe3360ed51975a57ca398 (patch)
treee749163520af667cf26aacd929bc96dc4b151bfe
parent35d8703dbe89f717ef6c71b35e4b29aa51bbd7a7 (diff)
downloadbcm5719-llvm-a989fb5ce7cfbb99342fe3360ed51975a57ca398.tar.gz
bcm5719-llvm-a989fb5ce7cfbb99342fe3360ed51975a57ca398.zip
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
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc3
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc16
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 becf67c77be..05ed8cf701f 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 cd256e913c8..9a6dfe29653 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);
OpenPOWER on IntegriCloud