From b716501e14f4b2c99ab50263fe1f1d56aed4f2b8 Mon Sep 17 00:00:00 2001 From: Vincent Fazio Date: Wed, 26 Mar 2025 19:07:20 -0500 Subject: [PATCH 1/4] mimalloc: fix mi_atomic_yield on 32-bit ARM Previously, `mi_atomic_yield` for 32-bit ARM: * Used a non-standard __ARM_ARCH__ macro to determine if the compiler was targeting ARMv7+ in order to emit a `yield` instruction, however it was often not defined so fell through to an `__armel__` branch * Had a logic gap in the #ifdef where an `__arm__` target would be expected to emit `mi_atomic_yield` but there was no condition to define a function for big-endian targets Now, the standard ACLE __ARM_ARCH macro [1] [2] is used which GCC and Clang support. The branching logic for `__armel__` has been removed so if the target architecture supports v7+ instructions, a `yield` is emitted, otherwise a `nop` is emitted. This covers both big and little endian scenarios. [1]: https://arm-software.github.io/acle/main/acle.html#arm-architecture-level [2]: https://arm-software.github.io/acle/main/acle.html#mapping-of-object-build-attributes-to-predefines Signed-off-by: Vincent Fazio --- Include/internal/mimalloc/mimalloc/atomic.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Include/internal/mimalloc/mimalloc/atomic.h b/Include/internal/mimalloc/mimalloc/atomic.h index cdd9c372beafd5..6a85fec0d453f4 100644 --- a/Include/internal/mimalloc/mimalloc/atomic.h +++ b/Include/internal/mimalloc/mimalloc/atomic.h @@ -338,7 +338,7 @@ static inline void mi_atomic_yield(void) { _mm_pause(); } #elif (defined(__GNUC__) || defined(__clang__)) && \ - (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__armel__) || defined(__ARMEL__) || \ + (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || \ defined(__aarch64__) || defined(__powerpc__) || defined(__ppc__) || defined(__PPC__)) || defined(__POWERPC__) #if defined(__x86_64__) || defined(__i386__) static inline void mi_atomic_yield(void) { @@ -348,10 +348,16 @@ static inline void mi_atomic_yield(void) { static inline void mi_atomic_yield(void) { __asm__ volatile("wfe"); } -#elif (defined(__arm__) && __ARM_ARCH__ >= 7) +#elif defined(__arm__) +#if __ARM_ARCH >= 7 static inline void mi_atomic_yield(void) { __asm__ volatile("yield" ::: "memory"); } +#else +static inline void mi_atomic_yield(void) { + __asm__ volatile ("nop" ::: "memory"); +} +#endif // __ARM_ARCH >= 7 #elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(__POWERPC__) #ifdef __APPLE__ static inline void mi_atomic_yield(void) { @@ -362,10 +368,6 @@ static inline void mi_atomic_yield(void) { __asm__ __volatile__ ("or 27,27,27" ::: "memory"); } #endif -#elif defined(__armel__) || defined(__ARMEL__) -static inline void mi_atomic_yield(void) { - __asm__ volatile ("nop" ::: "memory"); -} #endif #elif defined(__sun) // Fallback for other archs From 7302058ecce4e9e9ef00ac3060e7295a23d65360 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 27 Mar 2025 01:21:56 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Build/2025-03-27-01-21-50.gh-issue-131675.l2zfOO.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Build/2025-03-27-01-21-50.gh-issue-131675.l2zfOO.rst 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 new file mode 100644 index 00000000000000..b6fffc8da756d2 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2025-03-27-01-21-50.gh-issue-131675.l2zfOO.rst @@ -0,0 +1 @@ +Fix mimalloc library builds for 32bit ARM targets From 624ca3d4c92c112814fd26301d038362cb323ab4 Mon Sep 17 00:00:00 2001 From: Vincent Fazio Date: Fri, 28 Mar 2025 16:02:47 -0500 Subject: [PATCH 3/4] sync with upstream --- Include/internal/mimalloc/mimalloc/atomic.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Include/internal/mimalloc/mimalloc/atomic.h b/Include/internal/mimalloc/mimalloc/atomic.h index 6a85fec0d453f4..65fa477d643782 100644 --- a/Include/internal/mimalloc/mimalloc/atomic.h +++ b/Include/internal/mimalloc/mimalloc/atomic.h @@ -338,8 +338,9 @@ static inline void mi_atomic_yield(void) { _mm_pause(); } #elif (defined(__GNUC__) || defined(__clang__)) && \ - (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || \ - defined(__aarch64__) || defined(__powerpc__) || defined(__ppc__) || defined(__PPC__)) || defined(__POWERPC__) + (defined(__x86_64__) || defined(__i386__) || \ + defined(__aarch64__) || defined(__arm__) || \ + defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(__POWERPC__)) #if defined(__x86_64__) || defined(__i386__) static inline void mi_atomic_yield(void) { __asm__ volatile ("pause" ::: "memory"); @@ -357,7 +358,7 @@ static inline void mi_atomic_yield(void) { static inline void mi_atomic_yield(void) { __asm__ volatile ("nop" ::: "memory"); } -#endif // __ARM_ARCH >= 7 +#endif #elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(__POWERPC__) #ifdef __APPLE__ static inline void mi_atomic_yield(void) { From 0fe80a5d50a58e916389de24ecaeeea11b036e7b Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Mon, 31 Mar 2025 14:03:26 -0400 Subject: [PATCH 4/4] Update 2025-03-27-01-21-50.gh-issue-131675.l2zfOO.rst --- .../next/Build/2025-03-27-01-21-50.gh-issue-131675.l2zfOO.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index b6fffc8da756d2..be870a81df1739 100644 --- 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 @@ -1 +1 @@ -Fix mimalloc library builds for 32bit ARM targets +Fix mimalloc library builds for 32-bit ARM targets.