]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd: simplify _bfd_{add_merge,write_merged}_section() interface
authorJan Beulich <jbeulich@suse.com>
Fri, 24 Oct 2025 13:09:39 +0000 (15:09 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 24 Oct 2025 13:09:39 +0000 (15:09 +0200)
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.

bfd/elflink.c
bfd/libbfd-in.h
bfd/libbfd.h
bfd/merge.c

index 17d6e389c2d0c31f642438abb771eaff679f6ed6..28027339ccfeccf3ab91e1c09671b650e7cee440 100644 (file)
@@ -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:
index 213cc7d67595f91df415f0a23f0d1cd00b0b4406..f2c243f1d40f273cd23933a01c3415008fc36b20 100644 (file)
@@ -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.  */
 
index ca8eef50b1ca831dd8378645200af251e2ec448a..106bd344669c2d9abfed6efc55d579bc819da988 100644 (file)
@@ -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.  */
 
index f5a41b50a5325b29f35b04106c8855cbc9ae9cfe..83e5d895626eae83bb52ff0cd945a23804363e31 100644 (file)
@@ -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;