diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2012-09-13 06:01:04 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2015-09-23 09:03:45 -0700 |
commit | 7c846b63a8321c6822a6b5ad82b1134ff8d1d18b (patch) | |
tree | 56c09f594f27c761633e05d3b5f23f597411502c /sysdeps/nptl/bits/libc-lockP.h | |
parent | 6e1ae9bae180f0cf43d73ee2ee395252d1e22e17 (diff) | |
download | glibc-hjl/pthread/2.22.tar.gz glibc-hjl/pthread/2.22.tar.xz glibc-hjl/pthread/2.22.zip |
Use STB_SECONDARY on pthread functions in libc hjl/pthread/2.22
Use STB_SECONDARY binding on pthread functions in libc so that they will be preempted by definitions in libpthread at link-time as well as at run-time. * csu/libc-tls.c (__pthread_initialize_minimal): Mark it secondary if HAVE_ASM_SECONDARY_DIRECTIVE is defined. * misc/error.c (error): Replace pthread_setcancelstate with __pthread_setcancelstate. (error_at_line): Likewise. * posix/wordexp.c (parse_comm): Likewise. * stdlib/fmtmsg.c (fmtmsg): Likewise. * nptl/Makefile: (routines): Add libc-pthread-secondary. (CFLAGS-libc-pthread-secondary.c): New. * nptl/Versions [HAVE_ASM_SECONDARY_DIRECTIVE] (libc:GLIBC_2.0): Add pthread_once. [HAVE_ASM_SECONDARY_DIRECTIVE] (libc:GLIBC_PRIVATE): Add _pthread_cleanup_pop_restore, _pthread_cleanup_push_defer, __pthread_getspecific, __pthread_setspecific, __pthread_key_create, __pthread_mutex_lock, __pthread_mutex_unlock, __pthread_once, __pthread_rwlock_rdlock, __pthread_rwlock_wrlock, __pthread_rwlock_unlock and __pthread_unwind. [HAVE_ASM_SECONDARY_DIRECTIVE] (libpthread:GLIBC_PRIVATE): Likewise. * cleanup_defer_compat.c: Include <shlib-compat.h>. Add GLIBC_2_0 and GLIBC_PRIVATE versions for _pthread_cleanup_pop_restore and _pthread_cleanup_push_defer. * nptl/forward.c [HAVE_ASM_SECONDARY_DIRECTIVE] (FORWARD2): New. (FORWARD_NORETURN): Likewise. (pthread_setcancelstate): Renamed to ... (__pthread_setcancelstate): This. (pthread_setcancelstate): Add an alias. * nptl/libc-pthread-secondary.c: New file. * nptl/nptl-init.c (pthread_functions): Don't include secondary pthread functions in libc if HAVE_ASM_SECONDARY_DIRECTIVE is defined. Replace ptr_pthread_setcancelstate with ptr___pthread_setcancelstate. * sysdeps/nptl/pthread-functions.h (pthread_functions): Likewise. * nptl/pthread_getspecific.c: Include <shlib-compat.h>. Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_getspecific. * nptl/pthread_key_create.c: Include <shlib-compat.h>. Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_key_create. * nptl/pthread_mutex_lock.c: Include <shlib-compat.h>. Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_mutex_lock. * nptl/pthread_mutex_unlock.c: Include <shlib-compat.h>. Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_mutex_unlock. * nptl/pthread_once.c: Include <shlib-compat.h>. Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_once. * nptl/pthread_rwlock_rdlock.c: Include <shlib-compat.h>. Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_rwlock_rdlock. * nptl/pthread_rwlock_unlock.c: Include <shlib-compat.h>. Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_rwlock_unlock. * nptl/pthread_rwlock_wrlock.c: Include <shlib-compat.h>. Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_rwlock_wrlock. * nptl/pthread_setspecific.c: Include <shlib-compat.h>. Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_setspecific. * nptl/pthreadP.h (__pthread_unwind): Don't mark it weak if HAVE_ASM_SECONDARY_DIRECTIVE is defined. (__pthread_cond_broadcast_2_0): Declare only if not in libc. (__pthread_cond_destroy_2_0): Likewise. (__pthread_cond_init_2_0): Likewise. (__pthread_cond_signal_2_0): Likewise. (__pthread_cond_timedwait_2_0): Likewise. (__pthread_cond_wait_2_0): Likewise. * scripts/abilist.awk: Support secondary symbols. * sysdeps/generic/localplt.data: Add __pthread_getspecific, __pthread_key_create, __pthread_once, __pthread_rwlock_rdlock, __pthread_rwlock_wrlock, __pthread_rwlock_unlock, __pthread_setcancelstate, __pthread_setspecific, __pthread_unwind. _pthread_cleanup_pop_restore and _pthread_cleanup_push_defer. * sysdeps/unix/sysv/linux/i386/localplt.data: Likewise. * sysdeps/x86_64/localplt.data: Likewise. * sysdeps/nptl/bits/libc-lockP.h (PTFAVAIL): Defined as 1 if HAVE_ASM_SECONDARY_DIRECTIVE is defined. (__libc_maybe_call): Always call FUNC if HAVE_ASM_SECONDARY_DIRECTIVE is defined. (__libc_ptf_call): Likewise. (__libc_ptf_call_always): Likewise. (__pthread_mutex_init): Don't mark it weak if HAVE_ASM_SECONDARY_DIRECTIVE is defined. (__pthread_mutex_destroy): Likewise. (__pthread_mutex_lock): Likewise. (__pthread_mutex_trylock): Likewise. (__pthread_mutex_unlock): Likewise. (__pthread_mutexattr_init): Likewise. (__pthread_mutexattr_destroy): Likewise. (__pthread_mutexattr_settype): Likewise. (__pthread_rwlock_destroy): Likewise. (__pthread_rwlock_rdlock): Likewise. (__pthread_rwlock_tryrdlock): Likewise. (__pthread_rwlock_wrlock): Likewise. (__pthread_rwlock_trywrlock): Likewise. (__pthread_rwlock_unlock): Likewise. (__pthread_key_create): Likewise. (__pthread_setspecific): Likewise. (__pthread_getspecific): Likewise. (__pthread_once): Likewise. (__pthread_initialize): Likewise. (__pthread_atfork): Likewise. (_pthread_cleanup_push_defer): Likewise. (_pthread_cleanup_pop_restore): Likewise. (__pthread_setcancelstate): New prototype. (pthread_setcancelstate): Renamed to ... (__pthread_setcancelstate): This. Don't mark it weak if HAVE_ASM_SECONDARY_DIRECTIVE is defined. * sysdeps/nptl/jmp-unwind.c: Include <bits/libc-lock.h> instead of <nptl/pthreadP.h>. (__pthread_cleanup_upto): Don't mark it weak if HAVE_ASM_SECONDARY_DIRECTIVE is defined. (_longjmp_unwind): Use __libc_ptf_call. * sysdeps/unix/sysv/linux/s390/jmp-unwind.c: Likewise. * sysdeps/unix/sysv/linux/fatal-prepare.h (FATAL_PREPARE): Always call __pthread_setcancelstate if HAVE_ASM_SECONDARY_DIRECTIVE is defined. Replace pthread_setcancelstate with __pthread_setcancelstate. * sysdeps/unix/sysv/linux/i386/libc.abilist: Add pthread_once. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist: Likewise. * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S: Make __lll_lock_wait_private and __lll_unlock_wake_private weak in libc.a. * sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S: Likewise. * sysdeps/unix/sysv/linux/x86_64/cancellation.S (__pthread_unwind): Don't mark it weak if HAVE_ASM_SECONDARY_DIRECTIVE is defined.
Diffstat (limited to 'sysdeps/nptl/bits/libc-lockP.h')
-rw-r--r-- | sysdeps/nptl/bits/libc-lockP.h | 65 |
1 files changed, 40 insertions, 25 deletions
diff --git a/sysdeps/nptl/bits/libc-lockP.h b/sysdeps/nptl/bits/libc-lockP.h index f55f6212ec..f5753afb32 100644 --- a/sysdeps/nptl/bits/libc-lockP.h +++ b/sysdeps/nptl/bits/libc-lockP.h @@ -99,39 +99,51 @@ typedef pthread_key_t __libc_key_t; #define __rtld_lock_initialize(NAME) \ (void) ((NAME) = (__rtld_lock_recursive_t) _RTLD_LOCK_RECURSIVE_INITIALIZER) +#ifdef HAVE_ASM_SECONDARY_DIRECTIVE +/* All pthread functions are available. */ +# define PTFAVAIL(NAME) 1 + +/* When secondary symbols are used, FUNC is implemented to return ELSE so + that we can always call FUNC. */ +# define __libc_maybe_call(FUNC, ARGS, ELSE) FUNC ARGS +# define __libc_ptf_call(FUNC, ARGS, ELSE) FUNC ARGS +# define __libc_ptf_call_always(FUNC, ARGS) FUNC ARGS +#else /* If we check for a weakly referenced symbol and then perform a normal jump to it te code generated for some platforms in case of PIC is unnecessarily slow. What would happen is that the function is first referenced as data and then it is called indirectly through the PLT. We can make this a direct jump. */ -#ifdef __PIC__ -# define __libc_maybe_call(FUNC, ARGS, ELSE) \ - (__extension__ ({ __typeof (FUNC) *_fn = (FUNC); \ - _fn != NULL ? (*_fn) ARGS : ELSE; })) -#else -# define __libc_maybe_call(FUNC, ARGS, ELSE) \ - (FUNC != NULL ? FUNC ARGS : ELSE) -#endif +# ifdef __PIC__ +# define __libc_maybe_call(FUNC, ARGS, ELSE) \ + (__extension__ ({ __typeof (FUNC) *_fn = (FUNC); \ + _fn != NULL ? (*_fn) ARGS : ELSE; })) +# else +# define __libc_maybe_call(FUNC, ARGS, ELSE) \ + (FUNC != NULL ? FUNC ARGS : ELSE) +# endif /* Call thread functions through the function pointer table. */ -#if defined SHARED && IS_IN (libc) -# define PTFAVAIL(NAME) __libc_pthread_functions_init -# define __libc_ptf_call(FUNC, ARGS, ELSE) \ +# if defined SHARED && IS_IN (libc) \ + && !defined HAVE_ASM_SECONDARY_DIRECTIVE +# define PTFAVAIL(NAME) __libc_pthread_functions_init +# define __libc_ptf_call(FUNC, ARGS, ELSE) \ (__libc_pthread_functions_init ? PTHFCT_CALL (ptr_##FUNC, ARGS) : ELSE) -# define __libc_ptf_call_always(FUNC, ARGS) \ +# define __libc_ptf_call_always(FUNC, ARGS) \ PTHFCT_CALL (ptr_##FUNC, ARGS) -#elif IS_IN (libpthread) -# define PTFAVAIL(NAME) 1 -# define __libc_ptf_call(FUNC, ARGS, ELSE) \ +# elif IS_IN (libpthread) +# define PTFAVAIL(NAME) 1 +# define __libc_ptf_call(FUNC, ARGS, ELSE) \ FUNC ARGS -# define __libc_ptf_call_always(FUNC, ARGS) \ +# define __libc_ptf_call_always(FUNC, ARGS) \ FUNC ARGS -#else -# define PTFAVAIL(NAME) (NAME != NULL) -# define __libc_ptf_call(FUNC, ARGS, ELSE) \ - __libc_maybe_call (FUNC, ARGS, ELSE) -# define __libc_ptf_call_always(FUNC, ARGS) \ +# else +# define PTFAVAIL(NAME) (NAME != NULL) +# define __libc_ptf_call(FUNC, ARGS, ELSE) \ + __libc_maybe_call (FUNC, ARGS, ELSE) +# define __libc_ptf_call_always(FUNC, ARGS) \ FUNC ARGS +# endif #endif @@ -364,6 +376,8 @@ extern int __pthread_rwlock_unlock (pthread_rwlock_t *__rwlock); extern int __pthread_key_create (pthread_key_t *__key, void (*__destr_function) (void *)); +extern int __pthread_setcancelstate (int state, int *oldstate); + extern int __pthread_setspecific (pthread_key_t __key, const void *__pointer); @@ -379,8 +393,9 @@ extern int __pthread_atfork (void (*__prepare) (void), /* Make the pthread functions weak so that we can elide them from - single-threaded processes. */ -#ifndef __NO_WEAK_PTHREAD_ALIASES + single-threaded processes unless secondary symbols are used. */ +#if !defined __NO_WEAK_PTHREAD_ALIASES \ + && !defined HAVE_ASM_SECONDARY_DIRECTIVE # ifdef weak_extern weak_extern (__pthread_mutex_init) weak_extern (__pthread_mutex_destroy) @@ -405,7 +420,7 @@ weak_extern (__pthread_initialize) weak_extern (__pthread_atfork) weak_extern (_pthread_cleanup_push_defer) weak_extern (_pthread_cleanup_pop_restore) -weak_extern (pthread_setcancelstate) +weak_extern (__pthread_setcancelstate) # else # pragma weak __pthread_mutex_init # pragma weak __pthread_mutex_destroy @@ -429,7 +444,7 @@ weak_extern (pthread_setcancelstate) # pragma weak __pthread_atfork # pragma weak _pthread_cleanup_push_defer # pragma weak _pthread_cleanup_pop_restore -# pragma weak pthread_setcancelstate +# pragma weak __pthread_setcancelstate # endif #endif |