AIX system header <stdlib.h> maps system calls malloc and calloc to vec_malloc and vec_calloc under macro __VEC__ which is pre-defined by compiler when the target architecture supports Altivec. vec_malloc/vec_calloc give 16-byte aligned allocation and as a result, greatly increase the heap memory consumption if an application makes a large number of small heap allocations. This causes existing applications built with certain heap size to run out of memory unexpectedly when running against a newer version of libc++/libc++abi built with __VEC__ defined (on AIX, linker option -bmaxdata is used to specify the maximum size of user data area). For example, an application usually malloc()s 1.5GB heap memory through the new operator out of 40M allocations but it allocates more than 2GB when running against the newer libc++abi.
To mitigate this issue, this patch defines __libcpp_malloc()/__libcpp_calloc() that are true malloc()/calloc() and use them in libc++ and libc++abi implementations in places of the plain malloc()/calloc(} where a specific alignment is not required. For AIX, __libcpp_malloc()/__libcpp_calloc() map to assembly label malloc/calloc. For other platforms, they are function macros mapping to malloc/calloc. Functions std::malloc()/std::calloc() are not changed to maintain the original AIX semantic, i.e., they are mapped to vec_malloc()/vec_calloc() if macro __VEC__ is defined.
Calls to malloc()/calloc() in libunwind are used for DWARF based unwinding. Since AIX uses the traceback table based unwinding and the code for DWARF based unwinding is compiled out, the code in libunwind is not changed.