Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb: Add support for TLS under RTEMS
@ 2026-04-22 15:18 Kinsey Moore
  2026-04-24  1:54 ` Kevin Buettner
  2026-04-28 15:43 ` Tom Tromey
  0 siblings, 2 replies; 3+ messages in thread
From: Kinsey Moore @ 2026-04-22 15:18 UTC (permalink / raw)
  To: gdb-patches; +Cc: Kinsey Moore

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: Add support for TLS under RTEMS
  2026-04-22 15:18 [PATCH] gdb: Add support for TLS under RTEMS Kinsey Moore
@ 2026-04-24  1:54 ` Kevin Buettner
  2026-04-28 15:43 ` Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Kevin Buettner @ 2026-04-24  1:54 UTC (permalink / raw)
  To: Kinsey Moore; +Cc: gdb-patches

On Wed, 22 Apr 2026 10:18:40 -0500
Kinsey Moore <kinsey.moore@oarcorp.com> wrote:

> 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.

[...]
> 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
[...]

> +#include "solib-svr4.h"

[...]

> +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); +}

Does (or will) RTEMS have SVR4 shared library support?  If not, then
the various references to solib-svr4 files and mechanisms should
be removed.

Kevin


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: Add support for TLS under RTEMS
  2026-04-22 15:18 [PATCH] gdb: Add support for TLS under RTEMS Kinsey Moore
  2026-04-24  1:54 ` Kevin Buettner
@ 2026-04-28 15:43 ` Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2026-04-28 15:43 UTC (permalink / raw)
  To: Kinsey Moore; +Cc: gdb-patches

>>>>> Kinsey Moore <kinsey.moore@oarcorp.com> writes:

> 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.

Thanks for the patch.

> +/* Target-dependent code for RTEMS, architecture independent.
> +
> +   Copyright (C) 2026 Kinsey Moore <kinsey.moore@oarcorp.com>

gdb requires copyright assignment to the FSF, so this line will have to
change.

I don't know if your company has a blanket assignment in place...  if
not we'll have to get you set up with an assignment.

You can email 'assign@gnu.org' and explain that you have a patch to gdb,
they will get you started.

> +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;
> +    }
> +  }

Brace placement is wrong here but the easiest thing to do is just remove
the extra braces.

gdb uses a space before paren for calls but you might as well also use
streq like

    if (streq (bfd_section_name (), "..."))

> +  if (arch_info == NULL) {
> +    return;
> +  }

Remove braces.  Also gdb has been moving to 'nullptr' rather than
'NULL'.

thanks,
Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-28 15:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-22 15:18 [PATCH] gdb: Add support for TLS under RTEMS Kinsey Moore
2026-04-24  1:54 ` Kevin Buettner
2026-04-28 15:43 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox