From 6164dc4960805b5502f86f9a2dccc5fc557e44d6 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Tue, 4 Nov 2014 14:30:28 -0500 Subject: [PATCH] fortran: fix linking with Fortran sentinel values In OMPI 1.8 and 1.8.1, we didn't allow gfortran to use the ignore-TKR style "mpi" Fortran module (which is written in Fortran). Instead, gfortran used the TKR style "mpi" module, which is written in C. In OMPI 1.8.2, we removed the gfortran restriction (for suitably modern gfortran -- i.e., >= 4.9). This allowed gfortran to use the ignore-TKR style "mpi" module, but exposed a bug where MPI Fortran sentinel values wouldn't be linked properly on OS X. The solution is to use ```-Wl,-flat_namespace``` (see the OS X ld(1) man page for details) when both building the libraries and in the wrapper compilers. Thanks to Github user yafshar for rasising the issue. Fixes #259. --- config/ompi_setup_fc.m4 | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/config/ompi_setup_fc.m4 b/config/ompi_setup_fc.m4 index ec611005cd..7ac3ac8a81 100644 --- a/config/ompi_setup_fc.m4 +++ b/config/ompi_setup_fc.m4 @@ -13,7 +13,7 @@ dnl All rights reserved. dnl Copyright (c) 2007 Los Alamos National Security, LLC. All rights dnl reserved. dnl Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. -dnl Copyright (c) 2009-2013 Cisco Systems, Inc. All rights reserved. +dnl Copyright (c) 2009-2014 Cisco Systems, Inc. All rights reserved. dnl $COPYRIGHT$ dnl dnl Additional copyrights may follow @@ -131,23 +131,26 @@ AC_DEFUN([OMPI_SETUP_FC],[ [AC_FC_SRCEXT(f) AC_FC_SRCEXT(f90)]) - # Per #1982, on OS X, we may need some esoteric linker flags in - # the wrapper compilers. Assume that we need it for both F77 and - # FC flags (note that in an upcoming update where there will only - # be one Fortran compiler, anyway). + # Per trac #1982, on OS X, we may need some esoteric linker flags + # in the wrapper compilers. However, per + # https://github.com/open-mpi/ompi/issues/259, we need to use + # -Wl,-flat_namespace when *building* the library (and + # -Wl,-commons,use_dylibs isn't quite sufficient). AS_IF([test $ompi_fc_happy -eq 1], [AC_MSG_CHECKING([to see if Fortran compilers need additional linker flags]) case "$host" in *apple-darwin*) - # Test whether -Wl,-commons,use_dylibs works; if it - # does, use it. + # Test whether -Wl,-flat_namespace works; if it does, + # both use it to build the libraries, and also put it + # in the wrapper compiler LDFLAGS. LDFLAGS_save=$LDFLAGS - LDFLAGS="$LDFLAGS -Wl,-commons,use_dylibs" + LDFLAGS="$LDFLAGS -Wl,-flat_namespace" AC_LANG_PUSH([Fortran]) AC_LINK_IFELSE([AC_LANG_SOURCE([[program test integer :: i end program]])], - [OMPI_FORTRAN_WRAPPER_FLAGS="-Wl,-commons,use_dylibs" + [LDFLAGS_save=$LDFLAGS + OMPI_FORTRAN_WRAPPER_FLAGS="-Wl,-flat_namespace" OPAL_WRAPPER_FLAGS_ADD([FCFLAGS], [$OMPI_FORTRAN_WRAPPER_FLAGS])], [OMPI_FORTRAN_WRAPPER_FLAGS=none]) AC_LANG_POP([Fortran])