From 35fc9fedd23e2100819ffdaae942f001f8c355a5 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Wed, 15 Apr 2009 19:09:10 +0000 Subject: [PATCH] MTT is your friend: Cisco tests --enable-static --disable-shared, but we had already tested this scenario manually to know that it seemed to be working. What we ''didn't'' test was --enable-static --disable-shared --disable-dlopen -- but my MTT '''did.''' Yay! This commit fixes that scenario. Essentially we need to call a dummy function in hooks.c to ensure that the linker pulls in all those symbols into the final executable (and therefore pulls in the malloc_initialize_hook, etc.). Thanks for the heads-up from Brian in fixing this one! This commit was SVN r21022. --- opal/mca/memory/ptmalloc2/hooks.c | 19 ++++++++++++++++++- .../ptmalloc2/opal_ptmalloc2_component.c | 12 ++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/opal/mca/memory/ptmalloc2/hooks.c b/opal/mca/memory/ptmalloc2/hooks.c index 13a65dcebe..b0b60b0611 100644 --- a/opal/mca/memory/ptmalloc2/hooks.c +++ b/opal/mca/memory/ptmalloc2/hooks.c @@ -647,7 +647,7 @@ public_sET_STATe(Void_t* msptr) /*------------------------------------------------------------------------- - Per + OMPI change: Per http://www.gnu.org/software/libc/manual/html_mono/libc.html#Hooks-for-Malloc, we can define the __malloc_initialize_hook variable to be a function that is invoked before the first allocation is ever @@ -781,6 +781,23 @@ static void opal_memory_ptmalloc2_malloc_init_hook(void) } +/* OMPI change: add a dummy function here that will be called by the + ptmalloc2 component open() function. This dummy function is + necessary for when OMPI is built as --disable-shared + --enable-static --disable-dlopen, because we won't use + -Wl,--export-dynamic when building OMPI. So we need to ensure that + not only that all the symbols in this file end up in libmpi.a, but + they also end up in the final exectuable (so that + __malloc_initialize_hook is there, overrides the weak symbol in + glibc, ....etc. */ +static int bogus = 37; +void *opal_memory_ptmalloc2_hook_pull(void) +{ + return &bogus; +} + + + /* OMPI change: This is the symbol to override to make the above function get fired during malloc initialization time. */ void (*__malloc_initialize_hook) (void) = diff --git a/opal/mca/memory/ptmalloc2/opal_ptmalloc2_component.c b/opal/mca/memory/ptmalloc2/opal_ptmalloc2_component.c index 59b14b459d..dfc5354e6c 100644 --- a/opal/mca/memory/ptmalloc2/opal_ptmalloc2_component.c +++ b/opal/mca/memory/ptmalloc2/opal_ptmalloc2_component.c @@ -31,6 +31,13 @@ #include "opal/mca/memory/memory.h" #include "opal/memoryhooks/memory.h" +/* Need to call a function in hooks.c to ensure that all those symbols + get pulled in at link time (e.g., when building libmpi.a, so that + those symbols end up in the final executable -- especially if we + use --disable-dlopen and therefore -Wl,--export-dynamic isn't used + when we build OMPI). */ +extern void *opal_memory_ptmalloc2_hook_pull(void); + static int ptmalloc2_open(void); const opal_memory_base_component_2_0_0_t mca_memory_ptmalloc2_component = { @@ -67,6 +74,11 @@ static int ptmalloc2_open(void) void *p; int val = 0; + /* Call a dummy function in hooks.c. ***Do not remove this + call!*** See comment at the beginning of this file explaining + why it is here. */ + p = opal_memory_ptmalloc2_hook_pull(); + /* We will also provide malloc/free support if we've been activated. We don't rely on the __malloc_initialize_hook() previously being called because it's possible that our hook was