From 95549e8efbf9c27d351663a214006fd1b336c3f4 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 28 Jul 2022 10:37:30 +0200 Subject: [PATCH] Kill useless complexity in mmalloc: one of the dlsym dlsym is not necessary to retrieve the LD_PRELOAD-injected symbol. The killed code was intended to be used in libsimgrid, trying to detect when libsgmalloc was already in memory to use that copy instead. But that's useless: LD_PRELOAD ensures that the copy of the injected version is the only existing one in the process. In addition, that may resolve stability issues that my previous commit didn't solve as nicely on the build daemons than on my laptop with gcc. --- src/xbt/mmalloc/mm_module.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/xbt/mmalloc/mm_module.c b/src/xbt/mmalloc/mm_module.c index 37f301b1d7..56091d2aa2 100644 --- a/src/xbt/mmalloc/mm_module.c +++ b/src/xbt/mmalloc/mm_module.c @@ -193,23 +193,15 @@ static void mmalloc_fork_child(void) xbt_mheap_t mmalloc_preinit(void) { if (__mmalloc_default_mdp == NULL) { - xbt_mheap_t (*other)(void) = dlsym(RTLD_NEXT, "mmalloc_preinit"); - if (other != NULL) { // This is the second time that this module is loaded, let's use the other one - __mmalloc_default_mdp = other(); - // fprintf(stderr, "Reuse the other mmalloc_init\n"); - } else { - // fprintf(stderr, "New mmalloc_init\n"); - - if (!mmalloc_pagesize) - mmalloc_pagesize = getpagesize(); - unsigned long mask = ~((unsigned long)mmalloc_pagesize - 1); - void* addr = (void*)(((unsigned long)sbrk(0) + HEAP_OFFSET) & mask); - __mmalloc_default_mdp = xbt_mheap_new(addr, XBT_MHEAP_OPTION_MEMSET); - - // atfork mandated at least on FreeBSD, or simgrid-mc will fail to fork the verified app - int res = pthread_atfork(mmalloc_fork_prepare, mmalloc_fork_parent, mmalloc_fork_child); - mmalloc_assert(res == 0, "pthread_atfork() failed: return value %d", res); - } + if (!mmalloc_pagesize) + mmalloc_pagesize = getpagesize(); + unsigned long mask = ~((unsigned long)mmalloc_pagesize - 1); + void* addr = (void*)(((unsigned long)sbrk(0) + HEAP_OFFSET) & mask); + __mmalloc_default_mdp = xbt_mheap_new(addr, XBT_MHEAP_OPTION_MEMSET); + + // atfork mandated at least on FreeBSD, or simgrid-mc will fail to fork the verified app + int res = pthread_atfork(mmalloc_fork_prepare, mmalloc_fork_parent, mmalloc_fork_child); + mmalloc_assert(res == 0, "pthread_atfork() failed: return value %d", res); } mmalloc_assert(__mmalloc_default_mdp != NULL, "__mmalloc_default_mdp cannot be NULL"); -- 2.20.1