[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Git][xorg-team/lib/libpthread-stubs][upstream-unstable] 14 commits: fix pthread_exit proto



Title: GitLab

Andreas Boll pushed to branch upstream-unstable at X Strike Force / lib / libpthread-stubs

Commits:

7 changed files:

Changes:

  • .gitignore
    ... ... @@ -29,3 +29,4 @@ stamp-h1
    29 29
     *.pc
    
    30 30
     *.tar.bz2
    
    31 31
     *.tar.gz
    
    32
    +stubs.c

  • Makefile.am
    1 1
     pkgconfigdir = $(libdir)/pkgconfig
    
    2 2
     pkgconfig_DATA = pthread-stubs.pc
    3
    -
    
    4
    -if BUILD_LIB
    
    5
    -lib_LTLIBRARIES = libpthread-stubs.la
    
    6
    -libpthread_stubs_la_SOURCES = stubs.c
    
    7
    -endif

  • README
    1
    -This library provides weak aliases for pthread functions not provided in libc
    
    2
    -or otherwise available by default.  Libraries like libxcb rely on pthread
    
    3
    -stubs to use pthreads optionally, becoming thread-safe when linked to
    
    4
    -libpthread, while avoiding any performance hit when running single-threaded.
    
    5
    -libpthread-stubs supports this behavior even on platforms which do not supply
    
    6
    -all the necessary pthread stubs.  On platforms which already supply all the
    
    7
    -necessary pthread stubs, this package ships only the pkg-config file
    
    8
    -pthread-stubs.pc, to allow libraries to unconditionally express a dependency
    
    9
    -on pthread-stubs and still obtain correct behavior.
    1
    +Project description
    
    2
    +-------------------
    
    3
    +
    
    4
    +Currently the project provides only a pkg-config [.pc] file, pthread-stubs.pc.
    
    5
    +The latter contains the Cflags/Libs flags applicable to programs/libraries
    
    6
    +that use only lightweight pthread API. See the next sections for the reasoning
    
    7
    +and implementation details.
    
    8
    +
    
    9
    +Historically this project used to provide either:
    
    10
    + - a .pc file, when the C runtime was providing the pthread symbols
    
    11
    +or
    
    12
    + - a .pc file and a library which implements weak stubs for the pthread symbols,
    
    13
    +which are not available in the C runtime.
    
    14
    +
    
    15
    +Since then, the latter case was found to have a fundamental design issue.
    
    16
    +
    
    17
    +
    
    18
    +Design
    
    19
    +------
    
    20
    +
    
    21
    +On platforms where the lightweight pthread symbols are provided by the runtime,
    
    22
    +the .pc files provides empty Cflags/Libs flags.
    
    23
    +
    
    24
    +Currently the following platforms fit the above category:
    
    25
    + - GNU/Linux - GCC/Clang/GLibC/Musl
    
    26
    + - Solaris 10 and later
    
    27
    + - Cygwin
    
    28
    + - GNU/Hurd
    
    29
    + - GNU/kFreeBSD
    
    30
    +
    
    31
    +For others, each of Cflags/Libs expands to full blown pthread.
    
    32
    +
    
    33
    +For example:
    
    34
    + - FreeBSD and derivatives
    
    35
    + - OpenBSD - uses a heavily patched copy of pthread-stubs to workaround this
    
    36
    + - other BSD platforms ?
    
    37
    +
    
    38
    +Unchecked:
    
    39
    + - MSYS/MINGW
    
    40
    + - Darwin - GCC/Clang - should be the same as their Linux counter part
    
    41
    +
    
    42
    +
    
    43
    +Many platforms have their own eccentric way of managing pthread compilation and
    
    44
    +linkage. The ones realistically supported by pthread-stubs [and projects that
    
    45
    +depend on it] work with '-pthread'.
    
    46
    +
    
    47
    +GCC supports -pthread for:
    
    48
    +Aarch64, ARM, Darwin, IA-64, MIPS, PowerPC, SPARC, x86
    
    49
    +Cygwin and x86 Windows may need a trivial patch for older GCC versions.
    
    50
    +See SVN rev 214161 and 171833/171834 respectively.
    
    51
    +
    
    52
    +
    
    53
    +Clang:
    
    54
    +Aarch64, ARM, x86 and likely others.
    
    55
    +
    
    56
    +SunCC/Oracle compiler:
    
    57
    +Requires -mt -lpthread. As of Solaris 10 (oldest currently supported version)
    
    58
    +all the pthread API lives in libc. Thus we'll _never_ get here.
    
    59
    +
    
    60
    +
    
    61
    +With previous design, one could get mismatched calls to the pthreads API.
    
    62
    +Consider the following scenario:
    
    63
    + - Program and/or its dependencies links only against libpthread-stubs,
    
    64
    +since it uses lightweight API. Say pthread_mutex_lock.
    
    65
    + - At a later stage the program and/or its dependencies dlopens a library
    
    66
    +which effectively [either directly or via any of its own dependencies] pulls a
    
    67
    +full blown pthread. Let's call that libB.
    
    68
    + - The libpthread-stubs weak symbols get overridden by the libB ones.
    
    69
    + - pthread_mutex_unlock is executed (which now originates from libB) and BOOM.
    
    70
    +
    
    71
    +Amount and severity of issues depend on a number of factors. In either case
    
    72
    +things go horribly wrong sooner on later.
    
    73
    +
    
    74
    +
    
    75
    +The symbols
    
    76
    +-----------
    
    77
    +
    
    78
    +The following list of symbols is taken from the libc provided by GLibC.
    
    79
    +
    
    80
    +It is deemed sufficient and reasonably accurate of what the 'lightweight'
    
    81
    +pthread symbols are, since GLibC is one of the few (the only) implementations
    
    82
    +which has the distinct split.
    
    83
    +
    
    84
    +Most/all other C runtime implementations provide all the pthread API in a
    
    85
    +single library.
    
    86
    +
    
    87
    +Note that the following list is incomplete wrt libc-2.24.so and that further
    
    88
    +symbols may be added in the future to bring the two closer. Adding symbols
    
    89
    +which are not available in GLibC libc is NOT allowed.
    
    90
    +
    
    91
    +   pthread_condattr_destroy
    
    92
    +   pthread_condattr_init
    
    93
    +   pthread_cond_broadcast
    
    94
    +   pthread_cond_destroy
    
    95
    +   pthread_cond_init
    
    96
    +   pthread_cond_signal
    
    97
    +   pthread_cond_timedwait
    
    98
    +   pthread_cond_wait
    
    99
    +   pthread_equal
    
    100
    +   pthread_exit
    
    101
    +   pthread_mutex_destroy
    
    102
    +   pthread_mutex_init
    
    103
    +   pthread_mutex_lock
    
    104
    +   pthread_mutex_unlock
    
    105
    +   pthread_self

  • autogen.sh
    1 1
     #! /bin/sh
    
    2 2
     
    
    3
    -srcdir=`dirname $0`
    
    3
    +srcdir=`dirname "$0"`
    
    4 4
     test -z "$srcdir" && srcdir=.
    
    5 5
     
    
    6 6
     ORIGDIR=`pwd`
    
    7
    -cd $srcdir
    
    7
    +cd "$srcdir"
    
    8 8
     
    
    9 9
     autoreconf -v --install || exit 1
    
    10
    -cd $ORIGDIR || exit $?
    
    10
    +cd "$ORIGDIR" || exit $?
    
    11 11
     
    
    12
    -$srcdir/configure --enable-maintainer-mode "$@"
    12
    +if test -z "$NOCONFIGURE"; then
    
    13
    +    $srcdir/configure "$@"
    
    14
    +fi

  • configure.ac
    1 1
     AC_INIT([libpthread-stubs],
    
    2
    -        0.3,
    
    2
    +        0.4,
    
    3 3
             [xcb@lists.freedesktop.org])
    
    4 4
     AC_CONFIG_SRCDIR([pthread-stubs.pc.in])
    
    5 5
     AM_INIT_AUTOMAKE([foreign dist-bzip2])
    
    6 6
     
    
    7
    -AC_CONFIG_HEADERS([config.h])
    
    7
    +dnl Check if the following functions have stubs.
    
    8
    +dnl See the README for specifics about the list.
    
    9
    +funclist="\
    
    10
    +pthread_condattr_destroy \
    
    11
    +pthread_condattr_init \
    
    12
    +pthread_cond_broadcast \
    
    13
    +pthread_cond_destroy \
    
    14
    +pthread_cond_init \
    
    15
    +pthread_cond_signal \
    
    16
    +pthread_cond_timedwait \
    
    17
    +pthread_cond_wait \
    
    18
    +pthread_equal \
    
    19
    +pthread_exit \
    
    20
    +pthread_mutex_destroy \
    
    21
    +pthread_mutex_init \
    
    22
    +pthread_mutex_lock \
    
    23
    +pthread_mutex_unlock \
    
    24
    +pthread_self"
    
    8 25
     
    
    9
    -AC_PROG_LIBTOOL
    
    10
    -AC_PROG_CC
    
    26
    +AC_CHECK_FUNCS($funclist, [], [HAVE_STUBS=no])
    
    11 27
     
    
    12 28
     
    
    13
    -dnl Detection code for compilers supporting the __attribute__((weak, alias))
    
    14
    -dnl feature. Original code present in unieject's repository
    
    15
    -dnl Diego Pettenò <flameeyes@gentoo.org>
    
    16
    -ac_save_CFLAGS="$CFLAGS"
    
    17
    -CFLAGS="$CFLAGS -Werror"
    
    18
    -AC_CACHE_CHECK([if compiler supports __attribute__((weak, alias))],
    
    19
    -	[cc_cv_attribute_alias],
    
    20
    -	[AC_COMPILE_IFELSE([
    
    21
    -		void other_function(void *foo) { }
    
    22
    -		void some_function(void *foo) __attribute__((weak, alias("other_function")));
    
    23
    -		],
    
    24
    -		[cc_cv_attribute_alias=yes],
    
    25
    -		[cc_cv_attribute_alias=no])
    
    26
    -	])
    
    27
    -CFLAGS="$ac_save_CFLAGS"
    
    28
    -if test "x$cc_cv_attribute_alias" = "xyes"; then
    
    29
    -	AC_DEFINE([SUPPORT_ATTRIBUTE_ALIAS], 1, [Define this if the compiler supports the alias attribute])
    
    29
    +if test "x$HAVE_STUBS" != xno; then
    
    30
    +    PKG_CONFIG_CFLAGS=
    
    31
    +    PKG_CONFIG_LIBS=
    
    32
    +else
    
    33
    +    dnl See the README why '-pthread' is deemed sufficient.
    
    34
    +    PKG_CONFIG_CFLAGS="-pthread"
    
    35
    +    PKG_CONFIG_LIBS="-pthread"
    
    30 36
     fi
    
    31 37
     
    
    32
    -
    
    33
    -PKG_CONFIG_LIBS=
    
    34
    -AC_CHECK_FUNCS([pthread_self pthread_mutex_init pthread_mutex_destroy pthread_mutex_lock pthread_mutex_unlock pthread_cond_init pthread_cond_destroy pthread_condattr_init pthread_condattr_destroy pthread_cond_wait pthread_cond_timedwait pthread_cond_signal pthread_cond_broadcast pthread_equal pthread_exit],
    
    35
    -	       [], [PKG_CONFIG_LIBS='-L${libdir} -lpthread-stubs'])
    
    38
    +AC_SUBST([PKG_CONFIG_CFLAGS])
    
    36 39
     AC_SUBST([PKG_CONFIG_LIBS])
    
    37
    -AM_CONDITIONAL(BUILD_LIB, test "x$PKG_CONFIG_LIBS" != x)
    
    38 40
     
    
    39 41
     AC_CONFIG_FILES([Makefile pthread-stubs.pc])
    
    40 42
     AC_OUTPUT

  • pthread-stubs.pc.in
    ... ... @@ -3,6 +3,7 @@ exec_prefix=@exec_prefix@
    3 3
     libdir=@libdir@
    
    4 4
     
    
    5 5
     Name: pthread stubs
    
    6
    -Description: Stubs missing from libc for standard pthread functions
    
    6
    +Description: Meta package for pthread symbols - defaults to heavyweight ones if the C runtime does not provide lightweight ones.
    
    7 7
     Version: @PACKAGE_VERSION@
    
    8
    +Cflags: @PKG_CONFIG_CFLAGS@
    
    8 9
     Libs: @PKG_CONFIG_LIBS@

  • stubs.c deleted
    1
    -/* Copyright (C) 2006 Diego Pettenò
    
    2
    - * Inspired by libX11 code copyright (c) 1995 David E. Wexelblat.
    
    3
    - *
    
    4
    - * Permission is hereby granted, free of charge, to any person obtaining a
    
    5
    - * copy of this software and associated documentation files (the "Software"),
    
    6
    - * to deal in the Software without restriction, including without limitation
    
    7
    - * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    
    8
    - * and/or sell copies of the Software, and to permit persons to whom the
    
    9
    - * Software is furnished to do so, subject to the following conditions:
    
    10
    - * 
    
    11
    - * The above copyright notice and this permission notice shall be included in
    
    12
    - * all copies or substantial portions of the Software.
    
    13
    - * 
    
    14
    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    
    15
    - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    
    16
    - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    
    17
    - * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
    
    18
    - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    
    19
    - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    
    20
    - * 
    
    21
    - * Except as contained in this notice, the names of the authors or their
    
    22
    - * institutions shall not be used in advertising or otherwise to promote the
    
    23
    - * sale, use or other dealings in this Software without prior written
    
    24
    - * authorization from the authors.
    
    25
    - */
    
    26
    -
    
    27
    -#include <pthread.h>
    
    28
    -#include <stdlib.h>
    
    29
    -#include "config.h"
    
    30
    -
    
    31
    -#ifndef HAVE_PTHREAD_SELF
    
    32
    -#define NEED_ZERO_STUB
    
    33
    -# ifdef SUPPORT_ATTRIBUTE_ALIAS
    
    34
    -int pthread_self() __attribute__ ((weak, alias ("__pthread_zero_stub")));
    
    35
    -# else
    
    36
    -#  pragma weak pthread_self = __pthread_zero_stub
    
    37
    -# endif
    
    38
    -#endif
    
    39
    -
    
    40
    -#ifndef HAVE_PTHREAD_MUTEX_INIT
    
    41
    -#define NEED_ZERO_STUB
    
    42
    -# ifdef SUPPORT_ATTRIBUTE_ALIAS
    
    43
    -int pthread_mutex_init() __attribute__ ((weak, alias ("__pthread_zero_stub")));
    
    44
    -# else
    
    45
    -#  pragma weak pthread_mutex_init = __pthread_zero_stub
    
    46
    -# endif
    
    47
    -#endif
    
    48
    -
    
    49
    -#ifndef HAVE_PTHREAD_MUTEX_DESTROY
    
    50
    -#define NEED_ZERO_STUB
    
    51
    -# ifdef SUPPORT_ATTRIBUTE_ALIAS
    
    52
    -int pthread_mutex_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")));
    
    53
    -# else
    
    54
    -#  pragma weak pthread_mutex_destroy = __pthread_zero_stub
    
    55
    -# endif
    
    56
    -#endif
    
    57
    -
    
    58
    -#ifndef HAVE_PTHREAD_MUTEX_LOCK
    
    59
    -#define NEED_ZERO_STUB
    
    60
    -# ifdef SUPPORT_ATTRIBUTE_ALIAS
    
    61
    -int pthread_mutex_lock() __attribute__ ((weak, alias ("__pthread_zero_stub")));
    
    62
    -# else
    
    63
    -#  pragma weak pthread_mutex_lock = __pthread_zero_stub
    
    64
    -# endif
    
    65
    -#endif
    
    66
    -
    
    67
    -#ifndef HAVE_PTHREAD_MUTEX_UNLOCK
    
    68
    -#define NEED_ZERO_STUB
    
    69
    -# ifdef SUPPORT_ATTRIBUTE_ALIAS
    
    70
    -int pthread_mutex_unlock() __attribute__ ((weak, alias ("__pthread_zero_stub")));
    
    71
    -# else
    
    72
    -#  pragma weak pthread_mutex_unlock = __pthread_zero_stub
    
    73
    -# endif
    
    74
    -#endif
    
    75
    -
    
    76
    -#ifndef HAVE_PTHREAD_COND_INIT
    
    77
    -#define NEED_ZERO_STUB
    
    78
    -# ifdef SUPPORT_ATTRIBUTE_ALIAS
    
    79
    -int pthread_cond_init() __attribute__ ((weak, alias ("__pthread_zero_stub")));
    
    80
    -# else
    
    81
    -#  pragma weak pthread_cond_init = __pthread_zero_stub
    
    82
    -# endif
    
    83
    -#endif
    
    84
    -
    
    85
    -#ifndef HAVE_PTHREAD_COND_DESTROY
    
    86
    -#define NEED_ZERO_STUB
    
    87
    -# ifdef SUPPORT_ATTRIBUTE_ALIAS
    
    88
    -int pthread_cond_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")));
    
    89
    -# else
    
    90
    -#  pragma weak pthread_cond_destroy = __pthread_zero_stub
    
    91
    -# endif
    
    92
    -#endif
    
    93
    -
    
    94
    -#ifndef HAVE_PTHREAD_CONDATTR_INIT
    
    95
    -#define NEED_ZERO_STUB
    
    96
    -# ifdef SUPPORT_ATTRIBUTE_ALIAS
    
    97
    -int pthread_condattr_init() __attribute__ ((weak, alias ("__pthread_zero_stub")));
    
    98
    -# else
    
    99
    -#  pragma weak pthread_condattr_init = __pthread_zero_stub
    
    100
    -# endif
    
    101
    -#endif
    
    102
    -
    
    103
    -#ifndef HAVE_PTHREAD_CONDATTR_DESTROY
    
    104
    -#define NEED_ZERO_STUB
    
    105
    -# ifdef SUPPORT_ATTRIBUTE_ALIAS
    
    106
    -int pthread_condattr_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")));
    
    107
    -# else
    
    108
    -#  pragma weak pthread_condattr_destroy = __pthread_zero_stub
    
    109
    -# endif
    
    110
    -#endif
    
    111
    -
    
    112
    -#ifndef HAVE_PTHREAD_COND_WAIT
    
    113
    -#define NEED_ABORT_STUB
    
    114
    -# ifdef SUPPORT_ATTRIBUTE_ALIAS
    
    115
    -int pthread_cond_wait() __attribute__ ((weak, alias ("__pthread_abort_stub")));
    
    116
    -# else
    
    117
    -#  pragma weak pthread_cond_wait = __pthread_abort_stub
    
    118
    -# endif
    
    119
    -#endif
    
    120
    -
    
    121
    -#ifndef HAVE_PTHREAD_COND_TIMEDWAIT
    
    122
    -#define NEED_ABORT_STUB
    
    123
    -# ifdef SUPPORT_ATTRIBUTE_ALIAS
    
    124
    -int pthread_cond_timedwait() __attribute__ ((weak, alias ("__pthread_abort_stub")));
    
    125
    -# else
    
    126
    -#  pragma weak pthread_cond_timedwait = __pthread_abort_stub
    
    127
    -# endif
    
    128
    -#endif
    
    129
    -
    
    130
    -#ifndef HAVE_PTHREAD_COND_SIGNAL
    
    131
    -#define NEED_ZERO_STUB
    
    132
    -# ifdef SUPPORT_ATTRIBUTE_ALIAS
    
    133
    -int pthread_cond_signal() __attribute__ ((weak, alias ("__pthread_zero_stub")));
    
    134
    -# else
    
    135
    -#  pragma weak pthread_cond_signal = __pthread_zero_stub
    
    136
    -# endif
    
    137
    -#endif
    
    138
    -
    
    139
    -#ifndef HAVE_PTHREAD_COND_BROADCAST
    
    140
    -#define NEED_ZERO_STUB
    
    141
    -# ifdef SUPPORT_ATTRIBUTE_ALIAS
    
    142
    -int pthread_cond_broadcast() __attribute__ ((weak, alias ("__pthread_zero_stub")));
    
    143
    -# else
    
    144
    -#  pragma weak pthread_cond_broadcast = __pthread_zero_stub
    
    145
    -# endif
    
    146
    -#endif
    
    147
    -
    
    148
    -#ifndef HAVE_PTHREAD_EQUAL
    
    149
    -#define NEED_EQUAL_STUB
    
    150
    -# ifdef SUPPORT_ATTRIBUTE_ALIAS
    
    151
    -int pthread_equal() __attribute__ ((weak, alias ("__pthread_equal_stub")));
    
    152
    -# else
    
    153
    -#  pragma weak pthread_equal = __pthread_equal_stub
    
    154
    -# endif
    
    155
    -#endif
    
    156
    -
    
    157
    -#ifndef HAVE_PTHREAD_EXIT
    
    158
    -#define NEED_EXIT_STUB
    
    159
    -# ifdef SUPPORT_ATTRIBUTE_ALIAS
    
    160
    -int pthread_exit() __attribute__ ((weak, alias ("__pthread_exit_stub")));
    
    161
    -# else
    
    162
    -#  pragma weak pthread_exit = __pthread_exit_stub
    
    163
    -# endif
    
    164
    -#endif
    
    165
    -
    
    166
    -#ifdef NEED_ZERO_STUB
    
    167
    -static int __pthread_zero_stub()
    
    168
    -{
    
    169
    -    return 0;
    
    170
    -}
    
    171
    -#endif
    
    172
    -
    
    173
    -#ifdef NEED_ABORT_STUB
    
    174
    -static int __pthread_abort_stub()
    
    175
    -{
    
    176
    -    abort();
    
    177
    -}
    
    178
    -#endif
    
    179
    -
    
    180
    -#ifdef NEED_EQUAL_STUB
    
    181
    -static int __pthread_equal_stub(pthread_t t1, pthread_t t2)
    
    182
    -{
    
    183
    -    return (t1 == t2);
    
    184
    -}
    
    185
    -#endif
    
    186
    -
    
    187
    -#ifdef NEED_EXIT_STUB
    
    188
    -static void __pthread_exit_stub(void *ret)
    
    189
    -{
    
    190
    -    exit(EXIT_SUCCESS);
    
    191
    -}
    
    192
    -#endif


  • Reply to: