From: Kevin Buettner <kevinb@redhat.com>
To: gdb-patches@sourceware.org
Cc: Kevin Buettner <kevinb@redhat.com>
Subject: [PATCH v6 06/11] Internal, but disabled, TLS support for i386
Date: Fri, 4 Apr 2025 16:37:37 -0700 [thread overview]
Message-ID: <20250404234324.1931302-7-kevinb@redhat.com> (raw)
In-Reply-To: <20250404234324.1931302-1-kevinb@redhat.com>
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
next prev parent reply other threads:[~2025-04-04 23:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-04 23:37 [PATCH v6 00/11] GDB-internal TLS support for Linux targets Kevin Buettner
2025-04-04 23:37 ` [PATCH v6 01/11] Don't attempt to find TLS address when target has no registers Kevin Buettner
2025-04-04 23:37 ` [PATCH v6 02/11] Allow TLS access to work in gdb.server/no-thread-db.exp Kevin Buettner
2025-04-04 23:37 ` [PATCH v6 03/11] Track and fetch TLS module ids for MUSL and GLIBC Kevin Buettner
2025-04-04 23:37 ` [PATCH v6 04/11] Implement internal TLS address lookup for select Linux targets Kevin Buettner
2025-04-04 23:37 ` [PATCH v6 05/11] Internal TLS support for aarch64, x86_64, riscv, ppc64, and s390x Kevin Buettner
2025-04-04 23:37 ` Kevin Buettner [this message]
2025-04-04 23:37 ` [PATCH v6 07/11] Delete disabled i386 internal TLS support Kevin Buettner
2025-04-04 23:37 ` [PATCH v6 08/11] New test - gdb.base/tls-nothreads.exp Kevin Buettner
2025-04-04 23:37 ` [PATCH v6 09/11] New test - gdb.base/tls-multiobj.exp Kevin Buettner
2025-04-04 23:37 ` [PATCH v6 10/11] New test - gdb.base/tls-dlobj.exp Kevin Buettner
2025-04-04 23:37 ` [PATCH v6 11/11] Add TLS NEWS entry and document 'set force-internal-tls-address-lookup' command Kevin Buettner
2025-04-18 18:36 ` [PATCH v6 00/11] GDB-internal TLS support for Linux targets Kevin Buettner
2025-04-22 15:03 ` Tom Tromey
2025-04-23 14:12 ` Luis Machado
2025-04-23 22:14 ` Kevin Buettner
2025-04-24 6:34 ` Luis Machado
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250404234324.1931302-7-kevinb@redhat.com \
--to=kevinb@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox