1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-12-27 05:10:36 +00:00

Add new experimental option, LINUXTHREADS_WRAP_API, that adds wrapper

functions providing most of the native threads API while avoiding name
clashes by transparently prefixing all function names that directly
provide the linuxthreads API.
This commit is contained in:
Tor Egge 2003-06-09 03:48:31 +00:00
parent 78604ed669
commit f390ff8ee2
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=82560
5 changed files with 1789 additions and 65 deletions

View File

@ -7,7 +7,7 @@
PORTNAME= linuxthreads
PORTVERSION= 2.2.3
PORTREVISION= 11
PORTREVISION= 12
CATEGORIES= devel
MASTER_SITES= ${MASTER_SITE_GNU}
MASTER_SITE_SUBDIR= glibc
@ -16,6 +16,10 @@ DISTNAME= glibc-linuxthreads-${PORTVERSION}
MAINTAINER= tegge@freebsd.org
COMMENT= POSIX pthreads implementation using rfork to generate kernel threads
.if defined(LINUXTHREADS_WRAP_API)
USE_PERL5_BUILD=true
.endif
.include <bsd.port.pre.mk>
# This port only works on i386 right now.
@ -34,6 +38,10 @@ MAKE_ENV+= INSTALL_LIBLTHREAD_PIC_ARCHIVE=yes
.if defined(LINUXTHREADS_DETECT_UNSAFE_EXIT)
MAKE_ENV+= LINUXTHREADS_DETECT_UNSAFE_EXIT=yes
.endif
.if defined(LINUXTHREADS_WRAP_API)
MAKE_ENV+= LINUXTHREADS_WRAP_API=yes
MAKE_ENV+= LINUXTHREADS_WRAP_LD="sh ${FILESDIR}/ldwrap"
.endif
threads_files := README.FreeBSD clone.S clone.h freebsd-compat.h getgr_r.c \
gethostby_r.c getnetby_r.c getprotoby_r.c getpw_r.c getservby_r.c \
@ -58,6 +66,13 @@ pre-fetch:
@${ECHO} "LINUXTHREADS_DETECT_UNSAFE_EXIT, see files/README.FreeBSD"
@${ECHO} "for more info."
@${ECHO}
.endif
.if !defined(LINUXTHREADS_WRAP_API)
@${ECHO}
@${ECHO} "Some conflicts with native threads can be avoided by defining"
@${ECHO} "LINUXTHREADS_WRAP_API, see files/README.FreeBSD"
@${ECHO} "for more info."
@${ECHO}
.endif
@if ${TEST} -f /usr/src/gnu/lib/libgcc/Makefile; then \
: ; \
@ -122,8 +137,9 @@ post-extract:
${WRKSRC}/libsupc++/Makefile.inc
.endif
.if defined(WITH_CONDWAIT_PATCH)
.if defined(WITH_CONDWAIT_PATCH) || defined(LINUXTHREADS_WRAP_API)
post-patch:
.if defined(WITH_CONDWAIT_PATCH)
@${ECHO_MSG} "===> Applying experimental patch condwait-patch"
@if ${PATCH} ${PATCH_ARGS} < ${PATCHDIR}/condwait-patch; then \
${ECHO_MSG} "===> Patch condwait-patch applied successfully"; \
@ -132,6 +148,10 @@ post-patch:
${FALSE}; \
fi
.endif
.if defined(LINUXTHREADS_WRAP_API)
perl -pi -e '$$func=$$1 if m/^extern\s+\S+\s+\*?(\S+)\s+\(/; $$alias="#ifdef COMPILING_WRAPUTHREAD\n\t__attribute__((weak, alias(\"_$$func\")))\n#endif\n"; $$wrap="#ifndef COMPILING_LINUXTHREADS\n\t__asm__(\"linuxthreads_$$func\")\n#endif\n"; $$alias="" if ( $$func =~ m/^(pthread_spin|_pthread_cleanup|pthread_rwlockattr_[gs]etkind_np|pthread_kill_other_threads_np)/ ); s=__THROW=\n$$wrap$$alias\t__THROW= unless m/^#/;' ${WRKSRC}/sysdeps/pthread/pthread.h ${WRKSRC}/sysdeps/unix/sysv/linux/bits/sigthread.h
.endif
.endif
pre-build:
@cd ${WRKSRC}/libgcc_r ; \
@ -182,10 +202,18 @@ PLIST_SUB+= LIBLTHREADPICARCHIVE:="@comment "
.endif
.if defined(USING_GCC3)
PLIST_SUB+= GCC3ONLY:=""
.if defined(LINUXTHREADS_WRAP_API)
PLIST_SUB+= LTHREADSHMAJOR:="5"
.else
PLIST_SUB+= LTHREADSHMAJOR:="3"
.endif
.else
PLIST_SUB+= GCC3ONLY:="@comment "
.if defined(LINUXTHREADS_WRAP_API)
PLIST_SUB+= LTHREADSHMAJOR:="4"
.else
PLIST_SUB+= LTHREADSHMAJOR:="2"
.endif
.endif
.include <bsd.port.post.mk>

View File

@ -91,7 +91,25 @@ set at 20 + 16 * MAXUSERS.
library causes the liblgcc_r.a version of those functions to be used.
Use liblstdc++ and liblsupc++.
4) Exit handling is broken.
Experimental wrapper support:
If the linuxthreads library has been compiled with
LINUXTHREADS_WRAP_API defined in the ports makefile then
the API functions are internally prefixed with linuxthreads_
to avoid conflict with native threads. Weak symbols without
that prefix points to the wrapper functions (internally
prefixed by _) that makes the linuxthreads functions available
with the native threads API. Applications including the
linuxthreads version of pthread.h will try to call the
prefixed methods (e.g. linuxthreads_pthread_create) while
applications including the native pthread.h will use the
wrapper functions. This allows for some level of coexistence
of libraries compiled with linuxthreads header file and
libraries compiled with native threads header files as long
as none of the pthread data types leaks out as function arguments
or structure members.
5) Exit handling is broken.
If the linuxthreads library has been compiled with
LINUXTHREADS_DETECT_UNSAFE_EXIT defined in the ports makefile then

View File

@ -0,0 +1,117 @@
#!/bin/sh -e
#
# Gross hack. Wrapper for ld that renames various functions to avoid
# conflicts between linuxthreads and native threads
#
echo "[ldwrap $@]"
if test "$1" = "-o" -a "$2" != "wraputhread.o.tmp" -a "$2" != "wraputhread.Po.tmp" -a "$2" != "wraputhread.So.tmp"
then
target=$2
shift
shift
ld -o $target.tmp "$@"
objcopy \
--redefine-sym _pthread_cleanup_pop=linuxthreads__pthread_cleanup_pop \
--redefine-sym _pthread_cleanup_pop_restore=linuxthreads__pthread_cleanup_pop_restore \
--redefine-sym _pthread_cleanup_push=linuxthreads__pthread_cleanup_push \
--redefine-sym _pthread_cleanup_push_defer=linuxthreads__pthread_cleanup_push_defer \
--redefine-sym pthread_atfork=linuxthreads_pthread_atfork \
--redefine-sym pthread_attr_destroy=linuxthreads_pthread_attr_destroy \
--redefine-sym pthread_attr_getdetachstate=linuxthreads_pthread_attr_getdetachstate \
--redefine-sym pthread_attr_getguardsize=linuxthreads_pthread_attr_getguardsize \
--redefine-sym pthread_attr_getinheritsched=linuxthreads_pthread_attr_getinheritsched \
--redefine-sym pthread_attr_getschedparam=linuxthreads_pthread_attr_getschedparam \
--redefine-sym pthread_attr_getschedpolicy=linuxthreads_pthread_attr_getschedpolicy \
--redefine-sym pthread_attr_getscope=linuxthreads_pthread_attr_getscope \
--redefine-sym pthread_attr_getstack=linuxthreads_pthread_attr_getstack \
--redefine-sym pthread_attr_getstackaddr=linuxthreads_pthread_attr_getstackaddr \
--redefine-sym pthread_attr_getstacksize=linuxthreads_pthread_attr_getstacksize \
--redefine-sym pthread_attr_init=linuxthreads_pthread_attr_init \
--redefine-sym pthread_attr_setdetachstate=linuxthreads_pthread_attr_setdetachstate \
--redefine-sym pthread_attr_setguardsize=linuxthreads_pthread_attr_setguardsize \
--redefine-sym pthread_attr_setinheritsched=linuxthreads_pthread_attr_setinheritsched \
--redefine-sym pthread_attr_setschedparam=linuxthreads_pthread_attr_setschedparam \
--redefine-sym pthread_attr_setschedpolicy=linuxthreads_pthread_attr_setschedpolicy \
--redefine-sym pthread_attr_setscope=linuxthreads_pthread_attr_setscope \
--redefine-sym pthread_attr_setstack=linuxthreads_pthread_attr_setstack \
--redefine-sym pthread_attr_setstackaddr=linuxthreads_pthread_attr_setstackaddr \
--redefine-sym pthread_attr_setstacksize=linuxthreads_pthread_attr_setstacksize \
--redefine-sym pthread_barrier_destroy=linuxthreads_pthread_barrier_destroy \
--redefine-sym pthread_barrier_init=linuxthreads_pthread_barrier_init \
--redefine-sym pthread_barrier_wait=linuxthreads_pthread_barrier_wait \
--redefine-sym pthread_barrierattr_destroy=linuxthreads_pthread_barrierattr_destroy \
--redefine-sym pthread_barrierattr_getpshared=linuxthreads_pthread_barrierattr_getpshared \
--redefine-sym pthread_barrierattr_init=linuxthreads_pthread_barrierattr_init \
--redefine-sym pthread_barrierattr_setpshared=linuxthreads_pthread_barrierattr_setpshared \
--redefine-sym pthread_cancel=linuxthreads_pthread_cancel \
--redefine-sym pthread_cond_broadcast=linuxthreads_pthread_cond_broadcast \
--redefine-sym pthread_cond_destroy=linuxthreads_pthread_cond_destroy \
--redefine-sym pthread_cond_init=linuxthreads_pthread_cond_init \
--redefine-sym pthread_cond_signal=linuxthreads_pthread_cond_signal \
--redefine-sym pthread_cond_timedwait=linuxthreads_pthread_cond_timedwait \
--redefine-sym pthread_cond_wait=linuxthreads_pthread_cond_wait \
--redefine-sym pthread_condattr_destroy=linuxthreads_pthread_condattr_destroy \
--redefine-sym pthread_condattr_getpshared=linuxthreads_pthread_condattr_getpshared \
--redefine-sym pthread_condattr_init=linuxthreads_pthread_condattr_init \
--redefine-sym pthread_condattr_setpshared=linuxthreads_pthread_condattr_setpshared \
--redefine-sym pthread_create=linuxthreads_pthread_create \
--redefine-sym pthread_detach=linuxthreads_pthread_detach \
--redefine-sym pthread_equal=linuxthreads_pthread_equal \
--redefine-sym pthread_exit=linuxthreads_pthread_exit \
--redefine-sym pthread_getattr_np=linuxthreads_pthread_getattr_np \
--redefine-sym pthread_getconcurrency=linuxthreads_pthread_getconcurrency \
--redefine-sym pthread_getcpuclockid=linuxthreads_pthread_getcpuclockid \
--redefine-sym pthread_getschedparam=linuxthreads_pthread_getschedparam \
--redefine-sym pthread_getspecific=linuxthreads_pthread_getspecific \
--redefine-sym pthread_join=linuxthreads_pthread_join \
--redefine-sym pthread_key_create=linuxthreads_pthread_key_create \
--redefine-sym pthread_key_delete=linuxthreads_pthread_key_delete \
--redefine-sym pthread_kill=linuxthreads_pthread_kill \
--redefine-sym pthread_kill_other_threads_np=linuxthreads_pthread_kill_other_threads_np \
--redefine-sym pthread_mutex_destroy=linuxthreads_pthread_mutex_destroy \
--redefine-sym pthread_mutex_init=linuxthreads_pthread_mutex_init \
--redefine-sym pthread_mutex_lock=linuxthreads_pthread_mutex_lock \
--redefine-sym pthread_mutex_timedlock=linuxthreads_pthread_mutex_timedlock \
--redefine-sym pthread_mutex_trylock=linuxthreads_pthread_mutex_trylock \
--redefine-sym pthread_mutex_unlock=linuxthreads_pthread_mutex_unlock \
--redefine-sym pthread_mutexattr_destroy=linuxthreads_pthread_mutexattr_destroy \
--redefine-sym pthread_mutexattr_getpshared=linuxthreads_pthread_mutexattr_getpshared \
--redefine-sym pthread_mutexattr_gettype=linuxthreads_pthread_mutexattr_gettype \
--redefine-sym pthread_mutexattr_init=linuxthreads_pthread_mutexattr_init \
--redefine-sym pthread_mutexattr_setpshared=linuxthreads_pthread_mutexattr_setpshared \
--redefine-sym pthread_mutexattr_settype=linuxthreads_pthread_mutexattr_settype \
--redefine-sym pthread_once=linuxthreads_pthread_once \
--redefine-sym pthread_rwlock_destroy=linuxthreads_pthread_rwlock_destroy \
--redefine-sym pthread_rwlock_init=linuxthreads_pthread_rwlock_init \
--redefine-sym pthread_rwlock_rdlock=linuxthreads_pthread_rwlock_rdlock \
--redefine-sym pthread_rwlock_timedrdlock=linuxthreads_pthread_rwlock_timedrdlock \
--redefine-sym pthread_rwlock_timedwrlock=linuxthreads_pthread_rwlock_timedwrlock \
--redefine-sym pthread_rwlock_tryrdlock=linuxthreads_pthread_rwlock_tryrdlock \
--redefine-sym pthread_rwlock_trywrlock=linuxthreads_pthread_rwlock_trywrlock \
--redefine-sym pthread_rwlock_unlock=linuxthreads_pthread_rwlock_unlock \
--redefine-sym pthread_rwlock_wrlock=linuxthreads_pthread_rwlock_wrlock \
--redefine-sym pthread_rwlockattr_destroy=linuxthreads_pthread_rwlockattr_destroy \
--redefine-sym pthread_rwlockattr_getkind_np=linuxthreads_pthread_rwlockattr_getkind_np \
--redefine-sym pthread_rwlockattr_getpshared=linuxthreads_pthread_rwlockattr_getpshared \
--redefine-sym pthread_rwlockattr_init=linuxthreads_pthread_rwlockattr_init \
--redefine-sym pthread_rwlockattr_setkind_np=linuxthreads_pthread_rwlockattr_setkind_np \
--redefine-sym pthread_rwlockattr_setpshared=linuxthreads_pthread_rwlockattr_setpshared \
--redefine-sym pthread_self=linuxthreads_pthread_self \
--redefine-sym pthread_setcancelstate=linuxthreads_pthread_setcancelstate \
--redefine-sym pthread_setcanceltype=linuxthreads_pthread_setcanceltype \
--redefine-sym pthread_setconcurrency=linuxthreads_pthread_setconcurrency \
--redefine-sym pthread_setschedparam=linuxthreads_pthread_setschedparam \
--redefine-sym pthread_setspecific=linuxthreads_pthread_setspecific \
--redefine-sym pthread_sigmask=linuxthreads_pthread_sigmask \
--redefine-sym pthread_spin_destroy=linuxthreads_pthread_spin_destroy \
--redefine-sym pthread_spin_init=linuxthreads_pthread_spin_init \
--redefine-sym pthread_spin_lock=linuxthreads_pthread_spin_lock \
--redefine-sym pthread_spin_trylock=linuxthreads_pthread_spin_trylock \
--redefine-sym pthread_spin_unlock=linuxthreads_pthread_spin_unlock \
--redefine-sym pthread_testcancel=linuxthreads_pthread_testcancel \
--redefine-sym pthread_yield=linuxthreads_pthread_yield \
$target.tmp $target
rm -f $target.tmp
else
exec ld "$@"
fi

View File

@ -13,15 +13,23 @@ diff -ru ../../work/linuxthreads-2.2.3/Examples/Makefile ./Examples/Makefile
diff -ru ../../work/linuxthreads-2.2.3/Makefile ./Makefile
--- ../../work/linuxthreads-2.2.3/Makefile Wed Apr 25 21:50:59 2001
+++ ./Makefile Thu Jun 7 23:13:52 2001
@@ -1,128 +1,91 @@
@@ -1,128 +1,104 @@
-# Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
-# This file is part of the GNU C Library.
+LIB=lthread
+.if defined(LINUXTHREADS_WRAP_API)
+.if defined(USING_GCC3)
+SHLIB_MAJOR= 5
+.else
+SHLIB_MAJOR= 4
+.endif
+.else
+.if defined(USING_GCC3)
+SHLIB_MAJOR= 3
+.else
+SHLIB_MAJOR= 2
+.endif
+.endif
+SHLIB_MINOR= 2
+
+.if defined(INSTALL_LIBLTHREAD_PIC_ARCHIVE)
@ -61,6 +69,11 @@ diff -ru ../../work/linuxthreads-2.2.3/Makefile ./Makefile
+CFLAGS += -DLINUXTHREADS_DETECT_UNSAFE_EXIT
+.endif
+
+.if defined(LINUXTHREADS_WRAP_API)
+CFLAGS += -DLINUXTHREADS_WRAP_API
+LD=${LINUXTHREADS_WRAP_LD}
+.endif
+
+AINC = -I${LIBSRC_BASE}/libc/${MACHINE_ARCH} -I${.CURDIR}/sysdeps/${MACHINE_ARCH}
+
+# Contents of the library.
@ -262,14 +275,26 @@ diff -ru ../../work/linuxthreads-2.2.3/attr.c ./attr.c
diff -ru ../../work/linuxthreads-2.2.3/cancel.c ./cancel.c
--- ../../work/linuxthreads-2.2.3/cancel.c Thu Apr 12 23:10:53 2001
+++ ./cancel.c Thu Jun 7 22:59:29 2001
@@ -20,7 +20,6 @@
@@ -20,8 +20,10 @@
#include "internals.h"
#include "spinlock.h"
#include "restart.h"
-#include <stackinfo.h>
+#if 1
+#define FRAME_LEFT(frame, other) 0
+#else
#ifdef _STACK_GROWS_DOWN
# define FRAME_LEFT(frame, other) ((char *) frame >= (char *) other)
#elif _STACK_GROWS_UP
@@ -29,6 +31,7 @@
#else
# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
#endif
+#endif
int pthread_setcancelstate(int state, int * oldstate)
@@ -202,9 +201,11 @@
break;
}

File diff suppressed because it is too large Load Diff