From 7c846b63a8321c6822a6b5ad82b1134ff8d1d18b Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 13 Sep 2012 06:01:04 -0700 Subject: Use STB_SECONDARY on pthread functions in libc 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 . 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 . Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_getspecific. * nptl/pthread_key_create.c: Include . Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_key_create. * nptl/pthread_mutex_lock.c: Include . Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_mutex_lock. * nptl/pthread_mutex_unlock.c: Include . Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_mutex_unlock. * nptl/pthread_once.c: Include . Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_once. * nptl/pthread_rwlock_rdlock.c: Include . Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_rwlock_rdlock. * nptl/pthread_rwlock_unlock.c: Include . Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_rwlock_unlock. * nptl/pthread_rwlock_wrlock.c: Include . Add GLIBC_2_0 and GLIBC_PRIVATE versions for __pthread_rwlock_wrlock. * nptl/pthread_setspecific.c: Include . 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 instead of . (__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. --- sysdeps/unix/sysv/linux/fatal-prepare.h | 19 +++---------------- sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S | 6 ++++++ sysdeps/unix/sysv/linux/i386/libc.abilist | 1 + sysdeps/unix/sysv/linux/i386/localplt.data | 12 ++++++++++++ sysdeps/unix/sysv/linux/s390/jmp-unwind.c | 12 ++++-------- sysdeps/unix/sysv/linux/x86_64/64/libc.abilist | 1 + sysdeps/unix/sysv/linux/x86_64/cancellation.S | 2 +- sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S | 6 ++++++ sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist | 1 + 9 files changed, 35 insertions(+), 25 deletions(-) (limited to 'sysdeps/unix') diff --git a/sysdeps/unix/sysv/linux/fatal-prepare.h b/sysdeps/unix/sysv/linux/fatal-prepare.h index 45d88ce911..2a89567299 100644 --- a/sysdeps/unix/sysv/linux/fatal-prepare.h +++ b/sysdeps/unix/sysv/linux/fatal-prepare.h @@ -19,19 +19,6 @@ /* We have to completely disable cancellation. assert() must not be a cancellation point but the implementation uses write() etc. */ -#ifdef SHARED -# include -# define FATAL_PREPARE \ - { \ - if (__libc_pthread_functions_init) \ - PTHFCT_CALL (ptr_pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, \ - NULL)); \ - } -#else -# pragma weak pthread_setcancelstate -# define FATAL_PREPARE \ - { \ - if (pthread_setcancelstate != NULL) \ - pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); \ - } -#endif +#define FATAL_PREPARE \ + __libc_ptf_call (__pthread_setcancelstate, \ + (PTHREAD_CANCEL_DISABLE, NULL), 0) diff --git a/sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S b/sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S index 111e9c88ed..cf3f206445 100644 --- a/sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S +++ b/sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S @@ -16,4 +16,10 @@ License along with the GNU C Library; if not, see . */ +#if IS_IN (libc) && !defined SHARED +/* Allow libpthread.a to override the ones in libc.a. */ + weak_extern (__lll_lock_wait_private) + weak_extern (__lll_unlock_wake_private) +#endif + #include "lowlevellock.S" diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist index fcf1b72ab5..fe41fbd6ac 100644 --- a/sysdeps/unix/sysv/linux/i386/libc.abilist +++ b/sysdeps/unix/sysv/linux/i386/libc.abilist @@ -868,6 +868,7 @@ GLIBC_2.0 pthread_mutex_init F pthread_mutex_lock F pthread_mutex_unlock F + pthread_once F pthread_self F pthread_setcancelstate F pthread_setcanceltype F diff --git a/sysdeps/unix/sysv/linux/i386/localplt.data b/sysdeps/unix/sysv/linux/i386/localplt.data index 2e03821dfd..f9efb05c41 100644 --- a/sysdeps/unix/sysv/linux/i386/localplt.data +++ b/sysdeps/unix/sysv/linux/i386/localplt.data @@ -6,6 +6,18 @@ libc.so: free + REL R_386_GLOB_DAT libc.so: malloc + REL R_386_GLOB_DAT libc.so: memalign libc.so: realloc +# pthread functions may be preempted by libpthread at run-time. +libc.so: __pthread_getspecific +libc.so: __pthread_key_create +libc.so: __pthread_once +libc.so: __pthread_rwlock_rdlock +libc.so: __pthread_rwlock_unlock +libc.so: __pthread_rwlock_wrlock +libc.so: __pthread_setcancelstate +libc.so: __pthread_setspecific +libc.so: __pthread_unwind +libc.so: _pthread_cleanup_pop_restore +libc.so: _pthread_cleanup_push_defer libm.so: matherr # The dynamic loader uses __libc_memalign internally to allocate aligned # TLS storage. The other malloc family of functions are expected to allow diff --git a/sysdeps/unix/sysv/linux/s390/jmp-unwind.c b/sysdeps/unix/sysv/linux/s390/jmp-unwind.c index 52fe1019f2..b7f9080e5a 100644 --- a/sysdeps/unix/sysv/linux/s390/jmp-unwind.c +++ b/sysdeps/unix/sysv/linux/s390/jmp-unwind.c @@ -18,10 +18,12 @@ #include #include -#include +#include extern void __pthread_cleanup_upto (__jmp_buf env, char *targetframe); +#ifndef HAVE_ASM_SECONDARY_DIRECTIVE #pragma weak __pthread_cleanup_upto +#endif void @@ -29,11 +31,5 @@ _longjmp_unwind (jmp_buf env, int val) { char local_var; -#ifdef SHARED - if (__libc_pthread_functions_init) - PTHFCT_CALL (ptr___pthread_cleanup_upto, (env->__jmpbuf, &local_var)); -#else - if (__pthread_cleanup_upto != NULL) - __pthread_cleanup_upto (env->__jmpbuf, &local_var); -#endif + __libc_ptf_call (__pthread_cleanup_upto, (env->__jmpbuf, &local_var), 0); } diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist index b377b04e48..5be5d5ad05 100644 --- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist @@ -1299,6 +1299,7 @@ GLIBC_2.2.5 pthread_mutex_init F pthread_mutex_lock F pthread_mutex_unlock F + pthread_once F pthread_self F pthread_setcancelstate F pthread_setcanceltype F diff --git a/sysdeps/unix/sysv/linux/x86_64/cancellation.S b/sysdeps/unix/sysv/linux/x86_64/cancellation.S index 4c34bebc42..52a27dcc5e 100644 --- a/sysdeps/unix/sysv/linux/x86_64/cancellation.S +++ b/sysdeps/unix/sysv/linux/x86_64/cancellation.S @@ -26,7 +26,7 @@ # define __pthread_unwind __GI___pthread_unwind # endif #else -# ifndef SHARED +# if !defined SHARED && !defined HAVE_ASM_SECONDARY_DIRECTIVE .weak __pthread_unwind # endif #endif diff --git a/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S b/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S index 111e9c88ed..cf3f206445 100644 --- a/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S +++ b/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S @@ -16,4 +16,10 @@ License along with the GNU C Library; if not, see . */ +#if IS_IN (libc) && !defined SHARED +/* Allow libpthread.a to override the ones in libc.a. */ + weak_extern (__lll_lock_wait_private) + weak_extern (__lll_unlock_wake_private) +#endif + #include "lowlevellock.S" diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist index 5f7032980b..ac95bfa196 100644 --- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist @@ -1448,6 +1448,7 @@ GLIBC_2.16 pthread_mutex_init F pthread_mutex_lock F pthread_mutex_unlock F + pthread_once F pthread_self F pthread_setcancelstate F pthread_setcanceltype F -- cgit v1.2.3-70-g09d2