Index: lib/libc/gen/Symbol.map =================================================================== --- lib/libc/gen/Symbol.map +++ lib/libc/gen/Symbol.map @@ -485,7 +485,6 @@ _pthread_sigmask; _pthread_testcancel; _spinlock; - _spinlock_debug; _spinunlock; _rtld_addr_phdr; _rtld_atfork_pre; Index: lib/libc/gen/_spinlock_stub.c =================================================================== --- lib/libc/gen/_spinlock_stub.c +++ lib/libc/gen/_spinlock_stub.c @@ -38,7 +38,6 @@ long _atomic_lock_stub(volatile long *); void _spinlock_stub(spinlock_t *); void _spinunlock_stub(spinlock_t *); -void _spinlock_debug_stub(spinlock_t *, char *, int); __weak_reference(_atomic_lock_stub, _atomic_lock); @@ -48,7 +47,6 @@ return (0L); } -__weak_reference(_spinlock, _spinlock_debug); #pragma weak _spinlock void _spinlock(spinlock_t *lck) Index: lib/libc/include/spinlock.h =================================================================== --- lib/libc/include/spinlock.h +++ lib/libc/include/spinlock.h @@ -41,21 +41,17 @@ * Lock structure with room for debugging information. */ struct _spinlock { - volatile long access_lock; - volatile long lock_owner; - volatile char *fname; - volatile int lineno; + long spare1; + long spare2; + void *thr_extra; + int spare3; }; typedef struct _spinlock spinlock_t; #define _SPINLOCK_INITIALIZER { 0, 0, 0, 0 } #define _SPINUNLOCK(_lck) _spinunlock(_lck); -#ifdef _LOCK_DEBUG -#define _SPINLOCK(_lck) _spinlock_debug(_lck, __FILE__, __LINE__) -#else #define _SPINLOCK(_lck) _spinlock(_lck) -#endif /* * Thread function prototype definitions: @@ -64,7 +60,6 @@ long _atomic_lock(volatile long *); void _spinlock(spinlock_t *); void _spinunlock(spinlock_t *); -void _spinlock_debug(spinlock_t *, char *, int); __END_DECLS #endif /* _SPINLOCK_H_ */ Index: lib/libthr/Makefile =================================================================== --- lib/libthr/Makefile +++ lib/libthr/Makefile @@ -16,7 +16,7 @@ LIB=thr SHLIB_MAJOR= 3 -WARNS?= 3 +NO_WTHREAD_SAFETY=1 CFLAGS+=-DPTHREAD_KERNEL CFLAGS+=-I${SRCTOP}/lib/libc/include -I${.CURDIR}/thread \ -I${SRCTOP}/include @@ -27,6 +27,12 @@ CFLAGS+=-I${SRCTOP}/lib/libthread_db CFLAGS+=-Winline +CFLAGS.thr_stack.c+= -Wno-cast-align +.include +.if !(${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} < 40300) +CFLAGS.thr_symbols.c+= -Wno-missing-variable-declarations +.endif + .ifndef NO_THREAD_UNWIND_STACK CFLAGS+=-fexceptions CFLAGS+=-D_PTHREAD_FORCED_UNWIND Index: lib/libthr/thread/thr_init.c =================================================================== --- lib/libthr/thread/thr_init.c +++ lib/libthr/thread/thr_init.c @@ -173,7 +173,6 @@ STATIC_LIB_REQUIRE(_sigwait); STATIC_LIB_REQUIRE(_sigwaitinfo); STATIC_LIB_REQUIRE(_spinlock); -STATIC_LIB_REQUIRE(_spinlock_debug); STATIC_LIB_REQUIRE(_spinunlock); STATIC_LIB_REQUIRE(_thread_init_hack); Index: lib/libthr/thread/thr_rwlock.c =================================================================== --- lib/libthr/thread/thr_rwlock.c +++ lib/libthr/thread/thr_rwlock.c @@ -49,27 +49,42 @@ __weak_reference(_pthread_rwlock_wrlock, pthread_rwlock_wrlock); __weak_reference(_pthread_rwlock_timedwrlock, pthread_rwlock_timedwrlock); -#define CHECK_AND_INIT_RWLOCK \ - if (*rwlock == THR_PSHARED_PTR) { \ - prwlock = __thr_pshared_offpage(rwlock, 0); \ - if (prwlock == NULL) \ - return (EINVAL); \ - } else if (__predict_false((prwlock = (*rwlock)) <= \ - THR_RWLOCK_DESTROYED)) { \ - if (prwlock == THR_RWLOCK_INITIALIZER) { \ - int ret; \ - ret = init_static(_get_curthread(), rwlock); \ - if (ret) \ - return (ret); \ - } else if (prwlock == THR_RWLOCK_DESTROYED) { \ - return (EINVAL); \ - } \ - prwlock = *rwlock; \ - } +static int init_static(struct pthread *thread, pthread_rwlock_t *rwlock); +static int init_rwlock(pthread_rwlock_t *rwlock, pthread_rwlock_t *rwlock_out); -/* - * Prototypes - */ +static int __always_inline +check_and_init_rwlock(pthread_rwlock_t *rwlock, pthread_rwlock_t *rwlock_out) +{ + if (__predict_false(*rwlock == THR_PSHARED_PTR || + *rwlock <= THR_RWLOCK_DESTROYED)) + return (init_rwlock(rwlock, rwlock_out)); + *rwlock_out = *rwlock; + return (0); +} + +static int __noinline +init_rwlock(pthread_rwlock_t *rwlock, pthread_rwlock_t *rwlock_out) +{ + pthread_rwlock_t prwlock; + int ret; + + if (*rwlock == THR_PSHARED_PTR) { + prwlock = __thr_pshared_offpage(rwlock, 0); + if (prwlock == NULL) + return (EINVAL); + } else if ((prwlock = *rwlock) <= THR_RWLOCK_DESTROYED) { + if (prwlock == THR_RWLOCK_INITIALIZER) { + ret = init_static(_get_curthread(), rwlock); + if (ret != 0) + return (ret); + } else if (prwlock == THR_RWLOCK_DESTROYED) { + return (EINVAL); + } + prwlock = *rwlock; + } + *rwlock_out = prwlock; + return (0); +} static int rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) @@ -148,7 +163,9 @@ int flags; int ret; - CHECK_AND_INIT_RWLOCK + ret = check_and_init_rwlock(rwlock, &prwlock); + if (ret != 0) + return (ret); if (curthread->rdlock_count) { /* @@ -220,7 +237,9 @@ int flags; int ret; - CHECK_AND_INIT_RWLOCK + ret = check_and_init_rwlock(rwlock, &prwlock); + if (ret != 0) + return (ret); if (curthread->rdlock_count) { /* @@ -253,7 +272,9 @@ pthread_rwlock_t prwlock; int ret; - CHECK_AND_INIT_RWLOCK + ret = check_and_init_rwlock(rwlock, &prwlock); + if (ret != 0) + return (ret); ret = _thr_rwlock_trywrlock(&prwlock->lock); if (ret == 0) @@ -268,7 +289,9 @@ pthread_rwlock_t prwlock; int ret; - CHECK_AND_INIT_RWLOCK + ret = check_and_init_rwlock(rwlock, &prwlock); + if (ret != 0) + return (ret); /* * POSIX said the validity of the abstimeout parameter need Index: lib/libthr/thread/thr_spinlock.c =================================================================== --- lib/libthr/thread/thr_spinlock.c +++ lib/libthr/thread/thr_spinlock.c @@ -65,7 +65,7 @@ { struct spinlock_extra *_extra; - _extra = (struct spinlock_extra *)lck->fname; + _extra = lck->thr_extra; THR_UMUTEX_UNLOCK(_get_curthread(), &_extra->lock); } @@ -78,9 +78,9 @@ PANIC("Spinlock called when not threaded."); if (!initialized) PANIC("Spinlocks not initialized."); - if (lck->fname == NULL) + if (lck->thr_extra == NULL) init_spinlock(lck); - _extra = (struct spinlock_extra *)lck->fname; + _extra = lck->thr_extra; THR_UMUTEX_LOCK(_get_curthread(), &_extra->lock); } @@ -90,14 +90,14 @@ struct pthread *curthread = _get_curthread(); THR_UMUTEX_LOCK(curthread, &spinlock_static_lock); - if ((lck->fname == NULL) && (spinlock_count < MAX_SPINLOCKS)) { - lck->fname = (char *)&extra[spinlock_count]; + if ((lck->thr_extra == NULL) && (spinlock_count < MAX_SPINLOCKS)) { + lck->thr_extra = &extra[spinlock_count]; _thr_umutex_init(&extra[spinlock_count].lock); extra[spinlock_count].owner = lck; spinlock_count++; } THR_UMUTEX_UNLOCK(curthread, &spinlock_static_lock); - if (lck->fname == NULL) + if (lck->thr_extra == NULL) PANIC("Warning: exceeded max spinlocks"); } Index: lib/libthr/thread/thr_stack.c =================================================================== --- lib/libthr/thread/thr_stack.c +++ lib/libthr/thread/thr_stack.c @@ -290,19 +290,6 @@ return (-1); } -/* - * Disable this warning from clang: - * - * cast from 'char *' to - * 'struct stack *' increases required alignment from 1 to 8 - * [-Werror,-Wcast-align] - * spare_stack = (struct stack *) - */ -#ifdef __clang__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" -#endif - /* This function must be called with _thread_list_lock held. */ void _thr_stack_free(struct pthread_attr *attr) @@ -329,7 +316,3 @@ attr->stackaddr_attr = NULL; } } - -#ifdef __clang__ -#pragma GCC diagnostic pop -#endif Index: lib/libthr/thread/thr_symbols.c =================================================================== --- lib/libthr/thread/thr_symbols.c +++ lib/libthr/thread/thr_symbols.c @@ -37,10 +37,6 @@ #include "thr_private.h" -#ifdef __clang__ -#pragma GCC diagnostic ignored "-Wmissing-variable-declarations" -#endif - /* A collection of symbols needed by debugger */ /* int _libthr_debug */