aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2021-05-16Enable support for GCC 11 -Wmismatched-dealloc.Martin Sebor13-41/+308
To help detect common kinds of memory (and other resource) management bugs, GCC 11 adds support for the detection of mismatched calls to allocation and deallocation functions. At each call site to a known deallocation function GCC checks the set of allocation functions the former can be paired with and, if the two don't match, issues a -Wmismatched-dealloc warning (something similar happens in C++ for mismatched calls to new and delete). GCC also uses the same mechanism to detect attempts to deallocate objects not allocated by any allocation function (or pointers past the first byte into allocated objects) by -Wfree-nonheap-object. This support is enabled for built-in functions like malloc and free. To extend it beyond those, GCC extends attribute malloc to designate a deallocation function to which pointers returned from the allocation function may be passed to deallocate the allocated objects. Another, optional argument designates the positional argument to which the pointer must be passed. This change is the first step in enabling this extended support for Glibc.
2021-05-14nptl: Fix tst-pthread-gdb-attach for ptrace_scope equal 1Adhemerval Zanella1-17/+39
This is similar to the fix for elf/tst-pldd (2f9046fb059e94fe25): it checks ptrace_scope value (values higher than 2 are too restrictive to allow the test to run) and it rearranges the spawned processes to make the target process the gdb child. Checked on x86_64-linux-gnu with ptrace_scope set to 1.
2021-05-14stdlib: Fix data race in __run_exit_handlers [BZ #27749]Vitaly Buka3-17/+133
Keep __exit_funcs_lock almost all the time and unlock it only to execute callbacks. This fixed two issues. 1. f->func.cxa was modified outside the lock with rare data race like: thread 0: __run_exit_handlers unlock __exit_funcs_lock thread 1: __internal_atexit locks __exit_funcs_lock thread 0: f->flavor = ef_free; thread 1: sees ef_free and use it as new thread 1: new->func.cxa.fn = (void (*) (void *, int)) func; thread 1: new->func.cxa.arg = arg; thread 1: new->flavor = ef_cxa; thread 0: cxafct = f->func.cxa.fn; // it's wrong fn! thread 0: cxafct (f->func.cxa.arg, status); // it's wrong arg! thread 0: goto restart; thread 0: call the same exit_function again as it's ef_cxa 2. Don't unlock in main while loop after *listp = cur->next. If *listp is NULL and __exit_funcs_done is false another thread may fail in __new_exitfn on assert (l != NULL): thread 0: *listp = cur->next; // It can be the last: *listp = NULL. thread 0: __libc_lock_unlock thread 1: __libc_lock_lock in __on_exit thread 1: __new_exitfn thread 1: if (__exit_funcs_done) // false: thread 0 isn't there yet. thread 1: l = *listp thread 1: moves one and crashes on assert (l != NULL); The test needs multiple iterations to consistently fail without the fix. Fixes https://sourceware.org/bugzilla/show_bug.cgi?id=27749 Checked on x86_64-linux-gnu. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-13Make sysdeps/generic/libc.abilist emptyJoseph Myers1-1/+0
The __libc_single_threaded symbol was accidentally added to this file in commit 706ad1e7af37be1d25fc2359bda006d31fe0d11b.
2021-05-13support: Free gdb_script_nameSiddhesh Poyarekar1-0/+1
Identified by static analysis.
2021-05-13support: Close fds in copy_funcSiddhesh Poyarekar1-8/+13
copy_func may leave file descriptors open on error, so close them on function exit.
2021-05-13inet: Free result from getaddrinfoSiddhesh Poyarekar2-8/+9
Coverity discovered paths where the result from getaddrinfo was not freed.
2021-05-12linux/check_native: Always close socket on returnSiddhesh Poyarekar1-12/+11
The error paths of __check_native would leave the socket FD open on return, resulting in an FD leak. Rework function exit paths so that the fd is always closed on return.
2021-05-12Remove all usage of @BASH@ or ${BASH} in installed files, and hardcode ↵Romain GEISSLER8-15/+10
/bin/bash instead (FYI, this is a repost of https://sourceware.org/pipermail/libc-alpha/2019-July/105035.html now that FSF papers have been signed and confirmed on FSF side). This trivial patch attemps to fix BZ 24106. Basically the bash locally used when building glibc on the host shall not leak on the installed glibc, as the system where it is installed might be different and use another bash location. So I have looked for all occurences of @BASH@ or $(BASH) in installed files, and replaced it by /bin/bash. This was suggested by Florian Weimer in the bug report. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2021-05-11nptl: Move pthread_getconcurrency, pthread_setconcurrency into libcFlorian Weimer65-66/+152
The symbols were moved using scripts/move-symbol-to-libc.py, in one commit due to their dependency on the internal __concurrency_level variable. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move pthread_cancel into libcFlorian Weimer65-33/+72
The symbol was moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move __pthread_register_cancel_defer, ↵Florian Weimer64-64/+149
__pthread_unregister_cancel_restore to libc The symbols were moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move __pthread_register_cancel, __pthread_unregister_cancel to libcFlorian Weimer65-77/+154
The symbols were moved using scripts/move-symbol-to-libc.py. Also clean up some unwinder linking leftover in the same spot in nptl/pthreadP.h. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move pthread_attr_setstacksize into libcFlorian Weimer68-56/+125
The symbol was moved using scripts/move-symbol-to-libc.py. It is necessary to arrange for a __libpthread_version_placeholder@GLIBC_2.6 on some of the powerpc targets. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move pthread_attr_setstackaddr into libcFlorian Weimer64-33/+74
The symbol was moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move pthread_attr_setstack into libcFlorian Weimer64-52/+96
The symbol was moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move pthread_attr_setguardsize into libcFlorian Weimer64-33/+75
The symbol was moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move pthread_attr_getstacksize into libcFlorian Weimer64-33/+74
The symbol was moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move pthread_attr_getstackaddr into libcFlorian Weimer64-33/+74
The symbol was moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move pthread_attr_getstack into libcFlorian Weimer64-33/+74
The symbol was moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move pthread_attr_getguardsize into libcFlorian Weimer64-33/+75
The symbol was moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move pthread_attr_getaffinity_np into libcFlorian Weimer64-50/+93
The symbol was moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11elf: Fix DTV gap reuse logic [BZ #27135]Szabolcs Nagy3-15/+6
For some reason only dlopen failure caused dtv gaps to be reused. It is possible that the intent was to never reuse modids for a different module, but after dlopen failure all gaps are reused not just the ones caused by the unfinished dlopened. So the code has to handle reused modids already which seems to work, however the data races at thread creation and tls access (see bug 19329 and bug 27111) may be more severe if slots are reused so this is scheduled after those fixes. I think fixing the races are not simpler if reuse is disallowed and reuse has other benefits, so set GL(dl_tls_dtv_gaps) whenever entries are removed from the middle of the slotinfo list. The value does not have to be correct: incorrect true value causes the next modid query to do a slotinfo walk, incorrect false will leave gaps and new entries are added at the end. Fixes bug 27135. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11elf: Add test case for [BZ #19329]Szabolcs Nagy3-2/+76
Test concurrent dlopen and pthread_create when the loaded modules have TLS. This triggers dl-tls assertion failures more reliably than the nptl/tst-stack4 test. The dlopened module has 100 DT_NEEDED dependencies with TLS, they were reused from an existing TLS test. The number of created threads during dlopen depends on filesystem speed and hardware, but at most 3 threads are alive at a time to limit resource usage. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11elf: Use relaxed atomics for racy accesses [BZ #19329]Szabolcs Nagy4-17/+42
This is a follow up patch to the fix for bug 19329. This adds relaxed MO atomics to accesses that were previously data races but are now race conditions, and where relaxed MO is sufficient. The race conditions all follow the pattern that the write is behind the dlopen lock, but a read can happen concurrently (e.g. during tls access) without holding the lock. For slotinfo entries the read value only matters if it reads from a synchronized write in dlopen or dlclose, otherwise the related dtv entry is not valid to access so it is fine to leave it in an inconsistent state. The same applies for GL(dl_tls_max_dtv_idx) and GL(dl_tls_generation), but there the algorithm relies on the fact that the read of the last synchronized write is an increasing value. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11elf: Fix data races in pthread_create and TLS access [BZ #19329]Szabolcs Nagy1-16/+47
DTV setup at thread creation (_dl_allocate_tls_init) is changed to take the dlopen lock, GL(dl_load_lock). Avoiding data races here without locks would require design changes: the map that is accessed for static TLS initialization here may be concurrently freed by dlclose. That use after free may be solved by only locking around static TLS setup or by ensuring dlclose does not free modules with static TLS, however currently every link map with TLS has to be accessed at least to see if it needs static TLS. And even if that's solved, still a lot of atomics would be needed to synchronize DTV related globals without a lock. So fix both bug 19329 and bug 27111 with a lock that prevents DTV setup running concurrently with dlopen or dlclose. _dl_update_slotinfo at TLS access still does not use any locks so CONCURRENCY NOTES are added to explain the synchronization. The early exit from the slotinfo walk when max_modid is reached is not strictly necessary, but does not hurt either. An incorrect acquire load was removed from _dl_resize_dtv: it did not synchronize with any release store or fence and synchronization is now handled separately at thread creation and TLS access time. There are still a number of racy read accesses to globals that will be changed to relaxed MO atomics in a followup patch. This should not introduce regressions compared to existing behaviour and avoid cluttering the main part of the fix. Not all TLS access related data races got fixed here: there are additional races at lazy tlsdesc relocations see bug 27137. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11write_archive_locales: Fix memory leakSiddhesh Poyarekar1-0/+2
Fix memory leak identified by coverity.
2021-05-11nptl: Move thread join functions into libcFlorian Weimer71-178/+436
The symbols pthread_clockjoin_np, pthread_join, pthread_timedjoin_np, pthread_tryjoin_np, thrd_join were moved using scripts/move-symbol-to-libc.py. Moving the symbols at the same time avoids the need for temporary exports. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move pthread_detach, thrd_detach into libcFlorian Weimer67-66/+157
The symbols were moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move __free_tcb into libcFlorian Weimer7-29/+52
Under the name __nptl_free_tcb. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move stack cache management, __libpthread_freeres into libcFlorian Weimer10-158/+212
This replaces the FREE_P macro with the __nptl_stack_in_use inline function. stack_list_del is renamed to __nptl_stack_list_del, stack_list_add to __nptl_stack_list_add, __deallocate_stack to __nptl_deallocate_stack, free_stacks to __nptl_free_stacks. It is convenient to move __libpthread_freeres into libc at the same time. This removes the temporary __default_pthread_attr_freeres export and restores full freeres coverage for __default_pthread_attr. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Move pthread_setattr_default_np into libcFlorian Weimer65-35/+80
The symbol was moved using scripts/move-symbol-to-libc.py. The export of __default_pthread_attr_freeres is temporary. There is a minor regression in freeres coverage because in the dynamic case, __default_pthread_attr_freeres is no longer called if libpthread is not linked in. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Remove always-disabled debugging supportFlorian Weimer3-75/+5
This removes the DEBUGGING_P macro and the __pthread_debug variable. The __find_in_stack_list function is now unused and deleted as well. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11nptl: Replace pthread_sigqueue implementation with Linux oneFlorian Weimer2-75/+38
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2021-05-11get-translit.py: Fix typoSiddhesh Poyarekar1-1/+1
2021-05-11_dl_exception_create_format: Add missing va_endSiddhesh Poyarekar1-0/+1
Coverity discovered a missing va_end.
2021-05-10linux: Move funlockfile/_IO_funlockfile into libcAdhemerval Zanella32-92/+3
The nptl version is used as default, since now with symbol always present the single-thread optimization is tricky. Hurd is not change, it is used it own lock scheme (which call _cthreads_funlockfile). Checked on x86_64-linux-gnu.
2021-05-10linux: Move ftrylockfile/_IO_ftrylockfile into libcAdhemerval Zanella32-94/+3
The nptl version is used as default, since now with symbol always present the single-thread optimization is tricky. Hurd is not change, it is used it own lock scheme (which call _cthreads_ftrylockfile). Checked on x86_64-linux-gnu.
2021-05-10linux: Move flockfile/_IO_flockfile into libcAdhemerval Zanella32-94/+3
The nptl version is used as default, since now with symbol always present the single-thread optimization is tricky. Hurd is not change, it is used it own lock scheme (which call _cthreads_flockfile). Checked on x86_64-linux-gnu.
2021-05-10Use a #pragma to suppress a bogus GCC 10 warning instead of an assert [BZ ↵Martin Sebor1-1/+11
27832]. Reviewed-by: fweimer@redhat.com
2021-05-10Add PTRACE_SYSEMU and PT_SYSEMU_SINGLESTEP from Linux 5.12 for s390Joseph Myers1-0/+10
Linux 5.12 adds the constants PTRACE_SYSEMU and PTRACE_SYSEMU_SINGLESTEP for s390. Add these to glibc. Tested with build-many-glibcs.py for s390-linux-gnu and s390x-linux-gnu.
2021-05-10add workload traces for cbrtlPaul Zimmermann3-0/+1011
These workload traces cover the whole "long double" range. This patch was prepared with the help of Adhemerval Zanella. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-05-10Linux: Move __reclaim_stacks into the fork implementation in libcFlorian Weimer5-119/+110
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 __default_pthread_attr, __default_pthread_attr_lock into libcFlorian Weimer4-6/+14
The GLIBC_PRIVATE exports for these symbols are expected to be temporary. Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-05-10nptl: Simplify resetting the in-flight stack in __reclaim_stacksFlorian Weimer1-3/+3
stack_list_del overwrites the in-flight stack variable. 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 Weimer9-83/+100
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: Simplify the change_stack_perm calling conventionFlorian Weimer1-24/+5
Only ia64 needs the page mask, and it is straightforward to compute the value within the function itself. Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-05-10nptl: Move more stack management variables into _rtld_globalFlorian Weimer4-30/+36
Permissions of the cached stacks may have to be updated if an object is loaded that requires executable stacks, so the dynamic loader needs to know about these cached stacks. The move of in_flight_stack and stack_cache_actsize is a requirement for merging __reclaim_stacks into the fork implementation in libc. Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-05-10elf: Introduce __tls_pre_init_tpFlorian Weimer6-40/+60
This is an early variant of __tls_init_tp, primarily for initializing thread-related elements of _rtld_global/GL. Some existing initialization code not needed for NPTL is moved into the generic version of this function. Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-05-10nptl: Eliminate __pthread_multiple_threadsFlorian Weimer4-17/+3
It is no longer needed after the SINGLE_THREADED_P consolidation. Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>