Skip to content

Commit

Permalink
ompi_setup_fc.m4: use -Wl,-ld_classic if supported
Browse files Browse the repository at this point in the history
Per open-mpi#12427, on MacOS, add
-Wl,-ld_classic to the Fortran wrapper compiler if that flag is
supported. This is needed to support the -Wl,-commons,use_dylibs
linker flag, which is needed for common Fortran symbols on MaxOS.

Signed-off-by: Jeff Squyres <[email protected]>
  • Loading branch information
jsquyres committed Jul 2, 2024
1 parent 8b7e577 commit 817cc01
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions config/ompi_setup_fc.m4
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,39 @@ I = 3]])],
AC_MSG_CHECKING([to see if mpifort compiler needs additional linker flags])
case "$host" in
*apple-darwin*)
# Test whether -Wl,-commons,use_dylibs works; if it does, use it.
# Test whether -Wl,-ld_classic works; if it does, use it.
# See https://github.com/open-mpi/ompi/issues/12427 for
# details.
message_result=
LDFLAGS_save=$LDFLAGS
LDFLAGS="$LDFLAGS -Wl,-commons,use_dylibs"
LDFLAGS="$LDFLAGS -Wl,-ld_classic"
AC_LANG_PUSH([Fortran])
AC_LINK_IFELSE([AC_LANG_SOURCE([[program test
integer :: i
end program]])],
[OMPI_FORTRAN_WRAPPER_FLAGS="-Wl,-commons,use_dylibs"
[OMPI_FORTRAN_WRAPPER_FLAGS="-Wl,-ld_classic"
message_result=$OMPI_FORTRAN_WRAPPER_FLAGS
OPAL_WRAPPER_FLAGS_ADD([FCFLAGS], [$OMPI_FORTRAN_WRAPPER_FLAGS])],
[OMPI_FORTRAN_WRAPPER_FLAGS=none])
[LDFLAGS=$LDFLAGS_save])

# Test whether -Wl,-commons,use_dylibs works; if it does, use it.
#
# Note: if -Wl,-ld_classic worked, above, it will still be in
# LDFLAGS. If not, it won't be still in LDFLAGS. This is
# intended behavior for this test: there are cases where
# -commons,use_dylibs required -ld_classic, and there are
# cases where it does not.
LDFLAGS="$LDFLAGS -Wl,-commons,use_dylibs"
AC_LINK_IFELSE([AC_LANG_SOURCE([[program test
integer :: i
end program]])],
[OMPI_FORTRAN_WRAPPER_FLAGS="-Wl,-commons,use_dylibs"
message_result="$OMPI_FORTRAN_WRAPPER_FLAGS $message_result"
OPAL_WRAPPER_FLAGS_ADD([FCFLAGS], [$OMPI_FORTRAN_WRAPPER_FLAGS])])

AC_LANG_POP([Fortran])
LDFLAGS=$LDFLAGS_save
AC_MSG_RESULT([$OMPI_FORTRAN_WRAPPER_FLAGS])
AC_MSG_RESULT([$message_result])
;;
*)
AC_MSG_RESULT([none])
Expand Down

0 comments on commit 817cc01

Please sign in to comment.