Rainer Orth <[email protected]> writes:

> 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.

there have been no comments, but I've merged the documentation with
Sandra's updated version from here recent Solaris docs patch, which
actually inspired this one.

Unless she's suggestions for the wording, I'm going to commit it soon.

Thanks.
        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  880eae6c42f4333126b168206b5b4f5902d8db6d
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
@@ -34975,12 +34975,13 @@ support was added.
 @opindex pthreads
 @item -pthread
 @itemx -pthreads
-On Solaris targets, these both options define the preprocessor symbols
-@code{_REENTRANT} and @code{_PTHREADS}.  In modern versions of Solaris
-these symbols are no longer used in system headers and these options are
-unnecessary unless user code references them.  Additionally, since
-POSIX thread support is provided directly by the Solaris C library, it is
-not necessary to use @option{-pthread} for linking.
+On Solaris targets, these options used to link with @code{libpthread}
+and define the preprocessor symbols @code{_REENTRANT} and
+@code{_PTHREADS}.  However, in Solaris 11 @code{libpthread} has been
+folded into the Solaris C library.  In Solaris 11.4 @code{_REENTRANT}
+is no longer used in system headers and @code{_PTHREADS} is long
+unused.  Unless user code references them, they are unnecessary, so
+the @option{-pthread} option is silently ignored.
 @end table
 
 @node SPARC Options

Reply via email to