+
+#ifdef MMALLOC_WANT_OVERRIDE_LEGACY
+#if 0 && defined(HAVE_GNU_LD)
+
+#undef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#include <dlfcn.h>
+
+static void * (*real_malloc) (size_t) = NULL;
+static void * (*real_realloc) (void*,size_t) = NULL;
+static void * (*real_free) (void*) = NULL;
+
+static void mm_gnuld_legacy_init(void) { /* This function is called from mmalloc_preinit(); it works even if it's static because all mm is in mm.c */
+ real_malloc = (void * (*) (size_t)) dlsym(RTLD_NEXT, "malloc");
+ real_realloc = (void * (*) (void*,size_t)) dlsym(RTLD_NEXT, "realloc");
+ real_free = (void * (*) (void*)) dlsym(RTLD_NEXT, "free");
+ __mmalloc_current_heap = __mmalloc_default_mdp;
+}
+
+/* Hello pimple!
+ * DL needs some memory while resolving the malloc symbol, that is somehow problematic
+ * To that extend, we have a little area here living in .BSS that we return if asked for memory before the malloc is resolved.
+ */
+static int allocated_junk = 0; /* keep track of many blocks of our little area was already given to someone */
+#define JUNK_SIZE 8
+#define MAX_JUNK_AREAS (64 * 1024 / JUNK_SIZE)
+static char junkareas[MAX_JUNK_AREAS][JUNK_SIZE];
+
+/* This version use mmalloc if there is a current heap, or the legacy implem if not */
+static void *malloc_or_calloc(size_t n, int setzero) {
+ xbt_mheap_t mdp = __mmalloc_current_heap;
+ void *ret;
+#ifdef MM_LEGACY_VERBOSE
+ static int warned_raw = 0;
+ static int warned_mmalloc = 0;