Matthieu Longo <matthieu.lo...@arm.com> writes:
> GNU properties are emitted to provide some information about the features
> used in the generated code like BTI, GCS, or PAC. However, no debug
> comment are emitted in the generated assembly even if -dA is provided.
> It makes understanding the information stored in the .note.gnu.property
> section more difficult than needed.
>
> This patch adds assembly comments (if -dA is provided) next to the GNU
> properties. For instance, if BTI and PAC are enabled, it will emit:
>   .word  0x3  // GNU_PROPERTY_AARCH64_FEATURE_1_AND (BTI, PAC)
>
> gcc/ChangeLog:
>
>       * config/aarch64/aarch64.cc
>       (aarch64_file_end_indicate_exec_stack): Emit assembly comments.
>
> gcc/testsuite/ChangeLog:
>
>       * gcc.target/aarch64/bti-1.c: Emit assembly comments, and update
>       test assertion.

OK, thanks.

Richard

> ---
>  gcc/config/aarch64/aarch64.cc            | 35 ++++++++++++++++++++++--
>  gcc/testsuite/gcc.target/aarch64/bti-1.c | 13 +++++----
>  2 files changed, 40 insertions(+), 8 deletions(-)
>
> diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
> index 59ac08483f4..bc6e16ce807 100644
> --- a/gcc/config/aarch64/aarch64.cc
> +++ b/gcc/config/aarch64/aarch64.cc
> @@ -30028,10 +30028,41 @@ aarch64_file_end_indicate_exec_stack ()
>        type   = GNU_PROPERTY_AARCH64_FEATURE_1_AND
>        datasz = 4
>        data   = feature_1_and.  */
> -      assemble_integer (GEN_INT (GNU_PROPERTY_AARCH64_FEATURE_1_AND), 4, 32, 
> 1);
> +      fputs (integer_asm_op (4, true), asm_out_file);
> +      fprint_whex (asm_out_file, GNU_PROPERTY_AARCH64_FEATURE_1_AND);
> +      putc ('\n', asm_out_file);
>        assemble_integer (GEN_INT (4), 4, 32, 1);
> -      assemble_integer (GEN_INT (feature_1_and), 4, 32, 1);
>  
> +      fputs (integer_asm_op (4, true), asm_out_file);
> +      fprint_whex (asm_out_file, feature_1_and);
> +      if (flag_debug_asm)
> +     {
> +       struct flag_name
> +       {
> +         unsigned int mask;
> +         const char *name;
> +       };
> +       static const flag_name flags[] = {
> +         { GNU_PROPERTY_AARCH64_FEATURE_1_BTI, "BTI" },
> +         { GNU_PROPERTY_AARCH64_FEATURE_1_PAC, "PAC" },
> +         { GNU_PROPERTY_AARCH64_FEATURE_1_GCS, "GCS" },
> +       };
> +
> +       const char *separator = "";
> +       std::string s_features;
> +       for (auto &flag : flags)
> +         if (feature_1_and & flag.mask)
> +           {
> +             s_features.append (separator).append (flag.name);
> +             separator = ", ";
> +           }
> +
> +       asm_fprintf (asm_out_file,
> +                    "\t%s GNU_PROPERTY_AARCH64_FEATURE_1_AND (%s)\n",
> +                    ASM_COMMENT_START, s_features.c_str ());
> +     }
> +      else
> +     putc ('\n', asm_out_file);
>        /* Pad the size of the note to the required alignment.  */
>        assemble_align (POINTER_SIZE);
>      }
> diff --git a/gcc/testsuite/gcc.target/aarch64/bti-1.c 
> b/gcc/testsuite/gcc.target/aarch64/bti-1.c
> index 5a556b08ed1..53dc2d3cd8b 100644
> --- a/gcc/testsuite/gcc.target/aarch64/bti-1.c
> +++ b/gcc/testsuite/gcc.target/aarch64/bti-1.c
> @@ -1,6 +1,6 @@
>  /* { dg-do compile } */
>  /* -Os to create jump table.  */
> -/* { dg-options "-Os" } */
> +/* { dg-options "-Os -dA" } */
>  /* { dg-require-effective-target lp64 } */
>  /* If configured with --enable-standard-branch-protection, don't use
>     command line option.  */
> @@ -44,8 +44,8 @@ f_jump_table (int y, int n)
>    return (y == 0)? y+1:4;
>  }
>  /* f_jump_table should have PACIASP and AUTIASP.  */
> -/* { dg-final { scan-assembler-times "hint\t25" 1 } } */
> -/* { dg-final { scan-assembler-times "hint\t29" 1 } } */
> +/* { dg-final { scan-assembler-times "hint\t25 // paciasp" 1 } } */
> +/* { dg-final { scan-assembler-times "hint\t29 // autiasp" 1 } } */
>  
>  int
>  f_label_address ()
> @@ -59,6 +59,7 @@ lab2:
>    addr = &&lab1;
>    return 2;
>  }
> -/* { dg-final { scan-assembler-times "hint\t34" 1 } } */
> -/* { dg-final { scan-assembler-times "hint\t36" 12 } } */
> -/* { dg-final { scan-assembler ".note.gnu.property" { target *-*-linux* } } 
> } */
> +/* { dg-final { scan-assembler-times "hint\t34 // bti c" 1 } } */
> +/* { dg-final { scan-assembler-times "hint\t36 // bti j" 12 } } */
> +/* { dg-final { scan-assembler "\.section\t\.note\.gnu\.property" { target 
> *-*-linux* } } } */
> +/* { dg-final { scan-assembler "\.word\t0x7\t\/\/ 
> GNU_PROPERTY_AARCH64_FEATURE_1_AND \\(BTI, PAC, GCS\\)" { target *-*-linux* } 
> } } */
> \ No newline at end of file

Reply via email to