[PATCH] bfd: support for NT_386_TLS notes

Nick Clifton nickc@redhat.com
Thu Aug 14 12:08:24 GMT 2025


Hi Andrew,

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

The name is fine, as it is the patch itself - please go ahead an apply.

I do have a couple of suggestions for code improvement however, which
you might like to consider before committing:

> +static bool
> +elfcore_grok_i386_tls (bfd *abfd, Elf_Internal_Note *note)
> +{
> +  return elfcore_make_note_pseudosection (abfd, ".reg-i386-tls", note);
> +}

The ".reg-i386-tls" string is used several times.  It might be better
to replace this with a #define I386_TLS_SECTION_NAME (or some such) and
use that for consistency and ease of updating, should the section name
change.


> +	  && strcmp (note->namedata, "LINUX") == 0)

A similar comment could be made about the "LINUX" string, although
if you do make such a change there will be a lot more places that need
updating.


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

Do you really need to define the note_name local here ?  You could
just use the "LINUX" string in the call to elfcore_write_note().


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

I have always felt that 'strcmp() == 0' is a very confusing way to check
for string equality.  I prefer defining a macro "streq()" and using that.
This is just a personal preference however and again making this change
would mean updating a lot more code in the elf.c file.


Cheers
   Nick



More information about the Binutils mailing list