Bruno Haible
2018-02-17 08:56:15 UTC
In a testdir of the 'lock' module, on IRIX 6.5, I'm getting this compilation
failure:
cc -32 -DHAVE_CONFIG_H -I. -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I. -I.. -I./.. -I../gllib -I./../gllib -I/u/guest/bruno/prefix-32-cc/include -g -c -o glthread/thread.o glthread/thread.c
cfe: Warning 728: ./stddef.h, line 105: Long double not supported; double assumed.
long double __ld ;
--^
cfe: Error: ./glthread/thread.h, line 132: definition of secondary name 'pthread_sigmask' not found; pragma weak ignored.
__pragma(5, pthread_sigmask);
------------^
cfe: Warning 777: ./glthread/thread.h, line 137: weak definition for 'pthread_self' is later redefined; pragma weak ignored.
__pragma(5, pthread_self);
------------^
cfe: Error: ./glthread/thread.h, line 141: definition of secondary name 'pthread_atfork' not found; pragma weak ignored.
__pragma(5, pthread_atfork);
------------^
cfe: Warning 777: ./glthread/thread.h, line 145: weak definition for 'pthread_cancel' is later redefined; pragma weak ignored.
__pragma(5, pthread_cancel);
------------^
gmake[2]: *** [Makefile:1380: glthread/thread.o] Error 1
The first error occurs because pthread_sigmask is declared in <signal.h>,
not <pthread.h>, which is compliant to POSIX [1].
The first error occurs because pthread_atfork is declared in <unistd.h>,
not <pthread.h>, which is a POSIX violation [1].
[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html
This fixes it. In passing, it also fixes a potential problem in C++ mode:
It's better to write
#include <signal.h>
#ifdef __cplusplus
extern "C" {
#endif
...
#ifdef __cplusplus
}
#endif
than
#ifdef __cplusplus
extern "C" {
#endif
#include <signal.h>
...
#ifdef __cplusplus
}
#endif
2018-02-17 Bruno Haible <***@clisp.org>
thread: Fix compilation error on IRIX.
* lib/glthread/thread.h: Include <unistd.h>. Include <signal.h> when
needed; include it outside the C++ extern "C" {} block.
* doc/posix-headers/pthread.texi: Mention the problem with
pthread_atfork on IRIX.
diff --git a/lib/glthread/thread.h b/lib/glthread/thread.h
index 165754b..d8098c4 100644
--- a/lib/glthread/thread.h
+++ b/lib/glthread/thread.h
@@ -90,6 +90,17 @@ _GL_INLINE_HEADER_BEGIN
# include <pthread.h>
+/* On IRIX, pthread_atfork is declared in <unistd.h>, not in <pthread.h>. */
+# if defined __sgi
+# include <unistd.h>
+# endif
+
+# if USE_POSIX_THREADS_WEAK
+/* Compilers other than GCC need to see the declaration of pthread_sigmask
+ before the "#pragma weak pthread_sigmask" below. */
+# include <signal.h>
+# endif
+
# ifdef __cplusplus
extern "C" {
# endif
@@ -124,10 +135,6 @@ extern int glthread_in_use (void);
# pragma weak pthread_create
-# ifdef __clang__
- /* Without this, clang complains that pthread_sigmask is never declared. */
-# include <signal.h>
-# endif
# ifndef pthread_sigmask /* Do not declare rpl_pthread_sigmask weak. */
# pragma weak pthread_sigmask
# endif
diff --git a/doc/posix-headers/pthread.texi b/doc/posix-headers/pthread.texi
index 7f39132..de35b3b 100644
--- a/doc/posix-headers/pthread.texi
+++ b/doc/posix-headers/pthread.texi
@@ -21,4 +21,8 @@ This header file is missing on some platforms; the replacement does
not offer threads, so much as lightweight stubs that make conditional
compilation easier for fallbacks to single-threaded programs.
Minix 3.1.8, mingw 2.x, MSVC 14, BeOS.
+@item
+This header file lacks the declaration of @code{pthread_atfork} on some
+platforms:
+IRIX 6.5.
@end itemize
failure:
cc -32 -DHAVE_CONFIG_H -I. -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I. -I.. -I./.. -I../gllib -I./../gllib -I/u/guest/bruno/prefix-32-cc/include -g -c -o glthread/thread.o glthread/thread.c
cfe: Warning 728: ./stddef.h, line 105: Long double not supported; double assumed.
long double __ld ;
--^
cfe: Error: ./glthread/thread.h, line 132: definition of secondary name 'pthread_sigmask' not found; pragma weak ignored.
__pragma(5, pthread_sigmask);
------------^
cfe: Warning 777: ./glthread/thread.h, line 137: weak definition for 'pthread_self' is later redefined; pragma weak ignored.
__pragma(5, pthread_self);
------------^
cfe: Error: ./glthread/thread.h, line 141: definition of secondary name 'pthread_atfork' not found; pragma weak ignored.
__pragma(5, pthread_atfork);
------------^
cfe: Warning 777: ./glthread/thread.h, line 145: weak definition for 'pthread_cancel' is later redefined; pragma weak ignored.
__pragma(5, pthread_cancel);
------------^
gmake[2]: *** [Makefile:1380: glthread/thread.o] Error 1
The first error occurs because pthread_sigmask is declared in <signal.h>,
not <pthread.h>, which is compliant to POSIX [1].
The first error occurs because pthread_atfork is declared in <unistd.h>,
not <pthread.h>, which is a POSIX violation [1].
[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html
This fixes it. In passing, it also fixes a potential problem in C++ mode:
It's better to write
#include <signal.h>
#ifdef __cplusplus
extern "C" {
#endif
...
#ifdef __cplusplus
}
#endif
than
#ifdef __cplusplus
extern "C" {
#endif
#include <signal.h>
...
#ifdef __cplusplus
}
#endif
2018-02-17 Bruno Haible <***@clisp.org>
thread: Fix compilation error on IRIX.
* lib/glthread/thread.h: Include <unistd.h>. Include <signal.h> when
needed; include it outside the C++ extern "C" {} block.
* doc/posix-headers/pthread.texi: Mention the problem with
pthread_atfork on IRIX.
diff --git a/lib/glthread/thread.h b/lib/glthread/thread.h
index 165754b..d8098c4 100644
--- a/lib/glthread/thread.h
+++ b/lib/glthread/thread.h
@@ -90,6 +90,17 @@ _GL_INLINE_HEADER_BEGIN
# include <pthread.h>
+/* On IRIX, pthread_atfork is declared in <unistd.h>, not in <pthread.h>. */
+# if defined __sgi
+# include <unistd.h>
+# endif
+
+# if USE_POSIX_THREADS_WEAK
+/* Compilers other than GCC need to see the declaration of pthread_sigmask
+ before the "#pragma weak pthread_sigmask" below. */
+# include <signal.h>
+# endif
+
# ifdef __cplusplus
extern "C" {
# endif
@@ -124,10 +135,6 @@ extern int glthread_in_use (void);
# pragma weak pthread_create
-# ifdef __clang__
- /* Without this, clang complains that pthread_sigmask is never declared. */
-# include <signal.h>
-# endif
# ifndef pthread_sigmask /* Do not declare rpl_pthread_sigmask weak. */
# pragma weak pthread_sigmask
# endif
diff --git a/doc/posix-headers/pthread.texi b/doc/posix-headers/pthread.texi
index 7f39132..de35b3b 100644
--- a/doc/posix-headers/pthread.texi
+++ b/doc/posix-headers/pthread.texi
@@ -21,4 +21,8 @@ This header file is missing on some platforms; the replacement does
not offer threads, so much as lightweight stubs that make conditional
compilation easier for fallbacks to single-threaded programs.
Minix 3.1.8, mingw 2.x, MSVC 14, BeOS.
+@item
+This header file lacks the declaration of @code{pthread_atfork} on some
+platforms:
+IRIX 6.5.
@end itemize