From f7152a4bb78676cb211ac3c3e1e59aa53a307491 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 3 May 2022 10:10:07 -0700 Subject: QThread: re-fix currentThreadId() on Linux Commit 1808df9ce59a8c1d426f0361e25120a7852a6442 changed the Linux code to read the third field in the TCB header instead of the first, because that matches what FreeBSD does and what the documentation for the ABI appears to say. But it broke MUSL builds because they apparently don't obey the ABI. So don't use the inline code with libcs other than glibc. Pick-to: 6.2 6.3 Task-number: QTBUG-103000 Change-Id: I5ff8e16fcdcb4ffd9ab6fffd16eba7748de50ddd Reviewed-by: Volker Hilsheimer Reviewed-by: Mike Achtelik --- src/corelib/thread/qthread.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib/thread/qthread.h') diff --git a/src/corelib/thread/qthread.h b/src/corelib/thread/qthread.h index 45c5ab9487..934db4f7c3 100644 --- a/src/corelib/thread/qthread.h +++ b/src/corelib/thread/qthread.h @@ -191,12 +191,12 @@ inline Qt::HANDLE QThread::currentThreadId() noexcept Qt::HANDLE tid; // typedef to void* static_assert(sizeof(tid) == sizeof(void*)); // See https://akkadia.org/drepper/tls.pdf for x86 ABI -#if defined(Q_PROCESSOR_X86_32) && defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) // x86 32-bit always uses GS +#if defined(Q_PROCESSOR_X86_32) && defined(Q_OS_LINUX) && defined(__GLIBC__) // x86 32-bit always uses GS __asm__("movl %%gs:%c1, %0" : "=r" (tid) : "i" (2 * sizeof(void*)) : ); #elif defined(Q_PROCESSOR_X86_64) && defined(Q_OS_DARWIN64) // 64bit macOS uses GS, see https://github.com/apple/darwin-xnu/blob/master/libsyscall/os/tsd.h __asm__("movq %%gs:0, %0" : "=r" (tid) : : ); -#elif defined(Q_PROCESSOR_X86_64) && (defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)) && !defined(Q_OS_ANDROID) +#elif defined(Q_PROCESSOR_X86_64) && (defined(Q_OS_LINUX) && defined(__GLIBC__)) || defined(Q_OS_FREEBSD) // x86_64 Linux, BSD uses FS __asm__("movq %%fs:%c1, %0" : "=r" (tid) : "i" (2 * sizeof(void*)) : ); #elif defined(Q_PROCESSOR_X86_64) && defined(Q_OS_WIN) -- cgit v1.2.3