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.
This commit is contained in:
Matthieu Longo
2024-11-05 13:22:31 +00:00
parent ddbd1a4c98
commit 82061f8093
3 changed files with 35 additions and 0 deletions

View 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);
}

View 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 "

View 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) \