[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
once: Fix pthread-rwlock crashes with clang
From: |
Bruno Haible |
Subject: |
once: Fix pthread-rwlock crashes with clang |
Date: |
Sat, 17 Aug 2024 15:18:26 +0200 |
In continuous integration builds with clang (both an old clang 7
and a new clang 18 or 19-pre), I see three test failures:
FAIL: test-call_once2
FAIL: test-rwlock1
FAIL: test-lock
What's happening, is that clang, in the compilation unit of
glthread/lock.c, interprets the statements
#pragma weak pthread_rwlockattr_init
#pragma weak pthread_rwlock_init
as if they were
#pragma weak rpl_pthread_rwlockattr_init
#pragma weak rpl_pthread_rwlock_init
The first consequence is that 'nm glthread/lock.c' shows
w rpl_pthread_rwlockattr_init
w rpl_pthread_rwlock_init
instead of
U rpl_pthread_rwlockattr_init
U rpl_pthread_rwlock_init
The next consequence is that at link time, pthread-rwlock.o is not included.
The final consequence is that at run time, rpl_pthread_rwlockattr_init and
rpl_pthread_rwlock_init resolve to NULL pointers, and the function
glthread_rwlock_init_for_glibc thus crashes.
This patch works around it.
2024-08-17 Bruno Haible <bruno@clisp.org>
once: Fix pthread-rwlock crashes with clang (regr. 2024-08-07).
* lib/glthread/once.h: Don't mark pthread_rwlock_init,
pthread_rwlockattr_init as weak if we are overriding them.
diff --git a/lib/glthread/once.h b/lib/glthread/once.h
index fd00e42350..2452f88dc1 100644
--- a/lib/glthread/once.h
+++ b/lib/glthread/once.h
@@ -124,7 +124,10 @@ extern int glthread_in_use (void);
# pragma weak pthread_mutex_lock
# pragma weak pthread_mutex_unlock
# pragma weak pthread_mutex_destroy
-# pragma weak pthread_rwlock_init
+/* Work around clang bug <https://github.com/llvm/llvm-project/issues/104670>
*/
+# ifndef pthread_rwlock_init
+# pragma weak pthread_rwlock_init
+# endif
# pragma weak pthread_rwlock_rdlock
# pragma weak pthread_rwlock_wrlock
# pragma weak pthread_rwlock_unlock
@@ -138,7 +141,10 @@ extern int glthread_in_use (void);
# pragma weak pthread_mutexattr_init
# pragma weak pthread_mutexattr_settype
# pragma weak pthread_mutexattr_destroy
-# pragma weak pthread_rwlockattr_init
+/* Work around clang bug <https://github.com/llvm/llvm-project/issues/104670>
*/
+# ifndef pthread_rwlockattr_init
+# pragma weak pthread_rwlockattr_init
+# endif
# if __GNU_LIBRARY__ > 1
# pragma weak pthread_rwlockattr_setkind_np
# endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- once: Fix pthread-rwlock crashes with clang,
Bruno Haible <=