Index: lib/libc/include/spinlock.h =================================================================== --- lib/libc/include/spinlock.h +++ lib/libc/include/spinlock.h @@ -43,7 +43,7 @@ struct _spinlock { volatile long access_lock; volatile long lock_owner; - volatile char *fname; + void *fname; volatile int lineno; }; typedef struct _spinlock spinlock_t; Index: lib/libthr/Makefile =================================================================== --- lib/libthr/Makefile +++ lib/libthr/Makefile @@ -16,7 +16,6 @@ LIB=thr SHLIB_MAJOR= 3 -WARNS?= 3 CFLAGS+=-DPTHREAD_KERNEL CFLAGS+=-I${SRCTOP}/lib/libc/include -I${.CURDIR}/thread \ -I${SRCTOP}/include Index: lib/libthr/thread/thr_attr.c =================================================================== --- lib/libthr/thread/thr_attr.c +++ lib/libthr/thread/thr_attr.c @@ -607,7 +607,7 @@ /* Kernel checks invalid bits, we check it here too. */ size_t i; for (i = kern_size; i < cpusetsize; ++i) { - if (((char *)cpusetp)[i]) + if (((const char *)cpusetp)[i]) return (EINVAL); } } Index: lib/libthr/thread/thr_exit.c =================================================================== --- lib/libthr/thread/thr_exit.c +++ lib/libthr/thread/thr_exit.c @@ -119,7 +119,8 @@ #endif /* PIC */ static void -thread_unwind_cleanup(_Unwind_Reason_Code code, struct _Unwind_Exception *e) +thread_unwind_cleanup(_Unwind_Reason_Code code __unused, + struct _Unwind_Exception *e __unused) { /* * Specification said that _Unwind_Resume should not be used here, @@ -130,10 +131,10 @@ } static _Unwind_Reason_Code -thread_unwind_stop(int version, _Unwind_Action actions, - int64_t exc_class, - struct _Unwind_Exception *exc_obj, - struct _Unwind_Context *context, void *stop_parameter) +thread_unwind_stop(int version __unused, _Unwind_Action actions, + int64_t exc_class __unused, + struct _Unwind_Exception *exc_obj __unused, + struct _Unwind_Context *context, void *stop_parameter __unused) { struct pthread *curthread = _get_curthread(); struct pthread_cleanup *cur; Index: lib/libthr/thread/thr_mutex.c =================================================================== --- lib/libthr/thread/thr_mutex.c +++ lib/libthr/thread/thr_mutex.c @@ -760,6 +760,17 @@ return (ret); } +/* + * Disable the following warnings from clang: + * + * _pthread_mutex_unlock: error: mutex '__mutex' is still held + * at the end of function [-Werror,-Wthread-safety-analysis] + */ +#ifdef __clang__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wthread-safety-analysis" +#endif + int _pthread_mutex_unlock(pthread_mutex_t *mutex) { @@ -776,6 +787,10 @@ return (mutex_unlock_common(mp, false, NULL)); } +#ifdef __clang__ +#pragma GCC diagnostic pop +#endif + int _mutex_cv_lock(struct pthread_mutex *m, int count, bool rb_onlist) { Index: lib/libthr/thread/thr_pspinlock.c =================================================================== --- lib/libthr/thread/thr_pspinlock.c +++ lib/libthr/thread/thr_pspinlock.c @@ -108,6 +108,20 @@ return (THR_UMUTEX_TRYLOCK(_get_curthread(), &lck->s_lock)); } +/* + * Disable the following warnings from clang: + * + * _pthread_spin_lock: error: expecting mutex '__spin' to be held + * at the end of function [-Werror,-Wthread-safety-analysis] + * + * _pthread_spin_unlock: error: mutex '__spin' is still held + * at the end of function [-Werror,-Wthread-safety-analysis] + */ +#ifdef __clang__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wthread-safety-analysis" +#endif + int _pthread_spin_lock(pthread_spinlock_t *lock) { @@ -151,3 +165,7 @@ return (EINVAL); return (THR_UMUTEX_UNLOCK(_get_curthread(), &lck->s_lock)); } + +#ifdef __clang__ +#pragma GCC diagnostic pop +#endif Index: lib/libthr/thread/thr_rwlock.c =================================================================== --- lib/libthr/thread/thr_rwlock.c +++ lib/libthr/thread/thr_rwlock.c @@ -57,10 +57,10 @@ } 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); \ + int __ret; \ + __ret = init_static(_get_curthread(), rwlock); \ + if (__ret) \ + return (__ret); \ } else if (prwlock == THR_RWLOCK_DESTROYED) { \ return (EINVAL); \ } \ @@ -199,12 +199,27 @@ return (ret); } +/* + * Disable the following warnings from clang: + * + * _pthread_rwlock_rdlock: error: expecting mutex '__rwlock' + * to be held at the end of function [-Werror,-Wthread-safety-analysis] + */ +#ifdef __clang__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wthread-safety-analysis" +#endif + int _pthread_rwlock_rdlock (pthread_rwlock_t *rwlock) { return (rwlock_rdlock_common(rwlock, NULL)); } +#ifdef __clang__ +#pragma GCC diagnostic pop +#endif + int _pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock, const struct timespec *abstime) @@ -305,12 +320,27 @@ return (ret); } +/* + * Disable the following warnings from clang: + * + * _pthread_rwlock_wrlock: error: expecting mutex '__rwlock' + * to be held at the end of function [-Werror,-Wthread-safety-analysis] + */ +#ifdef __clang__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wthread-safety-analysis" +#endif + int _pthread_rwlock_wrlock (pthread_rwlock_t *rwlock) { return (rwlock_wrlock_common (rwlock, NULL)); } +#ifdef __clang__ +#pragma GCC diagnostic pop +#endif + int _pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock, const struct timespec *abstime) @@ -318,6 +348,17 @@ return (rwlock_wrlock_common (rwlock, abstime)); } +/* + * Disable the following warnings from clang: + * + * _pthread_rwlock_unlock: error: mutex '__rwlock' is still + * held at the end of function [-Werror,-Wthread-safety-analysis] + */ +#ifdef __clang__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wthread-safety-analysis" +#endif + int _pthread_rwlock_unlock(pthread_rwlock_t *rwlock) { @@ -350,3 +391,7 @@ return (ret); } + +#ifdef __clang__ +#pragma GCC diagnostic pop +#endif Index: lib/libthr/thread/thr_sig.c =================================================================== --- lib/libthr/thread/thr_sig.c +++ lib/libthr/thread/thr_sig.c @@ -441,7 +441,7 @@ } void -_thr_sigact_unload(struct dl_phdr_info *phdr_info) +_thr_sigact_unload(struct dl_phdr_info *phdr_info __unused) { #if 0 struct pthread *curthread = _get_curthread(); Index: lib/libthr/thread/thr_spec.c =================================================================== --- lib/libthr/thread/thr_spec.c +++ lib/libthr/thread/thr_spec.c @@ -42,7 +42,7 @@ #include "thr_private.h" -struct pthread_key _thread_keytable[PTHREAD_KEYS_MAX]; +static struct pthread_key _thread_keytable[PTHREAD_KEYS_MAX]; __weak_reference(_pthread_key_create, pthread_key_create); __weak_reference(_pthread_key_delete, pthread_key_delete); 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->fname; THR_UMUTEX_UNLOCK(_get_curthread(), &_extra->lock); } @@ -80,7 +80,7 @@ PANIC("Spinlocks not initialized."); if (lck->fname == NULL) init_spinlock(lck); - _extra = (struct spinlock_extra *)lck->fname; + _extra = lck->fname; THR_UMUTEX_LOCK(_get_curthread(), &_extra->lock); } @@ -91,7 +91,7 @@ THR_UMUTEX_LOCK(curthread, &spinlock_static_lock); if ((lck->fname == NULL) && (spinlock_count < MAX_SPINLOCKS)) { - lck->fname = (char *)&extra[spinlock_count]; + lck->fname = &extra[spinlock_count]; _thr_umutex_init(&extra[spinlock_count].lock); extra[spinlock_count].owner = lck; spinlock_count++; Index: lib/libthr/thread/thr_stack.c =================================================================== --- lib/libthr/thread/thr_stack.c +++ lib/libthr/thread/thr_stack.c @@ -290,6 +290,19 @@ 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) @@ -316,3 +329,7 @@ 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,6 +37,10 @@ #include "thr_private.h" +#ifdef __clang__ +#pragma GCC diagnostic ignored "-Wmissing-variable-declarations" +#endif + /* A collection of symbols needed by debugger */ /* int _libthr_debug */ Index: lib/libthr/thread/thr_umtx.h =================================================================== --- lib/libthr/thread/thr_umtx.h +++ lib/libthr/thread/thr_umtx.h @@ -44,7 +44,7 @@ int __thr_umutex_lock_spin(struct umutex *mtx, uint32_t id) __hidden; int __thr_umutex_timedlock(struct umutex *mtx, uint32_t id, const struct timespec *timeout) __hidden; -int __thr_umutex_unlock(struct umutex *mtx, uint32_t id) __hidden; +int __thr_umutex_unlock(struct umutex *mtx) __hidden; int __thr_umutex_trylock(struct umutex *mtx) __hidden; int __thr_umutex_set_ceiling(struct umutex *mtx, uint32_t ceiling, uint32_t *oldceiling) __hidden; @@ -155,7 +155,7 @@ if (atomic_cmpset_rel_32(&mtx->m_owner, id, noncst ? UMUTEX_RB_NOTRECOV : UMUTEX_UNOWNED)) return (0); - return (__thr_umutex_unlock(mtx, id)); + return (__thr_umutex_unlock(mtx)); } do { Index: lib/libthr/thread/thr_umtx.c =================================================================== --- lib/libthr/thread/thr_umtx.c +++ lib/libthr/thread/thr_umtx.c @@ -168,7 +168,7 @@ } int -__thr_umutex_unlock(struct umutex *mtx, uint32_t id) +__thr_umutex_unlock(struct umutex *mtx) { return (_umtx_op_err(mtx, UMTX_OP_MUTEX_UNLOCK, 0, 0, 0));