aboutsummaryrefslogtreecommitdiff
path: root/libexec/rtld-elf/powerpc64
Commit message (Collapse)AuthorAgeFilesLines
* Revert "Additional icache paranoia: non-PLT relocations can modify the text ↵Jessica Clarke2026-02-081-13/+0
| | | | | | | | | | | | | | | | | | segment." reloc_nonplt_object, and thus reloc_non_plt, only ever handles data relocations, so this paranoia is completely unfounded and only has the effect of significantly slowing down program startup for binaries with large amounts of code, like Clang. If this breaks any systems, that would likely be due to insufficient flushing in the pmap implementation for executable mappings, as this existing rtld behaviour would mask any such bugs. This reverts commit 4b51c69976fd84e93ec7695858375c8150c4fe61. Reviewed by: adrian Differential Revision: https://reviews.freebsd.org/D54221
* rtld: Simplify walking program headersJohn Baldwin2026-01-141-3/+1
| | | | | | | | | | Store phnum in Obj_Entry instead of phsize and use that to simplify the terminate expressions when iterating over program headers. Reviewed by: kib Obtained from: CheriBSD Sponsored by: AFRL, DARPA Differential Revision: https://reviews.freebsd.org/D54710
* rtld: fix powerpc buildKonstantin Belousov2025-11-241-3/+1
| | | | | | | | | | | In arch_fix_auxv(), remove local variable shadowing the argument, remove write-only variable, and declare the loop variable. The wrong patch was committed after series of local reverts and re-apply. Fixes: b2b3d2a962eb00005641546fbe672b95e5d0672a Sponsored by: The FreeBSD Foundation MFC after: 1 week
* rtld-elf: move powerpc-specific auxv compat code into arch hookKonstantin Belousov2025-11-212-0/+28
| | | | | | | Tested by: Timothy Pearson (tpearson_raptorengineering.com) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D53801
* rtld-elf: Pass struct tcb * around rather than struct dtv **Jessica Clarke2025-05-291-4/+1
| | | | | | | | | | | | | | | | | | | | 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-1/+1
| | | | | | | | | | | | | | 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: Push TLS_DTV_OFFSET into tls_get_addr_common's argumentsJessica Clarke2025-05-061-4/+2
| | | | | | | | | | Rather than calling tls_get_addr_common with a biased ti_offset and un-biasing the return value, we can instead un-bias the offset given in the first place and not need to adjust the return value. This is in fact how the MIPS implementation worked, and makes this call tail-recursive. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D50187
* 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: Move powerpc specific code to powerpc filesAndrew Turner2024-05-172-3/+14
| | | | | | | | | | | There are two variables set by dynamic tags in the powerpc runtime linker. Now we have a way to split out architecture-specific dynamic tags use it to handle these. Reviewed by: kib, jhibbits Obtained from: jhibbits (earlier version) Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D45182
* 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/+2
| | | | | | | | | | | | | | | | | | 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$: two-line .h patternWarner Losh2023-08-163-6/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* 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-NetBSD identifier is obsolete, drop -NetBSDWarner Losh2023-05-121-1/+1
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-NetBSD 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
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-121-1/+1
| | | | | | | | | 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-14/+5
| | | | | | | | | | | | | | | | | | | | | | | | - 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-161-1/+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-elf(1): remove obsolete pre_init() hookMarius Strobl2020-12-251-6/+0
| | | | | It's no longer used since 600ee699ed2805894f5972c6ac2c3d17dca7f6ce and r358358 respectively.
* Add CFI start/end proc directives to arm64, i386, and ppcConrad Meyer2020-12-051-0/+2
| | | | | | | | | | | | | | Follow-up to r353959 and r368070: do the same for other architectures. arm32 already seems to use its own .fnstart/.fnend directives, which appear to be ARM-specific variants of the same thing. Likewise, MIPS uses .frame directives. Reviewed by: arichardson Differential Revision: https://reviews.freebsd.org/D27387 Notes: svn path=/head/; revision=368354
* Align initial-exec TLS segments to the p_vaddr % align.Konstantin Belousov2020-04-191-2/+2
| | | | | | | | | | | | | | | 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
* Handle non-plt IRELATIVE relocations, at least for x86.Konstantin Belousov2020-02-131-0/+7
| | | | | | | | | | | | | 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-0/+2
| | | | | | | | | | | | | 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
* [PowerPC] powerpc64 rtld IFUNC handling codeBrandon Bergren2019-12-242-82/+237
| | | | | | | | | | | | | | | | | As PowerPC is moving to clang, we can finally start taking advantage of IFUNC. Implement the MD parts of IFUNC handling for rtld. Currently, it is necessary to look for R_PPC_IRELATIVE in the PLT in addition to RELA. This is an ABI violation, but LLD9 has some .iplt bugs that require this as a workaround. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D22789 Notes: svn path=/head/; revision=356055
* [PPC64] Fix rtld direct exec modeLeandro Lupori2019-08-051-5/+13
| | | | | | | | | | | | | | Instead of restoring the saved values of argc, argv and envp, these must be loaded from the stack that _rtld() modifies. This fixes rtld direct exec mode. E.g.: /libexec/ld-elf.so.1 /bin/ls Reviewed by: jhibbits Differential Revision: https://reviews.freebsd.org/D21131 Notes: svn path=/head/; revision=350587
* Fix rtld-elf compilation warning for powerpc64 ELFv2 ABIJustin Hibbits2019-01-131-1/+1
| | | | | | | | | | | | Summary: reloc_jmpslot function parameter 'defobj' is not used when using ELFv2 ABI Submitted by: alfredo.junior_eldorado.org.br Reviewed By: kib, git_bdragon.rtk0.net, emaste, jhibbits Differential Revision: https://reviews.freebsd.org/D18808 Notes: svn path=/head/; revision=342985
* rtld-elf: Fix powerpc64 TLS handling, matching powerpc's fixJustin Hibbits2019-01-011-1/+1
| | | | | | | | | | | | | We need to subtract the TLS_TCB_SIZE to get to the real data pointer, since r13 points to the end of the TCB structure. Prior to this, devel/protobuf-c port broke with recent update to devel/protobuf, which exposed this issue. Submitted by: andreast Reported by: Piotr Kubaj MFC after: 1 week Notes: svn path=/head/; revision=342671
* 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
* Flush data cache for executable loadable segments explicitly.Konstantin Belousov2018-11-031-2/+13
| | | | | | | | | | | | | | | Do not use textsize and do not flush everything between map base and base + textsize, because unmapped areas cannot be flushed. This makes Obj_Entry textsize only use go away, and I will remove it later. Reported by: tuexen Tested by: Mark Millard <marklmi26-fbsd@yahoo.com> Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=340102
* rtld-elf: compile with WANRS=4 warnings other than -Wcast-alignAlex Richardson2018-10-292-15/+19
| | | | | | | | | Reviewed By: kib Approved By: brooks (mentor) Differential Revision: https://reviews.freebsd.org/D17153 Notes: svn path=/head/; revision=339878
* Rework rtld's TLS Variant I implementation to match r326794Brooks Davis2018-09-051-1/+2
| | | | | | | | | | | | | | | | | | | | | The above commit fixed handling overaligned TLS segments in libc's TLS Variant I implementation, but rtld provides its own implementation for dynamically-linked executables which lacks these fixes. Thus, port these changes to rtld. This was previously commited as r337978 and reverted in r338149 due to exposing a bug the ARM rtld. This bug was fixed in r338317 by mmel. Submitted by: James Clarke Approved by: re (kib) Reviewed by: kbowling Testing by: kbowling (powerpc64), br (riscv), kevans (armv7) Obtained from: CheriBSD Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D16510 Notes: svn path=/head/; revision=338486
* Revert r337978: Rework rtld's TLS Variant I implementation to match r326794Brooks Davis2018-08-211-2/+1
| | | | | | | | | | Michal Meloun reports that it breaks ctype (isspace()..) related functions on armv7 so back out while we diagnose the issue. Reported by: Michal Meloun <melounmichal@gmail.com> Notes: svn path=/head/; revision=338149
* Rework rtld's TLS Variant I implementation to match r326794Brooks Davis2018-08-171-1/+2
| | | | | | | | | | | | | | | | | The above commit fixed handling overaligned TLS segments in libc's TLS Variant I implementation, but rtld provides its own implementation for dynamically-linked executables which lacks these fixes. Thus, port these changes to rtld. Submitted by: James Clarke Reviewed by: kbowling Testing byL kbowling (powerpc64), br (riscv), kevans (armv7) Obtained from: CheriBSD Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D16510 Notes: svn path=/head/; revision=337978
* o Let rtld(1) set up psABI user trap handlers prior to executing theMarius Strobl2018-02-031-0/+7
| | | | | | | | | | | | | | | | | 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
* rtld: fix warnings about redundant declarationsEric van Gyzen2017-05-261-5/+0
| | | | | | | | | | | | | Fix warnings about redundant declarations in rtld when libthr in increased to WARNS=6. Reviewed by: kib MFC after: 3 days Sponsored by: Dell EMC Differential Revision: https://reviews.freebsd.org/D10934 Notes: svn path=/head/; revision=318954
* Implement LD_BIND_NOT knob for rtld.Konstantin Belousov2017-03-152-5/+9
| | | | | | | | | | | | | | | | 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-1/+1
| | | | | | | | | | | | | | | | | | | (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-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* rtld-elf: use NULL instead of zero for pointers.Pedro F. Giffuni2016-04-191-1/+1
| | | | Notes: svn path=/head/; revision=298285
* Do not call callbacks for dl_iterate_phdr(3) with the rtld bind andKonstantin Belousov2016-01-201-2/+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
* Unify the ELFv1 and ELFv2 code paths and make ELFv1 (the normal ABI) moreNathan Whitehorn2016-01-012-39/+33
| | | | | | | | | correct in the process. MFC after: 2 weeks Notes: svn path=/head/; revision=293018
* Provide support for ELFv2 userland if using a newer compiler (recent clangNathan Whitehorn2015-12-032-9/+60
| | | | | | | or gcc) and binutils >= 2.24. Not enabled by default. Notes: svn path=/head/; revision=291668
* Remove some trailing space.Alexander Kabaev2015-10-091-5/+5
| | | | Notes: svn path=/head/; revision=289075
* IFUNC symbol type shall be processed for non-PLT relocations,Konstantin Belousov2014-08-291-0/+4
| | | | | | | | | | | | | | | | | | | | | | 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