From patchwork Fri Oct 25 02:26:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 99524 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 234AC3858435 for ; Fri, 25 Oct 2024 03:38:31 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 44C873858C78 for ; Fri, 25 Oct 2024 03:35:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 44C873858C78 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 44C873858C78 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729827319; cv=none; b=L90mn7m2M0ydKoiCkP1PJstAcH8TZMbWwJXSLgGRYwm46jhHjPZeTVKz7lU0DOp8NCq5uHsR/sJbnutug19erh3QK5tR3fXWDEypm1bbcCG9mZb5RKfedKvpZCnf1t0chV5qtwF41pZO4IrtdoGzJfiu4pm+uk4C1FhK7s9vGPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729827319; c=relaxed/simple; bh=2QqkLm6bDwRAOSzZITbwve82TIOa+YZXcMvOMLtTaz0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xPz4TGqNr2jMsSTKtazQ/k7b2j2RB6KJUTxRZ5QgnFFg4I6MJ8558DvbT6Yau9GX/48x2UaJ8YmQL3Q9JmpNrhE7ifprZZT7xUgErTK2HPSP59TU+p5Q0nBgpLkWiIXZXHDCtCr8lHOmGCftSE2ObK21b8o0ThrPLeaD+tdglUw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729827309; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VI5P22AmzOdpr+wG9HWWjsmFqVC9Ff5bAy++P8/+9AY=; b=ZhPBN6wB7YCDMoY4DrZnSYjM5IPyXVWrg2AmA/iYlvMNsWnbsIOWEPCYtuP5Q2GiXiWfdr eTGOehIFJnga+WCRtLSSU8HJQ70HYqI2FRAOcfHEO6JVjbcvGbagsNfsf4kQvFwkvdWDbh bQU9+W0UOOoHBO3bLQv3eZaMxCYJ/Dk= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-88-tUQHWD5bNWWNZlDjFIwCJQ-1; Thu, 24 Oct 2024 23:35:07 -0400 X-MC-Unique: tUQHWD5bNWWNZlDjFIwCJQ-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0F5F3195608A for ; Fri, 25 Oct 2024 03:35:07 +0000 (UTC) Received: from f41-1.lan (unknown [10.22.64.38]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3750C300018D; Fri, 25 Oct 2024 03:35:06 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Kevin Buettner Subject: [PATCH v3 06/11] Internal, but disabled, TLS support for i386 Date: Thu, 24 Oct 2024 19:26:24 -0700 Message-ID: <20241025033431.36274-7-kevinb@redhat.com> In-Reply-To: <20241025033431.36274-1-kevinb@redhat.com> References: <20241025033431.36274-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org This commit shows how internal TLS address lookup support could be implemented for the i386 target. Unfortunately, it doesn't work due to I386_GSBASE_REGNUM being unavailable for Linux targets. I looked at trying to access the gsbase register via PTRACE_GET_THREAD_AREA, but did not understand it well enough to finish it. Since the i386 target is much less important than it used to be, I gave up working on it. I don't want to leave this disabled code in our sources, so I will delete it in the next commit, however, this commit will be in our git repo, so it'll be available for someone with sufficient interest in the i386 target to look at. --- gdb/i386-linux-tdep.c | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c index 9dec83ac753..8e9ffe984a3 100644 --- a/gdb/i386-linux-tdep.c +++ b/gdb/i386-linux-tdep.c @@ -753,6 +753,45 @@ i386_linux_displaced_step_copy_insn (struct gdbarch *gdbarch, return closure_; } +#if 0 +/* Disabled because fetching I386_GSBASE_REGNUM causes an internal + error. */ + +/* Fetch and return the TLS DTV (dynamic thread vector) address for PTID. + Throw a suitable TLS error if something goes wrong. */ + +static CORE_ADDR +i386_linux_get_tls_dtv_addr (struct gdbarch *gdbarch, ptid_t ptid, + enum linux_libc libc) +{ + /* On i386, the thread pointer is found in the gsbase register. */ + regcache *regcache + = get_thread_arch_regcache (current_inferior (), ptid, gdbarch); + target_fetch_registers (regcache, I386_GSBASE_REGNUM); + ULONGEST gsbase; + if (regcache->cooked_read (I386_GSBASE_REGNUM, &gsbase) != REG_VALID) + throw_error (TLS_GENERIC_ERROR, _("Unable to fetch thread pointer")); + + /* The thread pointer (gsbase) points at the TCB (thread control + block). The first two members of this struct are both pointers, + where the first will be a pointer to the TCB (i.e. it points at + itself) and the second will be a pointer to the DTV (dynamic + thread vector). There are many other fields too, but the one + we care about here is the DTV pointer. Compute the address + of the DTV pointer, fetch it, and convert it to an address. */ + CORE_ADDR dtv_ptr_addr + = gsbase + gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT; + gdb_byte buf[gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT]; + if (target_read_memory (dtv_ptr_addr, buf, sizeof buf) != 0) + throw_error (TLS_GENERIC_ERROR, _("Unable to fetch DTV address")); + + const struct builtin_type *builtin = builtin_type (gdbarch); + CORE_ADDR dtv_addr = gdbarch_pointer_to_address + (gdbarch, builtin->builtin_data_ptr, buf); + return dtv_addr; +} +#endif + static void i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) { @@ -988,6 +1027,11 @@ i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) /* Enable TLS support. */ set_gdbarch_fetch_tls_load_module_address (gdbarch, svr4_fetch_objfile_link_map); +#if 0 + set_gdbarch_get_thread_local_address (gdbarch, + linux_get_thread_local_address); + linux_register_tls_methods (info, gdbarch, i386_linux_get_tls_dtv_addr); +#endif /* Core file support. */ set_gdbarch_iterate_over_regset_sections