From ea75839204a71ba390d7d0235be80bd96fdc51ab Mon Sep 17 00:00:00 2001 From: Andre Vehreschild Date: Wed, 18 Feb 2026 10:14:58 +0100 Subject: [PATCH] Fortran: Make caf_shmem build pthread presence aware. On some system pthreads needs special treatment. Use the present AX_PTHREADS macro to figure what is needed. libgfortran/ChangeLog: * Makefile.am: Only build caf_shmem when pthreads is available. * configure.ac: Check for pthreads availability and needed flags. gcc/testsuite/ChangeLog: * gfortran.dg/coarray/caf.exp: Only add caf_shmem to tests when is build. --- gcc/testsuite/gfortran.dg/coarray/caf.exp | 18 +++++++++++++----- libgfortran/Makefile.am | 5 ++++- libgfortran/configure.ac | 10 ++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/gcc/testsuite/gfortran.dg/coarray/caf.exp b/gcc/testsuite/gfortran.dg/coarray/caf.exp index 9cd99f8e0cb..02c3591f377 100644 --- a/gcc/testsuite/gfortran.dg/coarray/caf.exp +++ b/gcc/testsuite/gfortran.dg/coarray/caf.exp @@ -29,6 +29,7 @@ # Load procedures from common libraries. load_lib gfortran-dg.exp load_lib atomic-dg.exp +load_lib target-libpath.exp # If a testcase doesn't have special options, use these. global DEFAULT_FFLAGS @@ -48,6 +49,11 @@ global gfortran_test_path global gfortran_aux_module_flags set gfortran_test_path $srcdir/$subdir set gfortran_aux_module_flags $DEFAULT_FFLAGS +global enable_caf_shmem +set gccpath [get_multilibs] +set shlib_ext [get_shlib_extension] +set enable_caf_shmem [expr [file exists "${gccpath}/libgfortran/.libs/libcaf_shmem.a"] || \ + [file exists "${gccpath}/libgfortran/.libs/libcaf_shmem.${shlib_ext}"] ] proc dg-compile-aux-modules { args } { global gfortran_test_path @@ -110,11 +116,13 @@ foreach test [lsort [glob -nocomplain $srcdir/$subdir/*.\[fF\]{,90,95,03,08} ]] cleanup-modules "" } - foreach flags $option_list { - verbose "Testing $nshort (libcaf_shmem), $flags" 1 - set gfortran_aux_module_flags "-fcoarray=lib $flags -lcaf_shmem" - dg-test $test "-fcoarray=lib $flags -lcaf_shmem" {} - cleanup-modules "" + if "$enable_caf_shmem" { + foreach flags $option_list { + verbose "Testing $nshort (libcaf_shmem), $flags" 1 + set gfortran_aux_module_flags "-fcoarray=lib $flags -lcaf_shmem" + dg-test $test "-fcoarray=lib $flags -lcaf_shmem" {} + cleanup-modules "" + } } } torture-finish diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am index c5c0fa5717c..c57c5bec0e6 100644 --- a/libgfortran/Makefile.am +++ b/libgfortran/Makefile.am @@ -68,6 +68,8 @@ libcaf_single_la_LDFLAGS = -static libcaf_single_la_DEPENDENCIES = $(libcaf_shared_DEPS) libcaf_single_la_LINK = $(LINK) $(libcaf_single_la_LDFLAGS) +if ENABLE_CAF_SHMEM +libcaf_shmem_la_CFLAGS = $(CAF_SHMEM_CFLAGS) libcaf_shmem_la_SOURCES = $(libcaf_shared_SRCS) \ caf/shmem.c caf/shmem/alloc.c caf/shmem/allocator.c \ caf/shmem/collective_subroutine.c caf/shmem/counter_barrier.c \ @@ -80,7 +82,8 @@ libcaf_shmem_la_DEPENDENCIES = $(libcaf_shared_DEPS) caf/shmem/alloc.h \ caf/shmem/counter_barrier.h caf/shmem/hashmap.h \ caf/shmem/shared_memory.h caf/shmem/supervisor.h caf/shmem/sync.h \ caf/shmem/teams_mgmt.h caf/shmem/thread_support.h -libcaf_shmem_la_LINK = $(LINK) $(libcaf_shmem_la_LDFLAGS) +libcaf_shmem_la_LINK = $(LINK) $(libcaf_shmem_la_LDFLAGS) $(CAF_SHMEM_LIBS) +endif if IEEE_SUPPORT fincludedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/finclude diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac index b165dff1e05..fea8292225b 100644 --- a/libgfortran/configure.ac +++ b/libgfortran/configure.ac @@ -343,6 +343,16 @@ else freelocale uselocale strerror_l strtof128 strfromf128) fi +# Check for existing and usable pthreads. +AX_PTHREAD([ + enable_caf_shmem=true + CAF_SHMEM_CFLAGS="$PTHREAD_CFLAGS" + CAF_SHMEM_LIBS="$PTHREAD_LIBS" + ], [ + enable_caf_shmem=false + ]) +AM_CONDITIONAL([ENABLE_CAF_SHMEM], [test x$enable_caf_shmem = xtrue]) + # Check strerror_r, cannot be above as versions with two and three arguments exist LIBGFOR_CHECK_STRERROR_R