The GNU C Library supports replacing the built-in
with a different allocator with the same interface. For dynamically
linked programs, this happens through ELF symbol interposition, either
using shared object dependencies or
LD_PRELOAD. For static
malloc replacement library must be linked in before
libc.a (explicitly or implicitly).
Note: Failure to provide a complete set of replacement functions (that is, all the functions used by the application, the GNU C Library, and other linked-in libraries) can lead to static linking failures, and, at run time, to heap corruption and application crashes.
The minimum set of functions which has to be provided by a custom
malloc is given in the table below.
malloc-related functions are required for the GNU C Library to
malloc implementation in the GNU C Library provides additional
functionality not used by the library itself, but which is often used by
other system libraries and applications. A general-purpose replacement
malloc implementation should provide definitions of these
functions, too. Their names are listed in the following table.
In addition, very old applications may use the obsolete
malloc-related functions such as
mallinfo will not have any effect or return incorrect statistics
when a replacement
malloc is in use. However, failure to replace
these functions typically does not result in crashes or other incorrect
application behavior, but may result in static linking failures.
Versions of the GNU C Library before 2.25 required that a
__libc_memalign (with the same
interface as the