aboutsummaryrefslogtreecommitdiff
path: root/lib/libthr/arch
Commit message (Collapse)AuthorAgeFilesLines
* libthr/amd64: do not set THR_C_RUNTIME for thr_new() if the main thread did ↵Konstantin Belousov2025-06-228-0/+62
| | | | | | | | | | | | | | used AMD64_SET_TLSBASE It is up to the code that organizes the runtime to properly set the signal handler, and to set %fsbase if libthr signal handler is to be called. The change should leave the CPU state on the signal handler entry identical to what it was before introduction of TLSBASE, for code that provides its own startup and thread pointer, but still calls into libthr as a hack. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* libc, libthr: Ditch MD __pthread_distribute_static_tls helpersJessica Clarke2025-05-296-264/+0
| | | | | | | | | | | | | | | | | | _libc_get_static_tls_base() is just _tcb_get() followed by adding (for Variant I) or subtracting (for Variant II) the offset, so just inline that as the implementation (like we do in rtld-elf) rather than having another copy (or equivalent) of _tcb_get()'s assembly. _get_static_tls_base() doesn't even have any MD assembly as it's reading thr->tcb, the only difference is whether to add or subtract, so again just inline that. Whilst here add some missing blank lines to comply with style(9) for elf_utils.c's includes, and use a pointer type rather than uintptr_t to reduce the need to cast, as is done in rtld-elf. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D50592
* libthr: Preresolve selected EABI symbols on arm.Michal Meloun2024-07-257-0/+95
| | | | | | | | | | | Add the ability to pre-resolve architecture-specific EABI symbols and use it on arm for selected EABI functions. These functions can be called with rtld bind lock write-locked, so they should be resolved in forward. Reported by: Mark Millard <marklmi@yahoo.com>, John F Carr <jfc@mit.edu> Reviewed by: kib, imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D46104
* 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
* libthr _get_curthread i386: quiet gcc -Warray-boundsRyan Libby2024-07-031-2/+2
| | | | | | | | | Use a constant input operand instead of a bogus memory reference to tell the compiler about offsetof(struct tcb, tcb_thread) in the gs segment. Otherwise gcc complains if we tell it we are reading memory offset 0x8. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D45829
* libthr _get_curthread amd64: quiet gcc -Warray-boundsRyan Libby2024-07-031-2/+2
| | | | | | | | | Use a constant input operand instead of a bogus memory reference to tell the compiler about offsetof(struct tcb, tcb_thread) in the fs segment. Otherwise gcc complains if we tell it we are reading memory offset 0x10. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D45828
* libthr: move _umtx_op_err() to libsysBrooks Davis2024-02-059-132/+0
| | | | | | | | | | | Declare in sys/umtx.h and implement in libsys. Explicitly link libthr with libsys. When building libthr static include _umtx_op_err so we don't break static linkage with -lpthread. Reviewed by: kib, emaste, imp Pull Request: https://github.com/freebsd/freebsd-src/pull/908
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-165-5/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-1615-30/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-1210-10/+10
| | | | | | | | | 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
* Remove PAGE_SIZE from libthrAndrew Turner2022-05-036-0/+18
| | | | | | | | | | | | | | | | | In libthr we use PAGE_SIZE when allocating memory with mmap and to check various structs will fit into a single page so we can use this allocator for them. Ask the kernel for the page size on init for use by the page allcator and add a new machine dependent macro to hold the smallest page size the architecture supports to check the structure is small enough. This allows us to use the same libthr on arm64 with either 4k or 16k pages. Reviewed by: kib, markj, imp Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34984
* mips: remove pthread supportWarner Losh2021-12-312-97/+0
| | | | Sponsored by: Netflix
* libthr: Use <machine/tls.h> for most MD TLS details.John Baldwin2021-12-097-315/+16
| | | | | | | | | | Note that on amd64 this effectively removes the unused tcb_spare field from the end of struct tcb since the definition of struct tcb in <x86/tls.h> does not include that field. Reviewed by: kib, jrtc27 Sponsored by: The University of Cambridge, Google Inc. Differential Revision: https://reviews.freebsd.org/D33352
* libthr: Remove the DTV_OFFSET macro.John Baldwin2021-12-097-14/+0
| | | | | | | | | | This macro is confusing as it is not related to the similarly named TLS_DTV_OFFSET. Instead, replace its one use with the desired expression which is the same on all platforms. Reviewed by: kib, emaste, jrtc27 Sponsored by: The University of Cambridge, Google Inc. Differential Revision: https://reviews.freebsd.org/D33345
* Remove the last users of ARM_TP_ADDRESSAndrew Turner2021-04-081-8/+0
| | | | | | | | | This was only needed on 32-bit arm prior to ARMv6. As we only support ARMv6 or later remove it. Reviewed by: mannu Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D29624
* Add CFI start/end proc directives to arm64, i386, and ppcConrad Meyer2020-12-051-1/+4
| | | | | | | | | | | | | | 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
* Remove libthr, csu, libthread_db and testfloat sparc64 specific directories.Warner Losh2020-02-274-167/+0
| | | | | | | Submitted by: kib@ (libthr) Notes: svn path=/head/; revision=358364
* libthr: Add missing END() directive for umtx_op_err (amd64)Conrad Meyer2019-10-231-2/+5
| | | | | | | | | Like r353929, related to D22122. No functional change. Reviewed by: emaste, kib (earlier version both) Notes: svn path=/head/; revision=353958
* RISC-V: Fix an alignment warning in libthrMitchell Horne2019-10-091-4/+4
| | | | | | | | | | | | | | Compiling with clang gives a loss-of-alignment error due the cast to uint8_t *. Since the TLS is always tcb aligned and TP_OFFSET is defined as sizeof(struct tcb) we can guarantee there is no misalignment. Silence the error by moving the offset into the inline assembly. Reviewed by: br MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D21926 Notes: svn path=/head/; revision=353334
* Implement _umtx_op_err.S on powerpc / powerpc64.Brandon Bergren2019-08-093-0/+46
| | | | | | | | | | | | | | As per r177853, we need to avoid using errno inside user mutex code, since signal handlers can interfere with it and mess up libthr internal state. So, implement _umtx_op_err() instead, which makes a raw syscall and returns the error value directly instead of using errno. Approved by: jhibbits (mentor) Differential Revision: https://reviews.freebsd.org/D20946 Notes: svn path=/head/; revision=350826
* Fix initial exec TLS mode for dynamically loaded shared objects.Konstantin Belousov2019-03-298-0/+368
| | | | | | | | | | | | | | | | | | | | | | | | If dso uses initial exec TLS mode, rtld tries to allocate TLS in static space. If there is no space left, the dlopen(3) fails. If space if allocated, initial content from PT_TLS segment is distributed to all threads' pcbs, which was missed and caused un-initialized TLS segment for such dso after dlopen(3). The mode is auto-detected either due to the relocation used, or if the DF_STATIC_TLS dynamic flag is set. In the later case, the TLS segment is tried to allocate earlier, which increases chance of the dlopen(3) to succeed. LLD was recently fixed to properly emit the flag, ld.bdf did it always. Initial test by: dumbbell Tested by: emaste (amd64), ian (arm) Tested by: Gerald Aryeetey <aryeeteygerald_rogers.com> (arm64) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D19072 Notes: svn path=/head/; revision=345703
* silence cast-align warnings from clang on powerpc64Leandro Lupori2019-02-131-4/+5
| | | | | | | | | | | | | | | | | silence the following warning when compiling libthr with clang 8 for powerpc64 architecture: usr/src/lib/libthr/arch/powerpc/include/pthread_md.h:82:10: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'struct tcb *' increases required alignment from 1 to 8 [-Werror,-Wcast-align] 82: return ((struct tcb *)(_tp - TP_OFFSET)); Submitted by: alfredo.junior_eldorado.org.br Reviewed by: git_bdragon.rtk0.net, emaste, kib, jhibbits, luporl Differential Revision: https://reviews.freebsd.org/D18807 Notes: svn path=/head/; revision=344109
* lib: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-266-1/+13
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using mis-identified 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. Notes: svn path=/head/; revision=326219
* Fix misleading comment.Michal Meloun2017-10-291-1/+2
| | | | | | | | | Not a functional change. MFC after: 3 days Notes: svn path=/head/; revision=325103
* libthr: fix warnings at WARNS=6Eric van Gyzen2017-05-265-10/+0
| | | | | | | | | | | | Fix more warnings about redundant declarations. Reviewed by: kib emaste MFC after: 3 days Sponsored by: Dell EMC Differential Revision: https://reviews.freebsd.org/D10932 Notes: svn path=/head/; revision=318955
* [mips] convert over =v to =r for the inline assembly.Adrian Chadd2016-08-141-2/+2
| | | | | | | | | | | | | | | | | Later gcc and clang have deprecated =v (which maps to a specific temp register) and instead we should just use =r to have the assembler (hopefully!) save/restore things appropriately after choosing a register. Tested: * AR9344 SoC, with userreg support * AR9331 SoC, with no userreg support Sponsored by: Sponsored by: DARPA, AFRL (MIPS TLS user register work) Notes: svn path=/head/; revision=304096
* [mips] add support for using the MIPS user register for TLS data.Adrian Chadd2016-08-071-0/+50
| | | | | | | | | | | | | | | | | | | | | | | This work, originally from Stacey Son, uses the MIPS UserReg for reading the TLS data, and will fall back to the normal syscall path when it isn't supported. This code dynamically patches cpu_switch() to bypass the UserReg instruction so to avoid generating a machine exception. Thanks to sson for the original work, and to Dan Nelson for bringing it to date and testing it on MIPS32 with me. Tested: * mips64 (sson) * mips74k (dnelson_1901@yahoo.com) - AR9344 SoC, UserReg support * mips24k (adrian) - AR9331 SoC, no UserReg support Obtained from: sson, dnelson_1901@yahoo.com Notes: svn path=/head/; revision=303809
* Unmagic the thread pointer offset.Ruslan Bukin2016-04-141-1/+1
| | | | Notes: svn path=/head/; revision=297971
* Add pthread MD part for RISC-V.Ruslan Bukin2016-01-271-0/+92
| | | | | | | | | | Reviewed by: andrew Sponsored by: DARPA, AFRL Sponsored by: HEIF5 Differential Revision: https://reviews.freebsd.org/D5063 Notes: svn path=/head/; revision=294912
* Start support for the RISC-V 64-bit architecture developed by UC Berkeley.Ruslan Bukin2015-12-111-0/+1
| | | | | | | | | | | | | | | | | | RISC-V is a new ISA designed to support computer research and education, and is now become a standard open architecture for industry implementations. This is a minimal set of changes required to run 'make kernel-toolchain' using external (GNU) toolchain. The FreeBSD/RISC-V project home: https://wiki.freebsd.org/riscv. Reviewed by: andrew, bdrewery, emaste, imp Sponsored by: DARPA, AFRL Sponsored by: HEIF5 Differential Revision: https://reviews.freebsd.org/D4445 Notes: svn path=/head/; revision=292124
* Disable SSE in libthrEric van Gyzen2015-08-052-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Add pthread_md.h for arm64.Andrew Turner2015-03-301-0/+84
| | | | | | | | | Differential Revision: https://reviews.freebsd.org/D2137 Reviewed by: kib Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=280862
* Start to import support for the AArch64 architecture from ARM. This changeAndrew Turner2015-03-191-0/+2
| | | | | | | | | | | | | | | | | | | | only adds support for kernel-toolchain, however it is expected further changes to add kernel and userland support will be committed as they are reviewed. As our copy of binutils is too old the devel/aarch64-binutils port needs to be installed to pull in a linker. To build either TARGET needs to be set to arm64, or TARGET_ARCH set to aarch64. The latter is set so uname -p will return aarch64 as existing third party software expects this. Differential Revision: https://reviews.freebsd.org/D2005 Relnotes: Yes Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=280259
* Merge all the copies of _tcb_ctor and _tcb_dtor.Andrew Turner2015-01-2118-376/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The amd64, i386, and sparc64 versions were identical, with the one difference where the former two used inline asm instead of _tcb_get. I have compared the function before and after replacing the asm with _tcb_get and found the object files to be identical. The arm, mips, and powerpc versions were almost identical. The only difference was the powerpc version used an alignment of 1 where arm and mips used 16. As this is an increase in alignment is will be safe. Along with this arm, mips, and powerpc all passed, when initial was true, the value returned from _tcb_get as the first argument to _rtld_allocate_tls. This would then return this pointer back to the caller. We can remove these extra calls by checking if initial is set and setting the thread control block directly. As this is what the sparc64 code does we can use it directly. As after these observations all the architectures can now have identical code we can merge them into a common file. Differential Revision: https://reviews.freebsd.org/D1556 Reviewed by: kib Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=277490
* Avoid use of register variables. Clang 3.5 treats this as undefined behavior,Justin Hibbits2015-01-061-7/+7
| | | | | | | | | and bad things happen. MFC after: 1 week Notes: svn path=/head/; revision=276734
* Remove ia64.Marcel Moolenaar2014-07-074-174/+0
| | | | | | | | | | | | | | | | | | | | This includes: o All directories named *ia64* o All files named *ia64* o All ia64-specific code guarded by __ia64__ o All ia64-specific makefile logic o Mention of ia64 in comments and documentation This excludes: o Everything under contrib/ o Everything under crypto/ o sys/xen/interface o sys/sys/elf_common.h Discussed at: BSDcan Notes: svn path=/head/; revision=268351
* Merging of projects/armv6, part 2Oleksandr Tymoshenko2012-08-151-1/+13
| | | | | | | Handle TLS for ARMv6 and ARMv7 Notes: svn path=/head/; revision=239270
* - Switch to saving non-offseted pointer to TLS block in order too keep ↵Oleksandr Tymoshenko2012-03-061-8/+4
| | | | | | | things simple Notes: svn path=/head/; revision=232579
* Add thread-local storage support for arm:Oleksandr Tymoshenko2012-02-142-4/+5
| | | | | | | | - Switch to Variant I TCB layout - Use function from rtld for TCB allocation/deallocation Notes: svn path=/head/; revision=231619
* Switch MIPS TLS implementation to Variant I:Oleksandr Tymoshenko2012-02-102-13/+20
| | | | | | | | Save pointer to the TLS structure taking into account TP_OFFSET and TCB structure size. Notes: svn path=/head/; revision=231350
* The TCB_GET32() and TCB_GET64() macros in the i386 and amd64-specificDimitry Andric2011-12-152-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | versions of pthread_md.h have a special case of dereferencing a null pointer. Clang warns about this with: In file included from lib/libthr/arch/i386/i386/pthread_md.c:36: lib/libthr/arch/i386/include/pthread_md.h:96:10: error: indirection of non-volatile null pointer will be deleted, not trap [-Werror,-Wnull-dereference] return (TCB_GET32(tcb_self)); ^~~~~~~~~~~~~~~~~~~ lib/libthr/arch/i386/include/pthread_md.h:73:13: note: expanded from: : "m" (*(u_int *)(__tcb_offset(name)))); \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lib/libthr/arch/i386/include/pthread_md.h:96:10: note: consider using __builtin_trap() or qualifying pointer with 'volatile' Since this indirection is done relative to the fs or gs segment, to retrieve thread-specific data, it is an exception to the rule. Therefore, add a volatile qualifier to tell the compiler we really want to dereference a zero address. MFC after: 1 week Notes: svn path=/head/; revision=228536
* Merge from r161730:Marius Strobl2011-06-184-21/+54
| | | | | | | | | | | | | | | | | | | | | | | o Set TP using inline assembly to avoid dead code elimination. o Eliminate _tcb. Merge from r161840: Stylize: avoid using a global register variable. Merge from r157461: Simplify _get_curthread() and _tcb_ctor because libc and rtld now already allocate thread pointer space in tls block for initial thread. Merge from r177853: Replace function _umtx_op with _umtx_op_err, the later function directly returns errno, because errno can be mucked by user's signal handler and most of pthread api heavily depends on errno to be correct, this change should improve stability of the thread library. MFC after: 1 week Notes: svn path=/head/; revision=223228
* Add section .note.GNU-stack for assembly files used by 386 and amd64.Konstantin Belousov2011-01-072-0/+4
| | | | Notes: svn path=/head/; revision=217107
* Merge from tbemd, with a small amount of rework:Warner Losh2010-09-137-14/+0
| | | | | | | | | | | | | For all libthr contexts, use ${MACHINE_CPUARCH} for all libc contexts, use ${MACHINE_ARCH} if it exists, otherwise use ${MACHINE_CPUARCH} Move some common code up a layer (the .PATH statement was the same in all the arch submakefiles). # Hope she hasn't busted powerpc64 with this... Notes: svn path=/head/; revision=212516
* Unify 32-bit and 64-bit PowerPC libthr support. This reduces codeNathan Whitehorn2010-08-245-145/+14
| | | | | | | | | duplication, and simplifies the TBEMD import. Requested by: imp Notes: svn path=/head/; revision=211773
* Fix SVN mismerge. We somehow ended up with the 32-bit powerpc versionNathan Whitehorn2010-07-112-4/+4
| | | | | | | in arch/powerpc64 instead of the 64-bit one. Notes: svn path=/head/; revision=209893
* Powerpc64 thread libraries support.Nathan Whitehorn2010-07-103-0/+143
| | | | Notes: svn path=/head/; revision=209880
* Merge r195129 from project/mips to head by hand:Warner Losh2010-01-091-2/+6
| | | | | | | | r195129 | gonzo | 2009-06-27 17:28:56 -0600 (Sat, 27 Jun 2009) | 2 lines - Use sysarch(2) in MIPS version of _tcb_set/_tcb_get Notes: svn path=/head/; revision=201864
* Implement _umtx_op_err() for ia64.Marcel Moolenaar2009-10-243-1/+38
| | | | Notes: svn path=/head/; revision=198450
* Commit missing mips libthr support that I thought I'd committed earlierWarner Losh2008-05-112-0/+141
| | | | Notes: svn path=/head/; revision=178938