patch to compile with clang/llvm for Android arm64 and mips targets

Chih-hung Hsieh chh at google.com
Fri May 22 10:54:48 PDT 2015


When compiling include/jemalloc/internal/atomic.h
for Android with clang/llvm compiler and arm64 or mips targets,
JEMALLOC_C11ATOMICS should be defined, but there
are type errors in the arguments to function
atomic_compare_exchange_strong and atomic_store.

The following diff will fix the error:

diff --git a/include/jemalloc/internal/atomic.h
b/include/jemalloc/internal/atomic.h
index 522dd2a..a9aad35 100644
--- a/include/jemalloc/internal/atomic.h
+++ b/include/jemalloc/internal/atomic.h
@@ -143,15 +143,15 @@ atomic_sub_uint64(uint64_t *p, uint64_t x)
 JEMALLOC_INLINE bool
 atomic_cas_uint64(uint64_t *p, uint64_t c, uint64_t s)
 {
-
-       return (!atomic_compare_exchange_strong(p, &c, s));
+       volatile atomic_uint_least64_t *a = (volatile atomic_uint_least64_t *)p;
+       return (!atomic_compare_exchange_strong(a, &c, s));
 }

 JEMALLOC_INLINE void
 atomic_write_uint64(uint64_t *p, uint64_t x)
 {
-
-       atomic_store(p, x);
+       volatile atomic_uint_least64_t *a = (volatile atomic_uint_least64_t *)p;
+       atomic_store(a, x);
 }
 #  elif (defined(JEMALLOC_ATOMIC9))
 JEMALLOC_INLINE uint64_t
@@ -367,15 +367,15 @@ atomic_sub_uint32(uint32_t *p, uint32_t x)
 JEMALLOC_INLINE bool
 atomic_cas_uint32(uint32_t *p, uint32_t c, uint32_t s)
 {
-
-       return (!atomic_compare_exchange_strong(p, &c, s));
+       volatile atomic_uint_least32_t *a = (volatile atomic_uint_least32_t *)p;
+       return (!atomic_compare_exchange_strong(a, &c, s));
 }

 JEMALLOC_INLINE void
 atomic_write_uint32(uint32_t *p, uint32_t x)
 {
-
-       atomic_store(p, x);
+       volatile atomic_uint_least32_t *a = (volatile atomic_uint_least32_t *)p;
+       atomic_store(a, x);
 }
 #elif (defined(JEMALLOC_ATOMIC9))
 JEMALLOC_INLINE uint32_t



For people with access to Android Open Source, a patch is available at
https://android-review.googlesource.com/#/c/151171
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jemalloc.net/mailman/jemalloc-discuss/attachments/20150522/3b905da1/attachment.html>


More information about the jemalloc-discuss mailing list