Skip to content
Commits on Source (22)
......@@ -29,3 +29,4 @@ stamp-h1
*.pc
*.tar.bz2
*.tar.gz
stubs.c
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = pthread-stubs.pc
if BUILD_LIB
lib_LTLIBRARIES = libpthread-stubs.la
libpthread_stubs_la_SOURCES = stubs.c
endif
This library provides weak aliases for pthread functions not provided in libc
or otherwise available by default. Libraries like libxcb rely on pthread
stubs to use pthreads optionally, becoming thread-safe when linked to
libpthread, while avoiding any performance hit when running single-threaded.
libpthread-stubs supports this behavior even on platforms which do not supply
all the necessary pthread stubs. On platforms which already supply all the
necessary pthread stubs, this package ships only the pkg-config file
pthread-stubs.pc, to allow libraries to unconditionally express a dependency
on pthread-stubs and still obtain correct behavior.
Project description
-------------------
Currently the project provides only a pkg-config [.pc] file, pthread-stubs.pc.
The latter contains the Cflags/Libs flags applicable to programs/libraries
that use only lightweight pthread API. See the next sections for the reasoning
and implementation details.
Historically this project used to provide either:
- a .pc file, when the C runtime was providing the pthread symbols
or
- a .pc file and a library which implements weak stubs for the pthread symbols,
which are not available in the C runtime.
Since then, the latter case was found to have a fundamental design issue.
Design
------
On platforms where the lightweight pthread symbols are provided by the runtime,
the .pc files provides empty Cflags/Libs flags.
Currently the following platforms fit the above category:
- GNU/Linux - GCC/Clang/GLibC/Musl
- Solaris 10 and later
- Cygwin
- GNU/Hurd
- GNU/kFreeBSD
For others, each of Cflags/Libs expands to full blown pthread.
For example:
- FreeBSD and derivatives
- OpenBSD - uses a heavily patched copy of pthread-stubs to workaround this
- other BSD platforms ?
Unchecked:
- MSYS/MINGW
- Darwin - GCC/Clang - should be the same as their Linux counter part
Many platforms have their own eccentric way of managing pthread compilation and
linkage. The ones realistically supported by pthread-stubs [and projects that
depend on it] work with '-pthread'.
GCC supports -pthread for:
Aarch64, ARM, Darwin, IA-64, MIPS, PowerPC, SPARC, x86
Cygwin and x86 Windows may need a trivial patch for older GCC versions.
See SVN rev 214161 and 171833/171834 respectively.
Clang:
Aarch64, ARM, x86 and likely others.
SunCC/Oracle compiler:
Requires -mt -lpthread. As of Solaris 10 (oldest currently supported version)
all the pthread API lives in libc. Thus we'll _never_ get here.
With previous design, one could get mismatched calls to the pthreads API.
Consider the following scenario:
- Program and/or its dependencies links only against libpthread-stubs,
since it uses lightweight API. Say pthread_mutex_lock.
- At a later stage the program and/or its dependencies dlopens a library
which effectively [either directly or via any of its own dependencies] pulls a
full blown pthread. Let's call that libB.
- The libpthread-stubs weak symbols get overridden by the libB ones.
- pthread_mutex_unlock is executed (which now originates from libB) and BOOM.
Amount and severity of issues depend on a number of factors. In either case
things go horribly wrong sooner on later.
The symbols
-----------
The following list of symbols is taken from the libc provided by GLibC.
It is deemed sufficient and reasonably accurate of what the 'lightweight'
pthread symbols are, since GLibC is one of the few (the only) implementations
which has the distinct split.
Most/all other C runtime implementations provide all the pthread API in a
single library.
Note that the following list is incomplete wrt libc-2.24.so and that further
symbols may be added in the future to bring the two closer. Adding symbols
which are not available in GLibC libc is NOT allowed.
pthread_condattr_destroy
pthread_condattr_init
pthread_cond_broadcast
pthread_cond_destroy
pthread_cond_init
pthread_cond_signal
pthread_cond_timedwait
pthread_cond_wait
pthread_equal
pthread_exit
pthread_mutex_destroy
pthread_mutex_init
pthread_mutex_lock
pthread_mutex_unlock
pthread_self
#! /bin/sh
srcdir=`dirname $0`
srcdir=`dirname "$0"`
test -z "$srcdir" && srcdir=.
ORIGDIR=`pwd`
cd $srcdir
cd "$srcdir"
autoreconf -v --install || exit 1
cd $ORIGDIR || exit $?
cd "$ORIGDIR" || exit $?
$srcdir/configure --enable-maintainer-mode "$@"
if test -z "$NOCONFIGURE"; then
$srcdir/configure "$@"
fi
AC_INIT([libpthread-stubs],
0.3,
0.4,
[xcb@lists.freedesktop.org])
AC_CONFIG_SRCDIR([pthread-stubs.pc.in])
AM_INIT_AUTOMAKE([foreign dist-bzip2])
AC_CONFIG_HEADERS([config.h])
dnl Check if the following functions have stubs.
dnl See the README for specifics about the list.
funclist="\
pthread_condattr_destroy \
pthread_condattr_init \
pthread_cond_broadcast \
pthread_cond_destroy \
pthread_cond_init \
pthread_cond_signal \
pthread_cond_timedwait \
pthread_cond_wait \
pthread_equal \
pthread_exit \
pthread_mutex_destroy \
pthread_mutex_init \
pthread_mutex_lock \
pthread_mutex_unlock \
pthread_self"
AC_PROG_LIBTOOL
AC_PROG_CC
AC_CHECK_FUNCS($funclist, [], [HAVE_STUBS=no])
dnl Detection code for compilers supporting the __attribute__((weak, alias))
dnl feature. Original code present in unieject's repository
dnl Diego Pettenò <flameeyes@gentoo.org>
ac_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Werror"
AC_CACHE_CHECK([if compiler supports __attribute__((weak, alias))],
[cc_cv_attribute_alias],
[AC_COMPILE_IFELSE([
void other_function(void *foo) { }
void some_function(void *foo) __attribute__((weak, alias("other_function")));
],
[cc_cv_attribute_alias=yes],
[cc_cv_attribute_alias=no])
])
CFLAGS="$ac_save_CFLAGS"
if test "x$cc_cv_attribute_alias" = "xyes"; then
AC_DEFINE([SUPPORT_ATTRIBUTE_ALIAS], 1, [Define this if the compiler supports the alias attribute])
if test "x$HAVE_STUBS" != xno; then
PKG_CONFIG_CFLAGS=
PKG_CONFIG_LIBS=
else
dnl See the README why '-pthread' is deemed sufficient.
PKG_CONFIG_CFLAGS="-pthread"
PKG_CONFIG_LIBS="-pthread"
fi
PKG_CONFIG_LIBS=
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],
[], [PKG_CONFIG_LIBS='-L${libdir} -lpthread-stubs'])
AC_SUBST([PKG_CONFIG_CFLAGS])
AC_SUBST([PKG_CONFIG_LIBS])
AM_CONDITIONAL(BUILD_LIB, test "x$PKG_CONFIG_LIBS" != x)
AC_CONFIG_FILES([Makefile pthread-stubs.pc])
AC_OUTPUT
libpthread-stubs (0.4-1) UNRELEASED; urgency=medium
* New upstream release.
* Change maintainer to Debian X Strike Force.
* Update Vcs-* URLs to point to salsa.debian.org.
* Bump debhelper compat to 11.
* Set source format to 1.0.
* Switch URLs to https.
* Bump standards version to 4.3.0.
-- Andreas Boll <aboll@debian.org> Thu, 07 Feb 2019 23:29:46 +0100
libpthread-stubs (0.3-4) unstable; urgency=low
* Stop building libpthread-stubs0{,-udeb} (closes: 706865).
......
Source: libpthread-stubs
Priority: optional
Section: libdevel
Maintainer: XCB Developers <xcb@lists.freedesktop.org>
Maintainer: Debian X Strike Force <debian-x@lists.debian.org>
Uploaders: Julien Danjou <acid@debian.org>
Build-Depends: debhelper (>= 8.1.3), dh-autoreconf
Standards-Version: 3.8.3
Vcs-Git: git://anonscm.debian.org/git/collab-maint/libpthread-stubs
Vcs-Browser: http://anonscm.debian.org/gitweb/?p=collab-maint/libpthread-stubs.git
Build-Depends: debhelper (>= 11)
Standards-Version: 4.3.0
Vcs-Git: https://salsa.debian.org/xorg-team/lib/libpthread-stubs.git
Vcs-Browser: https://salsa.debian.org/xorg-team/lib/libpthread-stubs
Package: libpthread-stubs0-dev
Section: libdevel
......
......@@ -2,7 +2,7 @@ This package was debianized by Jamey Sharp <sharpone@debian.org> on
Fri, 24 Nov 2006 01:01:49 -0800. The package is co-maintained by the
XCB developers via the XCB mailing list <xcb@lists.freedesktop.org>.
It was downloaded from http://xcb.freedesktop.org/dist
It was downloaded from https://xcb.freedesktop.org/dist
Upstream Authors: Jamey Sharp <sharpone@debian.org>
Josh Triplett <josh@freedesktop.org>
......
#!/usr/bin/make -f
DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
%:
dh $@ --with autoreconf --builddirectory=build
dh $@ --builddirectory=build
override_dh_auto_configure: debian/copyright
dh_auto_configure --builddirectory=build
......@@ -15,4 +12,3 @@ override_dh_auto_install:
debian/copyright: debian/copyright.debian COPYING
cat $+ > $@
version=3
http://xcb.freedesktop.org/dist/libpthread-stubs-([0-9].*)\.tar\.gz
https://xcb.freedesktop.org/dist/libpthread-stubs-([0-9].*)\.tar\.gz
......@@ -3,6 +3,7 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
Name: pthread stubs
Description: Stubs missing from libc for standard pthread functions
Description: Meta package for pthread symbols - defaults to heavyweight ones if the C runtime does not provide lightweight ones.
Version: @PACKAGE_VERSION@
Cflags: @PKG_CONFIG_CFLAGS@
Libs: @PKG_CONFIG_LIBS@
/* Copyright (C) 2006 Diego Pettenò
* Inspired by libX11 code copyright (c) 1995 David E. Wexelblat.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the names of the authors or their
* institutions shall not be used in advertising or otherwise to promote the
* sale, use or other dealings in this Software without prior written
* authorization from the authors.
*/
#include <pthread.h>
#include <stdlib.h>
#include "config.h"
#ifndef HAVE_PTHREAD_SELF
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_self() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
# pragma weak pthread_self = __pthread_zero_stub
# endif
#endif
#ifndef HAVE_PTHREAD_MUTEX_INIT
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_mutex_init() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
# pragma weak pthread_mutex_init = __pthread_zero_stub
# endif
#endif
#ifndef HAVE_PTHREAD_MUTEX_DESTROY
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_mutex_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
# pragma weak pthread_mutex_destroy = __pthread_zero_stub
# endif
#endif
#ifndef HAVE_PTHREAD_MUTEX_LOCK
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_mutex_lock() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
# pragma weak pthread_mutex_lock = __pthread_zero_stub
# endif
#endif
#ifndef HAVE_PTHREAD_MUTEX_UNLOCK
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_mutex_unlock() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
# pragma weak pthread_mutex_unlock = __pthread_zero_stub
# endif
#endif
#ifndef HAVE_PTHREAD_COND_INIT
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_cond_init() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
# pragma weak pthread_cond_init = __pthread_zero_stub
# endif
#endif
#ifndef HAVE_PTHREAD_COND_DESTROY
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_cond_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
# pragma weak pthread_cond_destroy = __pthread_zero_stub
# endif
#endif
#ifndef HAVE_PTHREAD_CONDATTR_INIT
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_condattr_init() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
# pragma weak pthread_condattr_init = __pthread_zero_stub
# endif
#endif
#ifndef HAVE_PTHREAD_CONDATTR_DESTROY
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_condattr_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
# pragma weak pthread_condattr_destroy = __pthread_zero_stub
# endif
#endif
#ifndef HAVE_PTHREAD_COND_WAIT
#define NEED_ABORT_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_cond_wait() __attribute__ ((weak, alias ("__pthread_abort_stub")));
# else
# pragma weak pthread_cond_wait = __pthread_abort_stub
# endif
#endif
#ifndef HAVE_PTHREAD_COND_TIMEDWAIT
#define NEED_ABORT_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_cond_timedwait() __attribute__ ((weak, alias ("__pthread_abort_stub")));
# else
# pragma weak pthread_cond_timedwait = __pthread_abort_stub
# endif
#endif
#ifndef HAVE_PTHREAD_COND_SIGNAL
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_cond_signal() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
# pragma weak pthread_cond_signal = __pthread_zero_stub
# endif
#endif
#ifndef HAVE_PTHREAD_COND_BROADCAST
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_cond_broadcast() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
# pragma weak pthread_cond_broadcast = __pthread_zero_stub
# endif
#endif
#ifndef HAVE_PTHREAD_EQUAL
#define NEED_EQUAL_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_equal() __attribute__ ((weak, alias ("__pthread_equal_stub")));
# else
# pragma weak pthread_equal = __pthread_equal_stub
# endif
#endif
#ifndef HAVE_PTHREAD_EXIT
#define NEED_EXIT_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
void pthread_exit() __attribute__ ((weak, alias ("__pthread_exit_stub")));
# else
# pragma weak pthread_exit = __pthread_exit_stub
# endif
#endif
#ifdef NEED_ZERO_STUB
static int __pthread_zero_stub()
{
return 0;
}
#endif
#ifdef NEED_ABORT_STUB
static int __pthread_abort_stub()
{
abort();
}
#endif
#ifdef NEED_EQUAL_STUB
static int __pthread_equal_stub(pthread_t t1, pthread_t t2)
{
return (t1 == t2);
}
#endif
#ifdef NEED_EXIT_STUB
static void __pthread_exit_stub(void *ret)
{
exit(EXIT_SUCCESS);
}
#endif