From: Matthieu Longo Date: Fri, 14 Nov 2025 15:36:44 +0000 (+0000) Subject: OAv2 merge: find first input containing an object attributes section X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff37837d6be1150b9a627d7ac6bb6aa79a4368d6;p=thirdparty%2Fbinutils-gdb.git 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 --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; }