Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kinsey Moore <kinsey.moore@oarcorp.com>
To: gdb-patches@sourceware.org
Cc: Kinsey Moore <kinsey.moore@oarcorp.com>
Subject: [PATCH] gdb: Add support for TLS under RTEMS
Date: Wed, 22 Apr 2026 10:18:40 -0500	[thread overview]
Message-ID: <20260422151840.661343-1-kinsey.moore@oarcorp.com> (raw)

This support uses the presence of the ".rtemsroset" section to detect
whether an ELF was created using RTEMS. This works for current RTEMS
development (7) branch, 6 branch, 5 branch, and 4.11 branch. This
registers the TLS callback for architectures under which RTEMS is known
to support TLS. The RTEMS self-hosted GDB server is only expected to
support TLS in RTEMS 6 branch and the current development branch and
will only respond without error to qGetTLSAddr request in those
versions. Other GDB servers will respond with TLS information if
available.
---
 gdb/Makefile.in      |  2 ++
 gdb/configure.tgt    |  2 ++
 gdb/rtems-tdep.c     | 82 ++++++++++++++++++++++++++++++++++++++++++++
 gdbsupport/osabi.def |  1 +
 4 files changed, 87 insertions(+)
 create mode 100644 gdb/rtems-tdep.c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index e38ba95eebd..b7a2c9c777d 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -874,6 +874,7 @@ ALL_TARGET_OBS = \
 	rs6000-aix-tdep.o \
 	rs6000-lynx178-tdep.o \
 	rs6000-tdep.o \
+	rtems-tdep.o \
 	rx-tdep.o \
 	s12z-tdep.o \
 	s390-linux-tdep.o \
@@ -1938,6 +1939,7 @@ ALLDEPFILES = \
 	rs6000-aix-nat.c \
 	rs6000-lynx178-tdep.c \
 	rs6000-tdep.c \
+	rtems-tdep.c \
 	rx-tdep.c \
 	s390-linux-nat.c \
 	s390-linux-tdep.c \
diff --git a/gdb/configure.tgt b/gdb/configure.tgt
index ba418653e86..05160714069 100644
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -128,6 +128,8 @@ case "${targ}" in
 	os_obs="netbsd-tdep.o solib-svr4.o";;
 *-*-openbsd*)
 	os_obs="obsd-tdep.o solib-svr4.o";;
+*-rtems*)
+	os_obs="rtems-tdep.o solib-svr4.o";;
 esac
 
 # 3. Get the rest of objects.
diff --git a/gdb/rtems-tdep.c b/gdb/rtems-tdep.c
new file mode 100644
index 00000000000..b384352ffea
--- /dev/null
+++ b/gdb/rtems-tdep.c
@@ -0,0 +1,82 @@
+/* Target-dependent code for RTEMS, architecture independent.
+
+   Copyright (C) 2026 Kinsey Moore <kinsey.moore@oarcorp.com>
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "arch-utils.h"
+#include "gdbarch-gen.h"
+#include "osabi.h"
+#include "solib-svr4.h"
+
+/* Sniffer to detect RTEMS via section names. */
+
+static enum gdb_osabi
+rtems_osabi_sniffer (bfd *abfd)
+{
+  for (asection *sect : gdb_bfd_sections (abfd)) {
+    if (strcmp(bfd_section_name (sect), ".rtemsroset") == 0) {
+      return GDB_OSABI_RTEMS;
+    }
+  }
+
+  return GDB_OSABI_UNKNOWN;
+}
+
+/* Configure TLS ABI for RTEMS. */
+
+static void
+rtems_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
+{
+  set_gdbarch_fetch_tls_load_module_address (gdbarch,
+					     svr4_fetch_objfile_link_map);
+}
+
+/* Register OSABI components for RTEMS. */
+
+static void
+register_osabi (enum bfd_architecture arch, unsigned long machine)
+{
+  const struct bfd_arch_info *arch_info = bfd_lookup_arch (arch, machine);
+
+  if (arch_info == NULL) {
+    return;
+  }
+
+  gdbarch_register_osabi_sniffer (arch, bfd_target_elf_flavour,
+				  rtems_osabi_sniffer);
+  gdbarch_register_osabi (arch, machine, GDB_OSABI_RTEMS, rtems_init_abi);
+}
+
+/* Initializer for RTEMS TLS support across all relevant architectures. */
+
+void _initialize_rtems_tdep ();
+void
+_initialize_rtems_tdep ()
+{
+  /* mips, moxie, and or1k are supported by RTEMS, but omitted here since they
+     do not have TLS support in RTEMS. */
+
+  register_osabi (bfd_arch_arm, 0);
+  register_osabi (bfd_arch_aarch64, 0);
+  register_osabi (bfd_arch_i386, 0);
+  register_osabi (bfd_arch_m68k, 0);
+  register_osabi (bfd_arch_microblaze, 0);
+  register_osabi (bfd_arch_powerpc, 0);
+  register_osabi (bfd_arch_riscv, 0);
+  register_osabi (bfd_arch_sparc, 0);
+  register_osabi (bfd_arch_i386, bfd_mach_x86_64);
+}
diff --git a/gdbsupport/osabi.def b/gdbsupport/osabi.def
index 230c21f0236..1b518887eff 100644
--- a/gdbsupport/osabi.def
+++ b/gdbsupport/osabi.def
@@ -53,5 +53,6 @@ GDB_OSABI_DEF (LYNXOS178, "LynxOS178", nullptr)
 GDB_OSABI_DEF (NEWLIB, "Newlib", nullptr)
 GDB_OSABI_DEF (SDE, "SDE", nullptr)
 GDB_OSABI_DEF (PIKEOS, "PikeOS", nullptr)
+GDB_OSABI_DEF (RTEMS, "RTEMS", ".*-rtems.*")
 
 GDB_OSABI_DEF_LAST (INVALID, "<invalid>", nullptr)
-- 
2.47.3


             reply	other threads:[~2026-04-22 15:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-22 15:18 Kinsey Moore [this message]
2026-04-24  1:54 ` Kevin Buettner
2026-04-28 15:43 ` Tom Tromey

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=20260422151840.661343-1-kinsey.moore@oarcorp.com \
    --to=kinsey.moore@oarcorp.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