From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id uETUJHtw8GeiGycAWB0awg (envelope-from ) for ; Fri, 04 Apr 2025 19:51:23 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=POUo+Zxp; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 937F81E0C3; Fri, 4 Apr 2025 19:51:23 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 1D0191E0C0 for ; Fri, 4 Apr 2025 19:51:23 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C6ACD384A854 for ; Fri, 4 Apr 2025 23:51:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C6ACD384A854 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=POUo+Zxp 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 AD5C2384D15B for ; Fri, 4 Apr 2025 23:44:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD5C2384D15B Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 AD5C2384D15B 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=1743810256; cv=none; b=cRD4g6pH3F75ytHiAcuP3zRqVzNJER4urLMUplTR9zT/8gZwXpU6TAZjfrf7L4Fg/v0ZWaOcTEeZ6BGV1ymEKjpljhsFDVeWnZ7JHaZgJFbW7PDBFglX1TnH5Tbq4Hnqqfk0zpmKtWWcojxjUZdvnzTIOQcy2K7uLjEDEZ52KnI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1743810256; c=relaxed/simple; bh=CRwR5XyGBdNIDznU+ki1PGNxFnsd2R/5oGBjzREz4Bs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=IddyV08yJetQsT25rrLdB4HnCVxmdNS9pKDEqa58GGH0M2URqZQZbJZ6Q/PzUPooOOvjGfyTcUKi9zm9xaFkfPUSfB1iTTs77J3KEwtZpM6HxrTozKzJcpfP5zX3yhvuOWbYbwYiqJ2lFLKxhFZyQijOdStt9skW9079ZMxoGC4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD5C2384D15B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1743810256; 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=76RjKbzBCs6Kl8KE5qA2HQvkyxTru5jiIcWCYlFzQA4=; b=POUo+ZxpUXN2IJ80mmHYmRBE64Wk0dg+K6gLraVNkdog7AoWC1+Zl7hHj6+EzWp47VmuDT aXx/K47NARfPq98KrLDianugfdB/aEQzk3M2/BeVeSpifgZ7pgydZv1Z+dAIBQcr3WwHRd m6hOYxm1OVZ9MvIz2iCSCI1jIeDg/y4= Received: from mx-prod-mc-01.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-318-k7qKa8p1MYKSjUzH-sYLlg-1; Fri, 04 Apr 2025 19:44:15 -0400 X-MC-Unique: k7qKa8p1MYKSjUzH-sYLlg-1 X-Mimecast-MFC-AGG-ID: k7qKa8p1MYKSjUzH-sYLlg_1743810254 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 66E3919560B7 for ; Fri, 4 Apr 2025 23:44:14 +0000 (UTC) Received: from f42-1.lan (unknown [10.22.88.7]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8E53F1955BC2; Fri, 4 Apr 2025 23:44:13 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Kevin Buettner Subject: [PATCH v6 06/11] Internal, but disabled, TLS support for i386 Date: Fri, 4 Apr 2025 16:37:37 -0700 Message-ID: <20250404234324.1931302-7-kevinb@redhat.com> In-Reply-To: <20250404234324.1931302-1-kevinb@redhat.com> References: <20250404234324.1931302-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ZX6zSy44fYuGy3sA_YH9ry4WlHJVbINB1UapwYwMoZM_1743810254 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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 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 | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c index 2b7bd2b521f..d90fd9a4307 100644 --- a/gdb/i386-linux-tdep.c +++ b/gdb/i386-linux-tdep.c @@ -1237,6 +1237,47 @@ i386_linux_displaced_step_copy_insn (struct gdbarch *gdbarch, return closure_; } +#if 0 +/* Disabled because fetching I386_GSBASE_REGNUM causes an internal + error. */ + +#include "svr4-tls-tdep.h" + +/* 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 svr4_tls_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_vector buf (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT); + if (target_read_memory (dtv_ptr_addr, buf.data (), buf.size ()) != 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.data ()); + return dtv_addr; +} +#endif + static void i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) { @@ -1472,6 +1513,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, + svr4_tls_get_thread_local_address); + svr4_tls_register_tls_methods (info, gdbarch, i386_linux_get_tls_dtv_addr); +#endif /* Core file support. */ set_gdbarch_iterate_over_regset_sections -- 2.48.1