Skip to content

Commit feda9aa

Browse files
authored
gh-125444: Fix illegal instruction for older Arm architectures (#125574)
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.
1 parent 51410d8 commit feda9aa

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

Include/internal/mimalloc/mimalloc/prim.h

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ _Py_ThreadId(void)
192192
__asm__("movq %%gs:0, %0" : "=r" (tid)); // x86_64 macOSX uses GS
193193
#elif defined(__x86_64__)
194194
__asm__("movq %%fs:0, %0" : "=r" (tid)); // x86_64 Linux, BSD uses FS
195-
#elif defined(__arm__)
195+
#elif defined(__arm__) && __ARM_ARCH >= 7
196196
__asm__ ("mrc p15, 0, %0, c13, c0, 3\nbic %0, %0, #3" : "=r" (tid));
197197
#elif defined(__aarch64__) && defined(__APPLE__)
198198
__asm__ ("mrs %0, tpidrro_el0" : "=r" (tid));
Lines changed: 1 addition & 0 deletions
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)