0011-3.13-gh-131675-Fix-mi_atomic_yield-in-mimalloc-on-32.patch 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. From a9aae012b4ee83f1aba7c122943c63b69c5b9f97 Mon Sep 17 00:00:00 2001
  2. From: "Miss Islington (bot)"
  3. <31488909+miss-islington@users.noreply.github.com>
  4. Date: Mon, 31 Mar 2025 20:58:29 +0200
  5. Subject: [PATCH] [3.13] gh-131675: Fix `mi_atomic_yield` in mimalloc on 32-bit
  6. ARM (gh-131784) (gh-131954)
  7. Use the standard `__ARM_ARCH` macro, which is supported by GCC and Clang.
  8. The branching logic for of `__ARMEL__` has been removed so if the target
  9. architecture supports v7+ instructions, a yield is emitted, otherwise a nop
  10. is emitted. This covers both big and little endian scenarios.
  11. (cherry picked from commit 03f6c8e239723637811fd8d278661f5292351197)
  12. Upstream: https://github.com/python/cpython/pull/131954
  13. Signed-off-by: Vincent Fazio <vfazio@gmail.com>
  14. Co-authored-by: Vincent Fazio <vfazio@gmail.com>
  15. Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
  16. ---
  17. Include/internal/mimalloc/mimalloc/atomic.h | 17 ++++++++++-------
  18. ...25-03-27-01-21-50.gh-issue-131675.l2zfOO.rst | 1 +
  19. 2 files changed, 11 insertions(+), 7 deletions(-)
  20. create mode 100644 Misc/NEWS.d/next/Build/2025-03-27-01-21-50.gh-issue-131675.l2zfOO.rst
  21. diff --git a/Include/internal/mimalloc/mimalloc/atomic.h b/Include/internal/mimalloc/mimalloc/atomic.h
  22. index 1093c540864..a46a7676ad2 100644
  23. --- a/Include/internal/mimalloc/mimalloc/atomic.h
  24. +++ b/Include/internal/mimalloc/mimalloc/atomic.h
  25. @@ -338,8 +338,9 @@ static inline void mi_atomic_yield(void) {
  26. _mm_pause();
  27. }
  28. #elif (defined(__GNUC__) || defined(__clang__)) && \
  29. - (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__armel__) || defined(__ARMEL__) || \
  30. - defined(__aarch64__) || defined(__powerpc__) || defined(__ppc__) || defined(__PPC__)) || defined(__POWERPC__)
  31. + (defined(__x86_64__) || defined(__i386__) || \
  32. + defined(__aarch64__) || defined(__arm__) || \
  33. + defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(__POWERPC__))
  34. #if defined(__x86_64__) || defined(__i386__)
  35. static inline void mi_atomic_yield(void) {
  36. __asm__ volatile ("pause" ::: "memory");
  37. @@ -348,10 +349,16 @@ static inline void mi_atomic_yield(void) {
  38. static inline void mi_atomic_yield(void) {
  39. __asm__ volatile("wfe");
  40. }
  41. -#elif (defined(__arm__) && __ARM_ARCH__ >= 7)
  42. +#elif defined(__arm__)
  43. +#if __ARM_ARCH >= 7
  44. static inline void mi_atomic_yield(void) {
  45. __asm__ volatile("yield" ::: "memory");
  46. }
  47. +#else
  48. +static inline void mi_atomic_yield(void) {
  49. + __asm__ volatile ("nop" ::: "memory");
  50. +}
  51. +#endif
  52. #elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(__POWERPC__)
  53. #ifdef __APPLE__
  54. static inline void mi_atomic_yield(void) {
  55. @@ -362,10 +369,6 @@ static inline void mi_atomic_yield(void) {
  56. __asm__ __volatile__ ("or 27,27,27" ::: "memory");
  57. }
  58. #endif
  59. -#elif defined(__armel__) || defined(__ARMEL__)
  60. -static inline void mi_atomic_yield(void) {
  61. - __asm__ volatile ("nop" ::: "memory");
  62. -}
  63. #endif
  64. #elif defined(__sun)
  65. // Fallback for other archs
  66. diff --git a/Misc/NEWS.d/next/Build/2025-03-27-01-21-50.gh-issue-131675.l2zfOO.rst b/Misc/NEWS.d/next/Build/2025-03-27-01-21-50.gh-issue-131675.l2zfOO.rst
  67. new file mode 100644
  68. index 00000000000..be870a81df1
  69. --- /dev/null
  70. +++ b/Misc/NEWS.d/next/Build/2025-03-27-01-21-50.gh-issue-131675.l2zfOO.rst
  71. @@ -0,0 +1 @@
  72. +Fix mimalloc library builds for 32-bit ARM targets.
  73. --
  74. 2.34.1