[PATCH v3 1/3] aarch64: ld: Fix scanning of GNU properties for AARCH64_FEATURE_1_AND

Yury Khrustalev yury.khrustalev@arm.com
Wed Apr 2 13:05:24 GMT 2025


Fixes [1]. Previously iteration over GNU properties of an input file
could stop before reaching GNU_PROPERTY_AARCH64_FEATURE_1_AND which
would result in incorrect inference of properties of the output file.

In the particular use case described in [1], the memory seal property
GNU_PROPERTY_MEMORY_SEAL with number 3, if present in the input file,
prevented reading information from GNU_PROPERTY_AARCH64_FEATURE_1_AND
property due to filtering by property number.

[1] PR32818 https://sourceware.org/bugzilla/show_bug.cgi?id=32818
---
 bfd/elfxx-aarch64.c | 31 +++++++++++--------------------
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c
index 45a02058e81..c8477d2f3d1 100644
--- a/bfd/elfxx-aarch64.c
+++ b/bfd/elfxx-aarch64.c
@@ -930,28 +930,19 @@ _bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *info)
      GNU properties (if found).  */
   bfd *pbfd = _bfd_elf_link_setup_gnu_properties (info);
 
-  /* If pbfd has any GNU_PROPERTY_AARCH64_FEATURE_1_AND properties, update
-     outprop accordingly.  */
   if (pbfd != NULL)
     {
-      /* The property list is sorted in order of type.  */
-      for (elf_property_list *p = elf_properties (pbfd);
-	   (p != NULL)
-	   && (GNU_PROPERTY_AARCH64_FEATURE_1_AND <= p->property.pr_type);
-	   p = p->next)
-	{
-	  /* This merge of features should happen only once as all the identical
-	     properties are supposed to have been merged at this stage by
-	     _bfd_elf_link_setup_gnu_properties().  */
-	  if (p->property.pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)
-	    {
-	      outprop = (p->property.u.number
-			 & (GNU_PROPERTY_AARCH64_FEATURE_1_BTI
-			  | GNU_PROPERTY_AARCH64_FEATURE_1_PAC
-			  | GNU_PROPERTY_AARCH64_FEATURE_1_GCS));
-	      break;
-	    }
-	}
+      elf_property_list *p, *plist = elf_properties (pbfd);
+
+      /* If pbfd has any GNU_PROPERTY_AARCH64_FEATURE_1_AND properties, update
+	 outprop accordingly.  */
+      if ((p = _bfd_elf_find_property (plist,
+				       GNU_PROPERTY_AARCH64_FEATURE_1_AND, NULL))
+				       != NULL)
+        outprop = p->property.u.number
+		  & (GNU_PROPERTY_AARCH64_FEATURE_1_BTI
+		     | GNU_PROPERTY_AARCH64_FEATURE_1_PAC
+		     | GNU_PROPERTY_AARCH64_FEATURE_1_GCS);
     }
 
   tdata->gnu_property_aarch64_feature_1_and = outprop;
-- 
2.39.5



More information about the Binutils mailing list