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. --- nptl/libc-pthread-secondary.c | 132 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 nptl/libc-pthread-secondary.c (limited to 'nptl/libc-pthread-secondary.c') diff --git a/nptl/libc-pthread-secondary.c b/nptl/libc-pthread-secondary.c new file mode 100644 index 0000000000..71ceea2036 --- /dev/null +++ b/nptl/libc-pthread-secondary.c @@ -0,0 +1,132 @@ +/* Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifdef HAVE_ASM_SECONDARY_DIRECTIVE +# define pthread_mutex_lock __rename_pthread_mutex_lock +# define pthread_mutex_unlock __rename_pthread_mutex_unlock +# include +# include +# undef pthread_mutex_lock +# undef pthread_mutex_unlock + +static void __attribute__ ((unused)) +pthread_secondary_void (void) +{ +} + +static int __attribute__ ((unused)) +pthread_secondary_zero (void) +{ + return 0; +} + +static int __attribute__ ((unused)) +pthread_secondary_einval (void) +{ + return EINVAL; +} + +/* Use STB_SECONDARY on pthread functions in libc so that they are used + only when libpthread is not used. */ + +asm (".secondary _pthread_cleanup_push_defer"); +strong_alias (pthread_secondary_void, _pthread_cleanup_push_defer) + +asm (".secondary _pthread_cleanup_pop_restore"); + +void +_pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer, + int execute) +{ + if (execute) + buffer->__routine (buffer->__arg); +} + +asm (".secondary __pthread_cleanup_upto"); +strong_alias (pthread_secondary_void, __pthread_cleanup_upto) + +asm (".secondary __pthread_getspecific"); +strong_alias (pthread_secondary_zero, __pthread_getspecific) + +asm (".secondary __pthread_setspecific"); +strong_alias (pthread_secondary_einval, __pthread_setspecific) + +asm (".secondary __pthread_key_create"); +strong_alias (pthread_secondary_einval, __pthread_key_create) + +asm (".secondary __pthread_mutex_lock"); +strong_alias (pthread_secondary_zero, __pthread_mutex_lock) + +asm (".secondary __pthread_mutex_unlock"); +strong_alias (pthread_secondary_zero, __pthread_mutex_unlock) + +asm (".secondary __pthread_once"); +asm (".secondary pthread_once"); + +int +__pthread_once (pthread_once_t *once_control, + void (*init_routine) (void)) +{ + if (*once_control == PTHREAD_ONCE_INIT) + { + init_routine (); + *once_control |= 2; + } + return 0; +} +strong_alias (__pthread_once, pthread_once) + +asm (".secondary __pthread_rwlock_rdlock"); +strong_alias (pthread_secondary_zero, __pthread_rwlock_rdlock) + +asm (".secondary __pthread_rwlock_unlock"); +strong_alias (pthread_secondary_zero, __pthread_rwlock_unlock) + +asm (".secondary __pthread_rwlock_wrlock"); +strong_alias (pthread_secondary_zero, __pthread_rwlock_wrlock) + +asm (".secondary __pthread_unwind"); + +void +__attribute ((noreturn)) +__cleanup_fct_attribute +attribute_compat_text_section +__pthread_unwind (__pthread_unwind_buf_t *buf) +{ + /* We cannot call abort() here. */ + typedef __typeof (__safe_fatal) *fn_noreturn __attribute ((noreturn)); + fn_noreturn fn = (fn_noreturn) __safe_fatal; + fn (); +} + +# ifndef SHARED +asm (".secondary __pthread_setcancelstate"); +strong_alias (pthread_secondary_zero, __pthread_setcancelstate) + +asm (".secondary pthread_mutex_lock"); +strong_alias (__pthread_mutex_lock, pthread_mutex_lock) + +asm (".secondary pthread_mutex_unlock"); +strong_alias (__pthread_mutex_unlock, pthread_mutex_unlock) + +asm (".secondary __pthread_rwlock_destroy"); +strong_alias (pthread_secondary_zero, __pthread_rwlock_destroy) + +asm (".secondary __pthread_rwlock_init"); +strong_alias (pthread_secondary_zero, __pthread_rwlock_init) +# endif +#endif -- cgit v1.2.3-70-g09d2