aboutsummaryrefslogtreecommitdiff
path: root/libexec/rtld-elf/i386
Commit message (Collapse)AuthorAgeFilesLines
* rtld-elf: Pass struct tcb * around rather than struct dtv **Jessica Clarke2025-05-291-8/+2
| | | | | | | | | | | | | | | | | | | | When this code was first written we didn't have even a struct tcb, so to make it MI a pointer to the DTV pointer in the TCB was passed around. Now that we have a struct tcb we can simplify the code by instead passing around a pointer to that, and the MI code can access the tcb_dtv member wherever it happens to be in the layout. This reduces boilerplate in all the various callers of tls_get_addr_common/slow and makes it clearer that tls_get_addr_common/slow are operating on the TCB, rather than obfuscating it slightly through the double pointer. Whilst here, clarify the comments in aarch64's TLSDESC dynamic resolver, which were using tp without clarifying what this was for (previously a pointer to the DTV pointer, now a pointer to the TCB, which happen to be the same thing for Variant I TLS, and in the case of AArch64 are what TPIDR_EL0 point to directly, with no offset/bias). Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D50591
* tls: Introduce struct dtv and struct dtv_slotJessica Clarke2025-05-071-2/+2
| | | | | | | | | | | | | | Rather than treating the DTV as a raw array of uintptr_t, use proper struct types and gain the benefit of having different types for different members. In particular, the module slots now have real pointer types so less casting is generally needed. Note that, whilst struct dtv_slot may seem a little unnecessary, this will help downstream in CheriBSD where we wish to be able to easily alter the layout of a module's slot, which this helps abstract. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D50231
* rtld-elf/i386/reloc.c: apply clang-formatKonstantin Belousov2025-01-211-181/+186
| | | | | | Discussed with: emaste, imp Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D48509
* rtld-elf/{amd64,i386}/reloc.c: remove unneeded #ifdef dbgKonstantin Belousov2025-01-211-2/+0
| | | | | | | Discussed with: emaste, imp Sponsored by: The FreeBSD Foundation MFC after: 3 days Differential revision: https://reviews.freebsd.org/D48509
* rtld-elf: Pass parsed aux_info to ifunc_initJessica Clarke2024-08-221-1/+1
| | | | | | | | | | | | | | | | | | Currently we pass the raw pointer to the on-stack auxargs. This can legitimately have fewer than AT_COUNT entries, so the use of __min_size(AT_COUNT), i.e. static AT_COUNT, is inaccurate, and also needlessly forces the callee to iterate over the elements to find the entry for a given type. Instead we can just pass aux_info like we use for everything else. Note that the argument has been left unused by every callee since its introduction in 4352999e0e6c ("Pass CPUID[1] %edx (cpu_feature), %ecx (cpu_feature2) and CPUID[7].%ebx (cpu_stdext_feature), %ecx (cpu_stdext_feature2) to the ifunc resolvers on x86.") Reviewed by: kib MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D46276
* Remove residual blank line at start of MakefileWarner Losh2024-07-151-1/+0
| | | | | | | This is a residual of the $FreeBSD$ removal. MFC After: 3 days (though I'll just run the command on the branches) Sponsored by: Netflix
* rtld: Add arch_digest_dynamicAndrew Turner2024-05-171-0/+3
| | | | | | | | This will be used to handle the DT_AARCH64_VARIANT_PCS tag. Reviewed by: kib Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D45117
* rtld: Add MD_OBJ_ENTRY to extend Struct_Obj_EntryAndrew Turner2024-05-171-0/+2
| | | | | | | | | Add a macro the architectures can use to add per-arch fields to Struct_Obj_Entry. Reviewed by: kib Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D45116
* Support BTI in rtldAndrew Turner2024-04-121-0/+3
| | | | | | | | | Read the elf note to decide when to set the guard page on arm64. Reviewed by: kib Sponsored by: Arm Ltd Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39452
* rtld: introduce STATIC_TLS_EXTRAStephen J. Kiernan2023-10-301-1/+1
| | | | | | | | | | | | | | | | | | 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
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-161-1/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: one-line .h patternWarner Losh2023-08-161-1/+0
| | | | Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-163-6/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* 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: rename tls_done to tls_staticKonstantin Belousov2023-06-051-1/+1
| | | | | | | | | | The meaning of the flag is that static TLS allocation was done. Taken from NetBSD Joerg Sonnenberger change for src/libexec/ld.elf_so/tls.c rev. 1.18. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-122-2/+2
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* rtld: Revert "When loading dso without PT_GNU_STACK phdr, only call"John Baldwin2023-01-041-3/+0
| | | | | | | | | | | After the removal of ia64 and sparc64, all current architectures support executable stacks at an architectural level. This reverts commit 1290d38ac50b3afa7e5781d9d97346a1042c736c. Reviewed by: kib Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D37904
* TLS: Use <machine/tls.h> for libc and rtld.John Baldwin2021-12-092-9/+7
| | | | | | | | | | | | | | | | | | | | | | | | - Include <machine/tls.h> in MD rtld_machdep.h headers. - Remove local definitions of TLS_* constants from rtld_machdep.h headers and libc using the values from <machine/tls.h> instead. - Use _tcb_set() instead of inlined versions in MD allocate_initial_tls() routines in rtld. The one exception is amd64 whose _tcb_set() invokes the amd64_set_fsbase ifunc. rtld cannot use ifuncs, so amd64 inlines the logic to optionally write to fsbase directly. - Use _tcb_set() instead of _set_tp() in libc. - Use '&_tcb_get()->tcb_dtv' instead of _get_tp() in both rtld and libc. This permits removing _get_tp.c from rtld. - Use TLS_TCB_SIZE and TLS_TCB_ALIGN with allocate_tls() in MD allocate_initial_tls() routines in rtld. Reviewed by: kib, jrtc27 (earlier version) Differential Revision: https://reviews.freebsd.org/D33353
* rtld: Remove calculate_tls_endFangrui Song2021-08-162-7/+1
| | | | | | | | | | | Variant I architectures use off and Variant II ones use size + off. Define TLS_VARIANT_I/TLS_VARIANT_II symbols similarly to how libc handles it. Reviewed by: kib MFC after: 1 week Differential revision: https://reviews.freebsd.org/D31539 Differential revision: https://reviews.freebsd.org/D31541
* rtld: Fix i386/amd64 TP offset when p_vaddr % p_align != 0Fangrui Song2021-08-161-15/+12
| | | | | | | | | | | | | | | | | For a Variant II architecture, the TP offset of a TLS symbol is st_value - tlsoffset + r_addend. tlsoffset is computed by either calculate_tls_offset or calculate_first_tls_offset. The return value of calculate_first_tls_offset is the smallest integer satisfying res >= size and (-res) % p_align = p_vaddr % p_align (= p_offset % p_align). (The formula is a bit contrived. The basic idea is to subtract the minimum integer from size + align - 1 so that the result ihas the expected remainder.) Reviewed by: kib MFC after: 1 week Differential revision: https://reviews.freebsd.org/D31538 Differential revision: https://reviews.freebsd.org/D31541
* rtld: use _get_tp() in __tls_get_addr()Konstantin Belousov2021-04-091-8/+6
| | | | | | | | | | This eliminates some non-trivial amount of code duplication, where done. Only x86 and mips are handled right now. Tested by: bdragon (powerpc), mhorne (riscv) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D29623
* rtld: define TLS_DTV_OFFSET on all architecturesKonstantin Belousov2021-04-091-0/+2
| | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D29623
* rtld/x86/reloc.c: styleKonstantin Belousov2021-04-091-2/+4
| | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D29623
* rtld-elf(1): remove obsolete pre_init() hookMarius Strobl2020-12-251-6/+0
| | | | | It's no longer used since 600ee699ed2805894f5972c6ac2c3d17dca7f6ce and r358358 respectively.
* Align initial-exec TLS segments to the p_vaddr % align.Konstantin Belousov2020-04-192-8/+34
| | | | | | | | | | | | | | | This is continuation of D21163/r359634, which handled the alignment for global mode. Non-x86 arches are not handled, maintainers are welcomed. Tested by: emaste Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D24366 Notes: svn path=/head/; revision=360091
* r357895: fix typo in the relocation name for i386 IRELATIVE.Konstantin Belousov2020-02-141-1/+1
| | | | | | | | | Reported by: antoine Sponsored by: The FreeBSD Foundation MFC after: 6 days Notes: svn path=/head/; revision=357910
* Handle non-plt IRELATIVE relocations, at least for x86.Konstantin Belousov2020-02-131-17/+42
| | | | | | | | | | | | | lld 10.0 seems to generate this relocation for rdtsc_mb() ifunc in our libc. Reported, reviewed, and tested by: dim (amd64, previous version) Discussed with: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D23652 Notes: svn path=/head/; revision=357895
* rtld: clean up Makefile.Konstantin Belousov2020-01-111-1/+1
| | | | | | | | | | | | | Move all MD statements into $MACHINE_ARCH/Makefile.inc. Unconditionally apply version script to rtld, the interpreter is not functional without it for long time. Reviewed by: brooks, emaste Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D23083 Notes: svn path=/head/; revision=356631
* rtld-elf: Remove x86 elf_rtld.x linker scripts.Konstantin Belousov2019-08-042-134/+0
| | | | | | | | | | | | | | | | | First, amd64 version of the script cannot work at least due to the wrong architecture specification. Second, kernel can activate shared objects for long time, due to PIE support. It seems the intent was to allow ld-elf.so.1 to be build and used as an executable. Since we have direct exec mode implemented for dso ld-elf.so.1, the non-functional and commented out scripts can be finally removed. Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=350575
* rtld: pacify -Wmaybe-uninitialized from gcc6Eric van Gyzen2019-02-011-0/+4
| | | | | | | Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=343672
* Improve R_AARCH64_TLSDESC relocation.Michal Meloun2018-12-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | The original code did not support dynamically loaded libraries and used suboptimal access to TLS variables. New implementation removes lazy resolving of TLS relocation - due to flaw in TLSDESC design is impossible to switch resolver function at runtime without expensive locking. Due to this, 3 specialized resolvers are implemented: - load time resolver for TLS relocation from libraries loaded with main executable (thus with known TLS offset). - resolver for undefined thread weak symbols. - slower lazy resolver for dynamically loaded libraries with fast path for already resolved symbols. PR: 228892, 232149, 233204, 232311 MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D18417 Notes: svn path=/head/; revision=342113
* rtld-elf: compile with WANRS=4 warnings other than -Wcast-alignAlex Richardson2018-10-292-12/+13
| | | | | | | | | Reviewed By: kib Approved By: brooks (mentor) Differential Revision: https://reviews.freebsd.org/D17153 Notes: svn path=/head/; revision=339878
* o Let rtld(1) set up psABI user trap handlers prior to executing theMarius Strobl2018-02-031-0/+6
| | | | | | | | | | | | | | | | | objects' init functions instead of doing the setup via a constructor in libc as the init functions may already depend on these handlers to be in place. This gets us rid of: - the undefined order in which libc constructors as __guard_setup() and jemalloc_constructor() are executed WRT __sparc_utrap_setup(), - the requirement to link libc last so __sparc_utrap_setup() gets called prior to constructors in other libraries (see r122883). For static binaries, crt1.o still sets up the user trap handlers. o Move misplaced prototypes for MD functions in to the MD prototype section of rtld.h. o Sprinkle nitems(). Notes: svn path=/head/; revision=328834
* libexec: adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-272-0/+4
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. No functional change intended. Notes: svn path=/head/; revision=326274
* Implement LD_BIND_NOT knob for rtld.Konstantin Belousov2017-03-152-14/+18
| | | | | | | | | | | | | | | | From the manpage: When set to a nonempty string, prevents modifications of the PLT slots when doing bindings. As result, each call of the PLT-resolved function is resolved. In combination with debug output, this provides complete account of all bind actions at runtime. Same feature exists on Linux and Solaris. Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=315331
* Adjust r308689 to make rtld compilable with either in-tree orKonstantin Belousov2016-11-211-5/+17
| | | | | | | | | | | | | | | | | | | (hopefully) stock gcc 4.2.1 on i386 and other arches. In particular: - Do not use %ebx in the asm constraints on i386, since rtld is compiled with -fPIC and gcc cannot handle GOT-base register reload (clang and newer gcc can). - Avoid direct use of [static N] construct in the function declaration/definion. In-tree gcc was patched to support this, but stock 4.2.1 cannot handle the feature. Requested by: bde Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=308925
* Pass CPUID[1] %edx (cpu_feature), %ecx (cpu_feature2) andKonstantin Belousov2016-11-152-1/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | CPUID[7].%ebx (cpu_stdext_feature), %ecx (cpu_stdext_feature2) to the ifunc resolvers on x86. It is much more clean to use CPUID instruction in usermode to retrieve this information than to pass AT_HWCAP aux vector from kernel, on x86. Still, the change does allow for use of AT_HWCAP on arches where it is needed, by passing aux array to ifunc_init() initializer which should prepare arguments for ifunc resolvers. Current signature for resolvers on x86 is func_t iresolve(uint32_t cpu_feature, uint32_t cpu_feature2, uint32_t cpu_stdext_feature, uint32_t cpu_stdext_feature2); where arguments have identical meaning as the kernel variables of the same name. The ABIs allow to use resolvers with the void or shortened list of arguments. Reviewed by: jhb Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D8448 Notes: svn path=/head/; revision=308689
* Do not call callbacks for dl_iterate_phdr(3) with the rtld bind andKonstantin Belousov2016-01-201-1/+2
| | | | | | | | | | | | | | | | | | | | | phdr locks locked. This allows to call rtld services from the callback, which is only reasonable for dlopen(path, RTLD_NOLOAD) to test existence of the library in the image, and for dlsym(). The later might still be not quite safe, due to the lazy resolution of filters. To allow dropping the locks around iteration in dl_iterate_phdr(3), we insert markers to track current position between relocks. The global objects list is converted to tailq and all iterators skip markers, globallist_next() and globallist_curr() helpers are added. Reported and tested by: davide Reviewed by: kan Sponsored by: The FreeBSD Foundation MFC after: 3 weeks Notes: svn path=/head/; revision=294373
* Create a generalized exec hook that different architectures can hookWarner Losh2016-01-031-0/+2
| | | | | | | | | into if they need to, but default to no action. Differential Review: https://reviews.freebsd.org/D2718 Notes: svn path=/head/; revision=293066
* Disable SSE in libthrEric van Gyzen2015-08-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Clang emits SSE instructions on amd64 in the common path of pthread_mutex_unlock. If the thread does not otherwise use SSE, this usage incurs a context-switch of the FPU/SSE state, which reduces the performance of multiple real-world applications by a non-trivial amount (3-5% in one application). Instead of this change, I experimented with eagerly switching the FPU state at context-switch time. This did not help. Most of the cost seems to be in the read/write of memory--as kib@ stated--and not in the #NM handling. I tested on machines with and without XSAVEOPT. One counter-argument to this change is that most applications already use SIMD, and the number of applications and amount of SIMD usage are only increasing. This is absolutely true. I agree that--in general and in principle--this change is in the wrong direction. However, there are applications that do not use enough SSE to offset the extra context-switch cost. SSE does not provide a clear benefit in the current libthr code with the current compiler, but it does provide a clear loss in some cases. Therefore, disabling SSE in libthr is a non-loss for most, and a gain for some. I refrained from disabling SSE in libc--as was suggested--because I can't make the above argument for libc. It provides a wide variety of code; each case should be analyzed separately. https://lists.freebsd.org/pipermail/freebsd-current/2015-March/055193.html Suggestions from: dim, jmg, rpaulo Approved by: kib (mentor) MFC after: 2 weeks Sponsored by: Dell Inc. Notes: svn path=/head/; revision=286317
* Change compiler setting to make default visibility of the symbols forKonstantin Belousov2015-03-293-4/+5
| | | | | | | | | | | | | | rtld on x86 to be hidden. This is a micro-optimization, which allows intrinsic references inside rtld to be handled without indirection through PLT. The visibility of rtld symbols for other objects in the symbol namespace is controlled by a version script. Reviewed by: kan, jilles Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=280816
* Optimize r270798, only do the second pass over non-plt relocationsKonstantin Belousov2014-08-291-1/+3
| | | | | | | | | | when the first pass found IFUNCs. Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=270802
* IFUNC symbol type shall be processed for non-PLT relocations,Konstantin Belousov2014-08-291-144/+118
| | | | | | | | | | | | | | | | | | | | | | e.g. when a global variable is initialized with a pointer to ifunc. Add symbol type check and call resolver for STT_GNU_IFUNC symbol types when processing non-PLT relocations, but only after non-IFUNC relocations are done. The two-phase proceessing is required since resolvers may reference other symbols, which must be ready to use when resolver calls are done. Restructure reloc_non_plt() on x86 to call find_symdef() and handle IFUNC in single place. For non-x86 reloc_non_plt(), check for call for IFUNC relocation and do nothing, to avoid processing relocs twice. PR: 193048 Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=270798
* Add GNU hash support for rtld.Konstantin Belousov2012-04-301-1/+1
| | | | | | | | | | Based on dragonflybsd support for GNU hash by John Marino <draco marino st> Reviewed by: kan Tested by: bapt MFC after: 2 weeks Notes: svn path=/head/; revision=234841
* Fix several problems with our ELF filters implementation.Konstantin Belousov2012-03-201-14/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Do not relocate twice an object which happens to be needed by loaded binary (or dso) and some filtee opened due to symbol resolution when relocating need objects. Record the state of the relocation processing in Obj_Entry and short-circuit relocate_objects() if current object already processed. Do not call constructors for filtees loaded during the early relocation processing before image is initialized enough to run user-provided code. Filtees are loaded using dlopen_object(), which normally performs relocation and initialization. If filtee is lazy-loaded during the relocation of dso needed by the main object, dlopen_object() runs too earlier, when most runtime services are not yet ready. Postpone the constructors call to the time when main binary and depended libraries constructors are run, passing the new flag RTLD_LO_EARLY to dlopen_object(). Symbol lookups callers inform symlook_* functions about early stage of initialization with SYMLOOK_EARLY. Pass flags through all functions participating in object relocation. Use the opportunity and fix flags argument to find_symdef() in arch-specific reloc.c to use proper name SYMLOOK_IN_PLT instead of true, which happen to have the same numeric value. Reported and tested by: theraven Reviewed by: kan MFC after: 2 weeks Notes: svn path=/head/; revision=233231
* Add support for preinit, init and fini arrays. Some ABIs, inKonstantin Belousov2012-03-111-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | particular on ARM, do require working init arrays. Traditional FreeBSD crt1 calls _init and _fini of the binary, instead of allowing runtime linker to arrange the calls. This was probably done to have the same crt code serve both statically and dynamically linked binaries. Since ABI mandates that first is called preinit array functions, then init, and then init array functions, the init have to be called from rtld now. To provide binary compatibility to old FreeBSD crt1, which calls _init itself, rtld only calls intializers and finalizers for main binary if binary has a note indicating that new crt was used for linking. Add parsing of ELF notes to rtld, and cache p_osrel value since we parsed it anyway. The patch is inspired by init_array support for DragonflyBSD, written by John Marino. Reviewed by: kan Tested by: andrew (arm, previous version), flo (sparc64, previous version) MFC after: 3 weeks Notes: svn path=/head/; revision=232831
* Remove unneeded dtv variable.Ed Schouten2012-01-171-4/+0
| | | | | | | | | | It is only assigned and not used at all. The object files stay identical when the variables are removed. Approved by: kib Notes: svn path=/head/; revision=230281
* _rtld_bind() read-locks the bind lock, and possible plt resolutionKonstantin Belousov2011-12-141-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | from the dispatcher would also acquire bind lock in read mode, which is the supported operation. plt is explicitely designed to allow safe multithreaded updates, so the shared lock do not cause problems. The error in r228435 is that it allows read lock acquisition after the write lock for the bind block. If we dlopened the shared object that contains IRELATIVE or jump slot which target is STT_GNU_IFUNC, then possible recursive plt resolve from the dispatcher would cause it. Postpone the resolution for irelative/ifunc right before initializers are called, and drop bind lock around calls to dispatcher. Use initlist to iterate over the objects instead of the ->next, due to drop of the bind lock in iteration. For i386/reloc.c:reloc_iresolve(), fix calculation of the dispatch function address for dso, by taking into account possible non-zero relocbase. MFC after: 3 weeks Notes: svn path=/head/; revision=228503
* Add support for STT_GNU_IFUNC and R_MACHINE_IRELATIVE GNU extensions toKonstantin Belousov2011-12-121-15/+95
| | | | | | | | | | | | | | | | | | | | rtld on 386 and amd64. This adds runtime bits neccessary for the use of the dispatch functions from the dynamically-linked executables and shared libraries. To allow use of external references from the dispatch function, resolution of the R_MACHINE_IRESOLVE relocations in PLT is postponed until GOT entries for PLT are prepared, and normal resolution of the GOT entries is finished. Similar to how it is done by GNU, IRELATIVE relocations are resolved in advance, instead of normal lazy handling for PLT. Move the init_pltgot() call before the relocations for the object are processed. MFC after: 3 weeks Notes: svn path=/head/; revision=228435