From 29ff9055c80efe77a7130767a9fcb3ab8c67e8ce Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Sat, 24 Sep 2016 02:55:31 +0200 Subject: use a single libc and deduplicate threading code Similar to musl libc a single libc has many benefits and solves some open issues with uClibc-ng. - no pthread_mutex_* weak symbols exported anymore - applications no longer failing to link when either -lrt or -lpthread are missing for dynamic and static linking mode - smaller C library - slightly better runtime performance --- libpthread/nptl/sysdeps/pthread/Makefile.in | 51 -------- libpthread/nptl/sysdeps/pthread/bits/libc-lock.h | 10 -- libpthread/nptl/sysdeps/pthread/pt-initfini.c | 128 --------------------- libpthread/nptl/sysdeps/pthread/pt-sigaction.c | 7 +- .../nptl/sysdeps/pthread/pthread-functions.h | 108 ----------------- libpthread/nptl/sysdeps/pthread/setxid.h | 6 +- libpthread/nptl/sysdeps/pthread/uClibc-glue.h | 1 - 7 files changed, 4 insertions(+), 307 deletions(-) delete mode 100644 libpthread/nptl/sysdeps/pthread/pt-initfini.c delete mode 100644 libpthread/nptl/sysdeps/pthread/pthread-functions.h (limited to 'libpthread/nptl/sysdeps/pthread') diff --git a/libpthread/nptl/sysdeps/pthread/Makefile.in b/libpthread/nptl/sysdeps/pthread/Makefile.in index 9d99f3158..a501b6403 100644 --- a/libpthread/nptl/sysdeps/pthread/Makefile.in +++ b/libpthread/nptl/sysdeps/pthread/Makefile.in @@ -43,62 +43,11 @@ CFLAGS-pthread_spin_unlock.c = -D_GNU_SOURCE CFLAGS-unwind-forcedunwind.c = -fexceptions -fasynchronous-unwind-tables CFLAGS-OMIT-librt-cancellation.c = -DIS_IN_libpthread -CFLAGS-OMIT-rt-unwind-resume.c = -DIS_IN_libpthread CFLAGS-librt-cancellation.c = -DIS_IN_librt \ -fexceptions -fasynchronous-unwind-tables -CFLAGS-rt-unwind-resume.c = -DIS_IN_librt \ - -fexceptions -fasynchronous-unwind-tables - libpthread-so-y += $(patsubst %,$(libpthread_pthread_OUT)/%.oS, unwind-forcedunwind) librt-pt-routines-y = librt-cancellation.c -librt-pt-shared-only-routines-y = rt-unwind-resume.c - -ifeq ($(UCLIBC_CTOR_DTOR),y) -CFLAGS-OMIT-pt-initfini.c = $(CFLAGS-y-libpthread/nptl/sysdeps/pthread) -CFLAGS-pt-initfini.c = -S -g0 $(PICFLAG) -fno-inline-functions \ - $(call check_gcc,-fno-unit-at-a-time,) \ - $(SSP_DISABLE_FLAGS) \ - -finhibit-size-directive \ - -fno-asynchronous-unwind-tables -fno-unwind-tables \ - $(patsubst -f%,-fno-%,$(call check_gcc,-fexceptions,)) - -#ASFLAGS += $(PICFLAG) -I$(top_srcdir)include -I$(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH) -ifneq ($(wildcard $(libpthread_pthread_DIR)/../unix/sysv/linux/$(TARGET_ARCH)/pt-initfini.c),) -PTHREAD_INITFINI := $(libpthread_pthread_DIR)/../unix/sysv/linux/$(TARGET_ARCH)/pt-initfini.c -else -PTHREAD_INITFINI := $(libpthread_pthread_DIR)/pt-initfini.c -endif - -ASFLAGS-pt-crti.S = $(PICFLAG) -ASFLAGS-pt-crtn.S = $(PICFLAG) - -$(libpthread_pthread_OUT)/pt-crti.o: $(libpthread_pthread_OUT)/pt-crti.S - $(compile.S) - -$(libpthread_pthread_OUT)/pt-crtn.o: $(libpthread_pthread_OUT)/pt-crtn.S - $(compile.S) - -$(libpthread_pthread_OUT)/pt-initfini.s: $(PTHREAD_INITFINI) | $(headers_dep) - $(compile.c) -$(libpthread_pthread_OUT)/defs.h: $(PTHREAD_INITFINI) - $(do_sed) -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \ - $(AWK) -f $(top_srcdir)extra/scripts/defs.awk > $@.tmp - $(Q)mv $@.tmp $@ - -$(libpthread_pthread_OUT)/pt-crti.S: $(libpthread_pthread_OUT)/pt-initfini.s $(libpthread_pthread_OUT)/defs.h - $(do_sed) -n -e '/[ ]*\.file/d' \ - -e '1,/@HEADER_ENDS/p' \ - -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \ - -e '/@TRAILER_BEGINS/,$$p' $< > $@.tmp - $(Q)mv $@.tmp $@ -$(libpthread_pthread_OUT)/pt-crtn.S: $(libpthread_pthread_OUT)/pt-initfini.s $(libpthread_pthread_OUT)/defs.h - $(do_sed) -n -e '/[ ]*\.file/d' \ - -e '1,/@HEADER_ENDS/p' \ - -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \ - -e '/@TRAILER_BEGINS/,$$p' $< > $@.tmp - $(Q)mv $@.tmp $@ -endif objclean-y += CLEAN_libpthread/nptl/sysdeps/pthread diff --git a/libpthread/nptl/sysdeps/pthread/bits/libc-lock.h b/libpthread/nptl/sysdeps/pthread/bits/libc-lock.h index 633021ab1..a4c5b626b 100644 --- a/libpthread/nptl/sysdeps/pthread/bits/libc-lock.h +++ b/libpthread/nptl/sysdeps/pthread/bits/libc-lock.h @@ -34,7 +34,6 @@ #ifdef _LIBC # include # include -# include #endif /* Mutex type. */ @@ -152,20 +151,11 @@ typedef pthread_key_t __libc_key_t; (FUNC != NULL ? FUNC ARGS : ELSE) #endif -/* Call thread functions through the function pointer table. */ -#if defined SHARED && !defined NOT_IN_libc -# 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) \ - PTHFCT_CALL (ptr_##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 /* Initialize the named lock variable, leaving it in a consistent, unlocked diff --git a/libpthread/nptl/sysdeps/pthread/pt-initfini.c b/libpthread/nptl/sysdeps/pthread/pt-initfini.c deleted file mode 100644 index d9881c7a8..000000000 --- a/libpthread/nptl/sysdeps/pthread/pt-initfini.c +++ /dev/null @@ -1,128 +0,0 @@ -/* Special .init and .fini section support. Linuxthread version. - Copyright (C) 1995,1996,1997,2000,2001,2002 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 of the License, or (at your option) any later version. - - In addition to the permissions in the GNU Lesser General Public - License, the Free Software Foundation gives you unlimited - permission to link the compiled version of this file with other - programs, and to distribute those programs without any restriction - coming from the use of this file. (The Library General Public - License restrictions do apply in other respects; for example, they - cover modification of the file, and distribution when not linked - into another program.) - - 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; see the file COPYING.LIB. If not, - see . */ - -/* This file is compiled into assembly code which is then munged by a sed - script into two files: crti.s and crtn.s. - - * crti.s puts a function prologue at the beginning of the - .init and .fini sections and defines global symbols for - those addresses, so they can be called as functions. - - * crtn.s puts the corresponding function epilogues - in the .init and .fini sections. */ - -#include - -/* We use embedded asm for .section unconditionally, as this makes it - easier to insert the necessary directives into crtn.S. */ -#define SECTION(x) __asm__ (".section " x ) - -/* Embed an #include to pull in the alignment and .end directives. */ -__asm__ ("\n#include \"defs.h\""); -__asm__ ("\n#if defined __i686 && defined __ASSEMBLER__"); -__asm__ ("\n#undef __i686"); -__asm__ ("\n#define __i686 __i686"); -__asm__ ("\n#endif"); - -/* The initial common code ends here. */ -__asm__ ("\n/*@HEADER_ENDS*/"); - -/* To determine whether we need .end and .align: */ -__asm__ ("\n/*@TESTS_BEGIN*/"); -extern void dummy (void (*foo) (void)); -void -dummy (void (*foo) (void)) -{ - if (foo) - (*foo) (); -} -__asm__ ("\n/*@TESTS_END*/"); - -/* The beginning of _init: */ -__asm__ ("\n/*@_init_PROLOG_BEGINS*/"); - -static void -call_initialize_minimal (void) -{ - extern void __pthread_initialize_minimal_internal (void) - __attribute ((visibility ("hidden"))); - - __pthread_initialize_minimal_internal (); -} - -SECTION (".init"); -extern void __attribute__ ((section (".init"))) _init (void); -void -_init (void) -{ - /* The very first thing we must do is to set up the registers. */ - call_initialize_minimal (); - - __asm__ ("ALIGN"); - __asm__("END_INIT"); - /* Now the epilog. */ - __asm__ ("\n/*@_init_PROLOG_ENDS*/"); - __asm__ ("\n/*@_init_EPILOG_BEGINS*/"); - SECTION(".init"); -} -__asm__ ("END_INIT"); - -/* End of the _init epilog, beginning of the _fini prolog. */ -__asm__ ("\n/*@_init_EPILOG_ENDS*/"); -__asm__ ("\n/*@_fini_PROLOG_BEGINS*/"); - -SECTION (".fini"); -extern void __attribute__ ((section (".fini"))) _fini (void); -void -_fini (void) -{ - - /* End of the _fini prolog. */ - __asm__ ("ALIGN"); - __asm__ ("END_FINI"); - __asm__ ("\n/*@_fini_PROLOG_ENDS*/"); - - { - /* Let GCC know that _fini is not a leaf function by having a dummy - function call here. We arrange for this call to be omitted from - either crt file. */ - extern void i_am_not_a_leaf (void); - i_am_not_a_leaf (); - } - - /* Beginning of the _fini epilog. */ - __asm__ ("\n/*@_fini_EPILOG_BEGINS*/"); - SECTION (".fini"); -} -__asm__ ("END_FINI"); - -/* End of the _fini epilog. Any further generated assembly (e.g. .ident) - is shared between both crt files. */ -__asm__ ("\n/*@_fini_EPILOG_ENDS*/"); -__asm__ ("\n/*@TRAILER_BEGINS*/"); - -/* End of file. */ diff --git a/libpthread/nptl/sysdeps/pthread/pt-sigaction.c b/libpthread/nptl/sysdeps/pthread/pt-sigaction.c index 43a2da213..d8fa4c94f 100644 --- a/libpthread/nptl/sysdeps/pthread/pt-sigaction.c +++ b/libpthread/nptl/sysdeps/pthread/pt-sigaction.c @@ -22,9 +22,10 @@ /* We use the libc implementation but we tell it to not allow SIGCANCEL or SIGTIMER to be handled. */ +libc_hidden_proto(sigaction) extern __typeof(sigaction) __libc_sigaction; int -__sigaction (int sig, const struct sigaction *act, struct sigaction *oact) +sigaction (int sig, const struct sigaction *act, struct sigaction *oact) { if (unlikely (sig == SIGCANCEL || sig == SIGSETXID)) { @@ -34,6 +35,4 @@ __sigaction (int sig, const struct sigaction *act, struct sigaction *oact) return __libc_sigaction (sig, act, oact); } -libc_hidden_proto(sigaction) -weak_alias (__sigaction, sigaction) -libc_hidden_weak(sigaction) +libc_hidden_def(sigaction) diff --git a/libpthread/nptl/sysdeps/pthread/pthread-functions.h b/libpthread/nptl/sysdeps/pthread/pthread-functions.h deleted file mode 100644 index 9c78180c5..000000000 --- a/libpthread/nptl/sysdeps/pthread/pthread-functions.h +++ /dev/null @@ -1,108 +0,0 @@ -/* Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2003. - - 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 - . */ - -#ifndef _PTHREAD_FUNCTIONS_H -#define _PTHREAD_FUNCTIONS_H 1 - -#include -#include -#include -#include - -struct xid_command; - -/* Data type shared with libc. The libc uses it to pass on calls to - the thread functions. */ -struct pthread_functions -{ - int (*ptr_pthread_attr_destroy) (pthread_attr_t *); - int (*ptr___pthread_attr_init_2_0) (pthread_attr_t *); - int (*ptr___pthread_attr_init_2_1) (pthread_attr_t *); - int (*ptr_pthread_attr_getdetachstate) (const pthread_attr_t *, int *); - int (*ptr_pthread_attr_setdetachstate) (pthread_attr_t *, int); - int (*ptr_pthread_attr_getinheritsched) (const pthread_attr_t *, int *); - int (*ptr_pthread_attr_setinheritsched) (pthread_attr_t *, int); - int (*ptr_pthread_attr_getschedparam) (const pthread_attr_t *, - struct sched_param *); - int (*ptr_pthread_attr_setschedparam) (pthread_attr_t *, - const struct sched_param *); - int (*ptr_pthread_attr_getschedpolicy) (const pthread_attr_t *, int *); - int (*ptr_pthread_attr_setschedpolicy) (pthread_attr_t *, int); - int (*ptr_pthread_attr_getscope) (const pthread_attr_t *, int *); - int (*ptr_pthread_attr_setscope) (pthread_attr_t *, int); - int (*ptr_pthread_condattr_destroy) (pthread_condattr_t *); - int (*ptr_pthread_condattr_init) (pthread_condattr_t *); - int (*ptr___pthread_cond_broadcast) (pthread_cond_t *); - int (*ptr___pthread_cond_destroy) (pthread_cond_t *); - int (*ptr___pthread_cond_init) (pthread_cond_t *, - const pthread_condattr_t *); - int (*ptr___pthread_cond_signal) (pthread_cond_t *); - int (*ptr___pthread_cond_wait) (pthread_cond_t *, pthread_mutex_t *); - int (*ptr___pthread_cond_timedwait) (pthread_cond_t *, pthread_mutex_t *, - const struct timespec *); - int (*ptr___pthread_cond_broadcast_2_0) (pthread_cond_2_0_t *); - int (*ptr___pthread_cond_destroy_2_0) (pthread_cond_2_0_t *); - int (*ptr___pthread_cond_init_2_0) (pthread_cond_2_0_t *, - const pthread_condattr_t *); - int (*ptr___pthread_cond_signal_2_0) (pthread_cond_2_0_t *); - int (*ptr___pthread_cond_wait_2_0) (pthread_cond_2_0_t *, pthread_mutex_t *); - int (*ptr___pthread_cond_timedwait_2_0) (pthread_cond_2_0_t *, - pthread_mutex_t *, - const struct timespec *); - int (*ptr_pthread_equal) (pthread_t, pthread_t); - void (*ptr___pthread_exit) (void *); - int (*ptr_pthread_getschedparam) (pthread_t, int *, struct sched_param *); - int (*ptr_pthread_setschedparam) (pthread_t, int, - const struct sched_param *); - int (*ptr_pthread_mutex_destroy) (pthread_mutex_t *); - int (*ptr_pthread_mutex_init) (pthread_mutex_t *, - const pthread_mutexattr_t *); - int (*ptr_pthread_mutex_lock) (pthread_mutex_t *); - int (*ptr_pthread_mutex_unlock) (pthread_mutex_t *); - pthread_t (*ptr_pthread_self) (void); - int (*ptr_pthread_setcancelstate) (int, int *); - int (*ptr_pthread_setcanceltype) (int, int *); - void (*ptr___pthread_cleanup_upto) (__jmp_buf, char *); - int (*ptr___pthread_once) (pthread_once_t *, void (*) (void)); - int (*ptr___pthread_rwlock_rdlock) (pthread_rwlock_t *); - int (*ptr___pthread_rwlock_wrlock) (pthread_rwlock_t *); - int (*ptr___pthread_rwlock_unlock) (pthread_rwlock_t *); - int (*ptr___pthread_key_create) (pthread_key_t *, void (*) (void *)); - void *(*ptr___pthread_getspecific) (pthread_key_t); - int (*ptr___pthread_setspecific) (pthread_key_t, const void *); - void (*ptr__pthread_cleanup_push_defer) (struct _pthread_cleanup_buffer *, - void (*) (void *), void *); - void (*ptr__pthread_cleanup_pop_restore) (struct _pthread_cleanup_buffer *, - int); -#define HAVE_PTR_NTHREADS - unsigned int *ptr_nthreads; - void (*ptr___pthread_unwind) (__pthread_unwind_buf_t *) - __attribute ((noreturn)) __cleanup_fct_attribute; - void (*ptr__nptl_deallocate_tsd) (void); - int (*ptr__nptl_setxid) (struct xid_command *); - void (*ptr_freeres) (void); -}; - -/* Variable in libc.so. */ -extern struct pthread_functions __libc_pthread_functions attribute_hidden; -extern int __libc_pthread_functions_init attribute_hidden; - -# define PTHFCT_CALL(fct, params) \ - __libc_pthread_functions.fct params - -#endif /* pthread-functions.h */ diff --git a/libpthread/nptl/sysdeps/pthread/setxid.h b/libpthread/nptl/sysdeps/pthread/setxid.h index 9331649e4..c2763cd68 100644 --- a/libpthread/nptl/sysdeps/pthread/setxid.h +++ b/libpthread/nptl/sysdeps/pthread/setxid.h @@ -32,15 +32,11 @@ # define INLINE_SETXID_SYSCALL(name, nr, args...) \ ({ \ int __result; \ - if (__builtin_expect (__libc_pthread_functions_init, 0)) \ - { \ struct xid_command __cmd; \ __cmd.syscall_no = __NR_##name; \ __SETXID_##nr (__cmd, args); \ - __result = PTHFCT_CALL (ptr__nptl_setxid, (&__cmd)); \ + __result = PTHFCT_CALL (__nptl_setxid, (&__cmd)); \ } \ - else \ - __result = INLINE_SYSCALL (name, nr, args); \ __result; \ }) #else diff --git a/libpthread/nptl/sysdeps/pthread/uClibc-glue.h b/libpthread/nptl/sysdeps/pthread/uClibc-glue.h index b957dedc9..46f8f878c 100644 --- a/libpthread/nptl/sysdeps/pthread/uClibc-glue.h +++ b/libpthread/nptl/sysdeps/pthread/uClibc-glue.h @@ -26,7 +26,6 @@ #define __read read #define __close close #define __on_exit on_exit -#define __libc_current_sigrtmin_private __libc_current_sigrtmin #define __clone clone extern void *__libc_stack_end; -- cgit v1.2.3