[binutils-gdb] bfd: move merge_info from ELF to general link hash table

Jan Beulich jbeulich@sourceware.org
Fri Oct 24 13:14:27 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0bdfbd3710f49eaa6d737dcb32463912269ba826

commit 0bdfbd3710f49eaa6d737dcb32463912269ba826
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri Oct 24 15:08:33 2025 +0200

    bfd: move merge_info from ELF to general link hash table
    
    This is in prepration of supporting section merging also when the output
    isn't ELF (or not of the same class).

Diff:
---
 bfd/elf-bfd.h     | 3 ---
 bfd/elflink.c     | 7 +++----
 bfd/linker.c      | 2 ++
 include/bfdlink.h | 4 ++++
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index a2b3eb0fa9f..48e877f8a11 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -710,9 +710,6 @@ struct elf_link_hash_table
   /* The __ehdr_start symbol.  */
   struct elf_link_hash_entry *hehdr_start;
 
-  /* A pointer to information used to merge SEC_MERGE sections.  */
-  void *merge_info;
-
   /* Used to link stabs in sections.  */
   struct stab_info stab_info;
 
diff --git a/bfd/elflink.c b/bfd/elflink.c
index c7a5a52f1dd..b06d07c18b3 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -8201,15 +8201,15 @@ _bfd_elf_merge_sections (bfd *obfd, struct bfd_link_info *info)
 
 	    secdata = elf_section_data (sec);
 	    if (! _bfd_add_merge_section (obfd,
-					  &elf_hash_table (info)->merge_info,
+					  &info->hash->merge_info,
 					  sec, &secdata->sec_info))
 	      return false;
 	    else if (secdata->sec_info)
 	      sec->sec_info_type = SEC_INFO_TYPE_MERGE;
 	  }
 
-  if (elf_hash_table (info)->merge_info != NULL)
-    return _bfd_merge_sections (obfd, info, elf_hash_table (info)->merge_info,
+  if (info->hash->merge_info != NULL)
+    return _bfd_merge_sections (obfd, info, info->hash->merge_info,
 				merge_sections_remove_hook);
   return true;
 }
@@ -8449,7 +8449,6 @@ _bfd_elf_link_hash_table_free (bfd *obfd)
   htab = (struct elf_link_hash_table *) obfd->link.hash;
   if (htab->dynstr != NULL)
     _bfd_elf_strtab_free (htab->dynstr);
-  _bfd_merge_sections_free (htab->merge_info);
   /* NB: htab->dynamic->contents is always allocated by bfd_realloc.  */
   if (htab->dynamic != NULL)
     {
diff --git a/bfd/linker.c b/bfd/linker.c
index a9a23e5b9de..ae44ec3f2d2 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -492,6 +492,7 @@ _bfd_link_hash_table_init
     {
       /* Arrange for destruction of this hash table on closing ABFD.  */
       table->hash_table_free = _bfd_generic_link_hash_table_free;
+      table->merge_info = NULL;
       abfd->link.hash = table;
       abfd->is_linker_output = true;
     }
@@ -809,6 +810,7 @@ _bfd_generic_link_hash_table_free (bfd *obfd)
 
   BFD_ASSERT (obfd->is_linker_output && obfd->link.hash);
   ret = (struct generic_link_hash_table *) obfd->link.hash;
+  _bfd_merge_sections_free (ret->root.merge_info);
   bfd_hash_table_free (&ret->root.table);
   free (ret);
   obfd->link.hash = NULL;
diff --git a/include/bfdlink.h b/include/bfdlink.h
index 3d4d71b3347..0c47d09977f 100644
--- a/include/bfdlink.h
+++ b/include/bfdlink.h
@@ -214,6 +214,10 @@ struct bfd_link_hash_table
   struct bfd_link_hash_entry *undefs_tail;
   /* Function to free the hash table on closing BFD.  */
   void (*hash_table_free) (bfd *);
+
+  /* A pointer to information used to merge SEC_MERGE sections.  */
+  void *merge_info;
+
   /* The type of the link hash table.  */
   enum bfd_link_hash_table_type type;
 };


More information about the Binutils-cvs mailing list