From 787dd7bf65b3e8f5ebb0a64b455415e549364abe Mon Sep 17 00:00:00 2001 From: George Bosilca Date: Mon, 30 Oct 2023 15:54:05 -0400 Subject: [PATCH] Add support for __constructor__ The only remaining statically initialized recursive mutex has now support for the constructor attribute. Signed-off-by: George Bosilca --- config/opal_check_attributes.m4 | 10 ++++++++++ ompi/instance/instance.c | 6 ++++-- opal/include/opal_config_bottom.h | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/config/opal_check_attributes.m4 b/config/opal_check_attributes.m4 index 9b2d5488f38..2d2e1ba3d7f 100644 --- a/config/opal_check_attributes.m4 +++ b/config/opal_check_attributes.m4 @@ -559,6 +559,14 @@ AC_DEFUN([OPAL_CHECK_ATTRIBUTES], [ [], []) + _OPAL_CHECK_SPECIFIC_ATTRIBUTE([constructor], + [ + void foo(void) __attribute__ ((__constructor__)); + void foo(void) { return ; } + ], + [], + []) + _OPAL_CHECK_SPECIFIC_ATTRIBUTE([destructor], [ void foo(void) __attribute__ ((__destructor__)); @@ -631,6 +639,8 @@ AC_DEFUN([OPAL_CHECK_ATTRIBUTES], [ [Whether your compiler has __attribute__ warn unused result or not]) AC_DEFINE_UNQUOTED(OPAL_HAVE_ATTRIBUTE_WEAK_ALIAS, [$opal_cv___attribute__weak_alias], [Whether your compiler has __attribute__ weak alias or not]) + AC_DEFINE_UNQUOTED(OPAL_HAVE_ATTRIBUTE_CONSTRUCTOR, [$opal_cv___attribute__constructor], + [Whether your compiler has __attribute__ constructor or not]) AC_DEFINE_UNQUOTED(OPAL_HAVE_ATTRIBUTE_DESTRUCTOR, [$opal_cv___attribute__destructor], [Whether your compiler has __attribute__ destructor or not]) AC_DEFINE_UNQUOTED(OPAL_HAVE_ATTRIBUTE_OPTNONE, [$opal_cv___attribute__optnone], diff --git a/ompi/instance/instance.c b/ompi/instance/instance.c index 1427db7b982..6d85bdec0b4 100644 --- a/ompi/instance/instance.c +++ b/ompi/instance/instance.c @@ -61,11 +61,13 @@ ompi_predefined_instance_t ompi_mpi_instance_null = {{{{0}}}}; #if defined(OPAL_RECURSIVE_MUTEX_STATIC_INIT) static opal_recursive_mutex_t instance_lock = OPAL_RECURSIVE_MUTEX_STATIC_INIT; -#else +#elif defined(OPAL_HAVE_ATTRIBUTE_CONSTRUCTOR) static opal_recursive_mutex_t instance_lock; -__attribute__((__constructor__)) static void instance_lock_init(void) { +__opal_attribute_constructor__ static void instance_lock_init(void) { OBJ_CONSTRUCT(&instance_lock, opal_recursive_mutex_t); } +#else +#error "No support for recursive mutexes available on this platform. #endif /* defined(OPAL_RECURSIVE_MUTEX_STATIC_INIT) */ /** MPI_Init instance */ diff --git a/opal/include/opal_config_bottom.h b/opal/include/opal_config_bottom.h index 2c2392a5429..a7337ab6cbd 100644 --- a/opal/include/opal_config_bottom.h +++ b/opal/include/opal_config_bottom.h @@ -229,6 +229,12 @@ # define __opal_attribute_weak_alias__(a) #endif +#if OPAL_HAVE_ATTRIBUTE_CONSTRUCTOR +# define __opal_attribute_constructor__ __attribute__((__constructor__)) +#else +# define __opal_attribute_constructor__ +#endif + #if OPAL_HAVE_ATTRIBUTE_DESTRUCTOR # define __opal_attribute_destructor__ __attribute__((__destructor__)) #else