From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 111F6385780D for ; Wed, 13 Mar 2024 17:29:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 111F6385780D Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 111F6385780D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710350944; cv=none; b=a9tVjHXl1nhutpUXGT5sphJI/5wxUEjhmCCl8s54R5//joXLbm9ALhsr5hZAiaA2XNkEj4r0nkJkU5krTtH4gFn6nyLA9JRKaHmfI1ww+9G3B77iNRMOBoKs7esCWdCNTefp3dE9qTk5pgDUZyeIr4MU2PGfWIIg/E+nYylsFoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710350944; c=relaxed/simple; bh=px9SSkFZfDUkhcLiPR5ZZh3BvPNeIJXrxnkq7NOCKFQ=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=no43u7OwgD7g3cPOUTSqC2GC5oV2378pB9Ey1KlFwEaUd1s3qjrvnaEZPuUaL9RP3vY4MEn0WCFX2cBLqSY1SjRgNSuN+mXh/EWBikV4hhGZfY1hv0skgmZ/q5KGDhllmnGDa2CP1NZGnqcT4T7xSf5x0wZaoMfFgAQGUOgfGXw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1710350938; bh=px9SSkFZfDUkhcLiPR5ZZh3BvPNeIJXrxnkq7NOCKFQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=JkSo9c8BH8OoWtRHx7sl+qDtP/EtNhSUJlMctj8fSfMs51eC3UKH9MxqP5lJz1R3F ryCqnaiS4DAe5Ud9uR3rdyt4vqpA21t6FddYTxVVF4oa8nofSbKukMdkumD0F4aGJn BwHgKwMqbLoaKWHrTZoG2uhtrBqwNiF/8BKRvnKY= Received: from [127.0.0.1] (unknown [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 8C6FE66F66; Wed, 13 Mar 2024 13:28:56 -0400 (EDT) Message-ID: <11246ce260c4a32e7ad592b7ae2f1e9ae553eb07.camel@xry111.site> Subject: Re: [PATCH v3] LoongArch: Add support for TLS Descriptors From: Xi Ruoyao To: mengqinggang , libc-alpha@sourceware.org, adhemerval.zanella@linaro.org Cc: xuchenghua@loongson.cn, caiyinyu@loongson.cn, chenglulu@loongson.cn, cailulu@loongson.cn, i.swmail@xen0n.name, maskray@google.com, luweining@loongson.cn, wanglei@loongson.cn, hejinyang@loongson.cn, hjl.tools@gmail.com Date: Thu, 14 Mar 2024 01:28:55 +0800 In-Reply-To: <20240308074353.3627489-1-mengqinggang@loongson.cn> References: <20240308074353.3627489-1-mengqinggang@loongson.cn> Autocrypt: addr=xry111@xry111.site; prefer-encrypt=mutual; keydata=mDMEYnkdPhYJKwYBBAHaRw8BAQdAsY+HvJs3EVKpwIu2gN89cQT/pnrbQtlvd6Yfq7egugi0HlhpIFJ1b3lhbyA8eHJ5MTExQHhyeTExMS5zaXRlPoiTBBMWCgA7FiEEkdD1djAfkk197dzorKrSDhnnEOMFAmJ5HT4CGwMFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQrKrSDhnnEOPHFgD8D9vUToTd1MF5bng9uPJq5y3DfpcxDp+LD3joA3U2TmwA/jZtN9xLH7CGDHeClKZK/ZYELotWfJsqRcthOIGjsdAPuDgEYnkdPhIKKwYBBAGXVQEFAQEHQG+HnNiPZseiBkzYBHwq/nN638o0NPwgYwH70wlKMZhRAwEIB4h4BBgWCgAgFiEEkdD1djAfkk197dzorKrSDhnnEOMFAmJ5HT4CGwwACgkQrKrSDhnnEOPjXgD/euD64cxwqDIqckUaisT3VCst11RcnO5iRHm6meNIwj0BALLmWplyi7beKrOlqKfuZtCLbiAPywGfCNg8LOTt4iMD Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.4 MIME-Version: 1.0 X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,LIKELY_SPAM_FROM,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Qinggang and Adhemerval, I've built and tested Glibc with this patch, https://sourceware.org/pipermail/libc-alpha/2024-March/155297.html, and a change to enable the gnu2 tests: diff --git a/sysdeps/loongarch/preconfigure b/sysdeps/loongarch/preconfigure index dfc7ecfd9e..0d1e9ed8df 100644 --- a/sysdeps/loongarch/preconfigure +++ b/sysdeps/loongarch/preconfigure @@ -43,6 +43,7 @@ loongarch*) =20 =20 base_machine=3Dloongarch + mtls_descriptor=3Ddesc ;; esac with a patched GCC (https://gcc.gnu.org/pipermail/gcc-patches/2024-March/647597.html, and some changes I've suggested in this thread). The gnu2 tests have passed. There are two failures which seem unrelated though: FAIL: misc/tst-preadvwritev64v2 FAIL: misc/tst-preadvwritev2 It looks like they are caused by the recent addition of RWF_NOAPPEND in mainline Linux kernel. On Fri, 2024-03-08 at 15:43 +0800, mengqinggang wrote: > This is mostly based on AArch64 and RISC-V implementation. >=20 > Add R_LARCH_TLS_DESC32 and R_LARCH_TLS_DESC64 relocations. >=20 > For _dl_tlsdesc_dynamic function slow path, temporarily save and restore > all vector registers. > --- > Changes v2 -> v3:=20 > - Remove _dl_tlsdesc_return_lasx, _dl_tlsdesc_return_lsx.=20 > =C2=A0 Provide only one _dl_tlsdesc_dynamic implementation and check the= =20 > =C2=A0 required save/restore of vector register based on hwcap value. > - Other details mentained by Adhemerval Zanella Netto, H.J. Lu and caiyin= yu. >=20 > Changes v1 -> v2:=20 > - Fix vr24-vr31, xr24-xr31 typo. > - Save and restore max length float or vector registors in _dl_tlsdesc_dy= namic. > - Save and restore fcsr0 in _dl_tlsdesc_dynamic.=20 >=20 > v2 link: https://sourceware.org/pipermail/libc-alpha/2024-February/155068= .html > v1 link: https://sourceware.org/pipermail/libc-alpha/2023-December/153052= .html >=20 > =C2=A0elf/elf.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 |=C2=A0=C2=A0 2 + > =C2=A0sysdeps/loongarch/Makefile=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= |=C2=A0=C2=A0 6 + > =C2=A0sysdeps/loongarch/dl-machine.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 52 ++- > =C2=A0sysdeps/loongarch/dl-tls.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= |=C2=A0=C2=A0 9 +- > =C2=A0sysdeps/loongarch/dl-tlsdesc.S=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 417 ++++++++++++++= ++++ > =C2=A0sysdeps/loongarch/dl-tlsdesc.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 49 ++ > =C2=A0sysdeps/loongarch/linkmap.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2= =A0=C2=A0 3 +- > =C2=A0sysdeps/loongarch/sys/asm.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2= =A0=C2=A0 1 + > =C2=A0sysdeps/loongarch/sys/regdef.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 1 + > =C2=A0sysdeps/loongarch/tlsdesc.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2= =A0 39 ++ > =C2=A0sysdeps/loongarch/tlsdesc.sym=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 28 ++ > =C2=A0.../unix/sysv/linux/loongarch/localplt.data=C2=A0=C2=A0 |=C2=A0=C2= =A0 2 + > =C2=A012 files changed, 605 insertions(+), 4 deletions(-) > =C2=A0create mode 100644 sysdeps/loongarch/dl-tlsdesc.S > =C2=A0create mode 100644 sysdeps/loongarch/dl-tlsdesc.h > =C2=A0create mode 100644 sysdeps/loongarch/tlsdesc.c > =C2=A0create mode 100644 sysdeps/loongarch/tlsdesc.sym >=20 > diff --git a/elf/elf.h b/elf/elf.h > index f2206e5c06..eec24ea049 100644 > --- a/elf/elf.h > +++ b/elf/elf.h > @@ -4237,6 +4237,8 @@ enum > =C2=A0#define R_LARCH_TLS_TPREL32 10 > =C2=A0#define R_LARCH_TLS_TPREL64 11 > =C2=A0#define R_LARCH_IRELATIVE 12 > +#define R_LARCH_TLS_DESC32 13 > +#define R_LARCH_TLS_DESC64 14 > =C2=A0 > =C2=A0/* Reserved for future relocs that the dynamic linker must understa= nd.=C2=A0 */ > =C2=A0 > diff --git a/sysdeps/loongarch/Makefile b/sysdeps/loongarch/Makefile > index 43d2f583cd..181389e787 100644 > --- a/sysdeps/loongarch/Makefile > +++ b/sysdeps/loongarch/Makefile > @@ -3,9 +3,15 @@ sysdep_headers +=3D sys/asm.h > =C2=A0endif > =C2=A0 > =C2=A0ifeq ($(subdir),elf) > +sysdep-dl-routines +=3D tlsdesc dl-tlsdesc > =C2=A0gen-as-const-headers +=3D dl-link.sym > =C2=A0endif > =C2=A0 > +ifeq ($(subdir),csu) > +gen-as-const-headers +=3D tlsdesc.sym > +endif > + > + > =C2=A0# LoongArch's assembler also needs to know about PIC as it changes = the > =C2=A0# definition of some assembler macros. > =C2=A0ASFLAGS-.os +=3D $(pic-ccflag) > diff --git a/sysdeps/loongarch/dl-machine.h b/sysdeps/loongarch/dl-machin= e.h > index ab81b82d95..0e22337183 100644 > --- a/sysdeps/loongarch/dl-machine.h > +++ b/sysdeps/loongarch/dl-machine.h > @@ -25,7 +25,7 @@ > =C2=A0#include > =C2=A0#include > =C2=A0#include > -#include > +#include > =C2=A0#include > =C2=A0#include > =C2=A0 > @@ -187,6 +187,36 @@ elf_machine_rela (struct link_map *map, struct r_sco= pe_elem *scope[], > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *addr_field =3D TLS_TPREL_VALUE (sym= _map, sym) + reloc->r_addend; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 break; > =C2=A0 > +=C2=A0=C2=A0=C2=A0 case __WORDSIZE =3D=3D 64 ? R_LARCH_TLS_DESC64 : R_LA= RCH_TLS_DESC32: > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 { > + struct tlsdesc volatile *td =3D (struct tlsdesc volatile *)addr_field; > + if (sym =3D=3D NULL) > + =C2=A0 { > + =C2=A0=C2=A0=C2=A0 td->arg =3D (void*)reloc->r_addend; > + =C2=A0=C2=A0=C2=A0 td->entry =3D _dl_tlsdesc_undefweak; > + =C2=A0 } > + else > + =C2=A0 { > +# ifndef SHARED > + =C2=A0=C2=A0=C2=A0 CHECK_STATIC_TLS (map, sym_map); > +# else > + =C2=A0=C2=A0=C2=A0 if (!TRY_STATIC_TLS (map, sym_map)) > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 { > + td->arg =3D _dl_make_tlsdesc_dynamic (sym_map, > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 sym->st_value + reloc->r_addend); > + td->entry =3D _dl_tlsdesc_dynamic; > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > + =C2=A0=C2=A0=C2=A0 else > +# endif > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 { > + td->arg =3D (void *)(TLS_TPREL_VALUE (sym_map, sym) > + =C2=A0=C2=A0=C2=A0 + reloc->r_addend); > + td->entry =3D _dl_tlsdesc_return; > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > + =C2=A0 } > + break; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > + > =C2=A0=C2=A0=C2=A0=C2=A0 case R_LARCH_COPY: > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 { > =C2=A0 =C2=A0 if (sym =3D=3D NULL) > @@ -255,6 +285,26 @@ elf_machine_lazy_rel (struct link_map *map, struct r= _scope_elem *scope[], > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else > =C2=A0 *reloc_addr =3D map->l_mach.plt; > =C2=A0=C2=A0=C2=A0=C2=A0 } > +=C2=A0 else if (__glibc_likely (r_type =3D=3D R_LARCH_TLS_DESC64) > + =C2=A0=C2=A0=C2=A0 || __glibc_likely (r_type =3D=3D R_LARCH_TLS_DESC32)= ) > +=C2=A0=C2=A0=C2=A0 { > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const Elf_Symndx symndx =3D ELFW (R_SYM) = (reloc->r_info); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const ElfW (Sym) *symtab =3D (const void = *)D_PTR (map, l_info[DT_SYMTAB]); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const ElfW (Sym) *sym =3D &symtab[symndx]= ; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const struct r_found_version *version =3D= NULL; > + > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (map->l_info[VERSYMIDX (DT_VERSYM)] != =3D NULL) > + { > + =C2=A0 const ElfW (Half) *vernum =3D (const void *)D_PTR (map, > + =C2=A0 l_info[VERSYMIDX (DT_VERSYM)]); > + =C2=A0 version =3D &map->l_versions[vernum[symndx] & 0x7fff]; > + } > + > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Always initialize TLS descriptors comp= letely, because lazy > + initialization requires synchronization at every TLS access.=C2=A0 */ > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 elf_machine_rela (map, scope, reloc, sym,= version, reloc_addr, > + skip_ifunc); > +=C2=A0=C2=A0=C2=A0 } > =C2=A0=C2=A0 else > =C2=A0=C2=A0=C2=A0=C2=A0 _dl_reloc_bad_type (map, r_type, 1); > =C2=A0} > diff --git a/sysdeps/loongarch/dl-tls.h b/sysdeps/loongarch/dl-tls.h > index 29924b866d..de593c002d 100644 > --- a/sysdeps/loongarch/dl-tls.h > +++ b/sysdeps/loongarch/dl-tls.h > @@ -16,6 +16,9 @@ > =C2=A0=C2=A0=C2=A0 License along with the GNU C Library.=C2=A0 If not, se= e > =C2=A0=C2=A0=C2=A0 .=C2=A0 */ > =C2=A0 > +#ifndef _DL_TLS_H > +#define _DL_TLS_H > + > =C2=A0/* Type used for the representation of TLS information in the GOT.= =C2=A0 */ > =C2=A0typedef struct > =C2=A0{ > @@ -23,6 +26,8 @@ typedef struct > =C2=A0=C2=A0 unsigned long int ti_offset; > =C2=A0} tls_index; > =C2=A0 > +extern void *__tls_get_addr (tls_index *ti); > + > =C2=A0/* The thread pointer points to the first static TLS block.=C2=A0 *= / > =C2=A0#define TLS_TP_OFFSET 0 > =C2=A0 > @@ -37,10 +42,10 @@ typedef struct > =C2=A0/* Compute the value for a DTPREL reloc.=C2=A0 */ > =C2=A0#define TLS_DTPREL_VALUE(sym) ((sym)->st_value - TLS_DTV_OFFSET) > =C2=A0 > -extern void *__tls_get_addr (tls_index *ti); > - > =C2=A0#define GET_ADDR_OFFSET (ti->ti_offset + TLS_DTV_OFFSET) > =C2=A0#define __TLS_GET_ADDR(__ti) (__tls_get_addr (__ti) - TLS_DTV_OFFSE= T) > =C2=A0 > =C2=A0/* Value used for dtv entries for which the allocation is delayed.= =C2=A0 */ > =C2=A0#define TLS_DTV_UNALLOCATED ((void *) -1l) > + > +#endif > diff --git a/sysdeps/loongarch/dl-tlsdesc.S b/sysdeps/loongarch/dl-tlsdes= c.S > new file mode 100644 > index 0000000000..34028e988b > --- /dev/null > +++ b/sysdeps/loongarch/dl-tlsdesc.S > @@ -0,0 +1,417 @@ > +/* Thread-local storage handling in the ELF dynamic linker. > +=C2=A0=C2=A0 LoongArch version. > +=C2=A0=C2=A0 Copyright (C) 2011-2024 Free Software Foundation, Inc. > + > +=C2=A0=C2=A0 This file is part of the GNU C Library. > + > +=C2=A0=C2=A0 The GNU C Library is free software; you can redistribute it= and/or > +=C2=A0=C2=A0 modify it under the terms of the GNU Lesser General Public > +=C2=A0=C2=A0 License as published by the Free Software Foundation; eithe= r > +=C2=A0=C2=A0 version 2.1 of the License, or (at your option) any later v= ersion. > + > +=C2=A0=C2=A0 The GNU C Library is distributed in the hope that it will b= e useful, > +=C2=A0=C2=A0 but WITHOUT ANY WARRANTY; without even the implied warranty= of > +=C2=A0=C2=A0 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.=C2=A0 = See the GNU > +=C2=A0=C2=A0 Lesser General Public License for more details. > + > +=C2=A0=C2=A0 You should have received a copy of the GNU Lesser General P= ublic > +=C2=A0=C2=A0 License along with the GNU C Library; if not, see > +=C2=A0=C2=A0 .=C2=A0 */ > + > +#include > +#include > +#include "tlsdesc.h" > + > + .text > + > + /* Compute the thread pointer offset for symbols in the static > + =C2=A0=C2=A0 TLS block. The offset is the same for all threads. > + =C2=A0=C2=A0 Prototype: > + =C2=A0=C2=A0 _dl_tlsdesc_return (tlsdesc *);=C2=A0 */ > + .hidden _dl_tlsdesc_return > + .global _dl_tlsdesc_return > + .type _dl_tlsdesc_return,%function > + cfi_startproc > + .align 2 > +_dl_tlsdesc_return: > + REG_L=C2=A0 a0, a0, 8 > + RET > + cfi_endproc > + .size _dl_tlsdesc_return, .-_dl_tlsdesc_return > + > + /* Handler for undefined weak TLS symbols. > + =C2=A0=C2=A0 Prototype: > + =C2=A0=C2=A0 _dl_tlsdesc_undefweak (tlsdesc *); > + > + =C2=A0=C2=A0 The second word of the descriptor contains the addend. > + =C2=A0=C2=A0 Return the addend minus the thread pointer. This ensures > + =C2=A0=C2=A0 that when the caller adds on the thread pointer it gets ba= ck > + =C2=A0=C2=A0 the addend.=C2=A0 */ > + .hidden _dl_tlsdesc_undefweak > + .global _dl_tlsdesc_undefweak > + .type _dl_tlsdesc_undefweak,%function > + cfi_startproc > + .align=C2=A0 2 > +_dl_tlsdesc_undefweak: > + REG_L a0, a0, 8 > + sub.d a0, a0, tp > + RET > + cfi_endproc > + .size _dl_tlsdesc_undefweak, .-_dl_tlsdesc_undefweak > + > + > +#ifdef SHARED > + > +#define FRAME_SIZE =C2=A0 (-((-13 * SZREG) & ALMASK)) > +#define FRAME_SIZE_LSX =C2=A0 (-((-32 * SZVREG) & ALMASK)) > +#define FRAME_SIZE_LASX =C2=A0 (-((-32 * SZXREG) & ALMASK)) > +#define FRAME_SIZE_FLOAT=C2=A0 (-((-24 * SZFREG) & ALMASK)) > + > + /* Handler for dynamic TLS symbols. > + =C2=A0=C2=A0 Prototype: > + =C2=A0=C2=A0 _dl_tlsdesc_dynamic (tlsdesc *) ; > + > + =C2=A0=C2=A0 The second word of the descriptor points to a > + =C2=A0=C2=A0 tlsdesc_dynamic_arg structure. > + > + =C2=A0=C2=A0 Returns the offset between the thread pointer and the > + =C2=A0=C2=A0 object referenced by the argument. > + > + =C2=A0=C2=A0 ptrdiff_t > + =C2=A0=C2=A0 _dl_tlsdesc_dynamic (struct tlsdesc *tdp) > + =C2=A0=C2=A0 { > + =C2=A0=C2=A0=C2=A0=C2=A0 struct tlsdesc_dynamic_arg *td =3D tdp->arg; > + =C2=A0=C2=A0=C2=A0=C2=A0 dtv_t *dtv =3D *(dtv_t **)((char *)__thread_po= inter + TCBHEAD_DTV); > + =C2=A0=C2=A0=C2=A0=C2=A0 if (__glibc_likely (td->gen_count <=3D dtv[0].= counter > + && (dtv[td->tlsinfo.ti_module].pointer.val > + =C2=A0=C2=A0=C2=A0 !=3D TLS_DTV_UNALLOCATED), > + 1)) > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return dtv[td->tlsinfo.ti_module].= pointer.val > + + td->tlsinfo.ti_offset > + - __thread_pointer; > + > + =C2=A0=C2=A0=C2=A0=C2=A0 return ___tls_get_addr (&td->tlsinfo) - __thre= ad_pointer; > + =C2=A0=C2=A0 }=C2=A0 */ > + .hidden _dl_tlsdesc_dynamic > + .global _dl_tlsdesc_dynamic > + .type _dl_tlsdesc_dynamic,%function > + cfi_startproc > + .align 2 > +_dl_tlsdesc_dynamic: > + /* Save just enough registers to support fast path, if we fall > + =C2=A0=C2=A0 into slow path we will save additional registers.=C2=A0 */ > + ADDI sp, sp,-24 > + REG_S t0, sp, 0 > + REG_S t1, sp, 8 > + REG_S t2, sp, 16 > + > + REG_L t0, tp, -SIZE_OF_DTV=C2=A0 /* dtv(t0) =3D tp + TCBHEAD_DTV dtv st= art */ > + REG_L a0, a0, TLSDESC_ARG =C2=A0 /* td(a0) =3D tdp->arg */ > + REG_L t1, a0, TLSDESC_GEN_COUNT /* t1 =3D td->gen_count */ > + REG_L t2, t0, DTV_COUNTER =C2=A0 /* t2 =3D dtv[0].counter */ > + bltu t2, t1, .Lslow > + > + REG_L t1, a0, TLSDESC_MODID /* t1 =3D td->tlsinfo.ti_module */ > + slli.d t1, t1, 3 + 1 /* sizeof(dtv_t) =3D=3D sizeof(void*) * 2 */ > + add.d t1, t1, t0=C2=A0=C2=A0=C2=A0 /* t1 =3D dtv + ti_module * sizeof(d= tv_t) */ > + REG_L t1, t1, 0=C2=A0=C2=A0=C2=A0=C2=A0 /* t1 =3D dtv[td->tlsinfo.ti_mo= dule].pointer.val */ > + li.d t2, TLS_DTV_UNALLOCATED > + beq t1, t2, .Lslow > + REG_L t2, a0, TLSDESC_MODOFF /* t2 =3D td->tlsinfo.ti_offset */ > + /* dtv[td->tlsinfo.ti_module].pointer.val + td->tlsinfo.ti_offset */ > + add.d a0, t1, t2 > +.Lret: > + sub.d a0, a0, tp > + REG_L t0, sp, 0 > + REG_L t1, sp, 8 > + REG_L t2, sp, 16 > + ADDI sp, sp, 24 > + RET > + > +.Lslow: > + /* This is the slow path. We need to call __tls_get_addr() which > + =C2=A0=C2=A0 means we need to save and restore all the register that th= e > + =C2=A0=C2=A0 callee will trash.=C2=A0 */ > + > + /* Save the remaining registers that we must treat as caller save.=C2= =A0 */ > + ADDI sp, sp, -FRAME_SIZE > + REG_S ra, sp, 0 * SZREG > + REG_S a1, sp, 1 * SZREG > + REG_S a2, sp, 2 * SZREG > + REG_S a3, sp, 3 * SZREG > + REG_S a4, sp, 4 * SZREG > + REG_S a5, sp, 5 * SZREG > + REG_S a6, sp, 6 * SZREG > + REG_S a7, sp, 7 * SZREG > + REG_S t4, sp, 8 * SZREG > + REG_S t5, sp, 9 * SZREG > + REG_S t6, sp, 10 * SZREG > + REG_S t7, sp, 11 * SZREG > + REG_S t8, sp, 12 * SZREG > + > +#ifndef __loongarch_soft_float > + > + /* Save fcsr0 register. > + =C2=A0=C2=A0 Only one physical fcsr0 register, fcsr1-fcsr3 are aliases > + =C2=A0=C2=A0 of some fields in fcsr0.=C2=A0 */ > + ADDI sp, sp, -SZFCSREG > + movfcsr2gr=C2=A0 t0, fcsr0 > + st.w t0, sp, 0 > + > + /* Whether support LASX.=C2=A0 */ > + la.global=C2=A0=C2=A0 t0, _rtld_global_ro > + REG_L t0, t0, GLRO_DL_HWCAP_OFFSET > + andi t0, t0, HWCAP_LOONGARCH_LASX > + beqz t0, .Llsx > + > + /* Save 256-bit vector registers. > + =C2=A0=C2=A0 FIXME: Without vector ABI, save all vector registers.=C2= =A0 */ > + ADDI sp, sp, -FRAME_SIZE_LASX > + xvst xr0, sp, 0*SZXREG > + xvst xr1, sp, 1*SZXREG > + xvst xr2, sp, 2*SZXREG > + xvst xr3, sp, 3*SZXREG > + xvst xr4, sp, 4*SZXREG > + xvst xr5, sp, 5*SZXREG > + xvst xr6, sp, 6*SZXREG > + xvst xr7, sp, 7*SZXREG > + xvst xr8, sp, 8*SZXREG > + xvst xr9, sp, 9*SZXREG > + xvst xr10, sp, 10*SZXREG > + xvst xr11, sp, 11*SZXREG > + xvst xr12, sp, 12*SZXREG > + xvst xr13, sp, 13*SZXREG > + xvst xr14, sp, 14*SZXREG > + xvst xr15, sp, 15*SZXREG > + xvst xr16, sp, 16*SZXREG > + xvst xr17, sp, 17*SZXREG > + xvst xr18, sp, 18*SZXREG > + xvst xr19, sp, 19*SZXREG > + xvst xr20, sp, 20*SZXREG > + xvst xr21, sp, 21*SZXREG > + xvst xr22, sp, 22*SZXREG > + xvst xr23, sp, 23*SZXREG > + xvst xr24, sp, 24*SZXREG > + xvst xr25, sp, 25*SZXREG > + xvst xr26, sp, 26*SZXREG > + xvst xr27, sp, 27*SZXREG > + xvst xr28, sp, 28*SZXREG > + xvst xr29, sp, 29*SZXREG > + xvst xr30, sp, 30*SZXREG > + xvst xr31, sp, 31*SZXREG > + b =C2=A0=C2=A0=C2=A0 .Ltga > + > +.Llsx: > + /* Whether support LSX.=C2=A0 */ > + andi t0, t0, HWCAP_LOONGARCH_LSX > + beqz t0, .Lfloat > + > + /* Save 128-bit vector registers.=C2=A0 */ > + ADDI sp, sp, -FRAME_SIZE_LSX > + vst vr0, sp, 0*SZVREG > + vst vr1, sp, 1*SZVREG > + vst vr2, sp, 2*SZVREG > + vst vr3, sp, 3*SZVREG > + vst vr4, sp, 4*SZVREG > + vst vr5, sp, 5*SZVREG > + vst vr6, sp, 6*SZVREG > + vst vr7, sp, 7*SZVREG > + vst vr8, sp, 8*SZVREG > + vst vr9, sp, 9*SZVREG > + vst vr10, sp, 10*SZVREG > + vst vr11, sp, 11*SZVREG > + vst vr12, sp, 12*SZVREG > + vst vr13, sp, 13*SZVREG > + vst vr14, sp, 14*SZVREG > + vst vr15, sp, 15*SZVREG > + vst vr16, sp, 16*SZVREG > + vst vr17, sp, 17*SZVREG > + vst vr18, sp, 18*SZVREG > + vst vr19, sp, 19*SZVREG > + vst vr20, sp, 20*SZVREG > + vst vr21, sp, 21*SZVREG > + vst vr22, sp, 22*SZVREG > + vst vr23, sp, 23*SZVREG > + vst vr24, sp, 24*SZVREG > + vst vr25, sp, 25*SZVREG > + vst vr26, sp, 26*SZVREG > + vst vr27, sp, 27*SZVREG > + vst vr28, sp, 28*SZVREG > + vst vr29, sp, 29*SZVREG > + vst vr30, sp, 30*SZVREG > + vst vr31, sp, 31*SZVREG > + b =C2=A0=C2=A0=C2=A0 .Ltga > + > +.Lfloat: > + /* Save float registers.=C2=A0 */ > + ADDI sp, sp, -FRAME_SIZE_FLOAT > + FREG_S fa0, sp, 0*SZFREG > + FREG_S fa1, sp, 1*SZFREG > + FREG_S fa2, sp, 2*SZFREG > + FREG_S fa3, sp, 3*SZFREG > + FREG_S fa4, sp, 4*SZFREG > + FREG_S fa5, sp, 5*SZFREG > + FREG_S fa6, sp, 6*SZFREG > + FREG_S fa7, sp, 7*SZFREG > + FREG_S ft0, sp, 8*SZFREG > + FREG_S ft1, sp, 9*SZFREG > + FREG_S ft2, sp, 10*SZFREG > + FREG_S ft3, sp, 11*SZFREG > + FREG_S ft4, sp, 12*SZFREG > + FREG_S ft5, sp, 13*SZFREG > + FREG_S ft6, sp, 14*SZFREG > + FREG_S ft7, sp, 15*SZFREG > + FREG_S ft8, sp, 16*SZFREG > + FREG_S ft9, sp, 17*SZFREG > + FREG_S ft10, sp, 18*SZFREG > + FREG_S ft11, sp, 19*SZFREG > + FREG_S ft12, sp, 20*SZFREG > + FREG_S ft13, sp, 21*SZFREG > + FREG_S ft14, sp, 22*SZFREG > + FREG_S ft15, sp, 23*SZFREG > + > +#endif /* #ifndef __loongarch_soft_float */ > + > +.Ltga: > + bl __tls_get_addr > + ADDI a0, a0, -TLS_DTV_OFFSET > + > +#ifndef __loongarch_soft_float > + > + la.global=C2=A0=C2=A0 t0, _rtld_global_ro > + REG_L t0, t0, GLRO_DL_HWCAP_OFFSET > + andi t0, t0, HWCAP_LOONGARCH_LASX > + beqz t0, .Llsx1 > + > + /* Restore 256-bit vector registers.=C2=A0 */ > + xvld xr0, sp, 0*SZXREG > + xvld xr1, sp, 1*SZXREG > + xvld xr2, sp, 2*SZXREG > + xvld xr3, sp, 3*SZXREG > + xvld xr4, sp, 4*SZXREG > + xvld xr5, sp, 5*SZXREG > + xvld xr6, sp, 6*SZXREG > + xvld xr7, sp, 7*SZXREG > + xvld xr8, sp, 8*SZXREG > + xvld xr9, sp, 9*SZXREG > + xvld xr10, sp, 10*SZXREG > + xvld xr11, sp, 11*SZXREG > + xvld xr12, sp, 12*SZXREG > + xvld xr13, sp, 13*SZXREG > + xvld xr14, sp, 14*SZXREG > + xvld xr15, sp, 15*SZXREG > + xvld xr16, sp, 16*SZXREG > + xvld xr17, sp, 17*SZXREG > + xvld xr18, sp, 18*SZXREG > + xvld xr19, sp, 19*SZXREG > + xvld xr20, sp, 20*SZXREG > + xvld xr21, sp, 21*SZXREG > + xvld xr22, sp, 22*SZXREG > + xvld xr23, sp, 23*SZXREG > + xvld xr24, sp, 24*SZXREG > + xvld xr25, sp, 25*SZXREG > + xvld xr26, sp, 26*SZXREG > + xvld xr27, sp, 27*SZXREG > + xvld xr28, sp, 28*SZXREG > + xvld xr29, sp, 29*SZXREG > + xvld xr30, sp, 30*SZXREG > + xvld xr31, sp, 31*SZXREG > + ADDI sp, sp, FRAME_SIZE_LASX > + b .Lfcsr > + > +.Llsx1: > + andi t0, s0, HWCAP_LOONGARCH_LSX > + beqz t0, .Lfloat1 > + > + /* Restore 128-bit vector registers.=C2=A0 */ > + vld vr0, sp, 0*SZVREG > + vld vr1, sp, 1*SZVREG > + vld vr2, sp, 2*SZVREG > + vld vr3, sp, 3*SZVREG > + vld vr4, sp, 4*SZVREG > + vld vr5, sp, 5*SZVREG > + vld vr6, sp, 6*SZVREG > + vld vr7, sp, 7*SZVREG > + vld vr8, sp, 8*SZVREG > + vld vr9, sp, 9*SZVREG > + vld vr10, sp, 10*SZVREG > + vld vr11, sp, 11*SZVREG > + vld vr12, sp, 12*SZVREG > + vld vr13, sp, 13*SZVREG > + vld vr14, sp, 14*SZVREG > + vld vr15, sp, 15*SZVREG > + vld vr16, sp, 16*SZVREG > + vld vr17, sp, 17*SZVREG > + vld vr18, sp, 18*SZVREG > + vld vr19, sp, 19*SZVREG > + vld vr20, sp, 20*SZVREG > + vld vr21, sp, 21*SZVREG > + vld vr22, sp, 22*SZVREG > + vld vr23, sp, 23*SZVREG > + vld vr24, sp, 24*SZVREG > + vld vr25, sp, 25*SZVREG > + vld vr26, sp, 26*SZVREG > + vld vr27, sp, 27*SZVREG > + vld vr28, sp, 28*SZVREG > + vld vr29, sp, 29*SZVREG > + vld vr30, sp, 30*SZVREG > + vld vr31, sp, 31*SZVREG > + ADDI sp, sp, FRAME_SIZE_LSX > + b =C2=A0=C2=A0=C2=A0 .Lfcsr > + > +.Lfloat1: > + /* Restore float registers.=C2=A0 */ > + FREG_L fa0, sp, 0*SZFREG > + FREG_L fa1, sp, 1*SZFREG > + FREG_L fa2, sp, 2*SZFREG > + FREG_L fa3, sp, 3*SZFREG > + FREG_L fa4, sp, 4*SZFREG > + FREG_L fa5, sp, 5*SZFREG > + FREG_L fa6, sp, 6*SZFREG > + FREG_L fa7, sp, 7*SZFREG > + FREG_L ft0, sp, 8*SZFREG > + FREG_L ft1, sp, 9*SZFREG > + FREG_L ft2, sp, 10*SZFREG > + FREG_L ft3, sp, 11*SZFREG > + FREG_L ft4, sp, 12*SZFREG > + FREG_L ft5, sp, 13*SZFREG > + FREG_L ft6, sp, 14*SZFREG > + FREG_L ft7, sp, 15*SZFREG > + FREG_L ft8, sp, 16*SZFREG > + FREG_L ft9, sp, 17*SZFREG > + FREG_L ft10, sp, 18*SZFREG > + FREG_L ft11, sp, 19*SZFREG > + FREG_L ft12, sp, 20*SZFREG > + FREG_L ft13, sp, 21*SZFREG > + FREG_L ft14, sp, 22*SZFREG > + FREG_L ft15, sp, 23*SZFREG > + ADDI sp, sp, FRAME_SIZE_FLOAT > + > +.Lfcsr: > + /* Restore fcsr0 register.=C2=A0 */ > + ld.w t0, sp, 0 > + movgr2fcsr=C2=A0 fcsr0, t0 > + ADDI sp, sp, SZFCSREG > + > +#endif /* #ifndef __loongarch_soft_float */ > + > + REG_L ra, sp, 0 > + REG_L a1, sp, 1 * 8 > + REG_L a2, sp, 2 * 8 > + REG_L a3, sp, 3 * 8 > + REG_L a4, sp, 4 * 8 > + REG_L a5, sp, 5 * 8 > + REG_L a6, sp, 6 * 8 > + REG_L a7, sp, 7 * 8 > + REG_L t4, sp, 8 * 8 > + REG_L t5, sp, 9 * 8 > + REG_L t6, sp, 10 * 8 > + REG_L t7, sp, 11 * 8 > + REG_L t8, sp, 12 * 8 > + ADDI sp, sp, FRAME_SIZE > + > + b .Lret > + cfi_endproc > + .size _dl_tlsdesc_dynamic, .-_dl_tlsdesc_dynamic > + > +#endif /* #ifdef SHARED */ > diff --git a/sysdeps/loongarch/dl-tlsdesc.h b/sysdeps/loongarch/dl-tlsdes= c.h > new file mode 100644 > index 0000000000..7444dac520 > --- /dev/null > +++ b/sysdeps/loongarch/dl-tlsdesc.h > @@ -0,0 +1,49 @@ > +/* Thread-local storage descriptor handling in the ELF dynamic linker. > +=C2=A0=C2=A0 LoongArch version. > +=C2=A0=C2=A0 Copyright (C) 2011-2023 Free Software Foundation, Inc. > + > +=C2=A0=C2=A0 This file is part of the GNU C Library. > + > +=C2=A0=C2=A0 The GNU C Library is free software; you can redistribute it= and/or > +=C2=A0=C2=A0 modify it under the terms of the GNU Lesser General Public > +=C2=A0=C2=A0 License as published by the Free Software Foundation; eithe= r > +=C2=A0=C2=A0 version 2.1 of the License, or (at your option) any later v= ersion. > + > +=C2=A0=C2=A0 The GNU C Library is distributed in the hope that it will b= e useful, > +=C2=A0=C2=A0 but WITHOUT ANY WARRANTY; without even the implied warranty= of > +=C2=A0=C2=A0 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.=C2=A0 = See the GNU > +=C2=A0=C2=A0 Lesser General Public License for more details. > + > +=C2=A0=C2=A0 You should have received a copy of the GNU Lesser General P= ublic > +=C2=A0=C2=A0 License along with the GNU C Library; if not, see > +=C2=A0=C2=A0 .=C2=A0 */ > + > +#ifndef _DL_TLSDESC_H > +#define _DL_TLSDESC_H > + > +#include > + > +/* Type used to represent a TLS descriptor in the GOT.=C2=A0 */ > +struct tlsdesc > +{ > +=C2=A0 ptrdiff_t (*entry) (struct tlsdesc *); > +=C2=A0 void *arg; > +}; > + > +/* Type used as the argument in a TLS descriptor for a symbol that > +=C2=A0=C2=A0 needs dynamic TLS offsets.=C2=A0 */ > +struct tlsdesc_dynamic_arg > +{ > +=C2=A0 tls_index tlsinfo; > +=C2=A0 size_t gen_count; > +}; > + > +extern ptrdiff_t attribute_hidden _dl_tlsdesc_return (struct tlsdesc *); > +extern ptrdiff_t attribute_hidden _dl_tlsdesc_undefweak (struct tlsdesc = *); > + > +#ifdef SHARED > +extern void *_dl_make_tlsdesc_dynamic (struct link_map *, size_t); > +extern ptrdiff_t attribute_hidden _dl_tlsdesc_dynamic (struct tlsdesc *)= ; > +#endif > + > +#endif > diff --git a/sysdeps/loongarch/linkmap.h b/sysdeps/loongarch/linkmap.h > index 4d8737ee7f..833dc9eb82 100644 > --- a/sysdeps/loongarch/linkmap.h > +++ b/sysdeps/loongarch/linkmap.h > @@ -18,5 +18,6 @@ > =C2=A0 > =C2=A0struct link_map_machine > =C2=A0{ > -=C2=A0 ElfW (Addr) plt; /* Address of .plt.=C2=A0 */ > +=C2=A0 ElfW (Addr) plt; /* Address of .plt.=C2=A0 */ > +=C2=A0 void *tlsdesc_table; /* Address of TLS descriptor hash table.=C2= =A0 */ > =C2=A0}; > diff --git a/sysdeps/loongarch/sys/asm.h b/sysdeps/loongarch/sys/asm.h > index 51521a7eb4..23c1d12914 100644 > --- a/sysdeps/loongarch/sys/asm.h > +++ b/sysdeps/loongarch/sys/asm.h > @@ -25,6 +25,7 @@ > =C2=A0/* Macros to handle different pointer/register sizes for 32/64-bit = code.=C2=A0 */ > =C2=A0#define SZREG 8 > =C2=A0#define SZFREG 8 > +#define SZFCSREG 4 > =C2=A0#define SZVREG 16 > =C2=A0#define SZXREG 32 > =C2=A0#define REG_L ld.d > diff --git a/sysdeps/loongarch/sys/regdef.h b/sysdeps/loongarch/sys/regde= f.h > index f61ee25b25..80ce3e9c00 100644 > --- a/sysdeps/loongarch/sys/regdef.h > +++ b/sysdeps/loongarch/sys/regdef.h > @@ -97,6 +97,7 @@ > =C2=A0#define fcc5 $fcc5 > =C2=A0#define fcc6 $fcc6 > =C2=A0#define fcc7 $fcc7 > +#define fcsr0 $fcsr0 > =C2=A0 > =C2=A0#define vr0 $vr0 > =C2=A0#define vr1 $vr1 > diff --git a/sysdeps/loongarch/tlsdesc.c b/sysdeps/loongarch/tlsdesc.c > new file mode 100644 > index 0000000000..4a3d5d22ef > --- /dev/null > +++ b/sysdeps/loongarch/tlsdesc.c > @@ -0,0 +1,39 @@ > +/* Manage TLS descriptors.=C2=A0 LoongArch64 version. > + > +=C2=A0=C2=A0 Copyright (C) 2011-2024 Free Software Foundation, Inc. > + > +=C2=A0=C2=A0 This file is part of the GNU C Library. > + > +=C2=A0=C2=A0 The GNU C Library is free software; you can redistribute it= and/or > +=C2=A0=C2=A0 modify it under the terms of the GNU Lesser General Public > +=C2=A0=C2=A0 License as published by the Free Software Foundation; eithe= r > +=C2=A0=C2=A0 version 2.1 of the License, or (at your option) any later v= ersion. > + > +=C2=A0=C2=A0 The GNU C Library is distributed in the hope that it will b= e useful, > +=C2=A0=C2=A0 but WITHOUT ANY WARRANTY; without even the implied warranty= of > +=C2=A0=C2=A0 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.=C2=A0 = See the GNU > +=C2=A0=C2=A0 Lesser General Public License for more details. > + > +=C2=A0=C2=A0 You should have received a copy of the GNU Lesser General P= ublic > +=C2=A0=C2=A0 License along with the GNU C Library; if not, see > +=C2=A0=C2=A0 .=C2=A0 */ > + > +#include > +#include > +#include > +#include > +#include > + > +/* Unmap the dynamic object, but also release its TLS descriptor table > +=C2=A0=C2=A0 if there is one.=C2=A0 */ > + > +void > +_dl_unmap (struct link_map *map) > +{ > +=C2=A0 _dl_unmap_segments (map); > + > +#ifdef SHARED > +=C2=A0 if (map->l_mach.tlsdesc_table) > +=C2=A0=C2=A0=C2=A0 htab_delete (map->l_mach.tlsdesc_table); > +#endif > +} > diff --git a/sysdeps/loongarch/tlsdesc.sym b/sysdeps/loongarch/tlsdesc.sy= m > new file mode 100644 > index 0000000000..a0b945e449 > --- /dev/null > +++ b/sysdeps/loongarch/tlsdesc.sym > @@ -0,0 +1,28 @@ > +#include > +#include > +#include > +#include > +#include > + > +#define SHARED 1 > + > +#include > + > +#define GLRO_offsetof(name) offsetof (struct rtld_global_ro, _##name) > + > +-- > + > +-- Abuse tls.h macros to derive offsets relative to the thread register. > + > +TLSDESC_ARG offsetof(struct tlsdesc, arg) > +TLSDESC_GEN_COUNT offsetof(struct tlsdesc_dynamic_arg, gen_count) > +TLSDESC_MODID offsetof(struct tlsdesc_dynamic_arg, tlsinfo.ti_module) > +TLSDESC_MODOFF offsetof(struct tlsdesc_dynamic_arg, tlsinfo.ti_offset) > +TCBHEAD_DTV offsetof(tcbhead_t, dtv) > +DTV_COUNTER offsetof(dtv_t, counter) > +TLS_DTV_UNALLOCATED TLS_DTV_UNALLOCATED > +TLS_DTV_OFFSET TLS_DTV_OFFSET > +SIZE_OF_DTV sizeof(tcbhead_t) > +GLRO_DL_HWCAP_OFFSET=C2=A0=C2=A0=C2=A0 GLRO_offsetof (dl_hwcap) > +HWCAP_LOONGARCH_LSX HWCAP_LOONGARCH_LSX > +HWCAP_LOONGARCH_LASX HWCAP_LOONGARCH_LASX > diff --git a/sysdeps/unix/sysv/linux/loongarch/localplt.data b/sysdeps/un= ix/sysv/linux/loongarch/localplt.data > index 547b1c1b7f..ec32e6d13f 100644 > --- a/sysdeps/unix/sysv/linux/loongarch/localplt.data > +++ b/sysdeps/unix/sysv/linux/loongarch/localplt.data > @@ -5,3 +5,5 @@ libc.so: calloc > =C2=A0libc.so: free > =C2=A0libc.so: malloc > =C2=A0libc.so: realloc > +# The dynamic loader needs __tls_get_addr for TLS. > +ld.so: __tls_get_addr --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University