From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2d/FEy/YVGr2HQYAWB0awg (envelope-from ) for ; Mon, 13 Jul 2026 08:21:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1783945263; bh=C3TnO1aT+VOXC1ZFTp5S1+Od4JZQQJw0hDALsu/AdhE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=LZy9BEm66cZ/Qhx/BnMm0ysmtfSkNO9vosiwNRvhSsd+EtduduTseWzRxX4V3KZi5 ifZxPMF0kGoGAgNI9ovYqJloaZr15PdE6IC22NuM4cj0ypPLNGl46K1vWX1Xp3K2iR 16y0ockJvTwQyNHCVpjZ3fGD091x32i9K9SezlfA= Received: by simark.ca (Postfix, from userid 112) id 4C5CA1E09B; Mon, 13 Jul 2026 08:21:03 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=R8KogKFX; dkim-atps=neutral Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 840711E033 for ; Mon, 13 Jul 2026 08:21:02 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AAE574BA2E19 for ; Mon, 13 Jul 2026 12:21:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AAE574BA2E19 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=R8KogKFX Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id CFAE24BA2E25 for ; Mon, 13 Jul 2026 12:20:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CFAE24BA2E25 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CFAE24BA2E25 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783945238; cv=none; b=Ue+bVyt2Lgc8iFeTPh86EdEgPx88Cspyzeuy1IAKCxHlBTAP6J5s8+84fIu947S6utRMrLs/t6wDo43Mhg9uf6Ibfj1fS1XCQ9o+Azjtn6qbwJxFqXF2bUpCQz4nxJJ6HWuYHpxAUxT/5QND6l0TbN8QfmwxVPHisDnC2wbqZs4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783945238; c=relaxed/simple; bh=C3TnO1aT+VOXC1ZFTp5S1+Od4JZQQJw0hDALsu/AdhE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=MW8q05KpGu85TKBVczdJMFMrXLPeajg+wAlyka1lFFOGSNNpigYlehx1s+eoaustsxsTGVhVFX3sSMRScuz887KVGxfLH1NN6ZRgwHabjHpVtsIo8l2k/wtZFw/Sh5dXh4iw7heZYpdRrBlbfsg/H0AhmuMSMPPIjQOdvoJ/c1s= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=R8KogKFX DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CFAE24BA2E25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1783945236; bh=C3TnO1aT+VOXC1ZFTp5S1+Od4JZQQJw0hDALsu/AdhE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=R8KogKFXiIiIcUAqYG/XxVrg6yEFmaFipA6dpwDsfcIWu22i7lPTYqdTW+nGbQRxF UE+XfIIdj3SnZAYiRiU6gB5drhh8N+7kLUzI/wFtC2qqlLTDFlM6/7fdjOhMhLC7sQ krrd0tEYqNr+DwFT9dlIl6kXRU+O3i9IFBZ01eAw= Received: by simark.ca (Postfix) id E118B1E033; Mon, 13 Jul 2026 08:20:35 -0400 (EDT) Message-ID: <7894b01a-9ff6-4796-badb-048f45c4566e@simark.ca> Date: Mon, 13 Jul 2026 08:20:34 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb: LoongArch: Add internal TLS support To: Hui Li , gdb-patches@sourceware.org Cc: Tiezhu Yang References: <20260713103724.7713-1-lihui@loongson.cn> Content-Language: fr From: Simon Marchi In-Reply-To: <20260713103724.7713-1-lihui@loongson.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On 7/13/26 6:37 AM, Hui Li wrote: > Implements the LoongArch-specific get_tls_dtv_addr() and uses > svr4_tls_register_tls_methods() to register it, together with > svr4_tls_get_thread_local_address as the get_thread_local_address > gdbarch method, to support internal TLS address lookup. > > LoongArch doesn't need get_tls_dtp_offset since musl's DTP_OFFSET > is defined as 0. > > This is the LoongArch version of commit c34309bea22 > ("Internal TLS support for aarch64, x86_64, riscv, ppc64, and s390x"). > > Depends-On: bfc3ac0d13b > ("LoongArch: Support R_LARCH_TLS_DTPREL32/64 used in debug section") > > Before: > > make check-gdb TESTS="gdb.base/tls-nothreads.exp" > === gdb Summary === > > # of expected passes 101 > # of known failures 48 > > make check-gdb TESTS="gdb.base/tls-dlobj.exp" > === gdb Summary === > > # of expected passes 261 > > After: > > make check-gdb TESTS="gdb.base/tls-nothreads.exp" > === gdb Summary === > > # of expected passes 302 > > make check-gdb TESTS="gdb.base/tls-dlobj.exp" > === gdb Summary === > > # of expected passes 523 > > Signed-off-by: Hui Li Great, thanks. I compared the implementation to Aarch64, and it's very similar, so it looks reasonable to me. One nit below: > @@ -1137,6 +1138,57 @@ init_loongarch_linux_record_tdep (struct gdbarch *gdbarch) > loongarch_linux_record_tdep.arg7 = LOONGARCH_A0_REGNUM + 6; > } > > +/* Fetch and return the TLS DTV (dynamic thread vector) address for PTID. > + Throw a suitable TLS error if something goes wrong. */ > + > +static CORE_ADDR > +loongarch_linux_get_tls_dtv_addr (struct gdbarch *gdbarch, ptid_t ptid, > + svr4_tls_libc libc) > +{ > + /* On LoongArch, the thread pointer is found in TP. */ > + regcache *regcache > + = get_thread_arch_regcache (current_inferior (), ptid, gdbarch); > + target_fetch_registers (regcache, LOONGARCH_TP_REGNUM); > + ULONGEST thr_ptr; > + if (regcache->cooked_read (LOONGARCH_TP_REGNUM, &thr_ptr) != REG_VALID) > + throw_error (TLS_GENERIC_ERROR, _("Unable to fetch thread pointer")); > + > + CORE_ADDR dtv_ptr_addr; > + switch (libc) > + { > + case svr4_tls_libc_musl: > + /* MUSL: The DTV pointer is found at the very end of the pthread > + struct which is located *before* the thread pointer. I.e. > + the thread pointer will be just beyond the end of the struct, > + so the address of the DTV pointer is found one pointer-size > + before the thread pointer. */ > + dtv_ptr_addr = thr_ptr - (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT); > + break; > + case svr4_tls_libc_glibc: > + /* GLIBC: The thread pointer (TP) points just beyond the end of > + the TCB (thread control block). On LoongArch, this struct > + (tcbhead_t) is defined to contain two pointers. The first is > + a pointer to the DTV and the second is a pointer to private > + data. So the DTV pointer address is found two pointer-size > + before thread pointer. */ > + > + dtv_ptr_addr = thr_ptr - 2 * (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT); Remove empty line above. With, this: Approved-By: Simon Marchi Simon