[PATCH v1 17/27] aarch64: refactoring _bfd_aarch64_elf_check_bti_report

Matthieu Longo matthieu.longo@arm.com
Mon Dec 2 14:22:09 GMT 2024


Before this patch, warnings were reported normally, and errors
(introduced by a previous patch adding '-z bti-report' option)
were logged as error but were not provoking a link failure.
The root of the issue was a misuse of _bfd_error_handler to
report the errors.
Replacing _bfd_error_handler by info->callbacks->einfo, with the
addition of the formatter '%X' for errors fixed the issue.
---
 bfd/elfnn-aarch64.c |  4 ++--
 bfd/elfxx-aarch64.c | 17 +++++++++--------
 bfd/elfxx-aarch64.h |  2 +-
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 482ce6aac24..374b17a9eaa 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -10636,9 +10636,9 @@ elfNN_aarch64_merge_gnu_properties (struct bfd_link_info *info,
 	  && (bti_report != MARKING_NONE))
 	{
 	  if (!aprop || !(aprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI))
-	    _bfd_aarch64_elf_check_bti_report (bti_report, abfd);
+	    _bfd_aarch64_elf_check_bti_report (info, abfd);
 	  if (!bprop || !(bprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI))
-	    _bfd_aarch64_elf_check_bti_report (bti_report, bbfd);
+	    _bfd_aarch64_elf_check_bti_report (info, bbfd);
 	}
     }
 
diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c
index 5d2c9e9d30c..df62ec12e85 100644
--- a/bfd/elfxx-aarch64.c
+++ b/bfd/elfxx-aarch64.c
@@ -927,18 +927,19 @@ _bfd_aarch64_elf_link_fixup_gnu_properties
 
 /* Check AArch64 BTI report.  */
 void
-_bfd_aarch64_elf_check_bti_report (aarch64_feature_marking_report bti_report,
-				   bfd *ebfd)
+_bfd_aarch64_elf_check_bti_report (struct bfd_link_info *info, bfd *ebfd)
 {
-  if (bti_report == MARKING_NONE)
+  struct elf_aarch64_obj_tdata *tdata = elf_aarch64_tdata (info->output_bfd);
+
+  if (tdata->sw_protections.bti_report == MARKING_NONE)
     return;
 
   const char *msg
-    = (bti_report == MARKING_WARN)
+    = (tdata->sw_protections.bti_report == MARKING_WARN)
     ? _("%pB: warning: BTI turned on by -z force-bti on the output when all "
-	"inputs do not have BTI in NOTE section.")
-    : _("%pB: error: BTI turned on by -z force-bti on the output when all "
-	"inputs do not have BTI in NOTE section.");
+	"inputs do not have BTI in NOTE section.\n")
+    : _("%X%pB: error: BTI turned on by -z force-bti on the output when all "
+	"inputs do not have BTI in NOTE section.\n");
 
-  _bfd_error_handler (msg, ebfd);
+  info->callbacks->einfo (msg, ebfd);
 }
\ No newline at end of file
diff --git a/bfd/elfxx-aarch64.h b/bfd/elfxx-aarch64.h
index 8302654eeff..f08b092c4de 100644
--- a/bfd/elfxx-aarch64.h
+++ b/bfd/elfxx-aarch64.h
@@ -191,7 +191,7 @@ _bfd_aarch64_elf_merge_gnu_properties (struct bfd_link_info *, bfd *,
 				       uint32_t);
 
 extern void
-_bfd_aarch64_elf_check_bti_report (aarch64_feature_marking_report, bfd *);
+_bfd_aarch64_elf_check_bti_report (struct bfd_link_info *, bfd *);
 
 extern void
 _bfd_aarch64_elf_link_fixup_gnu_properties (struct bfd_link_info *,
-- 
2.47.0



More information about the Binutils mailing list