Build problem due to pthread_setspecific and pj_thread_register with picky compiler
Describe the bug
Get compilation problem when building an application using pjsip.
In function 'pj_thread_local_set', | inlined from 'suspend_logging' at ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/log.c:287:2, | inlined from 'pj_log' at ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/log.c:355:5: | ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c:1192:12: warning: 'pthread_setspecific' expecting 1 byte in a region of size 0 [-Wstringop-overread] | ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c: In function 'pj_log': | /usr/include/pthread.h:1308:12: note: in a call to function 'pthread_setspecific' declared with attribute 'access (none, 2)' | In function 'pj_thread_init', | inlined from 'pj_thread_init' at ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c:601:13, | inlined from 'pj_init' at ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c:185:13: | ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c:611:12: warning: 'pj_thread_register' accessing 256 bytes in a region of size 56 [-Wstringop-overflow=] | ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c: In function 'pj_init': | ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c:611:12: note: referencing argument 2 of type 'long int *' | ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c:526:21: note: in a call to function 'pj_thread_register'
Steps to reproduce
Building our application that uses pjsip.
One issue is resolved by using a pj_thread_desc instead of pj_thread_t:
--- a/pjlib/src/pj/os_core_unix.c
+++ b/pjlib/src/pj/os_core_unix.c
@@ -147,7 +147,8 @@ struct pj_event_t
static int initialized;
#if PJ_HAS_THREADS
- static pj_thread_t main_thread;
+ static pj_thread_desc main_thread;
static long thread_tls_id;
static pj_mutex_t critical_section;
Another issue seems to be fixed with:
--- a/pjlib/src/pj/log.c
+++ b/pjlib/src/pj/log.c
@@ -284,8 +284,9 @@ static void suspend_logging(int *saved_level)
#if PJ_HAS_THREADS
if (thread_suspended_tls_id != -1)
{
- pj_thread_local_set(thread_suspended_tls_id,
- (void*)(pj_ssize_t)PJ_TRUE);
+ static int suspend_log = PJ_TRUE;
+ pj_thread_local_set(thread_suspended_tls_id, &suspend_log);
}
else
#endif
PJSIP version
2.12
Context
Build using bitbake on Linux.
Log, call stack, etc
In function 'pj_thread_local_set',
| inlined from 'suspend_logging' at ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/log.c:287:2,
| inlined from 'pj_log' at ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/log.c:355:5:
| ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c:1192:12: warning: 'pthread_setspecific' expecting 1 byte in a region of size 0 [-Wstringop-overread]
| ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c: In function 'pj_log':
| /usr/include/pthread.h:1308:12: note: in a call to function 'pthread_setspecific' declared with attribute 'access (none, 2)'
| In function 'pj_thread_init',
| inlined from 'pj_thread_init' at ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c:601:13,
| inlined from 'pj_init' at ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c:185:13:
| ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c:611:12: warning: 'pj_thread_register' accessing 256 bytes in a region of size 56 [-Wstringop-overflow=]
| ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c: In function 'pj_init':
| ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c:611:12: note: referencing argument 2 of type 'long int *'
| ../../../pjproject/2.12-r0/pjproject-2.12/pjlib/build/../src/pj/os_core_unix.c:526:21: note: in a call to function 'pj_thread_register'
@johado Would you be able to create a pull request for this, then pjproject team can review it.
Created https://github.com/pjsip/pjproject/pull/3071