Hi all, The attached patch from Chris, fixes a build error by checking if the neccessary pthread implementation is available on the system and if not, disables building -lcaf_shmem.
Regression tested on x86_64-linux. I did regenerate with autoreconf 2.69 as stated in the PR. This fixes a P1. I prefer good review although it looks OK to me. Regards, Jerry Author: Christopher Albert <[email protected]> Date: Fri Mar 20 23:09:26 2026 +0100 libgfortran: Disable caf_shmem without usable process-shared pthreads [PR124512] Use a compile-time usability probe for the process-shared pthread API required by caf_shmem and only build libcaf_shmem when that probe succeeds. caf_shmem needs process-shared pthread primitives that are visible through the default pthread headers. AX_PTHREAD already established the baseline pthread flags; this additional check only verifies that the specific process-shared API surface is usable for caf/shmem/thread_support.c. PR fortran/124512 libgfortran/ChangeLog: * Makefile.am: Adjust the dependencies. * Makefile.in: Regenerate. * configure: Regenerate. * configure.ac: Add new check. Signed-off-by: Christopher Albert <[email protected]>
commit bd547511540679b8cd8f25b56d78364148bb6d49 Author: Christopher Albert <[email protected]> Date: Fri Mar 20 23:09:26 2026 +0100 libgfortran: Disable caf_shmem without usable process-shared pthreads [PR124512] Use a compile-time usability probe for the process-shared pthread API required by caf_shmem and only build libcaf_shmem when that probe succeeds. caf_shmem needs process-shared pthread primitives that are visible through the default pthread headers. AX_PTHREAD already established the baseline pthread flags; this additional check only verifies that the specific process-shared API surface is usable for caf/shmem/thread_support.c. PR fortran/124512 libgfortran/ChangeLog: * Makefile.am: Adjust the dependencies. * Makefile.in: Regenerate. * configure: Regenerate. * configure.ac: Add new check. Signed-off-by: Christopher Albert <[email protected]> diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am index c57c5bec0e6..da865af51cf 100644 --- a/libgfortran/Makefile.am +++ b/libgfortran/Makefile.am @@ -61,7 +61,7 @@ libgfortran_la_DEPENDENCIES = $(version_dep) libgfortran.spec $(LIBQUADLIB_DEP) libcaf_shared_DEPS = caf/libcaf.h caf/caf_error.h libcaf_shared_SRCS = caf/caf_error.c -cafexeclib_LTLIBRARIES = libcaf_single.la libcaf_shmem.la +cafexeclib_LTLIBRARIES = libcaf_single.la cafexeclibdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR) libcaf_single_la_SOURCES = caf/single.c $(libcaf_shared_SRCS) libcaf_single_la_LDFLAGS = -static @@ -69,6 +69,7 @@ libcaf_single_la_DEPENDENCIES = $(libcaf_shared_DEPS) libcaf_single_la_LINK = $(LINK) $(libcaf_single_la_LDFLAGS) if ENABLE_CAF_SHMEM +cafexeclib_LTLIBRARIES += libcaf_shmem.la 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 \ diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in index 4a13e3820bd..360187a10ce 100644 --- a/libgfortran/Makefile.in +++ b/libgfortran/Makefile.in @@ -93,8 +93,9 @@ host_triplet = @host@ target_triplet = @target@ @ENABLE_DARWIN_AT_RPATH_TRUE@am__append_1 = -Wc,-nodefaultrpaths \ @ENABLE_DARWIN_AT_RPATH_TRUE@ -Wl,-rpath,@loader_path -@LIBGFOR_MINIMAL_TRUE@am__append_2 = -DLIBGFOR_MINIMAL -@LIBGFOR_MINIMAL_FALSE@am__append_3 = \ +@ENABLE_CAF_SHMEM_TRUE@am__append_2 = libcaf_shmem.la +@LIBGFOR_MINIMAL_TRUE@am__append_3 = -DLIBGFOR_MINIMAL +@LIBGFOR_MINIMAL_FALSE@am__append_4 = \ @LIBGFOR_MINIMAL_FALSE@io/close.c \ @LIBGFOR_MINIMAL_FALSE@io/file_pos.c \ @LIBGFOR_MINIMAL_FALSE@io/format.c \ @@ -112,7 +113,7 @@ target_triplet = @target@ @LIBGFOR_MINIMAL_FALSE@io/fbuf.c \ @LIBGFOR_MINIMAL_FALSE@io/async.c -@LIBGFOR_MINIMAL_FALSE@am__append_4 = \ +@LIBGFOR_MINIMAL_FALSE@am__append_5 = \ @LIBGFOR_MINIMAL_FALSE@intrinsics/access.c \ @LIBGFOR_MINIMAL_FALSE@intrinsics/c99_functions.c \ @LIBGFOR_MINIMAL_FALSE@intrinsics/chdir.c \ @@ -145,9 +146,9 @@ target_triplet = @target@ @LIBGFOR_MINIMAL_FALSE@intrinsics/umask.c \ @LIBGFOR_MINIMAL_FALSE@intrinsics/unlink.c -@IEEE_SUPPORT_TRUE@am__append_5 = ieee/ieee_helper.c -@LIBGFOR_MINIMAL_TRUE@am__append_6 = runtime/minimal.c -@LIBGFOR_MINIMAL_FALSE@am__append_7 = \ +@IEEE_SUPPORT_TRUE@am__append_6 = ieee/ieee_helper.c +@LIBGFOR_MINIMAL_TRUE@am__append_7 = runtime/minimal.c +@LIBGFOR_MINIMAL_FALSE@am__append_8 = \ @LIBGFOR_MINIMAL_FALSE@runtime/backtrace.c \ @LIBGFOR_MINIMAL_FALSE@runtime/convert_char.c \ @LIBGFOR_MINIMAL_FALSE@runtime/environ.c \ @@ -236,6 +237,8 @@ am__objects_1 = caf/libcaf_shmem_la-caf_error.lo @ENABLE_CAF_SHMEM_TRUE@ caf/shmem/libcaf_shmem_la-teams_mgmt.lo \ @ENABLE_CAF_SHMEM_TRUE@ caf/shmem/libcaf_shmem_la-thread_support.lo libcaf_shmem_la_OBJECTS = $(am_libcaf_shmem_la_OBJECTS) +@ENABLE_CAF_SHMEM_TRUE@am_libcaf_shmem_la_rpath = -rpath \ +@ENABLE_CAF_SHMEM_TRUE@ $(cafexeclibdir) libcaf_single_la_LIBADD = am__objects_2 = caf/caf_error.lo am_libcaf_single_la_OBJECTS = caf/single.lo $(am__objects_2) @@ -805,7 +808,7 @@ AMTAR = @AMTAR@ # Some targets require additional compiler options for IEEE compatibility. AM_CFLAGS = @AM_CFLAGS@ -fcx-fortran-rules $(SECTION_FLAGS) \ - $(IEEE_FLAGS) $(am__append_2) + $(IEEE_FLAGS) $(am__append_3) AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AM_FCFLAGS = @AM_FCFLAGS@ $(IEEE_FLAGS) AR = @AR@ @@ -989,7 +992,7 @@ libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` libgfortran_la_DEPENDENCIES = $(version_dep) libgfortran.spec $(LIBQUADLIB_DEP) libcaf_shared_DEPS = caf/libcaf.h caf/caf_error.h libcaf_shared_SRCS = caf/caf_error.c -cafexeclib_LTLIBRARIES = libcaf_single.la libcaf_shmem.la +cafexeclib_LTLIBRARIES = libcaf_single.la $(am__append_2) cafexeclibdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR) libcaf_single_la_SOURCES = caf/single.c $(libcaf_shared_SRCS) libcaf_single_la_LDFLAGS = -static @@ -1021,7 +1024,7 @@ AM_CPPFLAGS = -iquote$(srcdir)/io -I$(srcdir)/$(MULTISRCTOP)../gcc \ -I$(MULTIBUILDTOP)../libbacktrace \ -I../libbacktrace -gfor_io_src = io/size_from_kind.c $(am__append_3) +gfor_io_src = io/size_from_kind.c $(am__append_4) gfor_io_headers = \ io/io.h \ io/fbuf.h \ @@ -1044,7 +1047,7 @@ gfor_helper_src = intrinsics/associated.c intrinsics/abort.c \ intrinsics/selected_real_kind.f90 intrinsics/trigd.c \ intrinsics/unpack_generic.c runtime/in_pack_generic.c \ runtime/in_unpack_generic.c runtime/in_pack_class.c \ - runtime/in_unpack_class.c $(am__append_4) $(am__append_5) + runtime/in_unpack_class.c $(am__append_5) $(am__append_6) @IEEE_SUPPORT_TRUE@gfor_ieee_helper_src = ieee/ieee_helper.c @IEEE_SUPPORT_FALSE@gfor_ieee_src = @IEEE_SUPPORT_TRUE@gfor_ieee_src = \ @@ -1054,7 +1057,7 @@ gfor_helper_src = intrinsics/associated.c intrinsics/abort.c \ gfor_src = runtime/bounds.c runtime/compile_options.c \ runtime/deep_copy.c runtime/memory.c runtime/string.c \ - runtime/select.c $(am__append_6) $(am__append_7) + runtime/select.c $(am__append_7) $(am__append_8) i_matmul_c = \ generated/matmul_i1.c \ generated/matmul_i2.c \ @@ -2038,7 +2041,7 @@ caf/shmem/libcaf_shmem_la-thread_support.lo: \ caf/shmem/$(am__dirstamp) caf/shmem/$(DEPDIR)/$(am__dirstamp) libcaf_shmem.la: $(libcaf_shmem_la_OBJECTS) $(libcaf_shmem_la_DEPENDENCIES) $(EXTRA_libcaf_shmem_la_DEPENDENCIES) - $(AM_V_GEN)$(libcaf_shmem_la_LINK) -rpath $(cafexeclibdir) $(libcaf_shmem_la_OBJECTS) $(libcaf_shmem_la_LIBADD) $(LIBS) + $(AM_V_GEN)$(libcaf_shmem_la_LINK) $(am_libcaf_shmem_la_rpath) $(libcaf_shmem_la_OBJECTS) $(libcaf_shmem_la_LIBADD) $(LIBS) caf/single.lo: caf/$(am__dirstamp) caf/$(DEPDIR)/$(am__dirstamp) caf/caf_error.lo: caf/$(am__dirstamp) caf/$(DEPDIR)/$(am__dirstamp) diff --git a/libgfortran/configure b/libgfortran/configure index d0ebed7ea84..75cf47e3a19 100755 --- a/libgfortran/configure +++ b/libgfortran/configure @@ -18414,6 +18414,44 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu +# caf_shmem needs process-shared pthread primitives that are visible through +# the default pthread headers. AX_PTHREAD already established the baseline +# pthread flags; this additional check only verifies that the specific +# process-shared API surface is usable for caf/shmem/thread_support.c. +if test x$enable_caf_shmem = xtrue; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for usable process-shared pthread support for caf_shmem" >&5 +$as_echo_n "checking for usable process-shared pthread support for caf_shmem... " >&6; } + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <pthread.h> +int +main () +{ +pthread_mutexattr_t mattr; + pthread_condattr_t cattr; + (void) &pthread_mutexattr_setpshared; + (void) &pthread_condattr_setpshared; + return pthread_mutexattr_init (&mattr) + || pthread_condattr_init (&cattr) + || pthread_mutexattr_setpshared (&mattr, PTHREAD_PROCESS_SHARED) + || pthread_condattr_setpshared (&cattr, PTHREAD_PROCESS_SHARED); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + enable_caf_shmem=false +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CFLAGS="$save_CFLAGS" +fi if test x$enable_caf_shmem = xtrue; then ENABLE_CAF_SHMEM_TRUE= ENABLE_CAF_SHMEM_FALSE='#' diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac index 530d15f0152..da9ae604cab 100644 --- a/libgfortran/configure.ac +++ b/libgfortran/configure.ac @@ -351,6 +351,30 @@ AX_PTHREAD([ ], [ enable_caf_shmem=false ]) +# caf_shmem needs process-shared pthread primitives that are visible through +# the default pthread headers. AX_PTHREAD already established the baseline +# pthread flags; this additional check only verifies that the specific +# process-shared API surface is usable for caf/shmem/thread_support.c. +if test x$enable_caf_shmem = xtrue; then + AC_MSG_CHECKING([for usable process-shared pthread support for caf_shmem]) + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include <pthread.h>]], + [[pthread_mutexattr_t mattr; + pthread_condattr_t cattr; + (void) &pthread_mutexattr_setpshared; + (void) &pthread_condattr_setpshared; + return pthread_mutexattr_init (&mattr) + || pthread_condattr_init (&cattr) + || pthread_mutexattr_setpshared (&mattr, PTHREAD_PROCESS_SHARED) + || pthread_condattr_setpshared (&cattr, PTHREAD_PROCESS_SHARED);]])], + [AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no]) + enable_caf_shmem=false]) + CFLAGS="$save_CFLAGS" +fi 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
