Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Check for a dlfunc() function to get handle if present
[simgrid.git] / src / xbt / mmalloc / mm_legacy.c
index 1652eb4..790ead6 100644 (file)
@@ -123,10 +123,17 @@ static void __attribute__((constructor(101))) mm_legacy_constructor()
   if (__malloc_use_mmalloc) {
     __mmalloc_current_heap = mmalloc_preinit();
   } else {
   if (__malloc_use_mmalloc) {
     __mmalloc_current_heap = mmalloc_preinit();
   } else {
+#if HAVE_DLFUNC
+    mm_real_realloc  = (void *(*)(void *, size_t))dlfunc(RTLD_NEXT, "realloc");
+    mm_real_malloc   = (void *(*)(size_t))dlfunc(RTLD_NEXT, "malloc");
+    mm_real_free     = (void (*)(void *))dlfunc(RTLD_NEXT, "free");
+    mm_real_calloc   = (void *(*)(size_t, size_t))dlfunc(RTLD_NEXT, "calloc");
+#else
     mm_real_realloc  = dlsym(RTLD_NEXT, "realloc");
     mm_real_malloc   = dlsym(RTLD_NEXT, "malloc");
     mm_real_free     = dlsym(RTLD_NEXT, "free");
     mm_real_calloc   = dlsym(RTLD_NEXT, "calloc");
     mm_real_realloc  = dlsym(RTLD_NEXT, "realloc");
     mm_real_malloc   = dlsym(RTLD_NEXT, "malloc");
     mm_real_free     = dlsym(RTLD_NEXT, "free");
     mm_real_calloc   = dlsym(RTLD_NEXT, "calloc");
+#endif
   }
   mm_initializing = 0;
   mm_initialized = 1;
   }
   mm_initializing = 0;
   mm_initialized = 1;