Use the compiler builtin for the ARM thread id.

The mrc to c13/c0/3 (thread id register) is undefined on ARMv5 (e.g.
ARM926EJ-S) and SIGILL'd during init. __builtin_thread_pointer lowers
to the same mrc on targets with a thread pointer register and to
__aeabi_read_tp on soft-TLS targets.
This commit is contained in:
Bartosz Taudul
2026-08-18 22:34:01 +02:00
parent a4b51631ed
commit fee9285d68

View File

@@ -743,7 +743,7 @@ get_thread_id(void) {
__asm__("movq %%fs:0, %0" : "=r" (tid) : : );
# endif
# elif defined(__arm__)
__asm__ volatile ("mrc p15, 0, %0, c13, c0, 3" : "=r" (tid));
tid = (uintptr_t)__builtin_thread_pointer();
# elif defined(__aarch64__)
# if defined(__MACH__)
// tpidr_el0 likely unused, always return 0 on iOS