Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,31 @@ m4_ifdef([project_ompi], [OMPI_FIND_MPI_AINT_COUNT_OFFSET])
# checkpoint results
AC_CACHE_SAVE

##################################
# Linker characteristics
##################################

AC_MSG_CHECKING([the linker for support for the -fini option])
LDFLAGS_save=$LDFLAGS
LDFLAGS="$LDFLAGS_save -Wl,-fini -Wl,finalize"
AC_TRY_LINK([void finalize (void) {}], [], [AC_MSG_RESULT([yes])
opal_ld_have_fini=1], [AC_MSG_RESULT([no])
opal_ld_have_fini=0])
LDFLAGS=$LDFLAGS_save

opal_destructor_use_fini=0
opal_no_destructor=0
if test x$opal_cv___attribute__destructor = x0 ; then
if test x$opal_ld_have_fini = x1 ; then
opal_destructor_use_fini=1
else
opal_no_destructor=1;
fi
fi

AC_DEFINE_UNQUOTED(OPAL_NO_LIB_DESTRUCTOR, [$opal_no_destructor],
[Whether libraries can be configured with destructor functions])
AM_CONDITIONAL(OPAL_DESTRUCTOR_USE_FINI, [test x$opal_destructor_use_fini = x1])

##################################
# Libraries
Expand Down
6 changes: 6 additions & 0 deletions opal/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ lib@OPAL_LIB_PREFIX@open_pal_la_LIBADD = \
lib@OPAL_LIB_PREFIX@open_pal_la_DEPENDENCIES = $(lib@OPAL_LIB_PREFIX@open_pal_la_LIBADD)
lib@OPAL_LIB_PREFIX@open_pal_la_LDFLAGS = -version-info $(libopen_pal_so_version)

if OPAL_DESTRUCTOR_USE_FINI

lib@OPAL_LIB_PREFIX@open_pal_la_LDFLAGS += -Wl,-fini -Wl,opal_cleanup

endif

# included subdirectory Makefile.am's and appended-to variables
headers =
noinst_LTLIBRARIES =
Expand Down
17 changes: 15 additions & 2 deletions opal/runtime/opal_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@

extern int opal_initialized;
extern int opal_util_initialized;
extern bool opal_init_called;

static void __opal_attribute_destructor__ opal_cleanup (void)
{
if (!opal_initialized) {
/* nothing to do */
return;
}

/* finalize the class/object system */
opal_class_finalize();
}

int
opal_finalize_util(void)
Expand Down Expand Up @@ -101,8 +113,9 @@ opal_finalize_util(void)

opal_datatype_finalize();

/* finalize the class/object system */
opal_class_finalize();
#if OPAL_NO_LIB_DESTRUCTOR
opal_cleanup ();
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go with a NEED_LD_FINI "composite" AM_CONDITIONAL, above, then perhaps we should have a composite AC_DEFINE, too. Perhaps "OPAL_NEED_MANUAL_DESTRUCTOR_INVOCATION"? (or perhaps something slightly less wordy ;-) )


free (opal_process_info.nodename);
opal_process_info.nodename = NULL;
Expand Down
13 changes: 13 additions & 0 deletions opal/runtime/opal_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
const char opal_version_string[] = OPAL_IDENT_STRING;

int opal_initialized = 0;
bool opal_init_called = false;
int opal_util_initialized = 0;
/* We have to put a guess in here in case hwloc is not available. If
hwloc is available, this value will be overwritten when the
Expand Down Expand Up @@ -266,6 +267,18 @@ opal_init_util(int* pargc, char*** pargv)
return OPAL_SUCCESS;
}

#if OPAL_NO_LIB_DESTRUCTOR
if (opal_init_called) {
/* can't use show_help here */
fprintf (stderr, "opal_init_util: attempted to initialize after finalize without compiler "
"support for either __attribute__(destructor) or linker support for -fini -- process "
"will likely abort\n");
return OPAL_ERR_NOT_SUPPORTED;
}
#endif

opal_init_called = true;

/* set the nodename right away so anyone who needs it has it. Note
* that we don't bother with fqdn and prefix issues here - we let
* the RTE later replace this with a modified name if the user
Expand Down