]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
aarch64: limit number of reported issues on missing GNU properties
authorMatthieu Longo <matthieu.longo@arm.com>
Tue, 5 Nov 2024 13:22:31 +0000 (13:22 +0000)
committerMatthieu Longo <matthieu.longo@arm.com>
Mon, 2 Dec 2024 15:18:40 +0000 (15:18 +0000)
This patch attempts to make the linker output more friendly for the
developers by limiting the number of emitted warning/error messages
related to BTI issues.

Every time an error/warning related to BTI is emitted, the logger
also increments the BTI issues counter. A batch of errors/warnings is
limited to a maximum of 20 explicit errors/warnings. At the end of
the merge, a summary of the total of errors/warning is given if the
number exceeds the limit of 20 invidual messages.

bfd/elfnn-aarch64.c
bfd/elfxx-aarch64.c
bfd/elfxx-aarch64.h

index 374b17a9eaa9d60e19faa9532e882fc829ee01e7..3a364e946b8b205b210dba025122662612dd1266 100644 (file)
@@ -5021,6 +5021,7 @@ bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
       |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI;
 
   elf_aarch64_tdata (output_bfd)->sw_protections = *sw_protections;
+  elf_aarch64_tdata (output_bfd)->n_bti_issues = 0;
 
   setup_plt_values (link_info, sw_protections->plt_type);
 }
index c01e0ab6599bc4fa02b9c69471d0bed86736eec7..67824805fe7fac4b01dc4c64f51d8efa66db0d61 100644 (file)
@@ -755,6 +755,30 @@ _bfd_aarch64_elf_create_gnu_property_section (struct bfd_link_info *info,
   elf_section_type (sec) = SHT_NOTE;
 }
 
+static const int GNU_PROPERTY_ISSUES_MAX = 20;
+
+/* Report a summary of the issues met during the merge of the GNU properties, if
+   the number of issues goes above GNU_PROPERTY_ISSUES_MAX.  */
+static void
+_bfd_aarch64_report_summary_merge_issues (struct bfd_link_info *info)
+{
+  const struct elf_aarch64_obj_tdata * tdata
+    = elf_aarch64_tdata (info->output_bfd);
+  aarch64_feature_marking_report bti_report = tdata->sw_protections.bti_report;
+
+  if (tdata->n_bti_issues > GNU_PROPERTY_ISSUES_MAX
+      && bti_report != MARKING_NONE)
+    {
+      const char *msg
+       = (tdata->sw_protections.bti_report == MARKING_ERROR)
+       ? _("%Xerror: found a total of %d inputs incompatible with "
+           "BTI requirements.\n")
+       : _("warning: found a total of %d inputs incompatible with "
+           "BTI requirements.\n");
+      info->callbacks->einfo (msg, tdata->n_bti_issues);
+    }
+}
+
 /* Find the first input bfd with GNU property and merge it with GPROP.  If no
    such input is found, add it to a new section at the last input.  Update
    GPROP accordingly.  */
@@ -825,6 +849,8 @@ _bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *info)
        }
     }
 
+  _bfd_aarch64_report_summary_merge_issues (info);
+
   tdata->gnu_property_aarch64_feature_1_and = outprop;
   return pbfd;
 }
@@ -966,6 +992,11 @@ _bfd_aarch64_elf_check_bti_report (struct bfd_link_info *info, bfd *ebfd)
   if (tdata->sw_protections.bti_report == MARKING_NONE)
     return;
 
+  ++tdata->n_bti_issues;
+
+  if (tdata->n_bti_issues > GNU_PROPERTY_ISSUES_MAX)
+    return;
+
   const char *msg
     = (tdata->sw_protections.bti_report == MARKING_WARN)
     ? _("%pB: warning: BTI turned on by -z force-bti on the output when all "
index f08b092c4deea9704af6e54ade178824297a37c7..48a2847bc5f7d76e44ef4a7485f5adee88696094 100644 (file)
@@ -84,6 +84,9 @@ struct elf_aarch64_obj_tdata
 
   /* Software protections options.  */
   struct aarch64_protection_opts sw_protections;
+
+  /* Number of reported BTI issues.  */
+  int n_bti_issues;
 };
 
 #define elf_aarch64_tdata(bfd)                         \