]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
OAv2 merge: translate GNU properties to Object Attributes v2 (and vice versa)
authorMatthieu Longo <matthieu.longo@arm.com>
Wed, 12 Nov 2025 16:05:07 +0000 (16:05 +0000)
committerMatthieu Longo <matthieu.longo@arm.com>
Thu, 22 Jan 2026 10:11:17 +0000 (10:11 +0000)
Some input objects may contain inconsistencies, i.e. they might include
GNU properties but lack the corresponding object attributes, or inversely.
The later case is never produced by Gas, but the former can occur with
older Gas versions that do not support object attributes.

To keep consistency during the merge process, each input object's GNU
properties are translated into their object attributes equivalents (if
they exists). Also, after object attributes have been merged at the file
scope, they are translated back to GNU properties to keep the GNU
properties merge process consistent. This final translation occurs before
merging the input with the global merge accumulator (a.k.a. REF) and the
global configuration (a.k.a FROZEN).

Note: the first parameter of translate_obj_attrs_to_gnu_props(), bfd *,
should be 'const', but this implies that _bfd_elf_get_property() should
also be constified, and this is out of scope.

bfd/elf-attrs.c
bfd/elf-bfd.h
bfd/elfxx-target.h

index 010c6acaeb2204930f1d9e162dd69db2712acce9..03914169483b44312fcaae16b5513bc8931f5605 100644 (file)
@@ -820,16 +820,29 @@ create_object_attributes_section (struct bfd_link_info *info,
 static void
 oav2_translate_gnu_props_to_obj_attrs (const bfd *abfd)
 {
-  (void) abfd;
-  /* TO IMPLEMENT */
+  const struct elf_backend_data *be = get_elf_backend_data (abfd);
+  if (be->translate_gnu_props_to_obj_attrs == NULL)
+    return;
+
+  for (const elf_property_list *p = elf_properties (abfd);
+       p != NULL;
+       p = p->next)
+    be->translate_gnu_props_to_obj_attrs (abfd, p);
 }
 
 /* Translate object attributes v2 that have GNU properties equivalents.  */
 static void
 oav2_translate_obj_attrs_to_gnu_props (bfd *abfd)
 {
-  (void) abfd;
-  /* TO IMPLEMENT */
+  const struct elf_backend_data *be = get_elf_backend_data (abfd);
+  if (be->translate_obj_attrs_to_gnu_props == NULL)
+    return;
+
+  for (const obj_attr_subsection_v2_t *subsec
+        = elf_obj_attr_subsections (abfd).first;
+       subsec != NULL;
+       subsec = subsec->next)
+    be->translate_obj_attrs_to_gnu_props (abfd, subsec);
 }
 
 /* Compact duplicated tag declarations in a subsection.
index 3a1e867250d38754040fea478d176437c4a75751..f368986dd055486e1639ca322018459f53fcfe4d 100644 (file)
@@ -1673,6 +1673,14 @@ struct elf_backend_data
   /* The size of the array of known subsections.  */
   const size_t obj_attr_v2_known_subsections_size;
 
+  /* Translate GNU properties that have object attributes v2 equivalents.  */
+  void (*translate_gnu_props_to_obj_attrs) (const bfd *,
+    const elf_property_list *);
+
+  /* Translate object attributes v2 that have GNU properties equivalents.  */
+  void (*translate_obj_attrs_to_gnu_props) (bfd *,
+    const obj_attr_subsection_v2_t *);
+
   /* Get default value for an attribute.  */
   bool (*obj_attr_v2_default_value) (const struct bfd_link_info *,
     const obj_attr_info_t *, const obj_attr_subsection_v2_t *, obj_attr_v2_t *);
index 04c1355455a0694013c04c308d80882c3b6e59df..672daeccb047e9635451dd3c932d22a69fde1d7e 100644 (file)
 #ifndef elf_backend_obj_attr_v2_known_subsections_size
 #define elf_backend_obj_attr_v2_known_subsections_size 0
 #endif
+#ifndef elf_backend_translate_gnu_props_to_obj_attrs
+#define elf_backend_translate_gnu_props_to_obj_attrs   NULL
+#endif
+#ifndef elf_backend_translate_obj_attrs_to_gnu_props
+#define elf_backend_translate_obj_attrs_to_gnu_props   NULL
+#endif
 #ifndef elf_backend_obj_attr_v2_default_value
 #define elf_backend_obj_attr_v2_default_value  NULL
 #endif
@@ -957,6 +963,8 @@ static const struct elf_backend_data elfNN_bed =
   elf_backend_obj_attrs_version_enc,
   elf_backend_obj_attr_v2_known_subsections,
   elf_backend_obj_attr_v2_known_subsections_size,
+  elf_backend_translate_gnu_props_to_obj_attrs,
+  elf_backend_translate_obj_attrs_to_gnu_props,
   elf_backend_obj_attr_v2_default_value,
   elf_backend_obj_attr_v2_merge,
   elf_backend_obj_attrs_order,