aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorMatthieu Longo <matthieu.longo@arm.com>2024-11-05 13:22:31 +0000
committerMatthieu Longo <matthieu.longo@arm.com>2024-12-02 15:18:40 +0000
commit82061f8093f1ddd5bb26708de6be220315460ff9 (patch)
treec48c264ac6e4c28e09df31a47154b59d519e86e5 /bfd
parentddbd1a4c98794de8a66d86dcfd8139e7a25088d2 (diff)
downloadbinutils-82061f8093f1ddd5bb26708de6be220315460ff9.zip
binutils-82061f8093f1ddd5bb26708de6be220315460ff9.tar.gz
binutils-82061f8093f1ddd5bb26708de6be220315460ff9.tar.bz2
aarch64: limit number of reported issues on missing GNU properties
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.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/elfnn-aarch64.c1
-rw-r--r--bfd/elfxx-aarch64.c31
-rw-r--r--bfd/elfxx-aarch64.h3
3 files changed, 35 insertions, 0 deletions
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 374b17a..3a364e9 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 c01e0ab..6782480 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 f08b092..48a2847 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) \