gcc supports -pthread/-pthreads on Solaris to provide a way to
transparently handle the platform-specific needs of multitheaded
programs.  In the past, this used to link with -lpthread.  However, this
has been removed in

        config: -pthread shouldn't link with -lpthread on Solaris
        https://gcc.gnu.org/pipermail/gcc-patches/2023-April/615080.html

since libpthread had been folded into libc.

The only thing these options do now is to define _REENTRANT and
_PTHREADS.  In Solaris 11.4, the system headers no longer reference the
former.  Checking gnulib as an important source of portability
information, I find that _REENTRANT is used for two purposes:

* Ensure that strerror_r, localtime_r and gmtime_r are declared.
  However, these declarations are no longer guarded by _REENTRANT, so
  this is moot.

* Besides, _REENTRANT is defined on Solaris in general, but this has no
  longer any effect.

There's no reference _PTHREADS at all, so this seems to be an ancient
relic no longer needed at all.

This patch silently ignores both options, keeping them for portability's
sake.

Bootstrapped without regressions on i386-pc-solaris2.11 and
sparc-sun-solaris2.11.

Unless someone comes up, I mean to commit this after a couple of days.

I mean to mention this in the GCC 16 changes.html caveat section,
referring to this mail.

        Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2026-01-14  Rainer Orth  <[email protected]>

        gcc:
        * config/sol2.h (CPP_SUBTARGET_SPEC): Remove.
        * config/sol2.opt (pthread): Ignore.
        (pthreads): Likewise.
        * config/i386/sol2.h (CPP_SPEC): Remove.
        (SUBTARGET_CPU_EXTRA_SPECS): Remove cpp_subtarget.
        * doc/invoke.texi (Solaris 2 Options, pthread): Document they are
        ignored.

# HG changeset patch
# Parent  e3eaecefb5880f23d6e9a1e6d842c1536b90e238
Silently ignore -pthread etc. on Solaris

diff --git a/gcc/config/i386/sol2.h b/gcc/config/i386/sol2.h
--- a/gcc/config/i386/sol2.h
+++ b/gcc/config/i386/sol2.h
@@ -51,9 +51,6 @@ along with GCC; see the file COPYING3.  
 #undef TARGET_SUN_TLS
 #define TARGET_SUN_TLS 1
 
-#undef CPP_SPEC
-#define CPP_SPEC "%(cpp_subtarget)"
-
 #undef CC1_SPEC
 #define CC1_SPEC "%(cc1_cpu) " ASAN_CC1_SPEC SCTF_CC1_SPEC \
   " %{mx32:%e-mx32 is not supported on Solaris}"
@@ -101,7 +98,6 @@ along with GCC; see the file COPYING3.  
    %{mpc80:crtprec80.o%s}"
 
 #define SUBTARGET_CPU_EXTRA_SPECS \
-  { "cpp_subtarget",	 CPP_SUBTARGET_SPEC },		\
   { "asm_cpu",		 ASM_CPU_SPEC },		\
   { "asm_cpu_default",	 ASM_CPU_DEFAULT_SPEC },	\
 
diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h
--- a/gcc/config/sol2.h
+++ b/gcc/config/sol2.h
@@ -81,10 +81,6 @@ along with GCC; see the file COPYING3.  
 #define INTPTR_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "int")
 #define UINTPTR_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "unsigned int")
 
-#undef CPP_SUBTARGET_SPEC
-#define CPP_SUBTARGET_SPEC "\
-%{pthreads|pthread:-D_REENTRANT -D_PTHREADS}"
-
 /* Names to predefine in the preprocessor for this target machine.  */
 #define TARGET_SUB_OS_CPP_BUILTINS()
 #define TARGET_OS_CPP_BUILTINS()			\
diff --git a/gcc/config/sol2.opt b/gcc/config/sol2.opt
--- a/gcc/config/sol2.opt
+++ b/gcc/config/sol2.opt
@@ -40,10 +40,10 @@ Target
 Pass -z text to linker.
 
 pthread
-Driver
+Ignore
 
 pthreads
-Driver
+Ignore
 
 rdynamic
 Driver
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -34679,8 +34679,9 @@ linking.  See @command{ctf(7)} for more 
 supported since Solaris 11.4 SRU 84 where the necessary toolchain
 support was added.
 @opindex pthreads
-@item -pthreads
-This is a synonym for @option{-pthread}.
+@item -pthread
+@itemx -pthreads
+Both options are unnecessary on Solaris 11.4 and are silently ignored.
 @end table
 
 @node SPARC Options

Reply via email to