[PATCH 2/4] RISC-V: Add GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS and GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED

Nelson Chu nelson@rivosinc.com
Tue Jun 10 06:15:49 GMT 2025


Looks good, thanks.  Will commit after all series are reviewed.

Nelson

On Thu, May 15, 2025 at 7:04 PM Kito Cheng <kito.cheng@sifive.com> wrote:

> This patch adds two new GNU properties for RISC-V:
> GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS and
> GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED.
>
> We only add readelf and define the properties in this patch.
>
> Ref: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/417
> ---
>  binutils/readelf.c                            | 39 ++++++++++++++++++
>  .../riscv/property-cfi-lp-unlabeled.d         |  8 ++++
>  .../binutils-all/riscv/property-cfi-ss.d      |  8 ++++
>  .../testsuite/binutils-all/riscv/property.s   | 41 +++++++++++++++++++
>  include/elf/common.h                          |  5 +++
>  5 files changed, 101 insertions(+)
>  create mode 100644
> binutils/testsuite/binutils-all/riscv/property-cfi-lp-unlabeled.d
>  create mode 100644 binutils/testsuite/binutils-all/riscv/property-cfi-ss.d
>  create mode 100644 binutils/testsuite/binutils-all/riscv/property.s
>
> diff --git a/binutils/readelf.c b/binutils/readelf.c
> index dd1871d8c75..77a88bff032 100644
> --- a/binutils/readelf.c
> +++ b/binutils/readelf.c
> @@ -21287,6 +21287,33 @@ decode_aarch64_feature_1_and (unsigned int
> bitmask)
>      }
>  }
>
> +static void
> +decode_riscv_feature_1_and (unsigned int bitmask)
> +{
> +  while (bitmask)
> +    {
> +      unsigned int bit = bitmask & (- bitmask);
> +
> +      bitmask &= ~ bit;
> +      switch (bit)
> +       {
> +       case GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED:
> +         printf ("CFI_LP_UNLABELED");
> +         break;
> +
> +       case GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS:
> +         printf ("CFI_SS");
> +         break;
> +
> +       default:
> +         printf (_("<unknown: %x>"), bit);
> +         break;
> +       }
> +      if (bitmask)
> +       printf (", ");
> +    }
> +}
> +
>  static void
>  decode_1_needed (unsigned int bitmask)
>  {
> @@ -21477,6 +21504,18 @@ print_gnu_property_note (Filedata * filedata,
> Elf_Internal_Note * pnote)
>                   goto next;
>                 }
>             }
> +         else if (filedata->file_header.e_machine == EM_RISCV)
> +           {
> +             if (type == GNU_PROPERTY_RISCV_FEATURE_1_AND)
> +               {
> +                 printf ("RISC-V AND feature: ");
> +                 if (datasz != 4)
> +                   printf (_("<corrupt length: %#x> "), datasz);
> +                 else
> +                   decode_riscv_feature_1_and (byte_get (ptr, 4));
> +                 goto next;
> +               }
> +           }
>         }
>        else
>         {
> diff --git
> a/binutils/testsuite/binutils-all/riscv/property-cfi-lp-unlabeled.d
> b/binutils/testsuite/binutils-all/riscv/property-cfi-lp-unlabeled.d
> new file mode 100644
> index 00000000000..396b4cda7c2
> --- /dev/null
> +++ b/binutils/testsuite/binutils-all/riscv/property-cfi-lp-unlabeled.d
> @@ -0,0 +1,8 @@
> +#as: -defsym __property_zicfilp_unlabeled__=1 -march=rv64i -mabi=lp64
> +#readelf: -n
> +#source: property.s
> +
> +Displaying notes found in: .note.gnu.property
> +[      ]+Owner[        ]+Data size[    ]+Description
> +[      ]+GNU[  ]+0x00000010[   ]+NT_GNU_PROPERTY_TYPE_0
> +[      ]+Properties: RISC-V AND feature: CFI_LP_UNLABELED
> diff --git a/binutils/testsuite/binutils-all/riscv/property-cfi-ss.d
> b/binutils/testsuite/binutils-all/riscv/property-cfi-ss.d
> new file mode 100644
> index 00000000000..5bc844aed73
> --- /dev/null
> +++ b/binutils/testsuite/binutils-all/riscv/property-cfi-ss.d
> @@ -0,0 +1,8 @@
> +#as: -defsym __property_zicfiss__=1 -march=rv64i -mabi=lp64
> +#readelf: -n
> +#source: property.s
> +
> +Displaying notes found in: .note.gnu.property
> +[      ]+Owner[        ]+Data size[    ]+Description
> +[      ]+GNU[  ]+0x00000010[   ]+NT_GNU_PROPERTY_TYPE_0
> +[      ]+Properties: RISC-V AND feature: CFI_SS
> diff --git a/binutils/testsuite/binutils-all/riscv/property.s
> b/binutils/testsuite/binutils-all/riscv/property.s
> new file mode 100644
> index 00000000000..1b6265499f5
> --- /dev/null
> +++ b/binutils/testsuite/binutils-all/riscv/property.s
> @@ -0,0 +1,41 @@
> +       .text
> +       .globl _start
> +       .type _start,@function
> +_start:
> +    ret
> +
> +.ifdef __property_zicfilp_unlabeled__
> +       .section ".note.gnu.property", "a"
> +       .p2align 3
> +       .long 1f - 0f           /* name length */
> +       .long 5f - 2f           /* data length */
> +       .long 5                 /* note type */
> +0:     .asciz "GNU"            /* vendor name */
> +1:
> +       .p2align 3
> +2:     .long 0xc0000000        /* pr_type.  */
> +       .long 4f - 3f           /* pr_datasz.  */
> +3:
> +       .long 0x1               /*
> GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED.  */
> +4:
> +       .p2align 3
> +5:
> +.endif
> +
> +.ifdef __property_zicfiss__
> +       .section ".note.gnu.property", "a"
> +       .p2align 3
> +       .long 1f - 0f           /* name length */
> +       .long 5f - 2f           /* data length */
> +       .long 5                 /* note type */
> +0:     .asciz "GNU"            /* vendor name */
> +1:
> +       .p2align 3
> +2:     .long 0xc0000000        /* pr_type.  */
> +       .long 4f - 3f           /* pr_datasz.  */
> +3:
> +       .long 0x2               /* GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS.  */
> +4:
> +       .p2align 3
> +5:
> +.endif
> diff --git a/include/elf/common.h b/include/elf/common.h
> index fd032d1e03e..01812b48caa 100644
> --- a/include/elf/common.h
> +++ b/include/elf/common.h
> @@ -1041,6 +1041,11 @@
>  #define GNU_PROPERTY_AARCH64_FEATURE_1_PAC     (1U << 1)
>  #define GNU_PROPERTY_AARCH64_FEATURE_1_GCS     (1U << 2)
>
> +/* RISC-V specific GNU PROPERTY. */
> +#define GNU_PROPERTY_RISCV_FEATURE_1_AND       0xc0000000
> +#define GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED  (1U << 0)
> +#define GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS            (1U << 1)
> +
>  /* Values used in GNU .note.ABI-tag notes (NT_GNU_ABI_TAG).  */
>  #define GNU_ABI_TAG_LINUX      0
>  #define GNU_ABI_TAG_HURD       1
> --
> 2.34.1
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20250610/d51587fe/attachment-0001.htm>


More information about the Binutils mailing list