diff mbox series

[1/3] nptl: Add tests for internal pthread_mutex_t offsets

Message ID 1508446807-21704-1-git-send-email-adhemerval.zanella@linaro.org
State New
Headers show
Series [1/3] nptl: Add tests for internal pthread_mutex_t offsets | expand

Commit Message

Adhemerval Zanella Oct. 19, 2017, 9 p.m. UTC
This patch adds a new build test to check for internal fields
offsets uses on pthread_mutex_t static initialization macros
(PTHREAD_MUTEX_INITIALIZER, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP, and
PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP).

Currently the only field which is statically initialized to a
non zero value is pthread_mutex_t.__data.__kind value, however
the test also check the offset of __kind, __spins, __elision (if
support), and __list internal member.  A internal header
(pthread-offset.h) is added to each major ABI with the reference
value.

Checked on x86_64-linux-gnu and with a build check for all affected
ABIs (aarch64-linux-gnu, alpha-linux-gnu, arm-linux-gnueabihf,
hppa-linux-gnu, i686-linux-gnu, ia64-linux-gnu, m68k-linux-gnu,
microblaze-linux-gnu, mips64-linux-gnu, mips64-n32-linux-gnu,
mips-linux-gnu, powerpc64le-linux-gnu, powerpc-linux-gnu,
s390-linux-gnu, s390x-linux-gnu, sh4-linux-gnu, sparc64-linux-gnu,
sparcv9-linux-gnu, tilegx-linux-gnu, tilegx-linux-gnu-x32,
tilepro-linux-gnu, x86_64-linux-gnu, and x86_64-linux-x32).

	* nptl/Makefile (tests-internal): Add tst-offsets.
	* nptl/tst-offsets.c: New file.
	* sysdeps/aarch64/nptl/pthread-offsets.h: Likewise.
	* sysdeps/alpha/nptl/pthread-offsets.h: Likewise.
	* sysdeps/arm/nptl/pthread-offsets.h: Likewise.
	* sysdeps/hppa/nptl/pthread-offsets.h: Likewise.
	* sysdeps/i386/nptl/pthread-offsets.h: Likewise.
	* sysdeps/ia64/nptl/pthread-offsets.h: Likewise.
	* sysdeps/m68k/nptl/pthread-offsets.h: Likewise.
	* sysdeps/microblaze/nptl/pthread-offsets.h: Likewise.
	* sysdeps/mips/nptl/pthread-offsets.h: Likewise.
	* sysdeps/nios2/nptl/pthread-offsets.h: Likewise.
	* sysdeps/powerpc/nptl/pthread-offsets.h: Likewise.
	* sysdeps/s390/nptl/pthread-offsets.h: Likewise.
	* sysdeps/sh/nptl/pthread-offsets.h: Likewise.
	* sysdeps/sparc/nptl/pthread-offsets.h: Likewise.
	* sysdeps/tile/nptl/pthread-offsets.h: Likewise.
	* sysdeps/x86_64/nptl/pthread-offsets.h: Likewise.
---
 ChangeLog                                 | 21 ++++++++++++
 nptl/Makefile                             |  2 +-
 nptl/tst-offsets.c                        | 54 +++++++++++++++++++++++++++++++
 sysdeps/aarch64/nptl/pthread-offsets.h    |  5 +++
 sysdeps/alpha/nptl/pthread-offsets.h      |  5 +++
 sysdeps/arm/nptl/pthread-offsets.h        |  5 +++
 sysdeps/hppa/nptl/pthread-offsets.h       |  5 +++
 sysdeps/i386/nptl/pthread-offsets.h       |  5 +++
 sysdeps/ia64/nptl/pthread-offsets.h       |  5 +++
 sysdeps/m68k/nptl/pthread-offsets.h       |  5 +++
 sysdeps/microblaze/nptl/pthread-offsets.h |  5 +++
 sysdeps/mips/nptl/pthread-offsets.h       | 13 ++++++++
 sysdeps/nios2/nptl/pthread-offsets.h      |  5 +++
 sysdeps/powerpc/nptl/pthread-offsets.h    | 15 +++++++++
 sysdeps/s390/nptl/pthread-offsets.h       | 15 +++++++++
 sysdeps/sh/nptl/pthread-offsets.h         |  5 +++
 sysdeps/sparc/nptl/pthread-offsets.h      | 15 +++++++++
 sysdeps/tile/nptl/pthread-offsets.h       | 15 +++++++++
 sysdeps/x86_64/nptl/pthread-offsets.h     |  5 +++
 19 files changed, 204 insertions(+), 1 deletion(-)
 create mode 100644 nptl/tst-offsets.c
 create mode 100644 sysdeps/aarch64/nptl/pthread-offsets.h
 create mode 100644 sysdeps/alpha/nptl/pthread-offsets.h
 create mode 100644 sysdeps/arm/nptl/pthread-offsets.h
 create mode 100644 sysdeps/hppa/nptl/pthread-offsets.h
 create mode 100644 sysdeps/i386/nptl/pthread-offsets.h
 create mode 100644 sysdeps/ia64/nptl/pthread-offsets.h
 create mode 100644 sysdeps/m68k/nptl/pthread-offsets.h
 create mode 100644 sysdeps/microblaze/nptl/pthread-offsets.h
 create mode 100644 sysdeps/mips/nptl/pthread-offsets.h
 create mode 100644 sysdeps/nios2/nptl/pthread-offsets.h
 create mode 100644 sysdeps/powerpc/nptl/pthread-offsets.h
 create mode 100644 sysdeps/s390/nptl/pthread-offsets.h
 create mode 100644 sysdeps/sh/nptl/pthread-offsets.h
 create mode 100644 sysdeps/sparc/nptl/pthread-offsets.h
 create mode 100644 sysdeps/tile/nptl/pthread-offsets.h
 create mode 100644 sysdeps/x86_64/nptl/pthread-offsets.h

-- 
2.7.4

Comments

H.J. Lu Oct. 19, 2017, 9:12 p.m. UTC | #1
On Thu, Oct 19, 2017 at 2:00 PM, Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
> This patch adds a new build test to check for internal fields

> offsets uses on pthread_mutex_t static initialization macros

> (PTHREAD_MUTEX_INITIALIZER, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,

> PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP, and

> PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP).

>

> Currently the only field which is statically initialized to a

> non zero value is pthread_mutex_t.__data.__kind value, however

> the test also check the offset of __kind, __spins, __elision (if

> support), and __list internal member.  A internal header

> (pthread-offset.h) is added to each major ABI with the reference

> value.

>

> Checked on x86_64-linux-gnu and with a build check for all affected

> ABIs (aarch64-linux-gnu, alpha-linux-gnu, arm-linux-gnueabihf,

> hppa-linux-gnu, i686-linux-gnu, ia64-linux-gnu, m68k-linux-gnu,

> microblaze-linux-gnu, mips64-linux-gnu, mips64-n32-linux-gnu,

> mips-linux-gnu, powerpc64le-linux-gnu, powerpc-linux-gnu,

> s390-linux-gnu, s390x-linux-gnu, sh4-linux-gnu, sparc64-linux-gnu,

> sparcv9-linux-gnu, tilegx-linux-gnu, tilegx-linux-gnu-x32,

> tilepro-linux-gnu, x86_64-linux-gnu, and x86_64-linux-x32).

>

>         * nptl/Makefile (tests-internal): Add tst-offsets.

>         * nptl/tst-offsets.c: New file.

>         * sysdeps/aarch64/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/alpha/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/arm/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/hppa/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/i386/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/ia64/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/m68k/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/microblaze/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/mips/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/nios2/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/powerpc/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/s390/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/sh/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/sparc/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/tile/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/x86_64/nptl/pthread-offsets.h: Likewise.

> ---

>  ChangeLog                                 | 21 ++++++++++++

>  nptl/Makefile                             |  2 +-

>  nptl/tst-offsets.c                        | 54 +++++++++++++++++++++++++++++++

>  sysdeps/aarch64/nptl/pthread-offsets.h    |  5 +++

>  sysdeps/alpha/nptl/pthread-offsets.h      |  5 +++

>  sysdeps/arm/nptl/pthread-offsets.h        |  5 +++

>  sysdeps/hppa/nptl/pthread-offsets.h       |  5 +++

>  sysdeps/i386/nptl/pthread-offsets.h       |  5 +++

>  sysdeps/ia64/nptl/pthread-offsets.h       |  5 +++

>  sysdeps/m68k/nptl/pthread-offsets.h       |  5 +++

>  sysdeps/microblaze/nptl/pthread-offsets.h |  5 +++

>  sysdeps/mips/nptl/pthread-offsets.h       | 13 ++++++++

>  sysdeps/nios2/nptl/pthread-offsets.h      |  5 +++

>  sysdeps/powerpc/nptl/pthread-offsets.h    | 15 +++++++++

>  sysdeps/s390/nptl/pthread-offsets.h       | 15 +++++++++

>  sysdeps/sh/nptl/pthread-offsets.h         |  5 +++

>  sysdeps/sparc/nptl/pthread-offsets.h      | 15 +++++++++

>  sysdeps/tile/nptl/pthread-offsets.h       | 15 +++++++++

>  sysdeps/x86_64/nptl/pthread-offsets.h     |  5 +++

>  19 files changed, 204 insertions(+), 1 deletion(-)

>  create mode 100644 nptl/tst-offsets.c

>  create mode 100644 sysdeps/aarch64/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/alpha/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/arm/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/hppa/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/i386/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/ia64/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/m68k/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/microblaze/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/mips/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/nios2/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/powerpc/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/s390/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/sh/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/sparc/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/tile/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/x86_64/nptl/pthread-offsets.h

>

> diff --git a/nptl/Makefile b/nptl/Makefile

> index d819349..7492b06 100644

> --- a/nptl/Makefile

> +++ b/nptl/Makefile

> @@ -304,7 +304,7 @@ tests = tst-attr1 tst-attr2 tst-attr3 tst-default-attr \

>         tst-thread_local1 tst-mutex-errorcheck tst-robust10 \

>         tst-robust-fork tst-create-detached tst-memstream

>

> -tests-internal := tst-typesizes \

> +tests-internal := tst-typesizes tst-offsets \

>                   tst-rwlock19 tst-rwlock20 \

>                   tst-sem11 tst-sem12 tst-sem13 \

>                   tst-barrier5 tst-signal7 tst-mutex8 tst-mutex8-static \

> diff --git a/nptl/tst-offsets.c b/nptl/tst-offsets.c

> new file mode 100644

> index 0000000..0df1155

> --- /dev/null

> +++ b/nptl/tst-offsets.c

> @@ -0,0 +1,54 @@

> +/* Check pthread internal offsets.

> +   Copyright (C) 2017 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

> +   modify it under the terms of the GNU Lesser General Public

> +   License as published by the Free Software Foundation; either

> +   version 2.1 of the License, or (at your option) any later version.

> +

> +   The GNU C Library is distributed in the hope that it will be useful,

> +   but WITHOUT ANY WARRANTY; without even the implied warranty of

> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU

> +   Lesser General Public License for more details.

> +

> +   You should have received a copy of the GNU Lesser General Public

> +   License along with the GNU C Library; if not, see

> +   <http://www.gnu.org/licenses/>.  */

> +

> +#include <stdio.h>

> +#include <pthreadP.h>

> +#include <semaphore.h>

> +

> +#include <pthread-offsets.h>

> +

> +#define STR_HELPER(x) #x

> +#define STR(x) STR_HELPER(x)

> +

> +static int

> +do_test (void)

> +{

> +#define TEST_OFFSET(type, member, offset) \

> +  _Static_assert (offsetof (type, member) == offset, \

> +                 "offset of " #member " field of " #type " != " \

> +                 STR (offset))

> +

> +  /* Check if internal fields in pthread_mutex_t used by static initializers

> +     have the expected offset.  */

> +  TEST_OFFSET (pthread_mutex_t, __data.__nusers,

> +              __PTHREAD_MUTEX_NUSERS_OFFSET);

> +  TEST_OFFSET (pthread_mutex_t, __data.__kind,

> +              __PTHREAD_MUTEX_KIND_OFFSET);

> +  TEST_OFFSET (pthread_mutex_t, __data.__spins,

> +              __PTHREAD_MUTEX_SPINS_OFFSET);

> +#if __PTHREAD_MUTEX_LOCK_ELISION

> +  TEST_OFFSET (pthread_mutex_t, __data.__elision,

> +              __PTHREAD_MUTEX_ELISION_OFFSET);

> +#endif

> +  TEST_OFFSET (pthread_mutex_t, __data.__list,

> +              __PTHREAD_MUTEX_LIST_OFFSET);

> +

> +  return 0;

> +}

> +

> +#include <support/test-driver.c>

> diff --git a/sysdeps/aarch64/nptl/pthread-offsets.h b/sysdeps/aarch64/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..16c6b0d

> --- /dev/null

> +++ b/sysdeps/aarch64/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

> diff --git a/sysdeps/alpha/nptl/pthread-offsets.h b/sysdeps/alpha/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..16c6b0d

> --- /dev/null

> +++ b/sysdeps/alpha/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

> diff --git a/sysdeps/arm/nptl/pthread-offsets.h b/sysdeps/arm/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..9617354

> --- /dev/null

> +++ b/sysdeps/arm/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +#define __PTHREAD_MUTEX_KIND_OFFSET     12

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     20

> diff --git a/sysdeps/hppa/nptl/pthread-offsets.h b/sysdeps/hppa/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..8ae01b9

> --- /dev/null

> +++ b/sysdeps/hppa/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   32

> +#define __PTHREAD_MUTEX_KIND_OFFSET     12

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    36

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     36

> diff --git a/sysdeps/i386/nptl/pthread-offsets.h b/sysdeps/i386/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..9617354

> --- /dev/null

> +++ b/sysdeps/i386/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +#define __PTHREAD_MUTEX_KIND_OFFSET     12

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     20

> diff --git a/sysdeps/ia64/nptl/pthread-offsets.h b/sysdeps/ia64/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..16c6b0d

> --- /dev/null

> +++ b/sysdeps/ia64/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

> diff --git a/sysdeps/m68k/nptl/pthread-offsets.h b/sysdeps/m68k/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..9617354

> --- /dev/null

> +++ b/sysdeps/m68k/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +#define __PTHREAD_MUTEX_KIND_OFFSET     12

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     20

> diff --git a/sysdeps/microblaze/nptl/pthread-offsets.h b/sysdeps/microblaze/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..9617354

> --- /dev/null

> +++ b/sysdeps/microblaze/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +#define __PTHREAD_MUTEX_KIND_OFFSET     12

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     20

> diff --git a/sysdeps/mips/nptl/pthread-offsets.h b/sysdeps/mips/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..0ac3eda

> --- /dev/null

> +++ b/sysdeps/mips/nptl/pthread-offsets.h

> @@ -0,0 +1,13 @@

> +#if _MIPS_SIM == _ABI64

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +# define __PTHREAD_MUTEX_KIND_OFFSET     16

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     24

> +#else

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +# define __PTHREAD_MUTEX_KIND_OFFSET     12

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     20

> +#endif

> diff --git a/sysdeps/nios2/nptl/pthread-offsets.h b/sysdeps/nios2/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..9617354

> --- /dev/null

> +++ b/sysdeps/nios2/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +#define __PTHREAD_MUTEX_KIND_OFFSET     12

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     20

> diff --git a/sysdeps/powerpc/nptl/pthread-offsets.h b/sysdeps/powerpc/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..bdda1f1

> --- /dev/null

> +++ b/sysdeps/powerpc/nptl/pthread-offsets.h

> @@ -0,0 +1,15 @@

> +#include <bits/wordsize.h>

> +

> +#if __WORDSIZE == 64

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +# define __PTHREAD_MUTEX_KIND_OFFSET     16

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     24

> +#else

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +# define __PTHREAD_MUTEX_KIND_OFFSET     12

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     20

> +#endif

> diff --git a/sysdeps/s390/nptl/pthread-offsets.h b/sysdeps/s390/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..bdda1f1

> --- /dev/null

> +++ b/sysdeps/s390/nptl/pthread-offsets.h

> @@ -0,0 +1,15 @@

> +#include <bits/wordsize.h>

> +

> +#if __WORDSIZE == 64

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +# define __PTHREAD_MUTEX_KIND_OFFSET     16

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     24

> +#else

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +# define __PTHREAD_MUTEX_KIND_OFFSET     12

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     20

> +#endif

> diff --git a/sysdeps/sh/nptl/pthread-offsets.h b/sysdeps/sh/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..9617354

> --- /dev/null

> +++ b/sysdeps/sh/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +#define __PTHREAD_MUTEX_KIND_OFFSET     12

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     20

> diff --git a/sysdeps/sparc/nptl/pthread-offsets.h b/sysdeps/sparc/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..bdda1f1

> --- /dev/null

> +++ b/sysdeps/sparc/nptl/pthread-offsets.h

> @@ -0,0 +1,15 @@

> +#include <bits/wordsize.h>

> +

> +#if __WORDSIZE == 64

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +# define __PTHREAD_MUTEX_KIND_OFFSET     16

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     24

> +#else

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +# define __PTHREAD_MUTEX_KIND_OFFSET     12

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     20

> +#endif

> diff --git a/sysdeps/tile/nptl/pthread-offsets.h b/sysdeps/tile/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..bdda1f1

> --- /dev/null

> +++ b/sysdeps/tile/nptl/pthread-offsets.h

> @@ -0,0 +1,15 @@

> +#include <bits/wordsize.h>

> +

> +#if __WORDSIZE == 64

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +# define __PTHREAD_MUTEX_KIND_OFFSET     16

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     24

> +#else

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +# define __PTHREAD_MUTEX_KIND_OFFSET     12

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     20

> +#endif

> diff --git a/sysdeps/x86_64/nptl/pthread-offsets.h b/sysdeps/x86_64/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..16c6b0d

> --- /dev/null

> +++ b/sysdeps/x86_64/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

> --


These are wrong for x32.  You need to add

#if __WORDSIZE == 64
...


-- 
H.J.
Adhemerval Zanella Oct. 19, 2017, 9:54 p.m. UTC | #2
On 19/10/2017 19:12, H.J. Lu wrote:
> On Thu, Oct 19, 2017 at 2:00 PM, Adhemerval Zanella

>> diff --git a/sysdeps/x86_64/nptl/pthread-offsets.h b/sysdeps/x86_64/nptl/pthread-offsets.h

>> new file mode 100644

>> index 0000000..16c6b0d

>> --- /dev/null

>> +++ b/sysdeps/x86_64/nptl/pthread-offsets.h

>> @@ -0,0 +1,5 @@

>> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

>> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

>> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

>> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

>> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

>> --

> 

> These are wrong for x32.  You need to add

> 

> #if __WORDSIZE == 64

> ...


Right, I used the values which are the one expected to avoid 
ABI breakage.  This indeed will break x32 tests build, but the
idea is to have at 1/3 and 3/3 patch pushed together (which 
I should have made explicit in patch submission).

If you prefer I can add the __WORDSIZE != 64 value for master
and  remove it on patch 3/3 or reorganize the patch set to put
3/3 before so 1/3 patch won't break the tests build.
H.J. Lu Oct. 19, 2017, 10:39 p.m. UTC | #3
On Thu, Oct 19, 2017 at 2:54 PM, Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>

>

> On 19/10/2017 19:12, H.J. Lu wrote:

>> On Thu, Oct 19, 2017 at 2:00 PM, Adhemerval Zanella

>>> diff --git a/sysdeps/x86_64/nptl/pthread-offsets.h b/sysdeps/x86_64/nptl/pthread-offsets.h

>>> new file mode 100644

>>> index 0000000..16c6b0d

>>> --- /dev/null

>>> +++ b/sysdeps/x86_64/nptl/pthread-offsets.h

>>> @@ -0,0 +1,5 @@

>>> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

>>> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

>>> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

>>> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

>>> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

>>> --

>>

>> These are wrong for x32.  You need to add

>>

>> #if __WORDSIZE == 64

>> ...

>

> Right, I used the values which are the one expected to avoid

> ABI breakage.  This indeed will break x32 tests build, but the

> idea is to have at 1/3 and 3/3 patch pushed together (which

> I should have made explicit in patch submission).


No.  1/3 should be backported to 2.26/2.25 branches unchanged.

> If you prefer I can add the __WORDSIZE != 64 value for master

> and  remove it on patch 3/3 or reorganize the patch set to put

> 3/3 before so 1/3 patch won't break the tests build.




-- 
H.J.
Adhemerval Zanella Oct. 20, 2017, 1:17 p.m. UTC | #4
On 19/10/2017 20:39, H.J. Lu wrote:
> On Thu, Oct 19, 2017 at 2:54 PM, Adhemerval Zanella

> <adhemerval.zanella@linaro.org> wrote:

>>

>>

>> On 19/10/2017 19:12, H.J. Lu wrote:

>>> On Thu, Oct 19, 2017 at 2:00 PM, Adhemerval Zanella

>>>> diff --git a/sysdeps/x86_64/nptl/pthread-offsets.h b/sysdeps/x86_64/nptl/pthread-offsets.h

>>>> new file mode 100644

>>>> index 0000000..16c6b0d

>>>> --- /dev/null

>>>> +++ b/sysdeps/x86_64/nptl/pthread-offsets.h

>>>> @@ -0,0 +1,5 @@

>>>> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

>>>> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

>>>> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

>>>> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

>>>> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

>>>> --

>>>

>>> These are wrong for x32.  You need to add

>>>

>>> #if __WORDSIZE == 64

>>> ...

>>

>> Right, I used the values which are the one expected to avoid

>> ABI breakage.  This indeed will break x32 tests build, but the

>> idea is to have at 1/3 and 3/3 patch pushed together (which

>> I should have made explicit in patch submission).

> 

> No.  1/3 should be backported to 2.26/2.25 branches unchanged.


So your suggestion is to have __WORDSIZE == 64 with the wrong
values and get them right on the subsequent patch?
H.J. Lu Oct. 20, 2017, 1:57 p.m. UTC | #5
On Fri, Oct 20, 2017 at 6:17 AM, Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>

>

> On 19/10/2017 20:39, H.J. Lu wrote:

>> On Thu, Oct 19, 2017 at 2:54 PM, Adhemerval Zanella

>> <adhemerval.zanella@linaro.org> wrote:

>>>

>>>

>>> On 19/10/2017 19:12, H.J. Lu wrote:

>>>> On Thu, Oct 19, 2017 at 2:00 PM, Adhemerval Zanella

>>>>> diff --git a/sysdeps/x86_64/nptl/pthread-offsets.h b/sysdeps/x86_64/nptl/pthread-offsets.h

>>>>> new file mode 100644

>>>>> index 0000000..16c6b0d

>>>>> --- /dev/null

>>>>> +++ b/sysdeps/x86_64/nptl/pthread-offsets.h

>>>>> @@ -0,0 +1,5 @@

>>>>> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

>>>>> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

>>>>> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

>>>>> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

>>>>> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

>>>>> --

>>>>

>>>> These are wrong for x32.  You need to add

>>>>

>>>> #if __WORDSIZE == 64

>>>> ...

>>>

>>> Right, I used the values which are the one expected to avoid

>>> ABI breakage.  This indeed will break x32 tests build, but the

>>> idea is to have at 1/3 and 3/3 patch pushed together (which

>>> I should have made explicit in patch submission).

>>

>> No.  1/3 should be backported to 2.26/2.25 branches unchanged.

>

> So your suggestion is to have __WORDSIZE == 64 with the wrong

> values and get them right on the subsequent patch?


The 1/3 patch should have the CORRECT offsets for x32, which
should pass on 2.25 branch and fail on 2.26/2.27 until the 3/3 patch
is applied.


-- 
H.J.
Adhemerval Zanella Oct. 20, 2017, 2:08 p.m. UTC | #6
On 20/10/2017 11:57, H.J. Lu wrote:
> On Fri, Oct 20, 2017 at 6:17 AM, Adhemerval Zanella

> <adhemerval.zanella@linaro.org> wrote:

>>

>>

>> On 19/10/2017 20:39, H.J. Lu wrote:

>>> On Thu, Oct 19, 2017 at 2:54 PM, Adhemerval Zanella

>>> <adhemerval.zanella@linaro.org> wrote:

>>>>

>>>>

>>>> On 19/10/2017 19:12, H.J. Lu wrote:

>>>>> On Thu, Oct 19, 2017 at 2:00 PM, Adhemerval Zanella

>>>>>> diff --git a/sysdeps/x86_64/nptl/pthread-offsets.h b/sysdeps/x86_64/nptl/pthread-offsets.h

>>>>>> new file mode 100644

>>>>>> index 0000000..16c6b0d

>>>>>> --- /dev/null

>>>>>> +++ b/sysdeps/x86_64/nptl/pthread-offsets.h

>>>>>> @@ -0,0 +1,5 @@

>>>>>> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

>>>>>> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

>>>>>> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

>>>>>> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

>>>>>> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

>>>>>> --

>>>>>

>>>>> These are wrong for x32.  You need to add

>>>>>

>>>>> #if __WORDSIZE == 64

>>>>> ...

>>>>

>>>> Right, I used the values which are the one expected to avoid

>>>> ABI breakage.  This indeed will break x32 tests build, but the

>>>> idea is to have at 1/3 and 3/3 patch pushed together (which

>>>> I should have made explicit in patch submission).

>>>

>>> No.  1/3 should be backported to 2.26/2.25 branches unchanged.

>>

>> So your suggestion is to have __WORDSIZE == 64 with the wrong

>> values and get them right on the subsequent patch?

> 

> The 1/3 patch should have the CORRECT offsets for x32, which

> should pass on 2.25 branch and fail on 2.26/2.27 until the 3/3 patch

> is applied.


I am not following then because I cherry pick the patch on 2.25 branch
it is works as is for x32.  And it also fails as expected on 2.26 with
make nptl/tests.
H.J. Lu Oct. 20, 2017, 2:43 p.m. UTC | #7
On Fri, Oct 20, 2017 at 7:08 AM, Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>

>

> On 20/10/2017 11:57, H.J. Lu wrote:

>> On Fri, Oct 20, 2017 at 6:17 AM, Adhemerval Zanella

>> <adhemerval.zanella@linaro.org> wrote:

>>>

>>>

>>> On 19/10/2017 20:39, H.J. Lu wrote:

>>>> On Thu, Oct 19, 2017 at 2:54 PM, Adhemerval Zanella

>>>> <adhemerval.zanella@linaro.org> wrote:

>>>>>

>>>>>

>>>>> On 19/10/2017 19:12, H.J. Lu wrote:

>>>>>> On Thu, Oct 19, 2017 at 2:00 PM, Adhemerval Zanella

>>>>>>> diff --git a/sysdeps/x86_64/nptl/pthread-offsets.h b/sysdeps/x86_64/nptl/pthread-offsets.h

>>>>>>> new file mode 100644

>>>>>>> index 0000000..16c6b0d

>>>>>>> --- /dev/null

>>>>>>> +++ b/sysdeps/x86_64/nptl/pthread-offsets.h

>>>>>>> @@ -0,0 +1,5 @@

>>>>>>> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

>>>>>>> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

>>>>>>> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

>>>>>>> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

>>>>>>> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

>>>>>>> --

>>>>>>

>>>>>> These are wrong for x32.  You need to add

>>>>>>

>>>>>> #if __WORDSIZE == 64

>>>>>> ...

>>>>>

>>>>> Right, I used the values which are the one expected to avoid

>>>>> ABI breakage.  This indeed will break x32 tests build, but the

>>>>> idea is to have at 1/3 and 3/3 patch pushed together (which

>>>>> I should have made explicit in patch submission).

>>>>

>>>> No.  1/3 should be backported to 2.26/2.25 branches unchanged.

>>>

>>> So your suggestion is to have __WORDSIZE == 64 with the wrong

>>> values and get them right on the subsequent patch?

>>

>> The 1/3 patch should have the CORRECT offsets for x32, which

>> should pass on 2.25 branch and fail on 2.26/2.27 until the 3/3 patch

>> is applied.

>

> I am not following then because I cherry pick the patch on 2.25 branch

> it is works as is for x32.  And it also fails as expected on 2.26 with

> make nptl/tests.


This doesn't sound right. Can I try your git branch?

-- 
H.J.
Adhemerval Zanella Oct. 20, 2017, 4:41 p.m. UTC | #8
On 20/10/2017 12:43, H.J. Lu wrote:
> On Fri, Oct 20, 2017 at 7:08 AM, Adhemerval Zanella

> <adhemerval.zanella@linaro.org> wrote:

>>

>>

>> On 20/10/2017 11:57, H.J. Lu wrote:

>>> On Fri, Oct 20, 2017 at 6:17 AM, Adhemerval Zanella

>>> <adhemerval.zanella@linaro.org> wrote:

>>>>

>>>>

>>>> On 19/10/2017 20:39, H.J. Lu wrote:

>>>>> On Thu, Oct 19, 2017 at 2:54 PM, Adhemerval Zanella

>>>>> <adhemerval.zanella@linaro.org> wrote:

>>>>>>

>>>>>>

>>>>>> On 19/10/2017 19:12, H.J. Lu wrote:

>>>>>>> On Thu, Oct 19, 2017 at 2:00 PM, Adhemerval Zanella

>>>>>>>> diff --git a/sysdeps/x86_64/nptl/pthread-offsets.h b/sysdeps/x86_64/nptl/pthread-offsets.h

>>>>>>>> new file mode 100644

>>>>>>>> index 0000000..16c6b0d

>>>>>>>> --- /dev/null

>>>>>>>> +++ b/sysdeps/x86_64/nptl/pthread-offsets.h

>>>>>>>> @@ -0,0 +1,5 @@

>>>>>>>> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

>>>>>>>> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

>>>>>>>> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

>>>>>>>> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

>>>>>>>> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

>>>>>>>> --

>>>>>>>

>>>>>>> These are wrong for x32.  You need to add

>>>>>>>

>>>>>>> #if __WORDSIZE == 64

>>>>>>> ...

>>>>>>

>>>>>> Right, I used the values which are the one expected to avoid

>>>>>> ABI breakage.  This indeed will break x32 tests build, but the

>>>>>> idea is to have at 1/3 and 3/3 patch pushed together (which

>>>>>> I should have made explicit in patch submission).

>>>>>

>>>>> No.  1/3 should be backported to 2.26/2.25 branches unchanged.

>>>>

>>>> So your suggestion is to have __WORDSIZE == 64 with the wrong

>>>> values and get them right on the subsequent patch?

>>>

>>> The 1/3 patch should have the CORRECT offsets for x32, which

>>> should pass on 2.25 branch and fail on 2.26/2.27 until the 3/3 patch

>>> is applied.

>>

>> I am not following then because I cherry pick the patch on 2.25 branch

>> it is works as is for x32.  And it also fails as expected on 2.26 with

>> make nptl/tests.

> 

> This doesn't sound right. Can I try your git branch?

> 


I pushed both a release/2.25/master [1] and a release/2.26/master [2] with
my test 1/3 patch applied on top of it.  The only change for 2.25 was to 
use #ifdef insteaf of #if to check for __elision existence (since it is
not defined on all architectures).

For 2.25 I saw no issue while on 2.26 I see:

tst-offsets.c: In function ‘do_test’:
tst-offsets.c:32:3: error: static assertion failed: "offset of __data.__nusers field of pthread_mutex_t != 12"
   _Static_assert (offsetof (type, member) == offset, \
   ^
tst-offsets.c:38:3: note: in expansion of macro ‘TEST_OFFSET’
   TEST_OFFSET (pthread_mutex_t, __data.__nusers,
   ^~~~~~~~~~~
tst-offsets.c:32:3: error: static assertion failed: "offset of __data.__kind field of pthread_mutex_t != 16"
   _Static_assert (offsetof (type, member) == offset, \
   ^
tst-offsets.c:40:3: note: in expansion of macro ‘TEST_OFFSET’
   TEST_OFFSET (pthread_mutex_t, __data.__kind,
   ^~~~~~~~~~~
tst-offsets.c:32:3: error: static assertion failed: "offset of __data.__list field of pthread_mutex_t != 24"
   _Static_assert (offsetof (type, member) == offset, \
   ^
tst-offsets.c:48:3: note: in expansion of macro ‘TEST_OFFSET’
   TEST_OFFSET (pthread_mutex_t, __data.__list,
   ^~~~~~~~~~~

[1] https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/bz22298-2.25
[2] https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/bz22298-2.26
H.J. Lu Oct. 20, 2017, 5:03 p.m. UTC | #9
On Fri, Oct 20, 2017 at 9:41 AM, Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>

>

> On 20/10/2017 12:43, H.J. Lu wrote:

>> On Fri, Oct 20, 2017 at 7:08 AM, Adhemerval Zanella

>> <adhemerval.zanella@linaro.org> wrote:

>>>

>>>

>>> On 20/10/2017 11:57, H.J. Lu wrote:

>>>> On Fri, Oct 20, 2017 at 6:17 AM, Adhemerval Zanella

>>>> <adhemerval.zanella@linaro.org> wrote:

>>>>>

>>>>>

>>>>> On 19/10/2017 20:39, H.J. Lu wrote:

>>>>>> On Thu, Oct 19, 2017 at 2:54 PM, Adhemerval Zanella

>>>>>> <adhemerval.zanella@linaro.org> wrote:

>>>>>>>

>>>>>>>

>>>>>>> On 19/10/2017 19:12, H.J. Lu wrote:

>>>>>>>> On Thu, Oct 19, 2017 at 2:00 PM, Adhemerval Zanella

>>>>>>>>> diff --git a/sysdeps/x86_64/nptl/pthread-offsets.h b/sysdeps/x86_64/nptl/pthread-offsets.h

>>>>>>>>> new file mode 100644

>>>>>>>>> index 0000000..16c6b0d

>>>>>>>>> --- /dev/null

>>>>>>>>> +++ b/sysdeps/x86_64/nptl/pthread-offsets.h

>>>>>>>>> @@ -0,0 +1,5 @@

>>>>>>>>> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

>>>>>>>>> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

>>>>>>>>> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

>>>>>>>>> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

>>>>>>>>> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

>>>>>>>>> --

>>>>>>>>

>>>>>>>> These are wrong for x32.  You need to add

>>>>>>>>

>>>>>>>> #if __WORDSIZE == 64

>>>>>>>> ...

>>>>>>>

>>>>>>> Right, I used the values which are the one expected to avoid

>>>>>>> ABI breakage.  This indeed will break x32 tests build, but the

>>>>>>> idea is to have at 1/3 and 3/3 patch pushed together (which

>>>>>>> I should have made explicit in patch submission).

>>>>>>

>>>>>> No.  1/3 should be backported to 2.26/2.25 branches unchanged.

>>>>>

>>>>> So your suggestion is to have __WORDSIZE == 64 with the wrong

>>>>> values and get them right on the subsequent patch?

>>>>

>>>> The 1/3 patch should have the CORRECT offsets for x32, which

>>>> should pass on 2.25 branch and fail on 2.26/2.27 until the 3/3 patch

>>>> is applied.

>>>

>>> I am not following then because I cherry pick the patch on 2.25 branch

>>> it is works as is for x32.  And it also fails as expected on 2.26 with

>>> make nptl/tests.

>>

>> This doesn't sound right. Can I try your git branch?

>>

>

> I pushed both a release/2.25/master [1] and a release/2.26/master [2] with

> my test 1/3 patch applied on top of it.  The only change for 2.25 was to

> use #ifdef insteaf of #if to check for __elision existence (since it is

> not defined on all architectures).

>

> For 2.25 I saw no issue while on 2.26 I see:

>

> tst-offsets.c: In function ‘do_test’:

> tst-offsets.c:32:3: error: static assertion failed: "offset of __data.__nusers field of pthread_mutex_t != 12"

>    _Static_assert (offsetof (type, member) == offset, \

>    ^

> tst-offsets.c:38:3: note: in expansion of macro ‘TEST_OFFSET’

>    TEST_OFFSET (pthread_mutex_t, __data.__nusers,

>    ^~~~~~~~~~~

> tst-offsets.c:32:3: error: static assertion failed: "offset of __data.__kind field of pthread_mutex_t != 16"

>    _Static_assert (offsetof (type, member) == offset, \

>    ^

> tst-offsets.c:40:3: note: in expansion of macro ‘TEST_OFFSET’

>    TEST_OFFSET (pthread_mutex_t, __data.__kind,

>    ^~~~~~~~~~~

> tst-offsets.c:32:3: error: static assertion failed: "offset of __data.__list field of pthread_mutex_t != 24"

>    _Static_assert (offsetof (type, member) == offset, \

>    ^

> tst-offsets.c:48:3: note: in expansion of macro ‘TEST_OFFSET’

>    TEST_OFFSET (pthread_mutex_t, __data.__list,

>    ^~~~~~~~~~~

>

> [1] https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/bz22298-2.25

> [2] https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/bz22298-2.26


You are right.  By pure luck, x32 and x86-64 have the same offsets
in struct __pthread_mutex_s.  Your 1/3 patch is correct for x32.
Sorry for the confusion.

Thanks.

-- 
H.J.
H.J. Lu Nov. 6, 2017, 2:16 p.m. UTC | #10
On Thu, Oct 19, 2017 at 2:00 PM, Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
> This patch adds a new build test to check for internal fields

> offsets uses on pthread_mutex_t static initialization macros

> (PTHREAD_MUTEX_INITIALIZER, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,

> PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP, and

> PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP).

>

> Currently the only field which is statically initialized to a

> non zero value is pthread_mutex_t.__data.__kind value, however

> the test also check the offset of __kind, __spins, __elision (if

> support), and __list internal member.  A internal header

> (pthread-offset.h) is added to each major ABI with the reference

> value.

>

> Checked on x86_64-linux-gnu and with a build check for all affected

> ABIs (aarch64-linux-gnu, alpha-linux-gnu, arm-linux-gnueabihf,

> hppa-linux-gnu, i686-linux-gnu, ia64-linux-gnu, m68k-linux-gnu,

> microblaze-linux-gnu, mips64-linux-gnu, mips64-n32-linux-gnu,

> mips-linux-gnu, powerpc64le-linux-gnu, powerpc-linux-gnu,

> s390-linux-gnu, s390x-linux-gnu, sh4-linux-gnu, sparc64-linux-gnu,

> sparcv9-linux-gnu, tilegx-linux-gnu, tilegx-linux-gnu-x32,

> tilepro-linux-gnu, x86_64-linux-gnu, and x86_64-linux-x32).

>

>         * nptl/Makefile (tests-internal): Add tst-offsets.

>         * nptl/tst-offsets.c: New file.

>         * sysdeps/aarch64/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/alpha/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/arm/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/hppa/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/i386/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/ia64/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/m68k/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/microblaze/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/mips/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/nios2/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/powerpc/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/s390/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/sh/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/sparc/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/tile/nptl/pthread-offsets.h: Likewise.

>         * sysdeps/x86_64/nptl/pthread-offsets.h: Likewise.

> ---

>  ChangeLog                                 | 21 ++++++++++++

>  nptl/Makefile                             |  2 +-

>  nptl/tst-offsets.c                        | 54 +++++++++++++++++++++++++++++++

>  sysdeps/aarch64/nptl/pthread-offsets.h    |  5 +++

>  sysdeps/alpha/nptl/pthread-offsets.h      |  5 +++

>  sysdeps/arm/nptl/pthread-offsets.h        |  5 +++

>  sysdeps/hppa/nptl/pthread-offsets.h       |  5 +++

>  sysdeps/i386/nptl/pthread-offsets.h       |  5 +++

>  sysdeps/ia64/nptl/pthread-offsets.h       |  5 +++

>  sysdeps/m68k/nptl/pthread-offsets.h       |  5 +++

>  sysdeps/microblaze/nptl/pthread-offsets.h |  5 +++

>  sysdeps/mips/nptl/pthread-offsets.h       | 13 ++++++++

>  sysdeps/nios2/nptl/pthread-offsets.h      |  5 +++

>  sysdeps/powerpc/nptl/pthread-offsets.h    | 15 +++++++++

>  sysdeps/s390/nptl/pthread-offsets.h       | 15 +++++++++

>  sysdeps/sh/nptl/pthread-offsets.h         |  5 +++

>  sysdeps/sparc/nptl/pthread-offsets.h      | 15 +++++++++

>  sysdeps/tile/nptl/pthread-offsets.h       | 15 +++++++++

>  sysdeps/x86_64/nptl/pthread-offsets.h     |  5 +++

>  19 files changed, 204 insertions(+), 1 deletion(-)

>  create mode 100644 nptl/tst-offsets.c

>  create mode 100644 sysdeps/aarch64/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/alpha/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/arm/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/hppa/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/i386/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/ia64/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/m68k/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/microblaze/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/mips/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/nios2/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/powerpc/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/s390/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/sh/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/sparc/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/tile/nptl/pthread-offsets.h

>  create mode 100644 sysdeps/x86_64/nptl/pthread-offsets.h

>

> diff --git a/nptl/Makefile b/nptl/Makefile

> index d819349..7492b06 100644

> --- a/nptl/Makefile

> +++ b/nptl/Makefile

> @@ -304,7 +304,7 @@ tests = tst-attr1 tst-attr2 tst-attr3 tst-default-attr \

>         tst-thread_local1 tst-mutex-errorcheck tst-robust10 \

>         tst-robust-fork tst-create-detached tst-memstream

>

> -tests-internal := tst-typesizes \

> +tests-internal := tst-typesizes tst-offsets \

>                   tst-rwlock19 tst-rwlock20 \

>                   tst-sem11 tst-sem12 tst-sem13 \

>                   tst-barrier5 tst-signal7 tst-mutex8 tst-mutex8-static \

> diff --git a/nptl/tst-offsets.c b/nptl/tst-offsets.c

> new file mode 100644

> index 0000000..0df1155

> --- /dev/null

> +++ b/nptl/tst-offsets.c

> @@ -0,0 +1,54 @@

> +/* Check pthread internal offsets.

> +   Copyright (C) 2017 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

> +   modify it under the terms of the GNU Lesser General Public

> +   License as published by the Free Software Foundation; either

> +   version 2.1 of the License, or (at your option) any later version.

> +

> +   The GNU C Library is distributed in the hope that it will be useful,

> +   but WITHOUT ANY WARRANTY; without even the implied warranty of

> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU

> +   Lesser General Public License for more details.

> +

> +   You should have received a copy of the GNU Lesser General Public

> +   License along with the GNU C Library; if not, see

> +   <http://www.gnu.org/licenses/>.  */

> +

> +#include <stdio.h>

> +#include <pthreadP.h>

> +#include <semaphore.h>

> +

> +#include <pthread-offsets.h>

> +

> +#define STR_HELPER(x) #x

> +#define STR(x) STR_HELPER(x)

> +

> +static int

> +do_test (void)

> +{

> +#define TEST_OFFSET(type, member, offset) \

> +  _Static_assert (offsetof (type, member) == offset, \

> +                 "offset of " #member " field of " #type " != " \

> +                 STR (offset))

> +

> +  /* Check if internal fields in pthread_mutex_t used by static initializers

> +     have the expected offset.  */

> +  TEST_OFFSET (pthread_mutex_t, __data.__nusers,

> +              __PTHREAD_MUTEX_NUSERS_OFFSET);

> +  TEST_OFFSET (pthread_mutex_t, __data.__kind,

> +              __PTHREAD_MUTEX_KIND_OFFSET);

> +  TEST_OFFSET (pthread_mutex_t, __data.__spins,

> +              __PTHREAD_MUTEX_SPINS_OFFSET);

> +#if __PTHREAD_MUTEX_LOCK_ELISION

> +  TEST_OFFSET (pthread_mutex_t, __data.__elision,

> +              __PTHREAD_MUTEX_ELISION_OFFSET);

> +#endif

> +  TEST_OFFSET (pthread_mutex_t, __data.__list,

> +              __PTHREAD_MUTEX_LIST_OFFSET);

> +

> +  return 0;

> +}

> +

> +#include <support/test-driver.c>

> diff --git a/sysdeps/aarch64/nptl/pthread-offsets.h b/sysdeps/aarch64/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..16c6b0d

> --- /dev/null

> +++ b/sysdeps/aarch64/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

> diff --git a/sysdeps/alpha/nptl/pthread-offsets.h b/sysdeps/alpha/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..16c6b0d

> --- /dev/null

> +++ b/sysdeps/alpha/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

> diff --git a/sysdeps/arm/nptl/pthread-offsets.h b/sysdeps/arm/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..9617354

> --- /dev/null

> +++ b/sysdeps/arm/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +#define __PTHREAD_MUTEX_KIND_OFFSET     12

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     20

> diff --git a/sysdeps/hppa/nptl/pthread-offsets.h b/sysdeps/hppa/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..8ae01b9

> --- /dev/null

> +++ b/sysdeps/hppa/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   32

> +#define __PTHREAD_MUTEX_KIND_OFFSET     12

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    36

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     36

> diff --git a/sysdeps/i386/nptl/pthread-offsets.h b/sysdeps/i386/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..9617354

> --- /dev/null

> +++ b/sysdeps/i386/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +#define __PTHREAD_MUTEX_KIND_OFFSET     12

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     20

> diff --git a/sysdeps/ia64/nptl/pthread-offsets.h b/sysdeps/ia64/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..16c6b0d

> --- /dev/null

> +++ b/sysdeps/ia64/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

> diff --git a/sysdeps/m68k/nptl/pthread-offsets.h b/sysdeps/m68k/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..9617354

> --- /dev/null

> +++ b/sysdeps/m68k/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +#define __PTHREAD_MUTEX_KIND_OFFSET     12

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     20

> diff --git a/sysdeps/microblaze/nptl/pthread-offsets.h b/sysdeps/microblaze/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..9617354

> --- /dev/null

> +++ b/sysdeps/microblaze/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +#define __PTHREAD_MUTEX_KIND_OFFSET     12

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     20

> diff --git a/sysdeps/mips/nptl/pthread-offsets.h b/sysdeps/mips/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..0ac3eda

> --- /dev/null

> +++ b/sysdeps/mips/nptl/pthread-offsets.h

> @@ -0,0 +1,13 @@

> +#if _MIPS_SIM == _ABI64

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +# define __PTHREAD_MUTEX_KIND_OFFSET     16

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     24

> +#else

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +# define __PTHREAD_MUTEX_KIND_OFFSET     12

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     20

> +#endif

> diff --git a/sysdeps/nios2/nptl/pthread-offsets.h b/sysdeps/nios2/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..9617354

> --- /dev/null

> +++ b/sysdeps/nios2/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +#define __PTHREAD_MUTEX_KIND_OFFSET     12

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     20

> diff --git a/sysdeps/powerpc/nptl/pthread-offsets.h b/sysdeps/powerpc/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..bdda1f1

> --- /dev/null

> +++ b/sysdeps/powerpc/nptl/pthread-offsets.h

> @@ -0,0 +1,15 @@

> +#include <bits/wordsize.h>

> +

> +#if __WORDSIZE == 64

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +# define __PTHREAD_MUTEX_KIND_OFFSET     16

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     24

> +#else

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +# define __PTHREAD_MUTEX_KIND_OFFSET     12

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     20

> +#endif

> diff --git a/sysdeps/s390/nptl/pthread-offsets.h b/sysdeps/s390/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..bdda1f1

> --- /dev/null

> +++ b/sysdeps/s390/nptl/pthread-offsets.h

> @@ -0,0 +1,15 @@

> +#include <bits/wordsize.h>

> +

> +#if __WORDSIZE == 64

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +# define __PTHREAD_MUTEX_KIND_OFFSET     16

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     24

> +#else

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +# define __PTHREAD_MUTEX_KIND_OFFSET     12

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     20

> +#endif

> diff --git a/sysdeps/sh/nptl/pthread-offsets.h b/sysdeps/sh/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..9617354

> --- /dev/null

> +++ b/sysdeps/sh/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +#define __PTHREAD_MUTEX_KIND_OFFSET     12

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     20

> diff --git a/sysdeps/sparc/nptl/pthread-offsets.h b/sysdeps/sparc/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..bdda1f1

> --- /dev/null

> +++ b/sysdeps/sparc/nptl/pthread-offsets.h

> @@ -0,0 +1,15 @@

> +#include <bits/wordsize.h>

> +

> +#if __WORDSIZE == 64

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +# define __PTHREAD_MUTEX_KIND_OFFSET     16

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     24

> +#else

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +# define __PTHREAD_MUTEX_KIND_OFFSET     12

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     20

> +#endif

> diff --git a/sysdeps/tile/nptl/pthread-offsets.h b/sysdeps/tile/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..bdda1f1

> --- /dev/null

> +++ b/sysdeps/tile/nptl/pthread-offsets.h

> @@ -0,0 +1,15 @@

> +#include <bits/wordsize.h>

> +

> +#if __WORDSIZE == 64

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +# define __PTHREAD_MUTEX_KIND_OFFSET     16

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     24

> +#else

> +# define __PTHREAD_MUTEX_NUSERS_OFFSET   16

> +# define __PTHREAD_MUTEX_KIND_OFFSET     12

> +# define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +# define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +# define __PTHREAD_MUTEX_LIST_OFFSET     20

> +#endif

> diff --git a/sysdeps/x86_64/nptl/pthread-offsets.h b/sysdeps/x86_64/nptl/pthread-offsets.h

> new file mode 100644

> index 0000000..16c6b0d

> --- /dev/null

> +++ b/sysdeps/x86_64/nptl/pthread-offsets.h

> @@ -0,0 +1,5 @@

> +#define __PTHREAD_MUTEX_NUSERS_OFFSET   12

> +#define __PTHREAD_MUTEX_KIND_OFFSET     16

> +#define __PTHREAD_MUTEX_SPINS_OFFSET    20

> +#define __PTHREAD_MUTEX_ELISION_OFFSET  22

> +#define __PTHREAD_MUTEX_LIST_OFFSET     24

> --

> 2.7.4

>


LGTM.

Thanks.


-- 
H.J.
diff mbox series

Patch

diff --git a/nptl/Makefile b/nptl/Makefile
index d819349..7492b06 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -304,7 +304,7 @@  tests = tst-attr1 tst-attr2 tst-attr3 tst-default-attr \
 	tst-thread_local1 tst-mutex-errorcheck tst-robust10 \
 	tst-robust-fork tst-create-detached tst-memstream
 
-tests-internal := tst-typesizes \
+tests-internal := tst-typesizes tst-offsets \
 		  tst-rwlock19 tst-rwlock20 \
 		  tst-sem11 tst-sem12 tst-sem13 \
 		  tst-barrier5 tst-signal7 tst-mutex8 tst-mutex8-static \
diff --git a/nptl/tst-offsets.c b/nptl/tst-offsets.c
new file mode 100644
index 0000000..0df1155
--- /dev/null
+++ b/nptl/tst-offsets.c
@@ -0,0 +1,54 @@ 
+/* Check pthread internal offsets.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+#include <pthreadP.h>
+#include <semaphore.h>
+
+#include <pthread-offsets.h>
+
+#define STR_HELPER(x) #x
+#define STR(x) STR_HELPER(x)
+
+static int
+do_test (void)
+{
+#define TEST_OFFSET(type, member, offset) \
+  _Static_assert (offsetof (type, member) == offset, \
+		  "offset of " #member " field of " #type " != " \
+		  STR (offset))
+
+  /* Check if internal fields in pthread_mutex_t used by static initializers
+     have the expected offset.  */
+  TEST_OFFSET (pthread_mutex_t, __data.__nusers,
+	       __PTHREAD_MUTEX_NUSERS_OFFSET);
+  TEST_OFFSET (pthread_mutex_t, __data.__kind,
+	       __PTHREAD_MUTEX_KIND_OFFSET);
+  TEST_OFFSET (pthread_mutex_t, __data.__spins,
+	       __PTHREAD_MUTEX_SPINS_OFFSET);
+#if __PTHREAD_MUTEX_LOCK_ELISION
+  TEST_OFFSET (pthread_mutex_t, __data.__elision,
+	       __PTHREAD_MUTEX_ELISION_OFFSET);
+#endif
+  TEST_OFFSET (pthread_mutex_t, __data.__list,
+	       __PTHREAD_MUTEX_LIST_OFFSET);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/aarch64/nptl/pthread-offsets.h b/sysdeps/aarch64/nptl/pthread-offsets.h
new file mode 100644
index 0000000..16c6b0d
--- /dev/null
+++ b/sysdeps/aarch64/nptl/pthread-offsets.h
@@ -0,0 +1,5 @@ 
+#define __PTHREAD_MUTEX_NUSERS_OFFSET   12
+#define __PTHREAD_MUTEX_KIND_OFFSET     16
+#define __PTHREAD_MUTEX_SPINS_OFFSET    20
+#define __PTHREAD_MUTEX_ELISION_OFFSET  22
+#define __PTHREAD_MUTEX_LIST_OFFSET     24
diff --git a/sysdeps/alpha/nptl/pthread-offsets.h b/sysdeps/alpha/nptl/pthread-offsets.h
new file mode 100644
index 0000000..16c6b0d
--- /dev/null
+++ b/sysdeps/alpha/nptl/pthread-offsets.h
@@ -0,0 +1,5 @@ 
+#define __PTHREAD_MUTEX_NUSERS_OFFSET   12
+#define __PTHREAD_MUTEX_KIND_OFFSET     16
+#define __PTHREAD_MUTEX_SPINS_OFFSET    20
+#define __PTHREAD_MUTEX_ELISION_OFFSET  22
+#define __PTHREAD_MUTEX_LIST_OFFSET     24
diff --git a/sysdeps/arm/nptl/pthread-offsets.h b/sysdeps/arm/nptl/pthread-offsets.h
new file mode 100644
index 0000000..9617354
--- /dev/null
+++ b/sysdeps/arm/nptl/pthread-offsets.h
@@ -0,0 +1,5 @@ 
+#define __PTHREAD_MUTEX_NUSERS_OFFSET   16
+#define __PTHREAD_MUTEX_KIND_OFFSET     12
+#define __PTHREAD_MUTEX_SPINS_OFFSET    20
+#define __PTHREAD_MUTEX_ELISION_OFFSET  22
+#define __PTHREAD_MUTEX_LIST_OFFSET     20
diff --git a/sysdeps/hppa/nptl/pthread-offsets.h b/sysdeps/hppa/nptl/pthread-offsets.h
new file mode 100644
index 0000000..8ae01b9
--- /dev/null
+++ b/sysdeps/hppa/nptl/pthread-offsets.h
@@ -0,0 +1,5 @@ 
+#define __PTHREAD_MUTEX_NUSERS_OFFSET   32
+#define __PTHREAD_MUTEX_KIND_OFFSET     12
+#define __PTHREAD_MUTEX_SPINS_OFFSET    36
+#define __PTHREAD_MUTEX_ELISION_OFFSET  22
+#define __PTHREAD_MUTEX_LIST_OFFSET     36
diff --git a/sysdeps/i386/nptl/pthread-offsets.h b/sysdeps/i386/nptl/pthread-offsets.h
new file mode 100644
index 0000000..9617354
--- /dev/null
+++ b/sysdeps/i386/nptl/pthread-offsets.h
@@ -0,0 +1,5 @@ 
+#define __PTHREAD_MUTEX_NUSERS_OFFSET   16
+#define __PTHREAD_MUTEX_KIND_OFFSET     12
+#define __PTHREAD_MUTEX_SPINS_OFFSET    20
+#define __PTHREAD_MUTEX_ELISION_OFFSET  22
+#define __PTHREAD_MUTEX_LIST_OFFSET     20
diff --git a/sysdeps/ia64/nptl/pthread-offsets.h b/sysdeps/ia64/nptl/pthread-offsets.h
new file mode 100644
index 0000000..16c6b0d
--- /dev/null
+++ b/sysdeps/ia64/nptl/pthread-offsets.h
@@ -0,0 +1,5 @@ 
+#define __PTHREAD_MUTEX_NUSERS_OFFSET   12
+#define __PTHREAD_MUTEX_KIND_OFFSET     16
+#define __PTHREAD_MUTEX_SPINS_OFFSET    20
+#define __PTHREAD_MUTEX_ELISION_OFFSET  22
+#define __PTHREAD_MUTEX_LIST_OFFSET     24
diff --git a/sysdeps/m68k/nptl/pthread-offsets.h b/sysdeps/m68k/nptl/pthread-offsets.h
new file mode 100644
index 0000000..9617354
--- /dev/null
+++ b/sysdeps/m68k/nptl/pthread-offsets.h
@@ -0,0 +1,5 @@ 
+#define __PTHREAD_MUTEX_NUSERS_OFFSET   16
+#define __PTHREAD_MUTEX_KIND_OFFSET     12
+#define __PTHREAD_MUTEX_SPINS_OFFSET    20
+#define __PTHREAD_MUTEX_ELISION_OFFSET  22
+#define __PTHREAD_MUTEX_LIST_OFFSET     20
diff --git a/sysdeps/microblaze/nptl/pthread-offsets.h b/sysdeps/microblaze/nptl/pthread-offsets.h
new file mode 100644
index 0000000..9617354
--- /dev/null
+++ b/sysdeps/microblaze/nptl/pthread-offsets.h
@@ -0,0 +1,5 @@ 
+#define __PTHREAD_MUTEX_NUSERS_OFFSET   16
+#define __PTHREAD_MUTEX_KIND_OFFSET     12
+#define __PTHREAD_MUTEX_SPINS_OFFSET    20
+#define __PTHREAD_MUTEX_ELISION_OFFSET  22
+#define __PTHREAD_MUTEX_LIST_OFFSET     20
diff --git a/sysdeps/mips/nptl/pthread-offsets.h b/sysdeps/mips/nptl/pthread-offsets.h
new file mode 100644
index 0000000..0ac3eda
--- /dev/null
+++ b/sysdeps/mips/nptl/pthread-offsets.h
@@ -0,0 +1,13 @@ 
+#if _MIPS_SIM == _ABI64
+# define __PTHREAD_MUTEX_NUSERS_OFFSET   12
+# define __PTHREAD_MUTEX_KIND_OFFSET     16
+# define __PTHREAD_MUTEX_SPINS_OFFSET    20
+# define __PTHREAD_MUTEX_ELISION_OFFSET  22
+# define __PTHREAD_MUTEX_LIST_OFFSET     24
+#else
+# define __PTHREAD_MUTEX_NUSERS_OFFSET   16
+# define __PTHREAD_MUTEX_KIND_OFFSET     12
+# define __PTHREAD_MUTEX_SPINS_OFFSET    20
+# define __PTHREAD_MUTEX_ELISION_OFFSET  22
+# define __PTHREAD_MUTEX_LIST_OFFSET     20
+#endif
diff --git a/sysdeps/nios2/nptl/pthread-offsets.h b/sysdeps/nios2/nptl/pthread-offsets.h
new file mode 100644
index 0000000..9617354
--- /dev/null
+++ b/sysdeps/nios2/nptl/pthread-offsets.h
@@ -0,0 +1,5 @@ 
+#define __PTHREAD_MUTEX_NUSERS_OFFSET   16
+#define __PTHREAD_MUTEX_KIND_OFFSET     12
+#define __PTHREAD_MUTEX_SPINS_OFFSET    20
+#define __PTHREAD_MUTEX_ELISION_OFFSET  22
+#define __PTHREAD_MUTEX_LIST_OFFSET     20
diff --git a/sysdeps/powerpc/nptl/pthread-offsets.h b/sysdeps/powerpc/nptl/pthread-offsets.h
new file mode 100644
index 0000000..bdda1f1
--- /dev/null
+++ b/sysdeps/powerpc/nptl/pthread-offsets.h
@@ -0,0 +1,15 @@ 
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __PTHREAD_MUTEX_NUSERS_OFFSET   12
+# define __PTHREAD_MUTEX_KIND_OFFSET     16
+# define __PTHREAD_MUTEX_SPINS_OFFSET    20
+# define __PTHREAD_MUTEX_ELISION_OFFSET  22
+# define __PTHREAD_MUTEX_LIST_OFFSET     24
+#else
+# define __PTHREAD_MUTEX_NUSERS_OFFSET   16
+# define __PTHREAD_MUTEX_KIND_OFFSET     12
+# define __PTHREAD_MUTEX_SPINS_OFFSET    20
+# define __PTHREAD_MUTEX_ELISION_OFFSET  22
+# define __PTHREAD_MUTEX_LIST_OFFSET     20
+#endif
diff --git a/sysdeps/s390/nptl/pthread-offsets.h b/sysdeps/s390/nptl/pthread-offsets.h
new file mode 100644
index 0000000..bdda1f1
--- /dev/null
+++ b/sysdeps/s390/nptl/pthread-offsets.h
@@ -0,0 +1,15 @@ 
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __PTHREAD_MUTEX_NUSERS_OFFSET   12
+# define __PTHREAD_MUTEX_KIND_OFFSET     16
+# define __PTHREAD_MUTEX_SPINS_OFFSET    20
+# define __PTHREAD_MUTEX_ELISION_OFFSET  22
+# define __PTHREAD_MUTEX_LIST_OFFSET     24
+#else
+# define __PTHREAD_MUTEX_NUSERS_OFFSET   16
+# define __PTHREAD_MUTEX_KIND_OFFSET     12
+# define __PTHREAD_MUTEX_SPINS_OFFSET    20
+# define __PTHREAD_MUTEX_ELISION_OFFSET  22
+# define __PTHREAD_MUTEX_LIST_OFFSET     20
+#endif
diff --git a/sysdeps/sh/nptl/pthread-offsets.h b/sysdeps/sh/nptl/pthread-offsets.h
new file mode 100644
index 0000000..9617354
--- /dev/null
+++ b/sysdeps/sh/nptl/pthread-offsets.h
@@ -0,0 +1,5 @@ 
+#define __PTHREAD_MUTEX_NUSERS_OFFSET   16
+#define __PTHREAD_MUTEX_KIND_OFFSET     12
+#define __PTHREAD_MUTEX_SPINS_OFFSET    20
+#define __PTHREAD_MUTEX_ELISION_OFFSET  22
+#define __PTHREAD_MUTEX_LIST_OFFSET     20
diff --git a/sysdeps/sparc/nptl/pthread-offsets.h b/sysdeps/sparc/nptl/pthread-offsets.h
new file mode 100644
index 0000000..bdda1f1
--- /dev/null
+++ b/sysdeps/sparc/nptl/pthread-offsets.h
@@ -0,0 +1,15 @@ 
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __PTHREAD_MUTEX_NUSERS_OFFSET   12
+# define __PTHREAD_MUTEX_KIND_OFFSET     16
+# define __PTHREAD_MUTEX_SPINS_OFFSET    20
+# define __PTHREAD_MUTEX_ELISION_OFFSET  22
+# define __PTHREAD_MUTEX_LIST_OFFSET     24
+#else
+# define __PTHREAD_MUTEX_NUSERS_OFFSET   16
+# define __PTHREAD_MUTEX_KIND_OFFSET     12
+# define __PTHREAD_MUTEX_SPINS_OFFSET    20
+# define __PTHREAD_MUTEX_ELISION_OFFSET  22
+# define __PTHREAD_MUTEX_LIST_OFFSET     20
+#endif
diff --git a/sysdeps/tile/nptl/pthread-offsets.h b/sysdeps/tile/nptl/pthread-offsets.h
new file mode 100644
index 0000000..bdda1f1
--- /dev/null
+++ b/sysdeps/tile/nptl/pthread-offsets.h
@@ -0,0 +1,15 @@ 
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __PTHREAD_MUTEX_NUSERS_OFFSET   12
+# define __PTHREAD_MUTEX_KIND_OFFSET     16
+# define __PTHREAD_MUTEX_SPINS_OFFSET    20
+# define __PTHREAD_MUTEX_ELISION_OFFSET  22
+# define __PTHREAD_MUTEX_LIST_OFFSET     24
+#else
+# define __PTHREAD_MUTEX_NUSERS_OFFSET   16
+# define __PTHREAD_MUTEX_KIND_OFFSET     12
+# define __PTHREAD_MUTEX_SPINS_OFFSET    20
+# define __PTHREAD_MUTEX_ELISION_OFFSET  22
+# define __PTHREAD_MUTEX_LIST_OFFSET     20
+#endif
diff --git a/sysdeps/x86_64/nptl/pthread-offsets.h b/sysdeps/x86_64/nptl/pthread-offsets.h
new file mode 100644
index 0000000..16c6b0d
--- /dev/null
+++ b/sysdeps/x86_64/nptl/pthread-offsets.h
@@ -0,0 +1,5 @@ 
+#define __PTHREAD_MUTEX_NUSERS_OFFSET   12
+#define __PTHREAD_MUTEX_KIND_OFFSET     16
+#define __PTHREAD_MUTEX_SPINS_OFFSET    20
+#define __PTHREAD_MUTEX_ELISION_OFFSET  22
+#define __PTHREAD_MUTEX_LIST_OFFSET     24