This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] fixinclude for Tru64's PTHREAD_MUTEX_INITIALIZER
> From: Bruce Korb <bkorb at veritas dot com>
>
> Roger Sayle wrote:
> >
> > Tru64's pthread.h contains incorrect definitions of the
> > initialization macros PTHREAD_MUTEX_INITIALIZER,
> > PTHREAD_COND_INITIALIZER and related
>
> Smells like Solaris. :-)
Speaking of which, can someone please help fix this same issue on
Solaris? It's been bugging me for a while cause it leads to a warning
(gasp!) during bootstrap. :-)
Currently, Solaris is in a halfway state, ie. GCC fixincl fixes
PTHREAD_MUTEX_INITIALIZER and PTHREAD_COND_INITIALIZER but leaves
PTHREAD_RWLOCK_INITIALIZER and PTHREAD_ONCE_INIT in their broken
forms.
E.g. when building the target support libs, I get these warnings:
> unwind-dw2.c:1237: warning: missing braces around initializer
> unwind-dw2.c:1237: warning: (near initialization for 'once_regsizes.__pthread_once_pad')
About a year and a half ago, I started working on it, but never got
around to full testing and submission. Patch included below, I
haven't verified it still works, but it should serve as a good
starting point.
Whoever picks up the ball, it would be nice to test the headers from
sol 2.5.1 through 2.9. (Hint hint Eric.)
The following C program compiled with -Wall is perhaps a testcase.
I've also seen it yield an extra warning on solaris2 with -ansi added.
As per the comments in the patch, solaris does something different in
pthread.h when __STDC__ is defined. That leads to the extra warning
but my patch accounted for it and fixed it too.
Thanks,
--Kaveh
#include <pthread.h>
#define AU __attribute__ ((__unused__))
int main()
{
pthread_mutex_t pmut AU = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t pcond AU = PTHREAD_COND_INITIALIZER;
pthread_rwlock_t prwl AU = PTHREAD_RWLOCK_INITIALIZER;
pthread_once_t po AU = PTHREAD_ONCE_INIT;
return 0;
}
2003-04-03 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* fixinc/inclhack.def (solaris_rwlock_init, solaris_once_init):
New fixes.
diff -rup orig/egcc-CVS20030403/gcc/fixinc/inclhack.def egcc-CVS20030403/gcc/fixinc/inclhack.def
--- orig/egcc-CVS20030403/gcc/fixinc/inclhack.def 2003-03-29 21:01:36.000000000 -0500
+++ egcc-CVS20030403/gcc/fixinc/inclhack.def 2003-04-03 19:00:20.257617000 -0500
@@ -2105,6 +2105,60 @@ fix = {
/*
+ * Sun Solaris defines PTHREAD_RWLOCK_INITIALIZER with a "0" for some
+ * fields of the pthread_rwlock_t structure, which are of type
+ * upad64_t, which itself is typedef'd to int64_t, but with __STDC__
+ * defined (e.g. by -ansi) it is a union. So change the initializer
+ * to "{0}" instead.
+ */
+fix = {
+ hackname = solaris_rwlock_init;
+ select = '@\(#\)pthread.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
+ files = pthread.h;
+ c_fix = format;
+ c_fix_arg = "#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)\n"
+ "%0\n"
+ "#else\n"
+ "%1{0, 0, 0, {{0}, {0}, {0}}, {{0}, {0}}, {{0}, {0}}}\n"
+ "#endif";
+ c_fix_arg = "(^#define[ \t]+PTHREAD_RWLOCK_INITIALIZER[ \t]+)"
+ "{0, 0, 0, {0, 0, 0}, {0, 0}, {0, 0}}";
+
+ test_text =
+ '#ident "@(#)pthread.h 1.26 98/04/12 SMI"'"\n"
+ "#define PTHREAD_RWLOCK_INITIALIZER\t"
+ "{0, 0, 0, {0, 0, 0}, {0, 0}, {0, 0}}";
+};
+
+
+/*
+ * Sun Solaris defines PTHREAD_ONCE_INIT with a "0" for some fields of
+ * the pthread_once_t structure, which are of type upad64_t, which
+ * itself is typedef'd to int64_t, but with __STDC__ defined (e.g. by
+ * -ansi) it is a union. So change the initializer to "{0}" instead.
+ * Also the structure contains an array so wrap the whole thing in
+ * brackets for both cases.
+ */
+fix = {
+ hackname = solaris_once_init;
+ select = '@\(#\)pthread.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
+ files = pthread.h;
+ c_fix = format;
+ c_fix_arg = "#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)\n"
+ "%1{%2%3%4%5}\n"
+ "#else\n"
+ "%1{%2{0}, {0}, {0}, {%4}%5}\n"
+ "#endif";
+ c_fix_arg = "(^#define[ \t]+PTHREAD_ONCE_INIT[ \t]+)({)"
+ "(0, 0, 0, )(PTHREAD_[A-Z_]+)(})";
+
+ test_text =
+ '#ident "@(#)pthread.h 1.26 98/04/12 SMI"'"\n"
+ "#define PTHREAD_ONCE_INIT\t{0, 0, 0, PTHREAD_ONCE_NOTDONE}";
+};
+
+
+/*
* Solaris 2.8 has what appears to be some gross workaround for
* some old version of their c++ compiler. G++ doesn't want it
* either, but doesn't want to be tied to SunPRO version numbers.