https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125324
--- Comment #4 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
I fed your comment to Claude to see what it says.
The reviewer is correct — OPT_pthread is an enum value
generated only on platforms that define -pthread in their .opt files. On
other
platforms the enum simply doesn't exist, causing a compile error in
gfortranspec.cc.
The simplest portable fix: replace append_option(OPT_pthread, NULL, 1) with
append_option(OPT_l, "pthread", 1). That uses OPT_l (always defined, it's the
fundamental -l option) to add -lpthread. For our purpose — fixing a linker
error
(undefined reference to pthread_mutex_trylock) — -lpthread is exactly right;
the
extra preprocessor defines that -pthread adds only matter at compile time,
which is
already done.
Also, the library ordering should be corrected: with static linking, the
linker
resolves left-to-right, so -lcaf_shmem (which uses pthread symbols) must come
before
-lpthread (which defines them). The current patch has them reversed. The
fix:
if (need_caf_shmem)
{
append_option (OPT_l, CAF_SHMEM_LIBRARY, 1);
append_option (OPT_l, "pthread", 1);
}
This is portable, requires no new spec files, uses no platform-specific enum,
and
gets the link order right. Want me to apply it?
--- snip ---
This is the diff.
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