[PATCH 1/8] bfd/aarch64-linux: Support reading and writing the GCS core file note

Luis Machado luis.machado@arm.com
Fri Jun 13 15:32:22 GMT 2025
Hi,

On 6/8/25 02:03, Thiago Jung Bauermann wrote:
> ---
>  bfd/elf.c            | 31 +++++++++++++++++++++++++++++++
>  include/elf/common.h |  3 +++
>  2 files changed, 34 insertions(+)
> 
> I just posted this patch to the binutils mailing list. I'm including it in
> this series for completeness.
> 
> diff --git a/bfd/elf.c b/bfd/elf.c
> index 3073f860621f..6a6b3f1bb9ee 100644
> --- a/bfd/elf.c
> +++ b/bfd/elf.c
> @@ -10629,6 +10629,15 @@ elfcore_grok_aarch_zt (bfd *abfd, Elf_Internal_Note *note)
>    return elfcore_make_note_pseudosection (abfd, ".reg-aarch-zt", note);
>  }
>  
> +/* Convert NOTE into a bfd_section called ".reg-aarch-gcs".  Return TRUE if
> +   successful, otherwise return FALSE.  */
> +
> +static bool
> +elfcore_grok_aarch_gcs (bfd *abfd, Elf_Internal_Note *note)
> +{
> +  return elfcore_make_note_pseudosection (abfd, ".reg-aarch-gcs", note);
> +}
> +
>  static bool
>  elfcore_grok_arc_v2 (bfd *abfd, Elf_Internal_Note *note)
>  {
> @@ -11372,6 +11381,12 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note)
>        else
>  	return true;
>  
> +    case NT_ARM_GCS:
> +      if (note->namesz == 6 && strcmp (note->namedata, "LINUX") == 0)
> +	return elfcore_grok_aarch_gcs (abfd, note);
> +      else
> +	return true;
> +
>      case NT_GDB_TDESC:
>        if (note->namesz == 4
>  	  && strcmp (note->namedata, "GDB") == 0)
> @@ -13042,6 +13057,20 @@ elfcore_write_aarch_zt (bfd *abfd,
>  			     size);
>  }
>  
> +/* Write the buffer of GCS register values in AARCH_GCS (length SIZE) into
> +   the note buffer BUF and update *BUFSIZ.  ABFD is the bfd the note is being
> +   written into.  Return a pointer to the new start of the note buffer, to
> +   replace BUF which may no longer be valid.  */
> +
> +static char *
> +elfcore_write_aarch_gcs (bfd *abfd, char *buf, int *bufsiz,
> +			 const void *aarch_gcs, int size)
> +{
> +  const char *note_name = "LINUX";
> +  return elfcore_write_note (abfd, buf, bufsiz, note_name, NT_ARM_GCS,
> +			     aarch_gcs, size);
> +}
> +
>  char *
>  elfcore_write_arc_v2 (bfd *abfd,
>  		      char *buf,
> @@ -13231,6 +13260,8 @@ elfcore_write_register_note (bfd *abfd,
>      return elfcore_write_aarch_za (abfd, buf, bufsiz, data, size);
>    if (strcmp (section, ".reg-aarch-zt") == 0)
>      return elfcore_write_aarch_zt (abfd, buf, bufsiz, data, size);
> +  if (strcmp (section, ".reg-aarch-gcs") == 0)
> +    return elfcore_write_aarch_gcs (abfd, buf, bufsiz, data, size);
>    if (strcmp (section, ".reg-arc-v2") == 0)
>      return elfcore_write_arc_v2 (abfd, buf, bufsiz, data, size);
>    if (strcmp (section, ".gdb-tdesc") == 0)
> diff --git a/include/elf/common.h b/include/elf/common.h
> index fd032d1e03ed..f4b543b353ac 100644
> --- a/include/elf/common.h
> +++ b/include/elf/common.h
> @@ -740,6 +740,9 @@
>  					/*   Note: name must be "LINUX".  */
>  #define NT_ARM_ZT       0x40d           /* AArch64 SME2 ZT registers.  */
>  					/*   Note: name must be "LINUX".  */
> +#define NT_ARM_GCS	0x410		/* AArch64 Guarded Control Stack
> +					   registers.  */
> +					/*   Note  name must be "LINUX".  */
>  #define NT_ARC_V2	0x600		/* ARC HS accumulator/extra registers.  */
>  					/*   note name must be "LINUX".  */
>  #define NT_LARCH_CPUCFG 0xa00		/* LoongArch CPU config registers */

Unrelated, but we might need to update these definitions based on the current Linux kernel list.

I see we have a couple entries before GCS. I'm not sure if we use these registers in userspace though.

#define NT_ARM_FPMR     0x40e           /* ARM floating point mode register */
#define NT_ARM_POE      0x40f           /* ARM POE registers */

The patch itself looks OK to me. But the binutils folks need to approve it (cc-ed).

Reviewed-By: Luis Machado <luis.machado@arm.com>


More information about the Binutils mailing list