This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


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

[PATCH] NPTL/Alpha binary incompatibility problem


Hi!

Alpha bits/pthreadtypes.h has:
typedef union
{
  struct
  {
    int __lock;
    unsigned int __nr_readers;
    unsigned int __readers_wakeup;
    unsigned int __writer_wakeup;
    unsigned int __nr_readers_queued;
    unsigned int __nr_writers_queued;
    int __writer;

    unsigned int __reserved[6];
    /* FLAGS must stay at this position in the structure to maintain
       binary compatibility.  */
    unsigned int __flags;
  } __data;
  char __size[56];
  long int __align;
} pthread_rwlock_t;

so __data.__flags (the only field for which binary compatibility
needs to be preserved (in addition to alignment and size of the
type)) is at offset 52.
But LinuxThreads had this field at offset 48 (on all 64-bit arches):
struct _pthread_fastlock
{
  long int __status;   /* "Free" or "taken" or head of waiting list */
  int __spinlock;      /* Used by compare_and_swap emulation. Also,
                          adaptive SMP lock stores spin count here. */
};

struct _pthread_descr_struct;
typedef struct _pthread_descr_struct *_pthread_descr;

typedef struct _pthread_rwlock_t
{
  struct _pthread_fastlock __rw_lock; /* Lock to guarantee mutual exclusion */
  int __rw_readers;                   /* Number of readers */
  _pthread_descr __rw_writer;         /* Identity of writer, or NULL if none */
  _pthread_descr __rw_read_waiting;   /* Threads waiting for reading */
  _pthread_descr __rw_write_waiting;  /* Threads waiting for writing */
  int __rw_kind;                      /* Reader/Writer preference selection */
  int __rw_pshared;                   /* Shared between processes or not */
} pthread_rwlock_t;

All other 64-bit NPTL arches use:
typedef union
{
  struct
  {
    int __lock;
    unsigned int __nr_readers;
    unsigned int __readers_wakeup;
    unsigned int __writer_wakeup;
    unsigned int __nr_readers_queued;
    unsigned int __nr_writers_queued;
    int __writer;

    int __pad1;
    unsigned long int __pad2;
    unsigned long int __pad3;
    /* FLAGS must stay at this position in the structure to maintain
       binary compatibility.  */
    unsigned int __flags;
  } __data;
  char __size[56];
  long int __align;
} pthread_rwlock_t;

instead, so __flags is at offset 48.
Furthermore, the NPTL <pthread.h> definition of
PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP is written for
the field count all non-alpha 64-bit NPTL arches are using:
#   define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
  { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
      PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } }
With the alpha definition that means
PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP value is at offset 40.

So, I'd suggest just to change alpha bits/pthreadtypes.h
to what LinuxThreads was using (I believe until recently
most of the Alpha distributions were compiling/linking against
LinuxThreads headers anyway) and what other 64-bit arches
are doing:

2005-07-11  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h (pthread_rwlock_t):
	Make sure __flags are located at offset 48 from the start of the
	structure.

--- libc/nptl/sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h.jj	2004-09-30 00:50:03.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h	2005-07-11 10:25:36.000000000 +0200
@@ -1,5 +1,5 @@
 /* Machine-specific pthread type layouts.  Alpha version.
-   Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -117,8 +117,9 @@ typedef union
     unsigned int __nr_readers_queued;
     unsigned int __nr_writers_queued;
     int __writer;
-
-    unsigned int __reserved[6];
+    int __pad1;
+    unsigned long int __pad2;
+    unsigned long int __pad3;
     /* FLAGS must stay at this position in the structure to maintain
        binary compatibility.  */
     unsigned int __flags;


	Jakub


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