[PATCH v10 21/28] OAv2 merge: translate GNU properties to Object Attributes v2 (and vice versa)
Matthieu Longo
matthieu.longo@arm.com
Thu Nov 20 17:59:12 GMT 2025
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).
---
bfd/elf-attrs.c | 18 ++++++++++++++----
bfd/elf-bfd.h | 8 ++++++++
bfd/elfxx-target.h | 8 ++++++++
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/bfd/elf-attrs.c b/bfd/elf-attrs.c
index 81f2868964d..305794d3029 100644
--- a/bfd/elf-attrs.c
+++ b/bfd/elf-attrs.c
@@ -847,16 +847,26 @@ 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 (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 (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 same subsection.
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index dce8aad4f7c..51178686376 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -1663,6 +1663,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 051e9797c6b..c72f2e531a2 100644
--- a/bfd/elfxx-target.h
+++ b/bfd/elfxx-target.h
@@ -565,6 +565,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