[PATCH v1 09/14] bfd: add support for copying Object Attributes v2
Matthieu Longo
matthieu.longo@arm.com
Fri Mar 21 17:14:43 GMT 2025
The OAv2 section's content of the source file is copied to the
destination object file without any alteration of the attributes
or subsections (no deduplication nor sorting of subsections or
object attributes is performed).
For now, only ELF format is supported.
---
bfd/elf-attrs.c | 41 ++++++++++++++++++++++++++++++++++-------
1 file changed, 34 insertions(+), 7 deletions(-)
diff --git a/bfd/elf-attrs.c b/bfd/elf-attrs.c
index 5f1cf5cbb1a..b1be9472645 100644
--- a/bfd/elf-attrs.c
+++ b/bfd/elf-attrs.c
@@ -541,9 +541,9 @@ bfd_elf_add_obj_attr_int_string (bfd *abfd, int vendor, unsigned int tag,
return elf_add_obj_attr_int_string (abfd, vendor, tag, i, s, NULL);
}
-/* Copy the object attributes from IBFD to OBFD. */
-void
-_bfd_elf_copy_obj_attributes (bfd *ibfd, bfd *obfd)
+/* Copy object attributes v1 from IBFD to OBFD. */
+static void
+_bfd_elf_copy_obj_attributes_v1 (bfd *ibfd, bfd *obfd)
{
obj_attribute *in_attr;
obj_attribute *out_attr;
@@ -551,10 +551,6 @@ _bfd_elf_copy_obj_attributes (bfd *ibfd, bfd *obfd)
int i;
int vendor;
- if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
- || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
- return;
-
for (vendor = OBJ_ATTR_FIRST; vendor <= OBJ_ATTR_LAST; vendor++)
{
in_attr
@@ -604,6 +600,37 @@ _bfd_elf_copy_obj_attributes (bfd *ibfd, bfd *obfd)
}
}
+/* Copy object attributes v2 from IBFD to OBFD. */
+static void
+_bfd_elf_copy_obj_attributes_v2 (bfd *ibfd, bfd *obfd)
+{
+ obj_attr_subsection_list *in_attr_subsecs = &elf_obj_attr_subsections (ibfd);
+ obj_attr_subsection_list *out_attr_subsecs = &elf_obj_attr_subsections (obfd);
+
+ for (obj_attr_subsection_v2* isubsec = in_attr_subsecs->first_;
+ isubsec != NULL;
+ isubsec = isubsec->next)
+ {
+ obj_attr_subsection_v2* osubsec =
+ _bfd_elf_obj_attr_subsection_v2_copy (isubsec);
+ LINKED_LIST_APPEND(obj_attr_subsection_v2) (out_attr_subsecs, osubsec);
+ }
+}
+
+/* Copy the object attributes from IBFD to OBFD. */
+void
+_bfd_elf_copy_obj_attributes (bfd *ibfd, bfd *obfd)
+{
+ if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
+ || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
+ return;
+
+ if (get_elf_backend_data (ibfd)->obj_attrs_version == 2)
+ _bfd_elf_copy_obj_attributes_v2 (ibfd, obfd);
+ else
+ _bfd_elf_copy_obj_attributes_v1 (ibfd, obfd);
+}
+
/* Determine whether a GNU object attribute tag takes an integer, a
string or both. */
static int
--
2.49.0
More information about the Binutils
mailing list