1
1

libltdl: dl component based on libltdl

Works on any system that libltdl supports and has ltdl.h and libltdl
available.
Этот коммит содержится в:
Jeff Squyres 2015-02-18 10:17:51 -08:00
родитель 7d340c0c26
Коммит 39364d315c
5 изменённых файлов: 482 добавлений и 0 удалений

26
opal/mca/dl/libltdl/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,26 @@
#
# Copyright (c) 2004-2010 The Trustees of Indiana University.
# All rights reserved.
# Copyright (c) 2014-2015 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
sources = \
dl_libltdl.h \
dl_libltdl_component.c \
dl_libltdl_module.c
# This component will only ever be built statically -- never as a DSO.
noinst_LTLIBRARIES = libmca_dl_libltdl.la
libmca_dl_libltdl_la_SOURCES = $(sources)
libmca_dl_libltdl_la_CPPFLAGS = $(opal_dl_libltdl_CPPFLAGS)
libmca_dl_libltdl_la_LDFLAGS = \
$(opal_dl_libltdl_LDFLAGS) \
-module -avoid-version
libmca_dl_libltdl_la_LIBS = $(opal_dl_libltdl_LIBS)

123
opal/mca/dl/libltdl/configure.m4 Обычный файл
Просмотреть файл

@ -0,0 +1,123 @@
# -*- shell-script -*-
#
# Copyright (c) 2009-2015 Cisco Systems, Inc. All rights reserved.
#
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
AC_DEFUN([MCA_opal_dl_libltdl_PRIORITY], [50])
#
# Force this component to compile in static-only mode
#
AC_DEFUN([MCA_opal_dl_libltdl_COMPILE_MODE], [
AC_MSG_CHECKING([for MCA component $2:$3 compile mode])
$4="static"
AC_MSG_RESULT([$$4])
])
# MCA_event_external_POST_CONFIG()
# ---------------------------------
AC_DEFUN([MCA_opal_dl_libltdl_POST_CONFIG],[
# If we won, then do all the rest of the setup
AS_IF([test "$1" = "1"],
[
# Add some stuff to CPPFLAGS so that the rest of the source
# tree can be built
LDFLAGS="$LDFLAGS $opal_dl_libltdl_ADD_LDFLAGS"
LIBS="$LIBS $opal_dl_libltdl_ADD_LIBS"
])
])dnl
# MCA_dl_libltdl_CONFIG([action-if-can-compile],
# [action-if-cant-compile])
# ------------------------------------------------
AC_DEFUN([MCA_opal_dl_libltdl_CONFIG],[
OPAL_VAR_SCOPE_PUSH([CPPFLAGS_save LDFLAGS_save LIBS_save])
AC_CONFIG_FILES([opal/mca/dl/libltdl/Makefile])
# Add --with options
AC_ARG_WITH([libltdl],
[AC_HELP_STRING([--with-libltdl(=DIR)],
[Build libltdl support, optionally adding DIR/include, DIR/lib, and DIR/lib64 to the search path for headers and libraries])])
AC_ARG_WITH([libltdl-libdir],
[AC_HELP_STRING([--with-libltdl-libdir=DIR],
[Search for libltdl libraries in DIR])])
# Sanity check the --with values
OPAL_CHECK_WITHDIR([libltdl], [$with_libltdl],
[include/ltdl.h])
OPAL_CHECK_WITHDIR([libltdl-libdir], [$with_libltdl_libdir],
[libltdl.*])
# Defaults
opal_check_libltdl_dir_msg="compiler default"
opal_check_libltdl_libdir_msg="linker default"
# Save directory names if supplied
AS_IF([test ! -z "$with_libltdl" && test "$with_libltdl" != "yes"],
[opal_check_libltdl_dir=$with_libltdl
opal_check_libltdl_dir_msg="$opal_check_libltdl_dir (from --with-libltdl)"])
AS_IF([test ! -z "$with_libltdl_libdir" && test "$with_libltdl_libdir" != "yes"],
[opal_check_libltdl_libdir=$with_libltdl_libdir
opal_check_libltdl_libdir_msg="$opal_check_libltdl_libdir (from --with-libltdl-libdir)"])
opal_dl_libltdl_happy=no
AS_IF([test "$with_libltdl" != "no"],
[AC_MSG_CHECKING([for libltdl dir])
AC_MSG_RESULT([$opal_check_libltdl_dir_msg])
AC_MSG_CHECKING([for libltdl library dir])
AC_MSG_RESULT([$opal_check_libltdl_libdir_msg])
OPAL_CHECK_PACKAGE([opal_dl_libltdl],
[ltdl.h],
[ltdl],
[lt_dlopen],
[],
[$opal_check_libltdl_dir],
[$opal_check_libltdl_libdir],
[opal_dl_libltdl_happy=yes],
[opal_dl_libltdl_happy=no])
])
# If we have libltdl, do we have lt_dladvise?
opal_dl_libltdl_have_lt_dladvise=0
AS_IF([test "$opal_dl_libltdl_happy" = "yes"],
[CPPFLAGS_save=$CPPFLAGS
LDFLAGS_save=$LDFLAGS
LIBS_save=$LIBS
CPPFLAGS="$opal_dl_libltdl_CPPFLAGS $CPPFLAGS"
LDFLAGS="$opal_dl_libltdl_LDFLAGS $LDFLAGS"
LIBS="$opal_dl_libltdl_LIBS $LIBS"
AC_CHECK_FUNC([lt_dladvise_init],
[opal_dl_libltdl_have_lt_dladvise=1])
CPPFLAGS=$CPPFLAGS_save
LDFLAGS=$LDFLAGS_save
LIBS=$LIBS_save
])
AC_DEFINE_UNQUOTED(OPAL_DL_LIBLTDL_HAVE_LT_DLADVISE,
[$opal_dl_libltdl_have_lt_dladvise],
[Whether we have lt_dladvise or not])
AS_IF([test "$opal_dl_libltdl_happy" = "yes"],
[opal_dl_libltdl_ADD_CPPFLAGS=$opal_dl_libltdl_CPPFLAGS
opal_dl_libltdl_ADD_LDFLAGS=$opal_dl_libltdl_LDFLAGS
opal_dl_libltdl_ADD_LIBS=$opal_dl_libltdl_LIBS
$1],
[AS_IF([test ! -z "$with_libltdl" && \
test "$with_libltdl" != "no"],
[AC_MSG_WARN([Libltdl support requested (via --with-libltdl) but not found.])
AC_MSG_ERROR([Cannot continue.])])
$2])
AC_SUBST(opal_dl_libltdl_CPPFLAGS)
AC_SUBST(opal_dl_libltdl_LDFLAGS)
AC_SUBST(opal_dl_libltdl_LIBS)
OPAL_VAR_SCOPE_POP
])

50
opal/mca/dl/libltdl/dl_libltdl.h Обычный файл
Просмотреть файл

@ -0,0 +1,50 @@
/*
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_DL_LIBLTDL
#define OPAL_DL_LIBLTDL
#include "opal_config.h"
#include "opal/mca/dl/dl.h"
#include <ltdl.h>
OPAL_DECLSPEC extern opal_dl_base_module_t opal_dl_libltdl_module;
/*
* Dynamic library handles generated by this component.
*
* If we're debugging, keep a copy of the name of the file we've opened.
*/
struct opal_dl_handle_t {
lt_dlhandle ltdl_handle;
#if OPAL_ENABLE_DEBUG
char *filename;
#endif
};
typedef struct {
opal_dl_base_component_t base;
#if OPAL_DL_LIBLTDL_HAVE_LT_DLADVISE
/* If the version of libltdl that we are compiling against has
lt_dladvise, use it to support opening DSOs in a variety of
modes. */
lt_dladvise advise_private_noext;
lt_dladvise advise_private_ext;
lt_dladvise advise_public_noext;
lt_dladvise advise_public_ext;
#endif
} opal_dl_libltdl_component_t;
OPAL_DECLSPEC extern opal_dl_libltdl_component_t mca_dl_libltdl_component;
#endif /* OPAL_DL_LIBLTDL */

155
opal/mca/dl/libltdl/dl_libltdl_component.c Обычный файл
Просмотреть файл

@ -0,0 +1,155 @@
/*
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal/mca/dl/dl.h"
#include "opal/mca/base/mca_base_var.h"
#include "opal/util/argv.h"
#include "dl_libltdl.h"
/*
* Public string showing the sysinfo ompi_linux component version number
*/
const char *opal_dl_libltdl_component_version_string =
"OPAL dl libltdl MCA component version " OPAL_VERSION;
/*
* Local functions
*/
static int libltdl_component_register(void);
static int libltdl_component_open(void);
static int libltdl_component_close(void);
static int libltdl_component_query(mca_base_module_t **module, int *priority);
/*
* Instantiate the public struct with all of our public information
* and pointers to our public functions in it
*/
opal_dl_libltdl_component_t mca_dl_libltdl_component = {
/* Fill in the mca_dl_base_component_t */
.base = {
/* First, the mca_component_t struct containing meta information
about the component itself */
.base_version = {
OPAL_DL_BASE_VERSION_1_0_0,
/* Component name and version */
"libltdl",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component functions */
.mca_register_component_params = libltdl_component_register,
.mca_open_component = libltdl_component_open,
.mca_close_component = libltdl_component_close,
.mca_query_component = libltdl_component_query,
},
.base_data = {
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
/* The dl framework members */
.priority = 50
}
/* Now fill in the libltdl component-specific members */
};
static int libltdl_component_register(void)
{
/* Register an info param indicating whether we have lt_dladvise
support or not */
bool supported = OPAL_INT_TO_BOOL(OPAL_DL_LIBLTDL_HAVE_LT_DLADVISE);
mca_base_component_var_register(&mca_dl_libltdl_component.base.base_version,
"have_lt_dladvise",
"Whether the version of libltdl that this component is built against supports lt_dladvise functionality or not",
MCA_BASE_VAR_TYPE_BOOL,
NULL,
0,
MCA_BASE_VAR_FLAG_DEFAULT_ONLY,
OPAL_INFO_LVL_7,
MCA_BASE_VAR_SCOPE_CONSTANT,
&supported);
return OPAL_SUCCESS;
}
static int libltdl_component_open(void)
{
if (lt_dlinit()) {
return OPAL_ERROR;
}
#if OPAL_DL_LIBLTDL_HAVE_LT_DLADVISE
opal_dl_libltdl_component_t *c = &mca_dl_libltdl_component;
if (lt_dladvise_init(&c->advise_private_noext)) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
if (lt_dladvise_init(&c->advise_private_ext) ||
lt_dladvise_ext(&c->advise_private_ext)) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
if (lt_dladvise_init(&c->advise_public_noext) ||
lt_dladvise_global(&c->advise_public_noext)) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
if (lt_dladvise_init(&c->advise_public_ext) ||
lt_dladvise_global(&c->advise_public_ext) ||
lt_dladvise_ext(&c->advise_public_ext)) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
#endif
return OPAL_SUCCESS;
}
static int libltdl_component_close(void)
{
#if OPAL_DL_LIBLTDL_HAVE_LT_DLADVISE
opal_dl_libltdl_component_t *c = &mca_dl_libltdl_component;
lt_dladvise_destroy(&c->advise_private_noext);
lt_dladvise_destroy(&c->advise_private_ext);
lt_dladvise_destroy(&c->advise_public_noext);
lt_dladvise_destroy(&c->advise_public_ext);
#endif
lt_dlexit();
return OPAL_SUCCESS;
}
static int libltdl_component_query(mca_base_module_t **module, int *priority)
{
/* The priority value is somewhat meaningless here; by
opal/mca/dl/configure.m4, there's at most one component
available. */
*priority = mca_dl_libltdl_component.base.priority;
*module = &opal_dl_libltdl_module.super;
return OPAL_SUCCESS;
}

128
opal/mca/dl/libltdl/dl_libltdl_module.c Обычный файл
Просмотреть файл

@ -0,0 +1,128 @@
/*
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal/mca/dl/dl.h"
#include "dl_libltdl.h"
static int libltdl_open(const char *fname, bool use_ext, bool private_namespace,
opal_dl_handle_t **handle, char **err_msg)
{
assert(fname);
assert(handle);
*handle = NULL;
if (NULL != err_msg) {
*err_msg = NULL;
}
lt_dlhandle local_handle;
#if OPAL_DL_LIBLTDL_HAVE_LT_DLADVISE
opal_dl_libltdl_component_t *c = &mca_dl_libltdl_component;
if (use_ext && private_namespace) {
local_handle = lt_dlopenadvise(fname, c->advise_private_ext);
} else if (use_ext && !private_namespace) {
local_handle = lt_dlopenadvise(fname, c->advise_public_ext);
} else if (!use_ext && private_namespace) {
local_handle = lt_dlopenadvise(fname, c->advise_private_noext);
} else if (!use_ext && !private_namespace) {
local_handle = lt_dlopenadvise(fname, c->advise_public_noext);
}
#else
if (use_ext) {
local_handle = lt_dlopenext(fname);
} else {
local_handle = lt_dlopen(fname);
}
#endif
if (NULL != local_handle) {
*handle = calloc(1, sizeof(opal_dl_handle_t));
(*handle)->ltdl_handle = local_handle;
#if OPAL_ENABLE_DEBUG
(*handle)->filename = strdup(fname);
#endif
return OPAL_SUCCESS;
}
if (NULL != err_msg) {
*err_msg = (char*) lt_dlerror();
}
return OPAL_ERROR;
}
static int libltdl_lookup(opal_dl_handle_t *handle, const char *symbol,
void **ptr, char **err_msg)
{
assert(handle);
assert(handle->ltdl_handle);
assert(symbol);
assert(ptr);
if (NULL != err_msg) {
*err_msg = NULL;
}
*ptr = lt_dlsym(handle->ltdl_handle, symbol);
if (NULL != *ptr) {
return OPAL_SUCCESS;
}
if (NULL != err_msg) {
*err_msg = (char*) lt_dlerror();
}
return OPAL_ERROR;
}
static int libltdl_close(opal_dl_handle_t *handle)
{
assert(handle);
int ret;
ret = lt_dlclose(handle->ltdl_handle);
#if OPAL_ENABLE_DEBUG
free(handle->filename);
#endif
free(handle);
return ret;
}
static int libltdl_foreachfile(const char *search_path,
int (*func)(const char *filename, void *data),
void *data)
{
assert(search_path);
assert(func);
int ret = lt_dlforeachfile(search_path, func, data);
return (0 == ret) ? OPAL_SUCCESS : OPAL_ERROR;
}
/*
* Module definition
*/
opal_dl_base_module_t opal_dl_libltdl_module = {
.open = libltdl_open,
.lookup = libltdl_lookup,
.close = libltdl_close,
.foreachfile = libltdl_foreachfile
};