[PATCH] bfd: support for NT_386_TLS notes

Andrew Burgess aburgess@redhat.com
Thu Jul 31 14:28:23 GMT 2025


In a later commit I'd like to add support to GDB for including the
NT_386_TLS note in the core files that GDB creates (using 'gcore'
command).

To achieve this we need some standard boilerplate code added to bfd.

The only part of this patch which I think needs consideration is the
name I selected for the pseudo section to hold the note contents when
a core file is loaded.  I chose '.reg-i386-tls'.  The '.reg' prefix is
the standard used by most other pseudo sections, and the '-i386-tls'
suffix seemed to match the note name, though I added the 'i' to
'i386', instead of just using '.reg-386-tls'.  I thought 'i386' seemed
clearer.

There's no test included here, but when I merge the NT_386_TLS
creation to GDB it will depend on this and act as a test.  I plan to
post that work to the GDB list once this patch is merged.
---
 bfd/elf-bfd.h |  2 ++
 bfd/elf.c     | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index b7916239737..f8f147e7509 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -2927,6 +2927,8 @@ extern char *elfcore_write_xstatereg
   (bfd *, char *, int *, const void *, int);
 extern char *elfcore_write_x86_segbases
   (bfd *, char *, int *, const void *, int);
+extern char *elfcore_write_i386_tls
+  (bfd *, char *, int *, const void *, int);
 extern char *elfcore_write_ppc_vmx
   (bfd *, char *, int *, const void *, int);
 extern char *elfcore_write_ppc_vsx
diff --git a/bfd/elf.c b/bfd/elf.c
index dfa04c9268d..bb5e842cb7c 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -10673,6 +10673,12 @@ elfcore_grok_gdb_tdesc (bfd *abfd, Elf_Internal_Note *note)
   return elfcore_make_note_pseudosection (abfd, ".gdb-tdesc", note);
 }
 
+static bool
+elfcore_grok_i386_tls (bfd *abfd, Elf_Internal_Note *note)
+{
+  return elfcore_make_note_pseudosection (abfd, ".reg-i386-tls", note);
+}
+
 static bool
 elfcore_grok_loongarch_cpucfg (bfd *abfd, Elf_Internal_Note *note)
 {
@@ -11336,6 +11342,13 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note)
       else
 	return true;
 
+    case NT_386_TLS:
+      if (note->namesz == 6
+	  && strcmp (note->namedata, "LINUX") == 0)
+	return elfcore_grok_i386_tls (abfd, note);
+      else
+	return true;
+
     case NT_ARM_HW_BREAK:
       if (note->namesz == 6
 	  && strcmp (note->namedata, "LINUX") == 0)
@@ -12593,6 +12606,15 @@ elfcore_write_x86_segbases (bfd *abfd, char *buf, int *bufsiz,
 			     note_name, NT_FREEBSD_X86_SEGBASES, regs, size);
 }
 
+char *
+elfcore_write_i386_tls (bfd *abfd, char *buf, int *bufsiz,
+			    const void *regs, int size)
+{
+  char *note_name = "LINUX";
+  return elfcore_write_note (abfd, buf, bufsiz,
+			     note_name, NT_386_TLS, regs, size);
+}
+
 char *
 elfcore_write_ppc_vmx (bfd *abfd,
 		       char *buf,
@@ -13287,6 +13309,8 @@ elfcore_write_register_note (bfd *abfd,
     return elfcore_write_loongarch_lsx (abfd, buf, bufsiz, data, size);
   if (strcmp (section, ".reg-loongarch-lasx") == 0)
     return elfcore_write_loongarch_lasx (abfd, buf, bufsiz, data, size);
+  if (strcmp (section, ".reg-i386-tls") == 0)
+    return elfcore_write_i386_tls (abfd, buf, bufsiz, data, size);
   return NULL;
 }
 

base-commit: c7c272f06d2d456d1d99762325fd0dd7db31d540
-- 
2.47.1



More information about the Binutils mailing list