Skip to content

Commit f7989f4

Browse files
committed
fortran.m4: disallow when sizeof(int) != sizeof(INTEGER)
NOTE: This is intentionally not a cherry pick from master. Instead, this is a cherry-pick from the equivalent commit on the v4.0.x branch. See below. There is a problem with the mpi_f08 module when sizeof(int) != sizeof(INTEGER): the size of TYPE(MPI_Status) is too small. This causes buffer overruns when Open MPI is configured with (for example) sizeof(int)==4 and sizeof(INTEGER)==8, and then you call the mpi_f08 MPI_RECV subroutine. This will end up copying the resulting C MPI_Status to the buffer pointing to the Fortran status, but the code does not know if the Fortran status is an mpif.h status or a TYPE(MPI_Status) -- it just blindly copies over as if the Fortran status is an INTEGER array of length MPI_STATUS_SIZE. Unfortunately, TYPE(MPI_Status) is actually smaller than this, so we overrun the buffer. Hilarity ensues. The simple fix for this is to make TYPE(MPI_Status) the same size as INTEGER(MPI_STATUS_SIZE), but we can't do that here on the release branch because it will break ABI. However: 1. It is a fairly uncommon case to have sizeof(int) != sizeof(INTEGER) 2. This has not worked since v4.0.0, so it is not a regression So instead of fixing it, we just now explicitly disallow this case: configure will abort if sizeof(int) != sizeof(INTEGER). Thanks to @ahaichen for reporting the issue. Note: the proper fix has been implemented on master (i.e., what will become v5.0.0), but since that breaks ABI, we can't cherry pick it back here to an existing release branch series. Hence, we cherry-picked this fix from the v4.0.x branch. Signed-off-by: Jeff Squyres <[email protected]> (cherry picked from commit affa853)
1 parent 64c5e21 commit f7989f4

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

config/ompi_setup_mpi_fortran.m4

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,31 @@ AC_DEFUN([OMPI_SETUP_MPI_FORTRAN],[
154154
OMPI_FORTRAN_CHECK([LOGICAL*8], [yes],
155155
[int, int64_t, long long, long], [8], [yes])
156156

157+
# This version of Open MPI does not properly handle if
158+
# sizeof(INTEGER) != sizeof(int). It could be fixed (and as of
159+
# July 2020, is fixed on master / what will eventually become Open
160+
# MPI v5.0.x), but will cause an ABI break. Hence, we're not
161+
# going to fix it here on this release branch, and will simply
162+
# refuse to build (i.e., abort configure) if we detect this
163+
# situation.
164+
#
165+
# See https://github.com/open-mpi/ompi/pull/7921 for details -- in
166+
# particular, the comment at
167+
# https://github.com/open-mpi/ompi/pull/7921#issuecomment-656418618.
168+
AC_MSG_NOTICE([NOTICE: this version of Open MPI does not support the case where])
169+
AC_MSG_NOTICE([sizeof(C int) is not the same as sizeof(Fortran INTEGER).])
170+
AC_MSG_NOTICE([The next set of tests will fail and Open MPI will refuse to build])
171+
AC_MSG_NOTICE([if sizeof(C int) != sizeof(Fortran INTEGER).])
172+
# We already checked for sizeof(int). But display it again, just
173+
# so that it's in the stdout in case the next set of tests fails.
174+
AC_MSG_CHECKING([size of int])
175+
AC_MSG_RESULT([$ac_cv_sizeof_int (cached)])
176+
177+
# Only check to see if Fortran INTEGER is the same as C int. Per
178+
# above, if it's not, fail the test/abort.
157179
OMPI_FORTRAN_CHECK([INTEGER], [yes],
158-
[int32_t, int, int64_t, long long, long], [-1], [yes])
180+
[int], [-1], [yes])
181+
159182
OMPI_FORTRAN_CHECK([INTEGER*1], [no],
160183
[char, int8_t, short, int, int64_t, long long, long], [1], [yes])
161184
OMPI_FORTRAN_CHECK([INTEGER*2], [no],

0 commit comments

Comments
 (0)