From 79b623d7e398cef9c39e38102bdab8409389ca82 Mon Sep 17 00:00:00 2001 From: Rolf vandeVaart Date: Fri, 1 Feb 2013 14:11:39 +0000 Subject: [PATCH] Add wrapper interface to LTDL functions so that other parts of the library can access the LTDL functionality. Reviewed by jsquyres. This commit was SVN r28011. --- opal/util/Makefile.am | 2 + opal/util/lt_interface.c | 178 +++++++++++++++++++++++++++++++++++++++ opal/util/lt_interface.h | 82 ++++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 opal/util/lt_interface.c create mode 100644 opal/util/lt_interface.h diff --git a/opal/util/Makefile.am b/opal/util/Makefile.am index a864c88d86..28f2ea7e5d 100644 --- a/opal/util/Makefile.am +++ b/opal/util/Makefile.am @@ -43,6 +43,7 @@ headers = \ fd.c \ if.h \ keyval_parse.h \ + lt_interface.h \ malloc.h \ net.h \ numtostr.h \ @@ -77,6 +78,7 @@ libopalutil_la_SOURCES = \ if.c \ keyval_parse.c \ malloc.c \ + lt_interface.c \ net.c \ numtostr.c \ opal_environ.c \ diff --git a/opal/util/lt_interface.c b/opal/util/lt_interface.c new file mode 100644 index 0000000000..f8aa9eb0e3 --- /dev/null +++ b/opal/util/lt_interface.c @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2013 NVIDIA Corporation. All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include "opal_config.h" +#include +#include "opal/constants.h" +#include "opal/util/lt_interface.h" + +OPAL_DECLSPEC int opal_lt_dlinit(void) +{ +#if OPAL_WANT_LIBLTDL + return lt_dlinit(); +#else /* OPAL_WANT_LIBLTDL */ + return OPAL_ERR_NOT_SUPPORTED; +#endif /* OPAL_WANT_LIBLTDL */ +} + +OPAL_DECLSPEC int opal_lt_dladdsearchdir(const char *search_dir) { +#if OPAL_WANT_LIBLTDL + return lt_dladdsearchdir(search_dir); +#else /* OPAL_WANT_LIBLTDL */ + return OPAL_ERR_NOT_SUPPORTED; +#endif /* OPAL_WANT_LIBLTDL */ +} + +OPAL_DECLSPEC int opal_lt_dlinsertsearchdir(const char *before, + const char *search_dir) { +#if OPAL_WANT_LIBLTDL + return lt_dlinsertsearchdir(before, search_dir); +#else /* OPAL_WANT_LIBLTDL */ + return OPAL_ERR_NOT_SUPPORTED; +#endif /* OPAL_WANT_LIBLTDL */ +} + +OPAL_DECLSPEC int opal_lt_dlsetsearchpath(const char *search_path) { +#if OPAL_WANT_LIBLTDL + return lt_dlsetsearchpath(search_path); +#else /* OPAL_WANT_LIBLTDL */ + return OPAL_ERR_NOT_SUPPORTED; +#endif /* OPAL_WANT_LIBLTDL */ +} + +OPAL_DECLSPEC const char *opal_lt_dlgetsearchpath(void) { +#if OPAL_WANT_LIBLTDL + return lt_dlgetsearchpath(); +#else /* OPAL_WANT_LIBLTDL */ + return NULL; +#endif /* OPAL_WANT_LIBLTDL */ +} +OPAL_DECLSPEC int opal_lt_dlforeachfile(const char *search_path, + int (*func) (const char *filename, void *data), + void *data) { +#if OPAL_WANT_LIBLTDL + return lt_dlforeachfile(search_path, func, data); +#else /* OPAL_WANT_LIBLTDL */ + return OPAL_ERR_NOT_SUPPORTED; +#endif /* OPAL_WANT_LIBLTDL */ +} + +OPAL_DECLSPEC int opal_lt_dlexit(void) { +#if OPAL_WANT_LIBLTDL + return lt_dlexit(); +#else /* OPAL_WANT_LIBLTDL */ + return OPAL_ERR_NOT_SUPPORTED; +#endif /* OPAL_WANT_LIBLTDL */ +} + +OPAL_DECLSPEC void *opal_lt_dlsym(opal_lt_dlhandle handle, const char *name) { +#if OPAL_WANT_LIBLTDL + return lt_dlsym(handle, name); +#else /* OPAL_WANT_LIBLTDL */ + return NULL; +#endif /* OPAL_WANT_LIBLTDL */ +} + +OPAL_DECLSPEC const char *opal_lt_dlerror(void) { +#if OPAL_WANT_LIBLTDL + return lt_dlerror(); +#else /* OPAL_WANT_LIBLTDL */ + return NULL; +#endif /* OPAL_WANT_LIBLTDL */ +} + +OPAL_DECLSPEC int opal_lt_dladvise_init(opal_lt_dladvise *advise) { +#if OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE + return lt_dladvise_init(advise); +#else /* OPAL_WANT_LIBLTDL */ + return OPAL_ERR_NOT_SUPPORTED; +#endif /* OPAL_WANT_LIBLTDL */ +} + +OPAL_DECLSPEC int opal_lt_dladvise_ext(opal_lt_dladvise *advise) { +#if OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE + return lt_dladvise_ext(advise); +#else /* OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE */ + return OPAL_ERR_NOT_SUPPORTED; +#endif /* OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE */ + +} +OPAL_DECLSPEC int opal_lt_dladvise_global(opal_lt_dladvise *advise) { +#if OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE + return lt_dladvise_global(advise); +#else /* OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE */ + return OPAL_ERR_NOT_SUPPORTED; +#endif /* OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE */ +} + +OPAL_DECLSPEC opal_lt_dlhandle opal_lt_dlopenadvise(const char *filename, opal_lt_dladvise advise) { +#if OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE + return lt_dlopenadvise(filename, advise); +#else /* OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE */ + return NULL; +#endif /* OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE */ +} + +OPAL_DECLSPEC int opal_lt_dladvise_destroy(opal_lt_dladvise *advise) { +#if OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE + return lt_dladvise_destroy(advise); +#else /* OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE */ + return OPAL_ERR_NOT_SUPPORTED; +#endif /* OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE */ +} + +OPAL_DECLSPEC int opal_lt_dladvise_resident(opal_lt_dladvise *advise) { +#if OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE + return lt_dladvise_resident(advise); +#else /* OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE */ + return OPAL_ERR_NOT_SUPPORTED; +#endif /* OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE */ +} + +OPAL_DECLSPEC int opal_lt_dladvise_local(opal_lt_dladvise *advise) { +#if OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE + return lt_dladvise_local(advise); +#else /* OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE */ + return OPAL_ERR_NOT_SUPPORTED; +#endif /* OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE */ +} + +OPAL_DECLSPEC int opal_lt_dladvise_preload(opal_lt_dladvise *advise) { +#if OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE + return lt_dladvise_preload(advise); +#else /* OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE */ + return OPAL_ERR_NOT_SUPPORTED; +#endif /* OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE */ +} + +/* Portable libltdl versions of the system dlopen() API. */ +OPAL_DECLSPEC opal_lt_dlhandle opal_lt_dlopen(const char *filename) { +#if OPAL_WANT_LIBLTDL + return lt_dlopen(filename); +#else /* OPAL_WANT_LIBLTDL */ + return NULL; +#endif /* OPAL_WANT_LIBLTDL */ +} + +OPAL_DECLSPEC opal_lt_dlhandle opal_lt_dlopenext(const char *filename) { +#if OPAL_WANT_LIBLTDL + return lt_dlopenext(filename); +#else /* OPAL_WANT_LIBLTDL */ + return 0; +#endif /* OPAL_WANT_LIBLTDL */ +} + +OPAL_DECLSPEC int opal_lt_dlclose(opal_lt_dlhandle handle) { +#if OPAL_WANT_LIBLTDL + return lt_dlclose(handle); +#else + return OPAL_ERR_NOT_SUPPORTED; +#endif +} diff --git a/opal/util/lt_interface.h b/opal/util/lt_interface.h new file mode 100644 index 0000000000..f4fd96eaaa --- /dev/null +++ b/opal/util/lt_interface.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2013 NVIDIA Corporation. All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +/** +* Wrappers to LTDL functions so that other parts of library can +* access the LTDL functionality that is embedded/linked in to Open +* MPI (vs. a LTDL library that was linked in by the application). +* The OPAL-linked LTDL library is intentionally not DECLSPEC'ed so +* that it is not visible to upper-layer applications; its functions +* are provided to the rest of the OMPI code base via the following +* OPAL wrappers. +*/ + +#if OPAL_WANT_LIBLTDL + #ifndef __WINDOWS__ + #if OPAL_LIBLTDL_INTERNAL + #include "opal/libltdl/ltdl.h" + #else + #include "ltdl.h" + #endif + #else + #include "ltdl.h" + #endif +#endif + +/** + * Create opal_lt_dlhandle and opal_lt_advise types so that consumers + * of this code can use these opal types rather than the LTDL versions. + * In that way, there is no need to use OPAL_WANT_LIBLTDL and + * OPAL_HAVE_LTDL_ADVISE anywhere else. + */ +#if OPAL_WANT_LIBLTDL +typedef lt_dlhandle opal_lt_dlhandle; +#else +typedef void *opal_lt_dlhandle; +#endif /* OPAL_WANT_LIBLTDL */ +#if OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE +typedef lt_dladvise opal_lt_dladvise; +#else +typedef void *opal_lt_dladvise; +#endif /* OPAL_WANT_LIBLTDL && OPAL_HAVE_LTDL_ADVISE */ + +/** + * Wrappers for the ltdl library. + */ + +OPAL_DECLSPEC int opal_lt_dlinit(void); +OPAL_DECLSPEC int opal_lt_dlexit(void); + +/* Module search path manipulation. */ +OPAL_DECLSPEC int opal_lt_dladdsearchdir(const char *search_dir); +OPAL_DECLSPEC int opal_lt_dlinsertsearchdir(const char *before, + const char *search_dir); +OPAL_DECLSPEC int opal_lt_dlsetsearchpath(const char *search_path); +OPAL_DECLSPEC const char *opal_lt_dlgetsearchpath(void); +OPAL_DECLSPEC int opal_lt_dlforeachfile(const char *search_path, + int (*func) (const char *filename, void *data), + void *data); +/* User module loading advisors. */ +OPAL_DECLSPEC int opal_lt_dladvise_init(opal_lt_dladvise *advise); +OPAL_DECLSPEC int opal_lt_dladvise_destroy(opal_lt_dladvise *advise); +OPAL_DECLSPEC int opal_lt_dladvise_ext(opal_lt_dladvise *advise); +OPAL_DECLSPEC int opal_lt_dladvise_resident(opal_lt_dladvise *advise); +OPAL_DECLSPEC int opal_lt_dladvise_local(opal_lt_dladvise *advise); +OPAL_DECLSPEC int opal_lt_dladvise_global(opal_lt_dladvise *advise); +OPAL_DECLSPEC int opal_lt_dladvise_preload(opal_lt_dladvise *advise); + +/* Portable libltdl versions of the system dlopen() API. */ +OPAL_DECLSPEC opal_lt_dlhandle opal_lt_dlopen(const char *filename); +OPAL_DECLSPEC opal_lt_dlhandle opal_lt_dlopenext(const char *filename); +OPAL_DECLSPEC void *opal_lt_dlsym(opal_lt_dlhandle handle, const char *name); +OPAL_DECLSPEC const char *opal_lt_dlerror(void); +OPAL_DECLSPEC int opal_lt_dlclose(opal_lt_dlhandle handle); +OPAL_DECLSPEC opal_lt_dlhandle opal_lt_dlopenadvise(const char *filename, + opal_lt_dladvise advise);