[binutils-gdb] OAv2 merge: find first input containing an object attributes section
Matthieu Longo
mlongo@sourceware.org
Thu Jan 22 10:13:01 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ff37837d6be1150b9a627d7ac6bb6aa79a4368d6
commit ff37837d6be1150b9a627d7ac6bb6aa79a4368d6
Author: Matthieu Longo <matthieu.longo@arm.com>
Date: Fri Nov 14 15:36:44 2025 +0000
OAv2 merge: find first input containing an object attributes section
During the merge process, the linker first scans the list of input files
to identify ELF object files that contain object attributes. If no such
object file is found, the merge process terminates. Otherwise, the first
matching file is used as the placeholder for the global merge result.
This patch implements a linear search to locate the first input BFD
containing an Object Attributes section, while recording a good candidate
otherwise.
It is worth noting that the position of the object file in the list, as
well as whether it contains object attributes or not, or whether it
contains an object attributes section or not, are not significant. Any
input ELF object files could serve this placeholder purpose if the merge
process was performed in parallel.
Diff:
---
bfd/elf-attrs.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 42 insertions(+), 2 deletions(-)
diff --git a/bfd/elf-attrs.c b/bfd/elf-attrs.c
index 6c32eb3f59c..b9b8abd5017 100644
--- a/bfd/elf-attrs.c
+++ b/bfd/elf-attrs.c
@@ -736,6 +736,41 @@ typedef struct
asection *sec;
} bfd_search_result_t;
+/* Checks whether a BFD contains object attributes, and if so search for the
+ relevant section storing them. The name and type of the section have to
+ match with what the backend expects, i.e. elf_backend_obj_attrs_section and
+ elf_backend_obj_attrs_section_type, otherwise the object attributes section
+ won't be recognized as such, and will be skipped.
+ Return True if an object attribute section is found, False otherwise. */
+static bool
+input_bfd_has_object_attributes (const struct bfd_link_info *info,
+ bfd *abfd,
+ bfd_search_result_t *res)
+{
+ /* The file may contain object attributes. Save this candidate. */
+ res->pbfd = abfd;
+
+ if (elf_obj_attr_subsections (abfd).size == 0)
+ return false;
+
+ res->has_object_attributes = true;
+
+ uint32_t sec_type = get_elf_backend_data (abfd)->obj_attrs_section_type;
+ const char *sec_name = get_elf_backend_data (abfd)->obj_attrs_section;
+ res->sec = bfd_get_section_by_name (abfd, sec_name);
+ if (res->sec != NULL)
+ {
+ if (elf_section_type (res->sec) != sec_type)
+ {
+ info->callbacks->minfo
+ (_("%X%pB: warning: ignoring section '%s' with unexpected type %#x\n"),
+ abfd, sec_name, elf_section_type (res->sec));
+ res->sec = NULL;
+ }
+ }
+ return (res->sec != NULL);
+}
+
/* Search for the first input object file containing object attributes.
If no such object is found, the result structure's PBFD points to the
last object file that could have contained object attributes. The
@@ -745,9 +780,14 @@ typedef struct
static bfd_search_result_t
bfd_linear_find_first_with_obj_attrs (const struct bfd_link_info *info)
{
- (void) info;
- /* TO IMPLEMENT */
bfd_search_result_t res = { .has_object_attributes = false };
+ for (bfd *abfd = info->input_bfds; abfd != NULL; abfd = abfd->link.next)
+ {
+ if (oav2_relevant_elf_object (info, abfd)
+ && abfd->section_count != 0
+ && input_bfd_has_object_attributes (info, abfd, &res))
+ break;
+ }
return res;
}
More information about the Binutils-cvs
mailing list