]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: add debug comments to feature properties in .note.gnu.property
authorMatthieu Longo <matthieu.longo@arm.com>
Mon, 23 Sep 2024 13:38:57 +0000 (14:38 +0100)
committerMatthieu Longo <matthieu.longo@arm.com>
Mon, 16 Jun 2025 09:13:45 +0000 (10:13 +0100)
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.

gcc/config/aarch64/aarch64.cc
gcc/testsuite/gcc.target/aarch64/bti-1.c

index c8977b5a9481c33c89b18d643c0d8d4c47594484..f2c9322da584864f980350386cac885283cdcc4a 100644 (file)
@@ -30006,10 +30006,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);
     }
index 5a556b08ed15679b25676a11fe9c7a64641ee671..53dc2d3cd8b27b9bcb8644d5774ddc41ccbfb2f5 100644 (file)
@@ -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