aboutsummaryrefslogtreecommitdiff
path: root/nptl/nptl-init.c
AgeCommit message (Collapse)Author
2021-05-21nptl: Remove remaining code from libpthreadFlorian Weimer
Only the placeholder compatibility symbols are left now. The __errno_location symbol was removed (moved) using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-21nptl: Move semi-public __pthread_get_minstack symbol into libcFlorian Weimer
No abilist updates here because it is a GLIBC_PRIVATE symbol. It's also necessary to move nptl_version into pthread_create, so that it still ends up in static binaries. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-21nptl: Eliminate the __static_tls_size, __static_tls_align_m1 variablesFlorian Weimer
Use the __nptl_tls_static_size_for_stack inline function instead, and the GLRO (dl_tls_static_align) value directly. The computation of GLRO (dl_tls_static_align) in _dl_determine_tlsoffset ensures that the alignment is at least TLS_TCB_ALIGN, which at least STACK_ALIGN (see allocate_stack). Therefore, the additional rounding-up step is removed. ALso move the initialization of the default stack size from __pthread_initialize_minimal_internal to __pthread_early_init. This introduces an extra system call during single-threaded startup, but this simplifies the initialization sequence. No locking is needed around the writes to __default_pthread_attr because the process is single-threaded at this point. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-21nptl: Perform signal initialization upon pthread_createFlorian Weimer
Install signal handlers and unblock signals before pthread_create creates the first thread. create_thread in sysdeps/unix/sysv/linux/createthread.c can send SIGCANCEL to the current thread, so the SIGCANCEL handler is currently needed even if pthread_cancel is never called. (The way timer_create uses SIGCANCEL does not need a signal handler; both SIG_DFL and SIG_IGN dispositions should work.) Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-17nptl: Move __nptl_initial_report_events into ld.so/startup codeFlorian Weimer
The initialization of the report_events TCB field is now performed in __tls_init_tp instead of __pthread_initialize_minimal_internal (in libpthread). The events interface is difficult to test because GDB stopped using it in 2015. The td_thr_get_info change to ignore lookup issues is enough to support GDB with this change. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-10Linux: Move __reclaim_stacks into the fork implementation in libcFlorian Weimer
As a result, __libc_pthread_init is no longer needed. Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-05-10nptl: Move changing of stack permissions into ld.soFlorian Weimer
All the stack lists are now in _rtld_global, so it is possible to change stack permissions directly from there, instead of calling into libpthread to do the change. Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-05-10nptl: Export __libc_multiple_threads from libc as an internal symbolFlorian Weimer
This allows the elimination of the __libc_multiple_threads_ptr variable in libpthread and its initialization procedure. Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-05-10elf, nptl: Resolve recursive lock implementation earlyFlorian Weimer
If libpthread is included in libc, it is not necessary to delay initialization of the lock/unlock function pointers until libpthread is loaded. This eliminates two unprotected function pointers from _rtld_global and removes some initialization code from libpthread. Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-05-05elf, nptl: Initialize static TLS directly in ld.soFlorian Weimer
The stack list is available in ld.so since commit 1daccf403b1bd86370eb94edca794dc106d02039 ("nptl: Move stack list variables into _rtld_global"), so it's possible to walk the stack list directly in ld.so and perform the initialization there. This eliminates an unprotected function pointer from _rtld_global and reduces the libpthread initialization code.
2021-04-21nptl: Remove remnants of the libc/libpthread forwarder interfaceFlorian Weimer
All previously forwarded functions are now implemented in libc. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-04-21nptl: Move setxid broadcast implementation into libcFlorian Weimer
The signal handler is exported as __nptl_setxid_sighandler, so that the libpthread initialization code can install it. This is sufficient for now because it is guarantueed to happen before the first pthread_create call.
2021-04-21nptl: Move core condition variable functions into libcFlorian Weimer
Onl pthread_cond_clockwait did not have a forwarder, so it needs a new symbol version. Some complications arise due to the need to supply hidden aliases, GLIBC_PRIVATE exports (for the C11 condition variable implementation that still remains in libpthread) and 64-bit time_t stubs. pthread_cond_broadcast, pthread_cond_signal, pthread_cond_timedwait, pthread_cond_wait, pthread_cond_clockwait have been moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-04-21nptl: Move core mutex functions into libcFlorian Weimer
This is complicated because of a second compilation of nptl/pthread_mutex_lock.c via nptl/pthread_mutex_cond_lock.c. PTHREAD_MUTEX_VERSIONS is introduced to suppress symbol versions in that case. The symbols __pthread_mutex_lock, __pthread_mutex_unlock, __pthread_mutex_init, __pthread_mutex_destroy, pthread_mutex_lock, pthread_mutex_unlock, pthread_mutex_init, pthread_mutex_destroy have been moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-04-21nptl: Move internal symbol __mutex_aconf into libcFlorian Weimer
This is in preparation of moving the mutex code into libc. __pthread_tunables_init is now called via __pthread_early_init. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-04-21nptl: Move rwlock functions with forwarders into libcFlorian Weimer
The forwarders were only used internally, so new symbol versions are needed. All symbols are moved at once because the forwarders are no-ops if libpthread is not loaded, leading to inconsistencies in case of a partial migration. The symbols __pthread_rwlock_rdlock, __pthread_rwlock_unlock, __pthread_rwlock_wrlock, pthread_rwlock_rdlock, pthread_rwlock_unlock, pthread_rwlock_wrlock have been moved using scripts/move-symbol-to-libc.py. The __ symbol variants are turned into compat symbols, which is why they do not receive a GLIBC_2.34 version.
2021-04-21nptl: Move pthread_setspecific, __pthread_setspecific into libcFlorian Weimer
The symbols have been moved using scripts/move-symbol-to-libc.py.
2021-04-21nptl: Move pthread_getspecific, __pthread_getspecific into libcFlorian Weimer
The symbols have been moved using scripts/move-symbol-to-libc.py.
2021-04-21nptl: Move pthread_key_create, __pthread_key_create into libcFlorian Weimer
The symbols have been moved using scripts/move-symbol-to-libc.py.
2021-04-21nptl: Move part of TCB initialization from libpthread to __tls_init_tpFlorian Weimer
This initalization should only happen once for the main thread's TCB. At present, auditors can achieve this by not linking against libpthread. If libpthread becomes part of libc, doing this initialization in libc would happen for every audit namespace, or too late (if it happens from the main libc only). That's why moving this code into ld.so seems the right thing to do, right after the TCB initialization. For !__ASSUME_SET_ROBUST_LIST ports, this also moves the symbol __set_robust_list_avail into ld.so, as __nptl_set_robust_list_avail. It also turned into a proper boolean flag. Inline the __pthread_initialize_pids function because it seems no longer useful as a separate function. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-04-21nptl: Invoke the set_robust_list system call directly in forkFlorian Weimer
This removes one of the pthread forwarder functions. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-04-21nptl: Move pthread_setcanceltype into libcFlorian Weimer
No new symbol version is required because there was a forwarder. The symbol has been moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-04-21nptl: Move pthread_setcancelstate into libcFlorian Weimer
No new symbol version is required because there was a forwarder. The symbol has been moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-04-21nptl: Move pthread_exit into libcFlorian Weimer
The pthread_exit symbol was moved using scripts/move-symbol-to-libc.py. No new symbol version is needed because there was a forwarder. The new tests nptl/tst-pthread_exit-nothreads and nptl/tst-pthread_exit-nothreads-static exercise the scenario that pthread_exit is called without libpthread having been linked in. This is not possible for the generic code, so these tests do not live in sysdeps/pthread for now. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-04-21nptl: Move __nptl_deallocate_tsd into libcFlorian Weimer
This prepares moving pthread_exit, and later the pthread_key_create infrastructure. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-04-21nptl: Move internal __nptl_nthreads variable into libcFlorian Weimer
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-04-21nptl: Move __pthread_unwind_next into libcFlorian Weimer
It's necessary to stub out __libc_disable_asynccancel and __libc_enable_asynccancel via rtld-stubbed-symbols because the new direct references to the unwinder result in symbol conflicts when the rtld exception handling from libc is linked in during the construction of librtld.map. unwind-forcedunwind.c is merged into unwind-resume.c. libc now needs the functions that were previously only used in libpthread. The GLIBC_PRIVATE exports of __libc_longjmp and __libc_siglongjmp are no longer needed, so switch them to hidden symbols. The symbol __pthread_unwind_next has been moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerva Zanella <adhemerval.zanella@linaro.org>
2021-04-21nptl: Move pthread_once and __pthread_once into libcFlorian Weimer
And also the fork generation counter, __fork_generation. This eliminates the need for __fork_generation_pointer. call_once remains in libpthread and calls the exported __pthread_once symbol. pthread_once and __pthread_once have been moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-04-21nptl: Move __pthread_cleanup_upto into libcFlorian Weimer
This internal symbol is used as part of the longjmp implementation. Rename the file from nptl/pt-cleanup.c to nptl/pthread_cleanup_upto.c so that the pt-* files remain restricted to libpthread. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-04-21nptl: Move legacy unwinding implementation into libcFlorian Weimer
It is still used internally. Since unwinding is now available unconditionally, avoid indirect calls through function pointers loaded from the stack by inlining the non-cancellation cleanup code. This avoids a regression in security hardening. The out-of-line __libc_cleanup_routine implementation is no longer needed because the inline definition is now static __always_inline. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-03-29fork.h: replace with register-atfork.hSamuel Thibault
UNREGISTER_ATFORK is now defined for all ports in register-atfork.h, so most previous includes of fork.h actually only need register-atfork.h now, and cxa_finalize.c does not need an ifdef UNREGISTER_ATFORK any more. The nptl-specific fork generation counters can then go to pthreadP.h, and fork.h be removed. Checked on x86_64-linux-gnu and i686-gnu. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-01-02Update copyright dates with scripts/update-copyrightsPaul Eggert
I used these shell commands: ../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright (cd ../glibc && git commit -am"[this commit message]") and then ignored the output, which consisted lines saying "FOO: warning: copyright statement not found" for each of 6694 files FOO. I then removed trailing white space from benchtests/bench-pthread-locks.c and iconvdata/tst-iconv-big5-hkscs-to-2ucs4.c, to work around this diagnostic from Savannah: remote: *** pre-commit check failed ... remote: *** error: lines with trailing whitespace found remote: error: hook declined to update refs/heads/master
2020-11-16nptl: Move stack list variables into _rtld_globalFlorian Weimer
Now __thread_gscope_wait (the function behind THREAD_GSCOPE_WAIT, formerly __wait_lookup_done) can be implemented directly in ld.so, eliminating the unprotected GL (dl_wait_lookup_done) function pointer. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-11-13nptl: Eliminate <smp.h> and __is_smpFlorian Weimer
Most systems are SMP, so optimizing for the UP case is no longer approriate. A dynamic check based on the kernel identification has been only implemented for i386 anyway. To disable adaptive mutexes on sh, define DEFAULT_ADAPTIVE_COUNT as zero for this architecture. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-07-07linux: Fix __NSIG_WORDS and add __NSIG_BYTESAdhemerval Zanella
The __NSIG_WORDS value is based on minimum number of words to hold the maximum number of signals supported by the architecture. This patch also adds __NSIG_BYTES, which is the number of bytes required to represent the supported number of signals. It is used in syscalls which takes a sigset_t. Checked on x86_64-linux-gnu and i686-linux-gnu. Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2020-06-02nptl: Change type of __default_pthread_attrFlorian Weimer
union pthread_attr_transparent has always the correct size, even if pthread_attr_t has padding that is not present in struct pthread_attr. This should not result in an observable behavioral change. The existing code appears to have been correct, but it was brittle because it was not clear which functions were allowed to write to an entire pthread_attr_t argument (e.g., by copying it). Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2020-03-03Linux: set_robust_list syscall number is always availableFlorian Weimer
Due to the built-in tables, __NR_set_robust_list is always defined (although it may not be available at run time). Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-20nptl: Move pthread_setschedparam implementation into libcFlorian Weimer
This is part of the libpthread removal project: <https://sourceware.org/ml/libc-alpha/2019-10/msg00080.html> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-20nptl: Move pthread_getschedparam implementation into libcFlorian Weimer
This is part of the libpthread removal project: <https://sourceware.org/ml/libc-alpha/2019-10/msg00080.html> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-20nptl: Move pthread_cond_init implementation into libcFlorian Weimer
It is necessary to export __pthread_cond_init from libc because the C11 condition variable needs it and is still left in libpthread. This is part of the libpthread removal project: <https://sourceware.org/ml/libc-alpha/2019-10/msg00080.html> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-20nptl: Move pthread_cond_destroy implementation into libcFlorian Weimer
It is necessary to export __pthread_cond_destroy from libc because the C11 condition variable needs it and is still left in libpthread. This is part of the libpthread removal project: <https://sourceware.org/ml/libc-alpha/2019-10/msg00080.html> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-20nptl: Move pthread_condattr_init implementation into libcFlorian Weimer
This is part of the libpthread removal project: <https://sourceware.org/ml/libc-alpha/2019-10/msg00080.html> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-20nptl: Move pthread_condattr_destroy implementation into libcFlorian Weimer
This is part of the libpthread removal project: <https://sourceware.org/ml/libc-alpha/2019-10/msg00080.html> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-20nptl: Move pthread_attr_setscope implementation into libcFlorian Weimer
This is part of the libpthread removal project: <https://sourceware.org/ml/libc-alpha/2019-10/msg00080.html> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-20nptl: Move pthread_attr_getscope implementation into libcFlorian Weimer
This is part of the libpthread removal project: <https://sourceware.org/ml/libc-alpha/2019-10/msg00080.html> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-20nptl: Move pthread_attr_setschedpolicy implementation into libcFlorian Weimer
This is part of the libpthread removal project: <https://sourceware.org/ml/libc-alpha/2019-10/msg00080.html> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-20nptl: Move pthread_attr_getschedpolicy implementation into libcFlorian Weimer
This is part of the libpthread removal project: <https://sourceware.org/ml/libc-alpha/2019-10/msg00080.html> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-14linux: Remove INTERNAL_SYSCALL_DECLAdhemerval Zanella
With all Linux ABIs using the expected Linux kABI to indicate syscalls errors, the INTERNAL_SYSCALL_DECL is an empty declaration on all ports. This patch removes the 'err' argument on INTERNAL_SYSCALL* macro and remove the INTERNAL_SYSCALL_DECL usage. Checked with a build against all affected ABIs.
2020-01-01Update copyright dates with scripts/update-copyrights.Joseph Myers
2019-10-18nptl: SIGCANCEL, SIGTIMER, SIGSETXID are always definedFlorian Weimer
All nptl targets have these signal definitions nowadays. This changes also replaces the nptl-generic version of pthread_sigmask with the Linux version. Tested on x86_64-linux-gnu and i686-linux-gnu. Built with build-many-glibcs.py. Reviewed-by: Carlos O'Donell <carlos@redhat.com>