summaryrefslogtreecommitdiff
path: root/libexec/ld.elf_so/rtld.c
AgeCommit message (Collapse)Author
2023-06-04ld.elf_so: Sprinkle more debug messages on dlopen and error.riastradh
PR pkg/57445
2023-04-23dlopen(3): Read _rtld_objtail under the lock.riastradh
XXX pullup-8 XXX pullup-9 XXX pullup-10
2022-09-13ld.elf_so(8): Make fork take a shared, not exclusive, lock.riastradh
We only need to ensure that there are no concurrent modifications to the rtld data structures in flight, since the threads that began those modifications will not exist in the child and will therefore be unable to complete them in the child. A shared lock suffices to ensure there are no such concurrent modifications in flight; an exclusive lock is not necessary, and can cause deadlock if fork is executed from a signal handler, which is explicitly allowed by POSIX (and our own sigaction(2) man page) which marks fork as async-signal-safe. PR lib/56979
2022-04-09rtld: Convert membar_exit/enter to membar_release/acquire.riastradh
These are basic CAS-based locking primitives needing release and acquire semantics, nothing fancy here -- except the membar_sync parts which are questionable but not relevant to the present audit.
2021-12-04Restore the fptr_t type of {init,fini}{,_array} that was removed when initialskrll
support for indirect functions was added. This fixes {init,fini}_array support on hppa where each member of the array is (already) a plabel. Discussed with joerg. 4 files changed, 29 insertions(+), 39 deletions(-) : ----------------------------------------------------------------------
2021-06-16ld.elf_so(1): Omit needless membar_enter.riastradh
The use of membar_enter is to separate atomic r/m/w on a lock from the body of the critical section so two different critical sections happen in order: body of previous critical section; exit critical section: membar_exit(); atomic_r/m/w(lock stuff); enter critical section: atomic_r/m/w(lock stuff); membar_enter(); body of next critical section; _rtld_shared_enter does this, but it _also_ issued an extraneous membar_enter before the atomic_r/m/w part, which doesn't impose any semantically important order but may cost some performance.
2021-05-30Don't use the return address hack with clang.joerg
2020-09-22Correct r_ldbase valusekamil
It shall be the relocbase value, not linkmap.
2020-09-21Upgrade the SVR4 RTLD r_debug protocol to version 1kamil
Changes: - Add a new field r_ldbase in the r_debug struct. - Set r_version to 1. This harmonizes the support with OpenBSD and Linux. FreeBSD uses version 0 (or no version). Solaris uses version 2 that is not implemented elsewhere and relies on SVR4 specific design and interfaces. Update the code comments as r_debug and link_map is used by other software than GDB, namely: sanitizers, rump, LLDB.
2020-04-19Rename __atomic_fork to __locked_fork and give it &errno as argument.joerg
rtld and libc use different storage, so the initial version would incorrectly report the failure reason for fork(). There is still a small race condition inside ld.elf_so as it doesn't use thread-safe errno internally, but that's a more contained internal issue.
2020-04-16Introduce intermediate locking for fork, so that the dynamic linker isjoerg
in a consistent state. This most importantly avoids races between dlopen and friends and fork, potentially resulting in dead locks in the child when it itself tries to acquire locks.
2020-03-04PT_GNU_RELRO segments are arranged such that their vaddr + memsz endsthorpej
on a linker common page size boundary. However, if the common page size used by the linker is less than the VM page size being used by the kernel, this can end up in the middle of a VM page and when the region is write- protected, this can cause objects in neighboring .data to get incorrectly write-protected, resulting in a crash. Avoid this situation by calculating the end of the RELRO region not by rounding memsz up to the VM page size, but rather by adding vaddr + memsz and then truncating to the VM page size. Fixes PR toolchain/55043. XXX pullup-9
2020-02-29Implement and integrate GNU Hashing functionkamil
Define Elf_Hash struct that contains ELF/SYSV and GNU hash checksum. Implement _rtld_gnu_hash() for DT_GNU_HASH. Adapt existing code to compute all Elf_Hash types, instead of only the ELF/SYSV one. Rename _rtld_elf_hash() to _rtld_sysv_hash() to match the GNU toolchain terminology. _rtld_gnu_hash() uses Dan Bernstein's string hash function posted eons ago on comp.lang.c.
2019-12-08_rtld_relro - fix debug printf format for a size_t argumentuwe
2019-10-04use __func__ (c99, c++11) instead of __FUNCTION__christos
2019-10-03improve error messagetnn
2019-09-15Return the ELF loader dl_phdr_info information for dl_iterate_phdr(3)kamil
Sync the behavior of dl_iterate_phdr(3) with Linux/FreeBSD/OpenBSD.
2019-04-14undo previous unlock/relock; it is not needed now that we added the tls modelchristos
declaration to all externs in jemalloc (suggested by joerg@)
2019-04-13Fix c++ exceptions on arm; jemalloc calls _rtld_tls_get_addr from insidechristos
dl_iterate_phdr, so we need to unlock and relock.
2018-12-30binutils 2.31.1 can put copy relocations in the relro segment. Delaychristos
protecting the relro segment for the main object until copy relocations are done.
2018-12-27explain why we skip objmain.christos
2018-10-17Move compatibility for pre-2.0 ELF binaries into separate file.joerg
Early ELF binaries defined dlopen and friends in crt0.o by using function pointers in the object handle passed from rtld. This contract wastes space when many shared objects are allocated and ties dynamic linker and rest of the system tightly together. Fake the entry points in a static object and restrict them to the platforms that had working ELF support at the time. Keep the magic and version field used by modern crt0.o for all architectures. The checks will be removed from crt0.o in a follow-up step.
2018-04-03Rework ifunc support to address a number of short comings:joerg
- Move to a shared _rtld_call_ifunc for rel and rela architectures - Architectures using rel format must patch IRELATIVE non-PLT relocations like RELATIVE in additition to the later ifunc handling - Consistently record the delta to the end of the relocation group for non-PLT IRELATIVE relocations Hidden ifunc is now supported on all ifunc platforms, even when using -fno-plt. The combination of -fno-plt and relro is broken due to incorrect GNU ld output though.
2018-03-09Like Sparc, PowerPC can use IRELATIVE relocations in non-PLT sections.joerg
2018-02-11Wrap PowerPC #pragma goop in #if __GNUC_PREREQ__(6,0).jakllsch
Our older GCC warns/errors on it.
2018-02-07update for GCC 6:mrg
ignore -Wframe-address warnings for the ppc hack.
2017-11-06init/fini for the main program is handled by crt0.o, so ifunc handlingjoerg
is skipped right now as it iterates the same list. Don't repeat that mistake and explicitly take care of it in the dynamic linker.
2017-08-12Add sparc/sparc64 support for irelative relocations.joerg
2017-08-10Add IRELATIVE support for ARM, X86 and PowerPC.joerg
2017-07-11Implement __cxa_thread_atexit and __cxa_thread_atexit_impl. Thisjoerg
functions are used for destructors of thread_local objects. If a pending destructor exists, prevent unloading of shared objects. Introduce __dl_cxa_refcount interface for this purpose. When the last reference is gone and the object has been dlclose'd before, the unloading is finalized. Ideally, __cxa_thread_atexit_impl wouldn't exist, but libstdc++ insists on providing __cxa_thread_atexit as direct wrapper without further patching.
2017-06-08Call _rtld_debug_state before running the global initialisers, so givejoerg
gdb a chance to set break points etc.
2017-02-27tag the powerpc hackish_return_address() as __noinline.chs
2016-12-01n dl_iterate_phdr return the path not the name.christos
2016-12-01Instead of using a function to resolve symbols that should be supplied bychristos
the dynamic linker itself, use a version script that exposes them. From joerg@
2016-11-30add missing newline in commentchristos
2016-11-30Emulate the standard symbol search order in dlsym() i.e. resolve weak orchristos
not found symbols that are in the dynamic linker list of exported symbols from the dynamic linker itself.
2016-05-24Put the name of the dynamic linker in allocated memory, so that it becomeschristos
part of the core file link-map, so that gdb can find it.
2015-04-06Fix membars around rtld internal mutex.yamt
This fixes the most of lockups i observed with Open vSwitch on NetBSD/amd64. ("most of" because it still occasionally locks up because of other problems. see PR/49816)
2015-04-04lib/49813: Release mutex on error.joerg
2015-03-05HPPA hack for a problem where gdb doesn't see _rtld_debug_state whenskrll
it's a single bv,n %r0(%rp) instruction. The nullify confuses something.
2014-08-25Add basic support for indirect functions. It allows providing a publicjoerg
function symbol with an implementation choosen at run time. Refactor calls to functions by address in ld.elf_so to create temporary function descriptors on the stack, if the address is not leaked outside. Limitations: - no support for initialising static storage with function pointers - no support for unnamed resolver functions Inspired by FreeBSD's r228435 by kib@freebsd.org.
2014-03-18Ignore LD_BIND_NOW for setuid binaries, but keep it in the environmentjoerg
otherwise.
2014-01-31Catch up with _lwp_park change.joerg
2013-11-20If dlopen of the dynamic linker is requested, e.g. by rump inskrll
rumpuser_dl_bootstrap, then return &_rtld_objself as the handle and do not create a duplicate mapping. The handle is mostly useless as _rtld_objself doesn't appear on _rtld_objlist. This fixes a problem on earm platforms where ld.elf_so (currently) has an init_array section. Calling this caused binaries to segv.
2013-10-19fix unused variable warningschristos
2013-05-09Remove redundant assignment. Hasn't been needed since 1999.skrll
2013-05-09remove stray debuggingchristos
2013-05-09convert to SIMPLEQ like the rest of the queues.christos
2013-05-06Fixed handling of DT_SONAME:christos
- add function to add name aliases for shared libraries loaded XXX[1]: we don't add a name during load time, only when DT_SONAME is present. - search already loaded objects in load_by_name for an already loaded object that matches our name and return it. - add missing initialization and cleanup for obj->names XXX[2]: should we make them SIMPLEQ? - Add XXX in rtld.c about getting the name of an object. NB: This makes the jdk work again without resorting to a hack of putting the build path of libjvm.so into the run path (which is a security problem). XXX: Pullup-6?
2013-05-06Trailing whitespaceskrll