]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
aarch64: ld: Fix scanning of GNU properties for AARCH64_FEATURE_1_AND
authorYury Khrustalev <yury.khrustalev@arm.com>
Thu, 27 Mar 2025 16:48:24 +0000 (16:48 +0000)
committerYury Khrustalev <yury.khrustalev@arm.com>
Thu, 17 Apr 2025 11:34:01 +0000 (12:34 +0100)
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

index 45a02058e814a572d82f65409dac53bc01cf55b3..68e004ef7cbeb514ef38b38a4307642dd9d0f65e 100644 (file)
@@ -930,28 +930,20 @@ _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;
+      elf_property_list *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;