This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pthread.h INITIALIZER macros on solaris (solaris9 & 10 need fixes)


Kaveh R. Ghazi wrote:
I know this has come up a few times before :-)

Yes. I do remember. :-( --------- ;-)


If I can get this working, I'd like to install the testcase to ensure
it stays working, or at least we notice when it breaks with later
releases of solaris.  (Crossing my fingers...)  They so helpfully
change this area for every release. :-(

Even in patches, too, so there is no os version to header version mapping. You have to look at the version of the header that defines upad64_t in order to figure out how to patch the pthread.h header.

The current solaris_mutex_init_2 does a partial job to fix this,
however it omits fixing the RWLOCK initializer.  Also it doesn't
trigger correctly on solaris9 because sun rearranged the macro
definition so the fixinc pattern doesn't match.  I'm also finding that
solaris10 headers fix the upad64_t by never using the union if the
compiler is GCC!  So we don't need the upad64_t fix there, but there's
still a problem with PTHREAD_ONCE_INIT separate from the upad64_t
issue that is common to all solaris versions I have.  (I have a simple
fix for that.)

I guess they _tried_ to be helpful. "almost". I had access to several versions at my last company, but only one today.

Anyway, Solaris 8, from sys/types.h:
> #pragma ident   "@(#)types.h    1.66    00/02/14 SMI"
[...]
#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)
typedef int64_t         pad64_t;
typedef uint64_t        upad64_t;
#else
typedef union {
        double   _d;
        int32_t  _l[2];
} pad64_t;
typedef union {
        double   _d;
        uint32_t _l[2];
} upad64_t;
#endif
$ uname -a
SunOS vega 5.8 Generic_108528-09 sun4u sparc SUNW,Ultra-4

typedef struct _pthread_mutex { /* = mutex_t in synch.h */ struct { uint16_t __pthread_mutex_flag1; uint8_t __pthread_mutex_flag2; uint8_t __pthread_mutex_ceiling; uint32_t __pthread_mutex_type; } __pthread_mutex_flags; union { struct { uint8_t __pthread_mutex_pad[8]; } __pthread_mutex_lock64; upad64_t __pthread_mutex_owner64; } __pthread_mutex_lock; upad64_t __pthread_mutex_data; } pthread_mutex_t;

#define PTHREAD_MUTEX_INITIALIZER {{0, 0, 0, 0}, {{{0}}}, 0}

typedef struct  _pthread_cond {         /* = cond_t in synch.h */
        struct {
                uint8_t         __pthread_cond_flag[4];
                uint32_t        __pthread_cond_type;
        } __pthread_cond_flags;
        upad64_t __pthread_cond_data;
} pthread_cond_t;

#define PTHREAD_COND_INITIALIZER {{{0}, 0}, 0} /* = DEFAULTCV */

typedef struct _pthread_rwlock {        /* = rwlock_t in synch.h */
        int32_t         __pthread_rwlock_readers;
        uint16_t        __pthread_rwlock_type;
        uint16_t        __pthread_rwlock_magic;
        upad64_t        __pthread_rwlock_pad1[3];
        upad64_t        __pthread_rwlock_pad2[2];
        upad64_t        __pthread_rwlock_pad3[2];
} pthread_rwlock_t;

#define PTHREAD_RWLOCK_INITIALIZER {0, 0, 0, {0, 0, 0}, {0, 0}, {0, 0}}

I'm playing with fixincludes but I only have access to solaris7, 9 and
10 and I don't know if there are multiple versions of pthread.h and
other headers within an individual solaris release that affect this
problem.

All the relevant structures are in sys/types.h and the problematic initializers are in pthread.h.

If you could let me see how your various solaris boxes define the
pthread.h macros, and how upad64_t is defined in sys/types.h on the
same boxes, I'm willing to tackle this issue again for solaris 9 and
10. :-)

Here's a really simple approach: remove all initialization values after the first element. They are all zero and omitted elements are zeroed. :) (Or, even plain ``{}'' as an initializer???)

Cheers - Bruce


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]