[PATCH v1 24/27] aarch64: limit number of reported issues on missing GNU properties
Matthieu Longo
matthieu.longo@arm.com
Mon Dec 2 14:22:16 GMT 2024
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 | 1 +
bfd/elfxx-aarch64.c | 31 +++++++++++++++++++++++++++++++
bfd/elfxx-aarch64.h | 3 +++
3 files changed, 35 insertions(+)
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 374b17a9eaa..3a364e946b8 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -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);
}
diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c
index c01e0ab6599..67824805fe7 100644
--- a/bfd/elfxx-aarch64.c
+++ b/bfd/elfxx-aarch64.c
@@ -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 "
diff --git a/bfd/elfxx-aarch64.h b/bfd/elfxx-aarch64.h
index f08b092c4de..48a2847bc5f 100644
--- a/bfd/elfxx-aarch64.h
+++ b/bfd/elfxx-aarch64.h
@@ -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) \
--
2.47.0
More information about the Binutils
mailing list