Enable broken_threadlocal_dtors for VxWorks

Changes applied in commit 4fabde349f16b59f37568da2a4c050c6dd53a34e broke
VxWorks tests and examples, many of which crash with error:
```
pthreadLib: unable to create POSIX thread internal attributes.
```

This error appeared in multiple tests, but was tested on tst_QSignalSpy,
where it was 100% reproducible (I haven't check other tests for
reproducibility).

This above error is printed when VxWorks task starts and initializes its
pthread containers. Pthread starting procedure results in error
`S_objLib_OBJ_ID_ERROR`, on which documentation states that it means
"The <tid> parameter is an invalid task ID". This happens because
VxWorks pthread implementation clears its internal data, and only then
passes control to `taskExit` system procedure, which calls thread_local
destructors. Any calls to `pthread` routines which require current
thread internal data ends with error and termination.

While VxWorks uses clang internally, it implements `__cxa_thread_atexit`
and `__cxa_thread_atexit_impl`, which makes it pass `TEST_cxa_atexit` in
CMake, even thou their call order is different than on other platforms.

Enable QT_FEATURE_broken_threadlocal_dtors for VxWorks by failing
compilation of cxa_thread_atexit* tests, which fixes the crashes on
VxWorks.

Task-number: QTBUG-115777
Change-Id: I4109b66903333a94301afe7fe5634ac4365a70b4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Michał Łoś 2024-10-31 11:08:59 +01:00
parent dc1ae86bad
commit a295f4f913
2 changed files with 14 additions and 1 deletions

View File

@ -2,6 +2,19 @@
// SPDX-License-Identifier: BSD-3-Clause
#include <stddef.h>
#if defined(__vxworks) || defined(__VXWORKS__)
/*
* In VxWorks pthread implementation, when thread is finishing it calls pthread_exit(), which:
* - calls pthread cleanup procedure
* - clears pthread data (setting current thread to null)
* - calls `taskExit` VxWorks system procedure
* `taskExit` procedure calls thread_local object destructors, which if call directly or indirectly
* `pthread_self()`, terminate with error, due to not being able to obtain pthread entity.
* Thus, we need to treat VxWorks pthread implementation as `broken` in terms of thread_local variables.
*/
# error "VxWorks threadlocal destructors are called after pthread data is destroyed, causing crash."
#endif
typedef void (*dtor_func) (void *);
int TEST_FUNC(dtor_func func, void *obj, void *dso_symbol);
int main()

View File

@ -615,7 +615,7 @@ qt_feature("cxx17_filesystem" PUBLIC
)
qt_feature("broken-threadlocal-dtors" PRIVATE
LABEL "Broken execution of thread_local destructors at exit() time"
# Windows broken in different ways from Unix
# Windows is broken in different ways from Unix
CONDITION WIN32 OR NOT (TEST_cxa_thread_atexit OR TEST_cxa_thread_atexit_impl)
)
qt_feature("dladdr" PRIVATE