aboutsummaryrefslogtreecommitdiff
path: root/libexec/rtld-elf
Commit message (Collapse)AuthorAgeFilesLines
...
* rtld: use generated map file to check for some leaks from libc into rtldKonstantin Belousov2024-02-291-0/+19
| | | | | | | Reviewed by: brooks, emaste (previous version) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D44136
* rtld: unconditionally generate map file during buildKonstantin Belousov2024-02-291-0/+6
| | | | | | | | | | | It is needed at least to ensure that undesirable code is not linked into rtld from libsys/libc, and adding the map file option each time is not productive. Reviewed by: brooks, emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D44136
* rtld-elf: support either byte-order of hints fileStefan Eßer2024-02-261-16/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | Accept either little-endian or big-endian representation of the ELF hints magic number in the header of a hints file and convert the parameters to the native byte-order of the repsective system. This is a pre-requisite for a planned change to always write the byte order in little-endian format on all architectures. The only relvant architecture that uses big-endian data is powerpc64, and it is not likely that new architectures will choose that representation of data in memory. When all supported architectures use little-endian data in the hints file, the byte swap logic can be enabled for big-endian CPUs at compile time. Up to that point, there is a very small run-time penalty that is paid on all systems to check the byte-order of the hints file and to provide the option to byte-swap the parameters read from the hints file header. This commit contains the changes from review D44080 (which had been split off from this patch for easier review), Reviewed by: kib MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D44053
* fdlopen(3): do not create a new object mapping if already loadedKonstantin Belousov2024-02-221-2/+3
| | | | | | | | | | This is expected behavior for both dlopen(3) and fdlopen(3). PR: 277169 Reviewed by: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D44019
* rtld: remove pointless "extern"Konstantin Belousov2024-02-211-1/+1
| | | | | | Reviewed by: brooks, imp Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D43985
* rtld: add some dlopen testsKyle Evans2024-02-132-0/+54
| | | | | | | | | | | | | | | | | dlopen_basic just tests that libthr.so can be dlopen()ed, which will just serve as a sanity check that "libthr.so" is a thing that can be dlopened in case we get a weird failure in dlopen_recursing. dlopen_recursing tests a regression reported after the libsys split, where some dlopen() may cause infinite recursion and a resulting crash. This case is inspired by bdrewery's description of what seemed to be causing his issue. The corresponding fix landed in commit 968a18975ad ("rtld: ignore load_filtees() calls if we already [...]") Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D43859
* rtld: ignore load_filtees() calls if we already loading filtees for the objKonstantin Belousov2024-02-132-1/+4
| | | | | | | | | | | | | | | | in addition to avoiding it for already loaded filtees. Issue is that during load, rtld needs to resolve some special ABI symbols, like executable stack fixer and static TLS initializer, which might trigger recursion. Example is libthr which is filter for libsys, and which exports __pthread_distribute_static_tls. Tested by: kevans, krion Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D43858
* rtld load_filtees(): reindent and reduce block nestingKonstantin Belousov2024-02-131-3/+2
| | | | | | | Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D43858
* rtld symlook_obj: move common code to check filtees into helperKonstantin Belousov2024-02-131-12/+19
| | | | | | | Revieved by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D43858
* rtld-elf: Avoid unnecessary lock_restart_for_upgrade() callsMark Johnston2024-02-021-1/+1
| | | | | | | | | | | | | | In order to atomically upgrade the rtld bind lock, load_filtees() may trigger a longjmp back to _rtld_bind() so that the binding can be done with the write lock held. However, the write lock is only needed when filtee objects haven't already been loaded, so move the lock_restart_for_upgrade() call to avoid unnecessary lock upgrades when a filtee is defined. Reviewed by: kib Tested by: brooks MFC after: 1 week Sponsored by: Innovate UK
* Stop #defining FREEBSD_ELFJohn Baldwin2023-12-121-1/+1
| | | | | | | | | | | | This was originally used (along with FREEBSD_AOUT) to prefer the use of ELF in various tools instead of a.out as part of the a.out to ELF transition in the 3.x days. The last use of it was removed from <link.h> in commit 66422f5b7a1a6055f0b2358268eb902aab6e2e3e back in 2002, but various files still #define it. Reviewed by: kevans, imp, emaste Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D42964
* rtld: add a test for RTLD_DEEPBINDKyle Evans2023-12-0110-2/+170
| | | | | | | | | | | This tests that with RTLD_DEEPBIND, symbols are looked up in all of the object's needed objects before the global object. PR: 275393 Reviewed by: kib Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D42843
* RTLD_DEEPBIND: make lookup not just symbolic, but walk all refobj' DAGsKonstantin Belousov2023-11-302-2/+7
| | | | | | | | | | | | | before starting the walk over the global list. Effectively we visit needed objects first as well, instead of just the object itself. This seems to better match the semantic offered by the glibc flag. Reported by: kevans PR: 275393 Reviewed by: kevans Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D42841
* libexec: Automated cleanup of cdefs and other formattingWarner Losh2023-11-276-6/+1
| | | | | | | | | | | | | | | | Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
* libexec: Remove ancient SCCS tags.Warner Losh2023-11-271-3/+0
| | | | | | | | Remove ancient SCCS tags from the tree, automated scripting, with two minor fixup to keep things compiling. All the common forms in the tree were removed with a perl script. Sponsored by: Netflix
* rtld/arm: fix initial-exec (IE) thread-local storage relocationR. Christian McDonald2023-11-031-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | net/frr[89] revealed an interesting edge-case on arm when dynamically linking a shared library that declares more than one static TLS variable with at least one using the "initial-exec" TLS model. In the case of frr[89], this library was libfrr.so which essentially does the following: #include <stdio.h> #include "lib.h" static __thread int *a __attribute__((tls_model("initial-exec"))); void lib_test() { static __thread int b = -1; printf("&a = %p\n", &a); printf(" a = %p\n", a); printf("\n"); printf("&b = %p\n", &b); printf(" b = %d\n", b); } Allocates a file scoped `static __thread` pointer with tls_model("initial-exec") and later a block scoped TLS int. Notice in the above minimal reproducer, `b == -1`. The relocation process does the wrong thing and ends up pointing both `a` and `b` at the same place in memory. The output of the above in the broken state is: &a = 0x4009c018 a = 0xffffffff &b = 0x4009c018 b = -1 With the patch applied, the output becomes: &a = 0x4009c01c a = 0x0 &b = 0x4009c018 b = -1 Reviewed by: kib Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D42415/
* ino64: Remove 'forward compat' code for thisWarner Losh2023-10-311-2/+2
| | | | | | | | | | | | | | | Forward compatibility code was added for running newer ino64 binaries on older kernels as a transition aide. Now that ino64 has been in the tree 6 years, this code is no longer useful and should have been removed long ago. Remove it now. Should be no user-visible changes at this point as all the 'upgrade' scenarios it was intended for are long since past. Also need to remove this stuff from rtld since the _foo versions no longer exist. Sponsored by: Netflix Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D42382
* rtld: Teach rtld about the BTI elf noteAndrew Turner2023-10-301-0/+4
| | | | | | | | | | Add the Branch Target Identification (BTI) note to libc assembly sources. As all obect files need the note for rtld to have it we need to insert it in all asm files. Reviewed by: markj, emaste Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D42228
* rtld: introduce STATIC_TLS_EXTRAStephen J. Kiernan2023-10-3010-12/+35
| | | | | | | | | | | | | | | | | | The new STATIC_TLS_EXTRA variable provides a means for applications to increases the size of the extra static TLS space allocated by rtld beyond the default of '128'. This extra static TLS space is used for objects loaded with dlopen. The value specified in the variable must be no less than the default value and no greater than the maximum allowed value for size_t type. If an invalid value is specified, rtld will ignore it and just use the default value. The rtld(1) man page is updated to document this new option. Obtained from: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D42025
* Purge more stray embedded $FreeBSD$ stringsJohn Baldwin2023-09-251-1/+0
| | | | | | | These do not use __FBSDID but instead use bare char arrays. Reviewed by: imp, emaste Differential Revision: https://reviews.freebsd.org/D41957
* rtld: output rtld errors into the dbg channelKonstantin Belousov2023-09-151-0/+1
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week
* __crt_aligned_alloc_offset(): fix ov_index for backing allocation addressKonstantin Belousov2023-09-061-1/+1
| | | | | | | | | | | Wrong value of ov_index resulted in magic check failure, and refuse to free() the memory allocated with __crt_aligned_alloc_offset(). Then the TLS segments of exited threads leaked. Reported and tested by: glebius Fixes: c29ee08204ce4106d4992474005c5f2fb7d5fbf1 Sponsored by: The FreeBSD Foundation MFC after: 3 days
* rtld: switch from malloc_aligned() to __crt_aligned_alloc()Konstantin Belousov2023-08-213-32/+15
| | | | | | | | | Use regular free(), since it works now. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D41150
* rtld_malloc: add __crt_aligned_alloc_offset()Konstantin Belousov2023-08-212-3/+32
| | | | | | | | | | | | It is modelled after aligned_alloc(3). Most importantly, to free the allocation, __crt_free() can be used. Additionally, caller may specify offset into the aligned allocation, so that we return offset-ed from alignment pointer. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D41150
* rtld_malloc: increase overhead index to uint16Konstantin Belousov2023-08-211-2/+2
| | | | | | | | | Reorder it with magic, to keep alignment. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D41150
* rtld_malloc.c: change return type of cp2op() to voidKonstantin Belousov2023-08-211-2/+2
| | | | | | | | | for it to be useful to return unaligned pointer. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D41150
* rtld: unlock bind lock when calling into crt __pthread_distribute_static_tls ↵Konstantin Belousov2023-08-201-0/+2
| | | | | | | | | | | | | | | | method The method might require resolving and binding symbols, which means recursing on the bind lock. It is safe to unlock the bind lock, since we operate on the private object list, and user attempting to unload an object from the list of not yet fully loaded objects caused self-inflicted race. It is similar to how we treat user' init/fini methods. Reported by: stevek Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Remove $FreeBSD$: two-line nroff patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-1615-15/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-167-13/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Remove $FreeBSD$: one-line .h patternWarner Losh2023-08-165-5/+0
| | | | Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-1639-78/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* libexec: Automatically generate rtld-elf list and generalise TAGSJessica Clarke2023-07-271-2/+6
| | | | | | | | | Note that the pattern for matching is made slightly more specific, so as to permit libcompats where one is a prefix of another (e.g. CheriBSD has lib64 and lib64c). Reviewed by: brooks, jhb, emaste, imp, kib Differential Revision: https://reviews.freebsd.org/D41183
* rtld_malloc: add cp2op() helperKonstantin Belousov2023-07-261-2/+8
| | | | | | | | converting user allocation address into overhead pointer Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D41150
* rtld_malloc: only include internal rtld headers when building for rtldKonstantin Belousov2023-07-261-0/+2
| | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D41150
* rtld: remove dup __crt_malloc prototypesKonstantin Belousov2023-07-262-5/+1
| | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D41150
* rtld_malloc: remove outdated commentsKonstantin Belousov2023-07-261-4/+0
| | | | | | | | | | | The ovu_magic is not neccessary overlaps with low byte of the ov_next, for the big endian machines. There is no range checking in the allocator. Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D41150
* libexec/rtld-elf/rtld-libc/Makefile.inc: do not use machdep string functionsRobert Clausecker2023-07-161-6/+16
| | | | | | | | | | | | | | With ifunc based SIMD dispatch, we cannot use the amd64 assembly implementations of string functions. Modify rtld to instead use the generic functions. To avoid an architecture-specific special case, this change is applied to all architectures. This change is a prerequisite to and formerly part of D40693. Sponsored by: FreeBSD Foundation Approved by: kib See also: D40693 Differential Revision: https://reviews.freebsd.org/D41050
* rtld: fix dlopen() for an object that is already mapped but not yet initializedKonstantin Belousov2023-07-161-5/+3
| | | | | | | | | | | | | | | | | For instance, dso might be mapped as needed but not yet initialized from the other subtree of needed objects, while current object' constructor does dlopen() for the dso. Right now rtld does relocations and other processing based on the arrival of new objects in the global list, which is not happens there. Directly check for the initialization state of the object, for which we would return the handle. One practical use case of this support is e.g. dlopen("libthr.so", RTLD_NOLOAD) by libraries that are threading-aware but happy to live with libc pthread shims if the program is not multithreaded. Reviewed by: tijl Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
* rtld: Annotate .rtld_start on i386Dmitry Chagin2023-07-111-0/+8
| | | | | | | | | | | | | | | | Add a stop indicator to rtld_start to satisfy unwinders: The right unwinding stop indicator should be CFI-undefined PC. https://dwarfstd.org/doc/Dwarf3.pdf - page 118: If a Return Address register is defined in the virtual unwind table, and its rule is undefined (for example, by DW_CFA_undefined), then there is no return address and no call address, and the virtual unwind of stack activations is complete. That is allows gdb and libunwind successfully stop when unwinding stack from global constructors and destructors. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D40949
* rtld: Microoptimize rtld_start on i386Dmitry Chagin2023-07-111-2/+1
| | | | | | | | Initial stack pointer is preserved in calle-saved %esi, use it bellow to pass initial stack pointer to _rtld(). Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D40950
* rtld-elf: Remove _PATH_ELF32_HINTS and _COMPAT32_PATH_RTLDJessica Clarke2023-07-091-8/+0
| | | | | | | | These are no longer referenced, with the one user of each now using the double-underscore version with "32" as an argument instead. Reviewed by: kib, brooks, jhb Differential Revision: https://reviews.freebsd.org/D40935
* rtld-elf: Migrate from COMPAT_32BIT to generic COMPAT_libcompat/LIBCOMPATJessica Clarke2023-07-092-22/+37
| | | | | | | | | | | | | | We still have a tiny amount of libcompat-specific code in rtld_paths.h, but it's been deduplicated as much as possible, and in future we may wish to just push these variables down to the few consumers of them and make them use the double-underscore variants with a libcompat argument rather than give them names here. See commit 8fad2cda93c7 ("bsd.compat.mk: Provide new CPP and sub-make variables") for the context behind this change. Reviewed by: kib, brooks, jhb Differential Revision: https://reviews.freebsd.org/D40925
* rtld-elf: Reuse _BASENAME_RTLD for debug.h rather than duplicating logicJessica Clarke2023-07-091-9/+4
| | | | | Reviewed by: kib, brooks, jhb Differential Revision: https://reviews.freebsd.org/D40919
* rtld: Annotate .rtld_start on aarch64Dmitry Chagin2023-07-071-0/+3
| | | | | | | | | | | | | | | | | | 1. Add a stop indicator to rtld_start to satisfy unwinders on aarch64: The right unwinding stop indicator should be CFI-undefined PC. https://dwarfstd.org/doc/Dwarf3.pdf - page 118: If a Return Address register is defined in the virtual unwind table, and its rule is undefined (for example, by DW_CFA_undefined), then there is no return address and no call address, and the virtual unwind of stack activations is complete. 2. Add a proper annotations for CFA. That is allows gdb and libunwind successfully stop when unwinding stack from global constructors and destructors. Reviewed by: Differential Revision: https://reviews.freebsd.org/D40844
* rtld: Sligtly optimizing .rtld_start on aarch64Dmitry Chagin2023-07-071-4/+1
| | | | | | | | Use the LDP (load pair registers) instruction to load entry point arguments from the stack. Reviewed by: Differential Revision: https://reviews.freebsd.org/D40843
* rtld: Add a stop indicator to rtld_start to satisfy unwinders on x86_64Dmitry Chagin2023-07-011-0/+5
| | | | | | | | | | | | | | | The right unwinding stop indicator should be CFI-undefined PC. https://dwarfstd.org/doc/Dwarf3.pdf - page 118: If a Return Address register is defined in the virtual unwind table, and its rule is undefined (for example, by DW_CFA_undefined), then there is no return address and no call address, and the virtual unwind of stack activations is complete. That is allows gdb and libunwind successfully stop when unwinding stack from global constructors and destructors. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D40794
* rtld-elf: Mark tls_init_align __unused in free_tls for Variant I TLS.John Baldwin2023-06-201-1/+1
| | | | | | | | | | Some architectures (powerpc and RISC-V) always use 0 for the post TLS size in which case tls_init_align isn't used by calculate_tls_post_size. Use __unused to quiet the warning for these platforms. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D40673
* rtld-elf: Remove set but unused variable on 32-bit arm.John Baldwin2023-06-201-2/+0
|
* rtld: fix typo in commentKonstantin Belousov2023-06-101-1/+1
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 3 days