[PATCH v12 18/25] OAv2 merge: translate GNU properties to Object Attributes v2 (and vice versa)
Matthieu Longo
matthieu.longo@arm.com
Fri Jan 16 18:59:38 GMT 2026
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 | 21 +++++++++++++++++----
bfd/elf-bfd.h | 8 ++++++++
bfd/elfxx-target.h | 8 ++++++++
3 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/bfd/elf-attrs.c b/bfd/elf-attrs.c
index f35c4df0028..0acc3348a0c 100644
--- a/bfd/elf-attrs.c
+++ b/bfd/elf-attrs.c
@@ -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.
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index f2a417d079e..4e441331ec2 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -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 *);
diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h
index 04c1355455a..672daeccb04 100644
--- a/bfd/elfxx-target.h
+++ b/bfd/elfxx-target.h
@@ -566,6 +566,12 @@
#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,
--
2.52.0
More information about the Binutils
mailing list