[PATCH v11 09/25] bfd: add support for copying Object Attributes v2
Matthieu Longo
matthieu.longo@arm.com
Tue Dec 30 23:05:10 GMT 2025
More information about the Binutils mailing list
Tue Dec 30 23:05:10 GMT 2025
- Previous message (by thread): [PATCH v11 08/25] bfd: parse Object Attributes v2's section in input object files
- Next message (by thread): [PATCH v11 10/25] objcopy tests for Object Attributes v2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 | 68 ++++++++++++++++++++++++++++++++++++++-----------
bfd/elf-bfd.h | 2 --
2 files changed, 53 insertions(+), 17 deletions(-)
diff --git a/bfd/elf-attrs.c b/bfd/elf-attrs.c
index 13c4386b55e..8873b3d888d 100644
--- a/bfd/elf-attrs.c
+++ b/bfd/elf-attrs.c
@@ -763,9 +763,9 @@ bfd_elf_add_obj_attr_int_string (bfd *abfd,
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
+oav1_copy_attributes (bfd *ibfd, bfd *obfd)
{
obj_attribute *in_attr;
obj_attribute *out_attr;
@@ -773,16 +773,6 @@ _bfd_elf_copy_obj_attributes (bfd *ibfd, bfd *obfd)
int i;
obj_attr_vendor_t vendor;
- if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
- || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
- return;
-
- obj_attr_version_t version = elf_obj_attr_version (ibfd);
- elf_obj_attr_version (obfd) = version;
-
- if (version == OBJ_ATTR_VERSION_NONE)
- return;
-
for (vendor = OBJ_ATTR_FIRST; vendor <= OBJ_ATTR_LAST; vendor++)
{
in_attr
@@ -832,6 +822,54 @@ _bfd_elf_copy_obj_attributes (bfd *ibfd, bfd *obfd)
}
}
+static obj_attr_subsection_v2_t *
+oav2_obj_attr_subsection_v2_copy (const obj_attr_subsection_v2_t *);
+
+/* Copy object attributes v2 from IBFD to OBFD. */
+static void
+oav2_copy_attributes (bfd *ibfd, bfd *obfd)
+{
+ const obj_attr_subsection_list_t *in_attr_subsecs
+ = &elf_obj_attr_subsections (ibfd);
+ obj_attr_subsection_list_t *out_attr_subsecs
+ = &elf_obj_attr_subsections (obfd);
+
+ for (const obj_attr_subsection_v2_t *isubsec = in_attr_subsecs->first;
+ isubsec != NULL;
+ isubsec = isubsec->next)
+ {
+ obj_attr_subsection_v2_t *osubsec
+ = oav2_obj_attr_subsection_v2_copy (isubsec);
+ LINKED_LIST_APPEND(obj_attr_subsection_v2_t) (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;
+
+ obj_attr_version_t version = elf_obj_attr_version (ibfd);
+ elf_obj_attr_version (obfd) = version;
+
+ switch (version)
+ {
+ case OBJ_ATTR_VERSION_NONE:
+ break;
+ case OBJ_ATTR_V1:
+ oav1_copy_attributes (ibfd, obfd);
+ break;
+ case OBJ_ATTR_V2:
+ oav2_copy_attributes (ibfd, obfd);
+ break;
+ default:
+ abort ();
+ }
+}
+
/* Determine whether a GNU object attribute tag takes an integer, a
string or both. */
static int
@@ -1599,8 +1637,8 @@ _bfd_elf_obj_attr_subsection_v2_free (obj_attr_subsection_v2_t *subsec)
/* Deep copy an object attribute subsection OTHER, and return a pointer to the
copy. */
-obj_attr_subsection_v2_t *
-_bfd_elf_obj_attr_subsection_v2_copy (const obj_attr_subsection_v2_t *other)
+static obj_attr_subsection_v2_t *
+oav2_obj_attr_subsection_v2_copy (const obj_attr_subsection_v2_t *other)
{
obj_attr_subsection_v2_t *new_subsec
= bfd_elf_obj_attr_subsection_v2_init (xstrdup (other->name), other->scope,
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 980bd39bf23..cada0a675f2 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -3208,8 +3208,6 @@ extern obj_attr_subsection_v2_t *bfd_elf_obj_attr_subsection_v2_init
(const char*, obj_attr_subsection_scope_v2_t, bool, obj_attr_encoding_v2_t);
extern void _bfd_elf_obj_attr_subsection_v2_free (obj_attr_subsection_v2_t *)
ATTRIBUTE_HIDDEN;
-extern obj_attr_subsection_v2_t *_bfd_elf_obj_attr_subsection_v2_copy
- (const obj_attr_subsection_v2_t *) ATTRIBUTE_HIDDEN;
extern int _bfd_elf_obj_attr_subsection_v2_cmp
(const obj_attr_subsection_v2_t *, const obj_attr_subsection_v2_t *)
ATTRIBUTE_HIDDEN;
--
2.52.0
- Previous message (by thread): [PATCH v11 08/25] bfd: parse Object Attributes v2's section in input object files
- Next message (by thread): [PATCH v11 10/25] objcopy tests for Object Attributes v2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list