Skip to content

Commit 18b9079

Browse files
[3.13] pythongh-125444: Fix illegal instruction for older Arm architectures (pythonGH-125574) (pythonGH-125595)
On Arm v5 it is not possible to get the thread ID via c13 register hence the illegal instruction. The c13 register started to provide thread ID since Arm v6K architecture variant. Other variants of Arm v6 (T2, Z and base) don’t provide the thread ID via c13. For the sake of simplicity we group v5 and v6 together and consider that instructions for Arm v7 only. (cherry picked from commit feda9aa) Co-authored-by: Diego Russo <[email protected]>
1 parent e3ae564 commit 18b9079

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

Include/internal/mimalloc/mimalloc/prim.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept {
151151
// If you test on another platform and it works please send a PR :-)
152152
// see also https://akkadia.org/drepper/tls.pdf for more info on the TLS register.
153153
#elif defined(__GNUC__) && ( \
154-
(defined(__GLIBC__) && (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__))) \
154+
(defined(__GLIBC__) && (defined(__x86_64__) || defined(__i386__) || (defined(__arm__) && __ARM_ARCH >= 7) || defined(__aarch64__))) \
155155
|| (defined(__APPLE__) && (defined(__x86_64__) || defined(__aarch64__))) \
156-
|| (defined(__BIONIC__) && (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__))) \
156+
|| (defined(__BIONIC__) && (defined(__x86_64__) || defined(__i386__) || (defined(__arm__) && __ARM_ARCH >= 7) || defined(__aarch64__))) \
157157
|| (defined(__FreeBSD__) && (defined(__x86_64__) || defined(__i386__) || defined(__aarch64__))) \
158158
|| (defined(__OpenBSD__) && (defined(__x86_64__) || defined(__i386__) || defined(__aarch64__))) \
159159
)

Include/object.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ _Py_ThreadId(void)
259259
__asm__("movq %%gs:0, %0" : "=r" (tid)); // x86_64 macOSX uses GS
260260
#elif defined(__x86_64__)
261261
__asm__("movq %%fs:0, %0" : "=r" (tid)); // x86_64 Linux, BSD uses FS
262-
#elif defined(__arm__)
262+
#elif defined(__arm__) && __ARM_ARCH >= 7
263263
__asm__ ("mrc p15, 0, %0, c13, c0, 3\nbic %0, %0, #3" : "=r" (tid));
264264
#elif defined(__aarch64__) && defined(__APPLE__)
265265
__asm__ ("mrs %0, tpidrro_el0" : "=r" (tid));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix illegal instruction for older Arm architectures. Patch by Diego Russo, testing by Ross Burton.

0 commit comments

Comments
 (0)