From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1936) id 7FF493858C51; Tue, 3 May 2022 23:10:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7FF493858C51 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: John Baldwin To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Support TLS variables on FreeBSD/Aarch64. X-Act-Checkin: binutils-gdb X-Git-Author: John Baldwin X-Git-Refname: refs/heads/master X-Git-Oldrev: 0a765c1a8e9c59f4cd0cdaf986291f957fe6ee90 X-Git-Newrev: f9fbb7636a5b67abae41a35f02ae70f58523d375 Message-Id: <20220503231059.7FF493858C51@sourceware.org> Date: Tue, 3 May 2022 23:10:59 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 May 2022 23:10:59 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Df9fbb7636a5b= 67abae41a35f02ae70f58523d375 commit f9fbb7636a5b67abae41a35f02ae70f58523d375 Author: John Baldwin Date: Tue May 3 16:05:10 2022 -0700 Support TLS variables on FreeBSD/Aarch64. =20 Derive the pointer to the DTV array from the tpidr register. Diff: --- gdb/aarch64-fbsd-tdep.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/gdb/aarch64-fbsd-tdep.c b/gdb/aarch64-fbsd-tdep.c index ed1b84387f0..fdf0795b9bf 100644 --- a/gdb/aarch64-fbsd-tdep.c +++ b/gdb/aarch64-fbsd-tdep.c @@ -23,6 +23,7 @@ #include "fbsd-tdep.h" #include "aarch64-tdep.h" #include "aarch64-fbsd-tdep.h" +#include "inferior.h" #include "osabi.h" #include "solib-svr4.h" #include "target.h" @@ -180,6 +181,30 @@ aarch64_fbsd_core_read_description (struct gdbarch *gd= barch, return aarch64_read_description (0, false, false, tls !=3D nullptr); } =20 +/* Implement the get_thread_local_address gdbarch method. */ + +static CORE_ADDR +aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t pti= d, + CORE_ADDR lm_addr, CORE_ADDR offset) +{ + aarch64_gdbarch_tdep *tdep =3D (aarch64_gdbarch_tdep *) gdbarch_tdep (gd= barch); + struct regcache *regcache; + + regcache =3D get_thread_arch_regcache (current_inferior ()->process_targ= et (), + ptid, gdbarch); + + target_fetch_registers (regcache, tdep->tls_regnum); + + ULONGEST tpidr; + if (regcache->cooked_read (tdep->tls_regnum, &tpidr) !=3D REG_VALID) + error (_("Unable to fetch %%tpidr")); + + /* %tpidr points to the TCB whose first member is the dtv + pointer. */ + CORE_ADDR dtv_addr =3D tpidr; + return fbsd_get_thread_local_address (gdbarch, dtv_addr, lm_addr, offset= ); +} + /* Implement the 'init_osabi' method of struct gdb_osabi_handler. */ =20 static void @@ -202,6 +227,14 @@ aarch64_fbsd_init_abi (struct gdbarch_info info, struc= t gdbarch *gdbarch) (gdbarch, aarch64_fbsd_iterate_over_regset_sections); set_gdbarch_core_read_description (gdbarch, aarch64_fbsd_core_read_description); + + if (tdep->has_tls ()) + { + set_gdbarch_fetch_tls_load_module_address (gdbarch, + svr4_fetch_objfile_link_map); + set_gdbarch_get_thread_local_address + (gdbarch, aarch64_fbsd_get_thread_local_address); + } } =20 void _initialize_aarch64_fbsd_tdep ();