Created attachment 12096 [details]
Clang has a facility for warning about access to variables or functions without the appropriate locking. This is very useful for multithreaded applications.
But it needs annotations on the type pthread_mutex_t and the functions pthread_mutex_lock and pthread_mutex_unlock. The user cannot provide the annotation on the type pthread_mutex_t, because that would require redefining the type pthread_mutex_t. So it must be done in the libc header files.
1) A test case that shows the warning in a demo program.
2) A patch to current glibc that implements the required annotations.
Later, the same thing could be done for pthread_rwlock_t.
Created attachment 12097 [details]
In general this sort of macro definition goes in sys/cdefs.h if possible
rather than scattering such compiler feature tests around other installed
headers. Any kind of attributes used in installed headers need to be
namespace-clean, so e.g. __acquire_capability__ not acquire_capability and
likewise for other names used.
Created attachment 12098 [details]
proposed patch v2
Find the issues addressed in the attached proposed patch.
The minimum clang version is increased from 4 to 5, because __acquire_capability__ with surrounding underscores was not supported from the beginning.
I'm not in a position to rebuild the full glibc and do regression testing on it; if someone could do it for me, please?