Skip to content

Commit

Permalink
java: try do dlopen libmpi with the full path
Browse files Browse the repository at this point in the history
Since OS X 10.11 (aka El Capitan) DYLD_LIBRARY_PATH is no more
propagated to children, so try to dlopen libmpi with the full path
using the directory of libmpi_java

Fixes open-mpi#1220

Thanks Alexander Daryin for reporting this
  • Loading branch information
ggouaillardet committed Dec 17, 2015
1 parent d668612 commit 99a29b3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
12 changes: 12 additions & 0 deletions config/ompi_setup_java.m4
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,22 @@ AC_DEFUN([OMPI_SETUP_JAVA_BINDINGS],[
# header file needs this file, so we need to check for
# it/include it in our sources when compiling on Mac).
AC_CHECK_HEADERS([TargetConditionals.h])

# dladdr is required to build the full path to libmpi on OS X 10.11 aka El Capitan
# OPAL_CHECK_PACKAGE([mpi_java], [dlfcn.h], [dl], [dladdr], [], [], [], [OMPI_HAVE_DLADDR=1], [OMPI_HAVE_DLADDR=0])
#AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <dlfcn.h> ]],
#[[Dl_info info; dladdr((void *)0, &info);]])],
#[OMPI_HAVE_DLADDR=1],
#[OMPI_HAVE_DLADDR=0])
AC_CHECK_TYPE([Dl_info], [OMPI_HAVE_DLADDR=1], [OMPI_HAVE_DLADDR=0], [[#include <dlfcn.h>]])

else
AC_MSG_RESULT([no])
WANT_MPI_JAVA_SUPPORT=0
OMPI_HAVE_DLADDR=0
fi
AC_DEFINE_UNQUOTED([OMPI_HAVE_DLADDR], [$OMPI_HAVE_DLADDR],
[do we have dladdr])
AC_DEFINE_UNQUOTED([OMPI_WANT_JAVA_BINDINGS], [$WANT_MPI_JAVA_SUPPORT],
[do we want java mpi bindings])
AM_CONDITIONAL(OMPI_WANT_JAVA_BINDINGS, test "$WANT_MPI_JAVA_SUPPORT" = "1")
Expand Down
6 changes: 4 additions & 2 deletions ompi/mpi/java/c/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- makefile -*-
#
# Copyright (c) 2011-2013 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2015 Los Alamos National Security, LLC. All rights
# reserved.
# Copyright (c) 2015 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
Expand Down Expand Up @@ -44,7 +46,7 @@ libmpi_java_la_SOURCES = \
mpi_Status.c \
mpi_Win.c

libmpi_java_la_LIBADD = $(top_builddir)/ompi/libmpi.la
libmpi_java_la_LIBADD = -ldl $(top_builddir)/ompi/libmpi.la
libmpi_java_la_LDFLAGS = -version-info $(libmpi_java_so_version)

endif
27 changes: 25 additions & 2 deletions ompi/mpi/java/c/mpi_MPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* reserved.
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Intel, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -64,6 +66,9 @@
#endif
#include <dlfcn.h>
#include <poll.h>
#if HAVE_LIBGEN_H
#include <libgen.h>
#endif

#include "opal/util/output.h"
#include "opal/datatype/opal_convertor.h"
Expand Down Expand Up @@ -125,8 +130,26 @@ OBJ_CLASS_INSTANCE(ompi_java_buffer_t,
jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
libmpi = dlopen("libmpi." OPAL_DYN_LIB_SUFFIX, RTLD_NOW | RTLD_GLOBAL);

if(libmpi == NULL)
#if OMPI_HAVE_DLADDR && HAVE_LIBGEN_H
/*
* OS X El Capitan does not propagate DYLD_LIBRARY_PATH to children any more
* so if previous dlopen failed, try to open libmpi in the same directory
* than the current libmpi_java
*/
if(NULL == libmpi) {
Dl_info info;
if(0 != dladdr((void *)JNI_OnLoad, &info)) {
char libmpipath[OPAL_PATH_MAX];
char *libmpijavapath = strdup(info.dli_fname);
if (NULL != libmpijavapath) {
snprintf(libmpipath, OPAL_PATH_MAX-1, "%s/libmpi." OPAL_DYN_LIB_SUFFIX, dirname(libmpijavapath));
free(libmpijavapath);
libmpi = dlopen(libmpipath, RTLD_NOW | RTLD_GLOBAL);
}
}
}
#endif
if(NULL == libmpi)
{
fprintf(stderr, "Java bindings failed to load libmpi: %s\n",dlerror());
exit(1);
Expand Down

0 comments on commit 99a29b3

Please sign in to comment.