From 0457b0db02c4b229eab11c01025df948032c31a7 Mon Sep 17 00:00:00 2001 From: Andrew Hsieh Date: Wed, 20 Feb 2013 16:17:40 +0800 Subject: Use memalign instead of posix_memalign in GCC x86 mm_malloc.h posix_memalign doesn't exist in NDK. Code inludes ?mmintrin.h which in turn includes mm_malloc.h may fail to link For AOSP platform build which uses the same compiler, add -DHAVE_POSIX_MEMALIGN to restore the original behavior. Other than non-zero return value which _mm_alloc already ignores, both paths are functioanlly identical (under the hood dlmalloc.c in 32-bit ensure alignment is at least 16-byte) Change-Id: I55e9bb8b80e1b55baa9744920df10fcf83218300 --- gcc-4.6/gcc/config/i386/pmm_malloc.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gcc-4.6') diff --git a/gcc-4.6/gcc/config/i386/pmm_malloc.h b/gcc-4.6/gcc/config/i386/pmm_malloc.h index 0a9f2e227..fcc0f8099 100644 --- a/gcc-4.6/gcc/config/i386/pmm_malloc.h +++ b/gcc-4.6/gcc/config/i386/pmm_malloc.h @@ -26,6 +26,7 @@ #include +#if !defined(__ANDROID__) || defined(HAVE_POSIX_MEMALIGN) /* We can't depend on since the prototype of posix_memalign may not be visible. */ #ifndef __cplusplus @@ -33,6 +34,7 @@ extern int posix_memalign (void **, size_t, size_t); #else extern "C" int posix_memalign (void **, size_t, size_t) throw (); #endif +#endif static __inline void * _mm_malloc (size_t size, size_t alignment) @@ -42,10 +44,14 @@ _mm_malloc (size_t size, size_t alignment) return malloc (size); if (alignment == 2 || (sizeof (void *) == 8 && alignment == 4)) alignment = sizeof (void *); +#if !defined(__ANDROID__) || defined(HAVE_POSIX_MEMALIGN) if (posix_memalign (&ptr, alignment, size) == 0) return ptr; else return NULL; +#else + return memalign(alignment, size); +#endif } static __inline void -- cgit v1.2.3