Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 93eba4f

Browse files
committed
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. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@198253 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 1adb1db commit 93eba4f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2586,7 +2586,8 @@ INTERCEPTOR(int, pthread_attr_getstack, void *attr, void **addr, SIZE_T *size) {
25862586
// We may need to call the real pthread_attr_getstack from the run-time
25872587
// in sanitizer_common, but we don't want to include the interception headers
25882588
// there. So, just define this function here.
2589-
int __sanitizer_pthread_attr_getstack(void *attr, void **addr, SIZE_T *size) {
2589+
extern "C" int __sanitizer_pthread_attr_getstack(void *attr, void **addr,
2590+
SIZE_T *size) {
25902591
return REAL(pthread_attr_getstack)(attr, addr, size);
25912592
}
25922593

lib/sanitizer_common/sanitizer_linux_libcdep.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,15 @@
3434
#endif
3535

3636
// This function is defined elsewhere if we intercepted pthread_attr_getstack.
37-
SANITIZER_WEAK_ATTRIBUTE
38-
int __sanitizer_pthread_attr_getstack(void *attr, void **addr, size_t *size) {
39-
return pthread_attr_getstack((pthread_attr_t*)attr, addr, size);
37+
extern "C" SANITIZER_WEAK_ATTRIBUTE int
38+
__sanitizer_pthread_attr_getstack(void *attr, void **addr, size_t *size);
39+
40+
static int my_pthread_attr_getstack(void *attr, void **addr, size_t *size) {
41+
if (__sanitizer_pthread_attr_getstack)
42+
return __sanitizer_pthread_attr_getstack((pthread_attr_t *)attr, addr,
43+
size);
44+
45+
return pthread_attr_getstack((pthread_attr_t *)attr, addr, size);
4046
}
4147

4248
namespace __sanitizer {
@@ -80,7 +86,7 @@ void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
8086
CHECK_EQ(pthread_getattr_np(pthread_self(), &attr), 0);
8187
uptr stacksize = 0;
8288
void *stackaddr = 0;
83-
__sanitizer_pthread_attr_getstack(&attr, &stackaddr, (size_t*)&stacksize);
89+
my_pthread_attr_getstack(&attr, &stackaddr, (size_t*)&stacksize);
8490
pthread_attr_destroy(&attr);
8591

8692
CHECK_LE(stacksize, kMaxThreadStackSize); // Sanity check.
@@ -276,7 +282,7 @@ void AdjustStackSizeLinux(void *attr_) {
276282
pthread_attr_t *attr = (pthread_attr_t *)attr_;
277283
uptr stackaddr = 0;
278284
size_t stacksize = 0;
279-
__sanitizer_pthread_attr_getstack(attr, (void**)&stackaddr, &stacksize);
285+
my_pthread_attr_getstack(attr, (void**)&stackaddr, &stacksize);
280286
// GLibC will return (0 - stacksize) as the stack address in the case when
281287
// stacksize is set, but stackaddr is not.
282288
bool stack_set = (stackaddr != 0) && (stackaddr + stacksize != 0);

0 commit comments

Comments
 (0)