From: Matthieu Volat Date: Mon, 7 Nov 2016 11:25:21 +0000 (+0100) Subject: Check for a dlfunc() function to get handle if present X-Git-Tag: v3_14~230 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/9e568a13c5bf3fea2a09bb4418f2465fa759af3b Check for a dlfunc() function to get handle if present dlfunc() is a (for now) FreeBSD-only function that is to be used when trying to retrieve function handles from code segments, rather than dlsym(), but let's make the code generic in case somebody else likes the idea... --- diff --git a/CMakeLists.txt b/CMakeLists.txt index aa1e7538f0..d1bf3e841c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -305,6 +305,7 @@ CHECK_INCLUDE_FILE("ucontext.h" HAVE_UCONTEXT_H) CHECK_INCLUDE_FILE("linux/futex.h" HAVE_FUTEX_H) CHECK_FUNCTION_EXISTS(backtrace HAVE_BACKTRACE) +CHECK_FUNCTION_EXISTS(dlfunc HAVE_DLFUNC) CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY) CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP) CHECK_FUNCTION_EXISTS(getdtablesize HAVE_GETDTABLESIZE) diff --git a/src/xbt/mmalloc/mm_legacy.c b/src/xbt/mmalloc/mm_legacy.c index 1652eb4cbd..790ead6c56 100644 --- a/src/xbt/mmalloc/mm_legacy.c +++ b/src/xbt/mmalloc/mm_legacy.c @@ -123,10 +123,17 @@ static void __attribute__((constructor(101))) mm_legacy_constructor() 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"); +#endif } mm_initializing = 0; mm_initialized = 1; diff --git a/tools/cmake/src/internal_config.h.in b/tools/cmake/src/internal_config.h.in index 172bc4c773..b5c7fdc8ee 100644 --- a/tools/cmake/src/internal_config.h.in +++ b/tools/cmake/src/internal_config.h.in @@ -59,6 +59,7 @@ /* Other function checks */ #define HAVE_BACKTRACE @HAVE_BACKTRACE@ /* Function backtrace */ +#define HAVE_DLFUNC @HAVE_DLFUNC@ /* Function dlfunc */ #define HAVE_MMAP @HAVE_MMAP@ /* Function mmap */ #define HAVE_MREMAP @HAVE_MREMAP@ /* Function mremap */ #define HAVE_SEM_INIT @HAVE_SEM_INIT@ /* Function sem_init (part of XPG6 standard only) */ @@ -69,4 +70,4 @@ /* Other checks */ #cmakedefine ADDR2LINE "@ADDR2LINE@" /* Path to the addr2line tool */ #define HAVE_GRAPHVIZ @HAVE_GRAPHVIZ@ /* The graphviz library */ -#define HAVE_LIBUNWIND @HAVE_LIBUNWIND@ /* The lib unwind library (for MC and backtrace display) */ \ No newline at end of file +#define HAVE_LIBUNWIND @HAVE_LIBUNWIND@ /* The lib unwind library (for MC and backtrace display) */