[PATCH] PR 125324 Fix - -fcoarray=shared should imply -pthread / gfortran.dg/coarray_51.f90 FAIL

Jerry D <[email protected]>
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
As stated in the PR, this issue is possibly related to the version of glibc 
installed on some systems. I can't test this on so many systems, so I want to 
see if the auto testers pick it up. The patch is fairly simple. I copied Tobias 
as the original reporter.

Assisted by Claude Sonnet 4.6 to be clear. See attached.

OK for mainline? If accepted probably should be backported to 16.

Jerry

---
fortran: also link -lpthread when -fcoarray=shared is used

  [PR125324]

When the driver auto-links -lcaf_shmem for -fcoarray=shared it must also
link -lpthread because the shmem CAF runtime uses POSIX threads internally.

	PR fortran/125324

gcc/fortran/ChangeLog:

	* gfortranspec.cc (lang_specific_driver): Also append -lpthread
	when need_caf_shmem is set.

Assisted by: Claude Sonnet 4.6
---
0001-fortran-also-link-lpthread-when-fcoarray-shared-is-u.patch (text/x-patch, 1.1 KB)
From bc334e5e5add66b300df0dabc067c785e3db9a15 Mon Sep 17 00:00:00 2001
From: Jerry DeLisle <[email protected]>
Date: Wed, 27 May 2026 09:24:26 -0700
Subject: [PATCH] fortran: also link -lpthread when -fcoarray=shared is used
 [PR125324]

When the driver auto-links -lcaf_shmem for -fcoarray=shared it must also
link -lpthread because the shmem CAF runtime uses POSIX threads internally.

Assisted by: Claude Sonnet 4.6

	PR fortran/125324

gcc/fortran/ChangeLog:

	* gfortranspec.cc (lang_specific_driver): Also append -lpthread
	when need_caf_shmem is set.

---
 gcc/fortran/gfortranspec.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/gfortranspec.cc b/gcc/fortran/gfortranspec.cc
index 13b240013e8..a98c538889e 100644
--- a/gcc/fortran/gfortranspec.cc
+++ b/gcc/fortran/gfortranspec.cc
@@ -428,7 +428,10 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
 	}
 
       if (need_caf_shmem)
-	append_option (OPT_l, CAF_SHMEM_LIBRARY, 1);
+	{
+	  append_option (OPT_l, CAF_SHMEM_LIBRARY, 1);
+	  append_option (OPT_l, "pthread", 1);
+	}
     }
 
 #ifdef ENABLE_SHARED_LIBGCC
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.