Skip to content
Snippets Groups Projects
Commit 74c7e2d3 authored by Thomas Jahns's avatar Thomas Jahns :cartwheel:
Browse files

Add workaround for libxml2-caused exceptions.

* These may occur during mpich 4.1.x startup.
parent 591edaac
No related branches found
No related tags found
No related merge requests found
......@@ -83,6 +83,8 @@ EXTRA_DIST = util/sunf95preproc-wrapper \
config/checkdoc/mpich_4.0.x_ddt_transfer.txt \
config/checkpatch/mpich_4.0.x_ddt_transfer.patch \
config/checksrc/mpich_4.0.x_ddt_transfer.c \
config/checkdoc/mpi_fortran_startup.txt \
config/checksrc/mpi_fortran_startup.f90 \
contrib/00nagfor-libtool-patch/README.txt \
contrib/00nagfor-libtool-patch/nagfor-libtool-2.4.2.patch \
contrib/00nagfor-libtool-patch/nagfor-libtool-2.4.6.patch \
......
This test checks that the Fortran run-time is configured correctly.
Unfortunately, the following cases are known where this might not be
the case:
1. Some versions of MPICH need libxml2 of which in turn there are
older versions which raise arithmetic exceptions due to divisions
by zero (which is UB) being executed in xmlXPathInit.
This then causes issues with builds that have floating point
run-time checks enabled, like the ifort -fpe0 option.
!>
!! @file mpi_fortran_startup.f90
!! @brief Test startup of MPI-parallel Fortran programs
!!
!! @copyright Copyright (C) 2023 Jörg Behrens <behrens@dkrz.de>
!! Moritz Hanke <hanke@dkrz.de>
!! Thomas Jahns <jahns@dkrz.de>
!!
!! @author Jörg Behrens <behrens@dkrz.de>
!! Moritz Hanke <hanke@dkrz.de>
!! Thomas Jahns <jahns@dkrz.de>
!!
!
! Maintainer: Jörg Behrens <behrens@dkrz.de>
! Moritz Hanke <hanke@dkrz.de>
! Thomas Jahns <jahns@dkrz.de>
! URL: https://dkrz-sw.gitlab-pages.dkrz.de/yaxt/
!
! Redistribution and use in source and binary forms, with or without
! modification, are permitted provided that the following conditions are
! met:
!
! Redistributions of source code must retain the above copyright notice,
! this list of conditions and the following disclaimer.
!
! Redistributions in binary form must reproduce the above copyright
! notice, this list of conditions and the following disclaimer in the
! documentation and/or other materials provided with the distribution.
!
! Neither the name of the DKRZ GmbH nor the names of its contributors
! may be used to endorse or promote products derived from this software
! without specific prior written permission.
!
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
! IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
! PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
! OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
! EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
! PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
! LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
! NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
!
! acx_mpirun_num_tasks=2
PROGRAM mpi_hello
! INCLUDE "mpif.h"
USE mpi
USE iso_c_binding
INTERFACE
SUBROUTINE posix_exit(code) BIND(c, name="exit")
IMPORT :: c_int
INTEGER(c_int), VALUE, INTENT(in) :: code
END SUBROUTINE posix_exit
END INTERFACE
INTEGER :: ierror, comm_size, comm_rank
INTEGER :: procnum, acx_mpirun_num_tasks
CALL mpi_init(ierror)
CALL handle_mpi_error(ierror)
CALL mpi_comm_rank(mpi_comm_world, comm_rank, ierror)
CALL handle_mpi_error(ierror)
CALL mpi_comm_size(mpi_comm_world, comm_size, ierror)
CALL handle_mpi_error(ierror)
acx_mpirun_num_tasks = 2
procnum = 1
CALL mpi_allreduce(mpi_in_place, procnum, 1, mpi_integer, &
mpi_sum, mpi_comm_world, ierror)
IF (procnum /= acx_mpirun_num_tasks) THEN
CALL mpi_abort(mpi_comm_world, 1, ierror)
END IF
CALL mpi_finalize(ierror)
CALL handle_mpi_error(ierror)
CONTAINS
SUBROUTINE handle_mpi_error(ierror)
INTEGER, INTENT(in) :: ierror
INTEGER :: msg_len, msg_ierror
CHARACTER(len=MPI_MAX_ERROR_STRING) :: msg
IF (ierror /= MPI_SUCCESS) THEN
CALL mpi_error_string(ierror, msg, msg_len, msg_ierror)
WRITE (0, *) msg(1:msg_len)
FLUSH(0)
CALL posix_exit(1_c_int)
END IF
END SUBROUTINE handle_mpi_error
END PROGRAM mpi_hello
!
! Local Variables:
! f90-continuation-indent: 5
! coding: utf-8
! indent-tabs-mode: nil
! show-trailing-whitespace: t
! require-trailing-newline: t
! End:
!
......@@ -437,6 +437,10 @@ ACX_MPI_DEFECTS(,,
XT_WORKAROUND_MPI_CPPFLAGS="-I$ac_pwd/$acx_yaksa_add_workaround ${XT_WORKAROUND_MPI_CPPFLAGS-$CPPFLAGS}"],
[AC_MSG_WARN([Cannot apply MPICH YAKSA datatype bug work-around.])
mpi_defect_fail_action])],
[mpi_fortran_startup],
[AC_MSG_WARN([known problem detected, attempting work-around!])
ACX_LIBXML2_WORKAROUND(,[mpi_fortran_startup.f90],
[AC_LIBOBJ([xt_xmlXPathInit])])],
[mpich_unweighted_topo_comm_dup],
[AC_MSG_WARN([known MPICH 3.0-3.4.2 problem detected, activating work-around!])
AC_DEFINE([NEED_MPICH_UNWEIGHTED_COMM_DUP_WORKAROUND],,
......
dnl acx_libxml2_workaround.m4 --- test whether libxml2 can be
dnl run-time-patched to work around a known problem executing division
dnl by zero during xmlXPathInit
dnl
dnl Copyright (C) 2023 Thomas Jahns <jahns@dkrz.de>
dnl
dnl Keywords: configure configure.ac autoconf libxml2 xmlXPathInit SIGFPE
dnl Author: Thomas Jahns <jahns@dkrz.de>
dnl Maintainer: Thomas Jahns <jahns@dkrz.de>
dnl URL: https://www.dkrz.de/redmine/projects/scales-ppm
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions are
dnl met:
dnl
dnl Redistributions of source code must retain the above copyright notice,
dnl this list of conditions and the following disclaimer.
dnl
dnl Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl Neither the name of the DKRZ GmbH nor the names of its contributors
dnl may be used to endorse or promote products derived from this software
dnl without specific prior written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
dnl IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
dnl TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
dnl PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
dnl OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
dnl
dnl ACX_LIBXML2_WORKAROUND([TEST-SOURCE-DIR=config/checksrc],
dnl [LIST-OF-WORK-AROUND-TESTS],
dnl [ACTION-IF-WORKAROUND-SUCCEEDS],
dnl [ACTION-IF-WORKAROUND-FAILED=AC_MSG_FAILURE],
dnl [WORKAROUND-FILE=src/mpi-workarounds/xt_xmlXPathInit.c])
dnl
dnl Assumes CC and CFLAGS are setup for MPI.
dnl Then builds files needed for work-around in addition to test programs
dnl and checks if linking with those fixes the issue.
dnl See ACX_MPI_DEFECTS for further description of tests.
AC_DEFUN([ACX_LIBXML2_WORKAROUND],
[AC_LANG_PUSH([C])
dnl 1. detect libxml2 version
dnl currently skipped, only one implementation known to be needed
dnl so far
acx_saved_LIBS=$LIBS
acx_saved_CPPFLAGS=$CPPFLAGS
acx_is_affected_libxml2=:
dnl 2. copy workaround source into place for configure logic
acx_temp="m4_default([$5],[src/mpi-workarounds/])"
for acx_workaround in xt_xmlXPathInit xt_xmlInitParser \
xt_xmlInitParser.c_def
do
AS_IF([test "$acx_workaround" = xt_xmlInitParser.c_def],
[acx_workaround=xt_xmlInitParser
CPPFLAGS="$CPPFLAGS -DXT_LIBXML_INCLUDE_SUBDIR"])
cp "$srcdir/$acx_temp/${acx_workaround}.c" conftest.c
dnl 3. build fixed xt_xmlXPathInit.c
AC_COMPILE_IFELSE(,
[ACX_MV_OBJ([conftest],[xt_workaround])],
[rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
continue])
dnl 4. verify listed tests now succeed
LIBS="xt_workaround.$ac_objext -lxml2 $LIBS"
acx_libxml2_check_dir=`echo "acx_mpi_check_src_" | sed 's@/@<:@^/@:>@*$[]@@'`
ACX_MPI_DEFECTS([$acx_libxml2_check_dir],, [acx_is_affected_libxml2=false], [$2])
rm -f xt_workaround.*
done
LIBS=$acx_saved_LIBS
dnl 5. execute action corresponding to outcome of tests
AS_IF([$acx_is_affected_libxml2],
[$3
AS_IF([test "x$CPPFLAGS" != "x$acx_saved_CPPFLAGS"],
[AC_DEFINE([XT_LIBXML_INCLUDE_SUBDIR],,
[are libxml header files buried in sub-directory?])])],
[m4_default([$4],
[AC_MSG_FAILURE(
[Cannot apply libxml2 SIGFPE bug work-around.])])])
CPPFLAGS=$acx_saved_CPPFLAGS
AC_LANG_POP([C])])
dnl
dnl Local Variables:
dnl mode: autoconf
dnl license-project-url: "https://www.dkrz.de/redmine/projects/scales-ppm"
dnl license-default: "bsd"
dnl End:
......@@ -49,6 +49,8 @@ libmpi_workaround_la_SOURCES =
libmpi_workaround_la_LIBADD = $(LIBOBJS) $(xt_mpi_workaround_LIBS) $(MPI_C_LIB)
endif
EXTRA_DIST = xt_xmlInitParser.c
distclean-local:
-rm -rf '$(DEPDIR)'
......
/**
* @file xt_xmlInitParser.c
*
* Simple workaround for libxml2 versions creating division-by-zero
* errors
*
* @copyright Copyright (C) 2023 Jörg Behrens <behrens@dkrz.de>
* Moritz Hanke <hanke@dkrz.de>
* Thomas Jahns <jahns@dkrz.de>
*
* @author Jörg Behrens <behrens@dkrz.de>
* Moritz Hanke <hanke@dkrz.de>
* Thomas Jahns <jahns@dkrz.de>
*/
/*
* Maintainer: Jörg Behrens <behrens@dkrz.de>
* Moritz Hanke <hanke@dkrz.de>
* Thomas Jahns <jahns@dkrz.de>
* URL: https://dkrz-sw.gitlab-pages.dkrz.de/yaxt/
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of the DKRZ GmbH nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef XT_LIBXML_INCLUDE_SUBDIR
#include <libxml2/libxml/parser.h>
#else
#include <libxml/parser.h>
#endif
#include <fenv.h>
static void __attribute__((constructor))
xt_init_xml_parser_nofpe(void) {
fenv_t prev_fenv;
fegetenv(&prev_fenv)
int prevmask = fedisableexcept(FE_DIVBYZERO);
xmlInitParser();
fesetenv(&prev_fenv)
}
/*
* Local Variables:
* c-basic-offset: 2
* coding: utf-8
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
/**
* @file xt_xmlXPathInit.c
*
* Simple workaround for libxml2 versions creating division-by-zero
* errors
*
* @copyright Copyright (C) 2023 Jörg Behrens <behrens@dkrz.de>
* Moritz Hanke <hanke@dkrz.de>
* Thomas Jahns <jahns@dkrz.de>
*
* @author Jörg Behrens <behrens@dkrz.de>
* Moritz Hanke <hanke@dkrz.de>
* Thomas Jahns <jahns@dkrz.de>
*/
/*
* Maintainer: Jörg Behrens <behrens@dkrz.de>
* Moritz Hanke <hanke@dkrz.de>
* Thomas Jahns <jahns@dkrz.de>
* URL: https://dkrz-sw.gitlab-pages.dkrz.de/yaxt/
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of the DKRZ GmbH nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <math.h>
extern double xmlXPathPINF, xmlXPathNINF, xmlXPathNAN;
void
xmlXPathInit(void) {
xmlXPathPINF = INFINITY;
xmlXPathNINF = -INFINITY;
xmlXPathNAN = NAN;
}
/*
* Local Variables:
* c-basic-offset: 2
* coding: utf-8
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment