From: Jan Beulich Date: Fri, 24 Oct 2025 13:09:39 +0000 (+0200) Subject: bfd: simplify _bfd_{add_merge,write_merged}_section() interface X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=eef49e5b1c7d784d6507a3a8807187c7e9776e20;p=thirdparty%2Fbinutils-gdb.git bfd: simplify _bfd_{add_merge,write_merged}_section() interface As sec_info is now hanging off of sec, there's no need for the extra 4th / 3rd parameter anymore. Along these line struct sec_merge_sec_info's psecinfo member then isn't needed anymore either. Furthermore there also hasn't been a good reason to have the caller of _bfd_add_merge_section() set sec_info_type. --- diff --git a/bfd/elflink.c b/bfd/elflink.c index 17d6e389c2d..28027339ccf 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -8192,15 +8192,11 @@ _bfd_elf_merge_sections (bfd *obfd, struct bfd_link_info *info) == get_elf_backend_data (obfd)->s->elfclass)) for (sec = ibfd->sections; sec != NULL; sec = sec->next) if ((sec->flags & SEC_MERGE) != 0 - && !bfd_is_abs_section (sec->output_section)) - { - if (! _bfd_add_merge_section (obfd, - &info->hash->merge_info, - sec, &sec->sec_info)) + && !bfd_is_abs_section (sec->output_section) + && !_bfd_add_merge_section (obfd, + &info->hash->merge_info, + sec)) return false; - else if (sec->sec_info) - sec->sec_info_type = SEC_INFO_TYPE_MERGE; - } if (info->hash->merge_info != NULL) return _bfd_merge_sections (obfd, info, info->hash->merge_info, @@ -12229,7 +12225,7 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd) return false; break; case SEC_INFO_TYPE_MERGE: - if (! _bfd_write_merged_section (output_bfd, o, o->sec_info)) + if (! _bfd_write_merged_section (output_bfd, o)) return false; break; case SEC_INFO_TYPE_EH_FRAME: diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h index 213cc7d6759..f2c243f1d40 100644 --- a/bfd/libbfd-in.h +++ b/bfd/libbfd-in.h @@ -691,7 +691,7 @@ extern bfd_reloc_status_type _bfd_clear_contents /* Register a SEC_MERGE section as a candidate for merging. */ extern bool _bfd_add_merge_section - (bfd *, void **, asection *, void **) ATTRIBUTE_HIDDEN; + (bfd *, void **, asection *) ATTRIBUTE_HIDDEN; /* Attempt to merge SEC_MERGE sections. */ @@ -702,7 +702,7 @@ extern bool _bfd_merge_sections /* Write out a merged section. */ extern bool _bfd_write_merged_section - (bfd *, asection *, void *) ATTRIBUTE_HIDDEN; + (bfd *, asection *) ATTRIBUTE_HIDDEN; /* Find an offset within a modified SEC_MERGE section. */ diff --git a/bfd/libbfd.h b/bfd/libbfd.h index ca8eef50b1c..106bd344669 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -697,7 +697,7 @@ extern bfd_reloc_status_type _bfd_clear_contents /* Register a SEC_MERGE section as a candidate for merging. */ extern bool _bfd_add_merge_section - (bfd *, void **, asection *, void **) ATTRIBUTE_HIDDEN; + (bfd *, void **, asection *) ATTRIBUTE_HIDDEN; /* Attempt to merge SEC_MERGE sections. */ @@ -708,7 +708,7 @@ extern bool _bfd_merge_sections /* Write out a merged section. */ extern bool _bfd_write_merged_section - (bfd *, asection *, void *) ATTRIBUTE_HIDDEN; + (bfd *, asection *) ATTRIBUTE_HIDDEN; /* Find an offset within a modified SEC_MERGE section. */ diff --git a/bfd/merge.c b/bfd/merge.c index f5a41b50a53..83e5d895626 100644 --- a/bfd/merge.c +++ b/bfd/merge.c @@ -132,8 +132,6 @@ struct sec_merge_sec_info struct sec_merge_sec_info *next; /* The corresponding section. */ asection *sec; - /* Pointer to merge_info pointing to us. */ - void **psecinfo; /* The merge entity this is a part of. */ struct sec_merge_info *sinfo; /* The section associated with sinfo (i.e. the representative section). @@ -611,8 +609,7 @@ sec_merge_emit (bfd *abfd, struct sec_merge_sec_info *secinfo, This function is called for all non-dynamic SEC_MERGE input sections. */ bool -_bfd_add_merge_section (bfd *abfd, void **psinfo, asection *sec, - void **psecinfo) +_bfd_add_merge_section (bfd *abfd, void **psinfo, asection *sec) { struct sec_merge_info *sinfo; struct sec_merge_sec_info *secinfo; @@ -671,12 +668,11 @@ _bfd_add_merge_section (bfd *abfd, void **psinfo, asection *sec, /* Initialize the descriptor for this input section. */ - *psecinfo = secinfo = bfd_zalloc (abfd, sizeof (*secinfo)); - if (*psecinfo == NULL) + sec->sec_info = secinfo = bfd_zalloc (abfd, sizeof (*secinfo)); + if (sec->sec_info == NULL) goto error_return; secinfo->sec = sec; - secinfo->psecinfo = psecinfo; /* Search for a matching output merged section. */ for (sinfo = (struct sec_merge_info *) *psinfo; sinfo; sinfo = sinfo->next) @@ -710,10 +706,12 @@ _bfd_add_merge_section (bfd *abfd, void **psinfo, asection *sec, secinfo->sinfo = sinfo; secinfo->reprsec = sinfo->chain->sec; + sec->sec_info_type = SEC_INFO_TYPE_MERGE; + return true; error_return: - *psecinfo = NULL; + sec->sec_info = NULL; return false; } @@ -997,7 +995,7 @@ _bfd_merge_sections (bfd *abfd, if (secinfo->sec->flags & SEC_EXCLUDE || !record_section (sinfo, secinfo)) { - *secinfo->psecinfo = NULL; + secinfo->sec->sec_info = NULL; if (remove_hook) (*remove_hook) (abfd, secinfo->sec); } @@ -1061,15 +1059,13 @@ _bfd_merge_sections (bfd *abfd, /* Write out the merged section. */ bool -_bfd_write_merged_section (bfd *output_bfd, asection *sec, void *psecinfo) +_bfd_write_merged_section (bfd *output_bfd, asection *sec) { - struct sec_merge_sec_info *secinfo; + struct sec_merge_sec_info *secinfo = sec->sec_info; file_ptr pos; unsigned char *contents; Elf_Internal_Shdr *hdr; - secinfo = (struct sec_merge_sec_info *) psecinfo; - if (!secinfo) return false;