]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd: simplify _bfd_{link,write,discard}_section_stabs() interface
authorJan Beulich <jbeulich@suse.com>
Fri, 24 Oct 2025 13:10:35 +0000 (15:10 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 24 Oct 2025 13:10:35 +0000 (15:10 +0200)
... as well as that of _bfd_stab_section_offset(): As sec_info is now
hanging off of sec, there's no need for the extra 4th parameter anymore.
Along these line struct struct coff_section_tdata's stab_info member then
isn't needed anymore either.

Furthermore there also hasn't been a good reason to have the caller of
_bfd_link_section_stabs() set sec_info_type.

bfd/coff-bfd.h
bfd/cofflink.c
bfd/elf.c
bfd/elflink.c
bfd/libbfd.h
bfd/stabs.c

index 9b2f2b7ae91b584da8964780c8804190a5f97237..ebcc934c7e8b5799030bdc66bfea0b5947fce20e 100644 (file)
@@ -54,8 +54,6 @@ struct coff_section_tdata
   /* Optional information about a COMDAT entry; NULL if not COMDAT. */
   struct coff_comdat_info *comdat;
   int line_base;
-  /* A pointer used for .stab linking optimizations.  */
-  void * stab_info;
   /* Available for individual backends.  */
   void * tdata;
 };
index 38278e230dae4a7d0cb5b4d80c307492b0b86181..2ce5a0273ae24e84489fb6616aedfa1b4c65f7d4 100644 (file)
@@ -584,23 +584,11 @@ coff_link_add_symbols (bfd *abfd,
                    || (stab->name[5] == '.' && ISDIGIT (stab->name[6]))))
            {
              struct coff_link_hash_table *table;
-             struct coff_section_tdata *secdata
-               = coff_section_data (abfd, stab);
-
-             if (secdata == NULL)
-               {
-                 amt = sizeof (struct coff_section_tdata);
-                 stab->used_by_bfd = bfd_zalloc (abfd, amt);
-                 if (stab->used_by_bfd == NULL)
-                   goto error_return;
-                 secdata = coff_section_data (abfd, stab);
-               }
 
              table = coff_hash_table (info);
 
              if (! _bfd_link_section_stabs (abfd, &table->stab_info,
                                             stab, stabstr,
-                                            &secdata->stab_info,
                                             &string_offset))
                goto error_return;
            }
@@ -2541,7 +2529,7 @@ _bfd_coff_link_input_bfd (struct coff_final_link_info *flaginfo, bfd *input_bfd)
        }
 
       /* Write out the modified section contents.  */
-      if (secdata == NULL || secdata->stab_info == NULL)
+      if (o->sec_info_type != SEC_INFO_TYPE_STABS)
        {
          file_ptr loc = (o->output_offset
                          * bfd_octets_per_byte (output_bfd, o));
@@ -2553,7 +2541,7 @@ _bfd_coff_link_input_bfd (struct coff_final_link_info *flaginfo, bfd *input_bfd)
        {
          if (! (_bfd_write_section_stabs
                 (output_bfd, &coff_hash_table (flaginfo->info)->stab_info,
-                 o, &secdata->stab_info, contents)))
+                 o, contents)))
            return false;
        }
     }
index 9999b09a9eb0faac8a60acf0f21b454773390002..56a5857e29edbeb741a9dec5e83ba9c88dbbb304 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -13308,7 +13308,7 @@ _bfd_elf_section_offset (bfd *abfd,
   switch (sec->sec_info_type)
     {
     case SEC_INFO_TYPE_STABS:
-      return _bfd_stab_section_offset (sec, sec->sec_info, offset);
+      return _bfd_stab_section_offset (sec, offset);
 
     case SEC_INFO_TYPE_EH_FRAME:
       return _bfd_elf_eh_frame_section_offset (abfd, info, sec, offset);
index b7380ef34e324c7ae93e7ff0ee321e322862feb9..2dd121de4a7412a44287265a762e1190f6de227a 100644 (file)
@@ -6113,15 +6113,10 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
                && (!stab->name[5] ||
                    (stab->name[5] == '.' && ISDIGIT (stab->name[6])))
                && (stab->flags & SEC_MERGE) == 0
-               && !bfd_is_abs_section (stab->output_section))
-             {
-               if (! _bfd_link_section_stabs (abfd, &htab->stab_info, stab,
-                                              stabstr, &stab->sec_info,
-                                              &string_offset))
-                 goto error_return;
-               if (stab->sec_info)
-                 stab->sec_info_type = SEC_INFO_TYPE_STABS;
-           }
+               && !bfd_is_abs_section (stab->output_section)
+               && !_bfd_link_section_stabs (abfd, &htab->stab_info, stab,
+                                            stabstr, &string_offset))
+             goto error_return;
        }
     }
 
@@ -12217,8 +12212,7 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
        case SEC_INFO_TYPE_STABS:
          if (! (_bfd_write_section_stabs
                 (output_bfd,
-                 &elf_hash_table (flinfo->info)->stab_info,
-                 o, &o->sec_info, contents)))
+                 &elf_hash_table (flinfo->info)->stab_info, o, contents)))
            return false;
          break;
        case SEC_INFO_TYPE_MERGE:
@@ -15204,7 +15198,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
          if (!init_reloc_cookie_for_section (&cookie, info, i, false))
            return -1;
 
-         if (_bfd_discard_section_stabs (abfd, i, i->sec_info,
+         if (_bfd_discard_section_stabs (abfd, i,
                                          bfd_elf_reloc_symbol_deleted_p,
                                          &cookie))
            changed = 1;
index 3e1f1ec0fea21d89a4fe4f8b74d33d2fffe7f60f..9c3c98e04cbab383946c48eda34b0b9834118bb3 100644 (file)
@@ -3705,18 +3705,18 @@ bool _bfd_unrecognized_reloc
 
 /* Extracted from stabs.c.  */
 bool _bfd_link_section_stabs
-   (bfd *, struct stab_info *, asection *, asection *, void **,
+   (bfd *, struct stab_info *, asection *, asection *,
     bfd_size_type *) ATTRIBUTE_HIDDEN;
 
 bool _bfd_discard_section_stabs
-   (bfd *, asection *, void *, bool (*) (bfd_vma, void *), void *) ATTRIBUTE_HIDDEN;
+   (bfd *, asection *, bool (*) (bfd_vma, void *), void *) ATTRIBUTE_HIDDEN;
 
 bool _bfd_write_section_stabs
-   (bfd *, struct stab_info *, asection *, void **, bfd_byte *) ATTRIBUTE_HIDDEN;
+   (bfd *, struct stab_info *, asection *, bfd_byte *) ATTRIBUTE_HIDDEN;
 
 bool _bfd_write_stab_strings (bfd *, struct stab_info *) ATTRIBUTE_HIDDEN;
 
-bfd_vma _bfd_stab_section_offset (asection *, void *, bfd_vma) ATTRIBUTE_HIDDEN;
+bfd_vma _bfd_stab_section_offset (asection *, bfd_vma) ATTRIBUTE_HIDDEN;
 
 /* Extracted from targets.c.  */
 #ifdef __cplusplus
index a7c99daf383164db45e86af82f32bfbe2fa5643d..f1b866bf7dd5d7f5b412664259f8b97b3a105f25 100644 (file)
@@ -176,7 +176,6 @@ _bfd_link_section_stabs (bfd *abfd,
                         struct stab_info *sinfo,
                         asection *stabsec,
                         asection *stabstrsec,
-                        void * *psecinfo,
                         bfd_size_type *pstring_offset)
 {
   bool first;
@@ -242,11 +241,12 @@ _bfd_link_section_stabs (bfd *abfd,
 
   amt = sizeof (struct stab_section_info);
   amt += (count - 1) * sizeof (bfd_size_type);
-  *psecinfo = bfd_alloc (abfd, amt);
-  if (*psecinfo == NULL)
+  secinfo = bfd_alloc (abfd, amt);
+  if (secinfo == NULL)
     goto error_return;
 
-  secinfo = (struct stab_section_info *) *psecinfo;
+  stabsec->sec_info = secinfo;
+  stabsec->sec_info_type = SEC_INFO_TYPE_STABS;
   secinfo->excls = NULL;
   stabsec->rawsize = stabsec->size;
   secinfo->cumulative_skips = NULL;
@@ -546,7 +546,6 @@ DESCRIPTION
 bool
 _bfd_discard_section_stabs (bfd *abfd,
                            asection *stabsec,
-                           void * psecinfo,
                            bool (*reloc_symbol_deleted_p) (bfd_vma, void *),
                            void * cookie)
 {
@@ -576,11 +575,11 @@ _bfd_discard_section_stabs (bfd *abfd,
   /* We should have initialized our data in _bfd_link_section_stabs.
      If there was some bizarre error reading the string sections, though,
      we might not have.  Bail rather than asserting.  */
-  if (psecinfo == NULL)
+  if (stabsec->sec_info_type != SEC_INFO_TYPE_STABS)
     return false;
 
   count = stabsec->rawsize / STABSIZE;
-  secinfo = (struct stab_section_info *) psecinfo;
+  secinfo = stabsec->sec_info;
 
   /* Read the stabs information from abfd.  */
   if (!bfd_malloc_and_get_section (abfd, stabsec, &stabbuf))
@@ -705,17 +704,14 @@ bool
 _bfd_write_section_stabs (bfd *output_bfd,
                          struct stab_info *sinfo,
                          asection *stabsec,
-                         void * *psecinfo,
                          bfd_byte *contents)
 {
-  struct stab_section_info *secinfo;
+  struct stab_section_info *secinfo = stabsec->sec_info;
   struct stab_excl_list *e;
   bfd_byte *sym, *tosym, *symend;
   bfd_size_type *pstridx;
 
-  secinfo = (struct stab_section_info *) *psecinfo;
-
-  if (secinfo == NULL)
+  if (stabsec->sec_info_type != SEC_INFO_TYPE_STABS)
     return bfd_set_section_contents (output_bfd, stabsec->output_section,
                                     contents, stabsec->output_offset,
                                     stabsec->size);
@@ -823,14 +819,11 @@ DESCRIPTION
 
 bfd_vma
 _bfd_stab_section_offset (asection *stabsec,
-                         void * psecinfo,
                          bfd_vma offset)
 {
-  struct stab_section_info *secinfo;
-
-  secinfo = (struct stab_section_info *) psecinfo;
+  struct stab_section_info *secinfo = stabsec->sec_info;
 
-  if (secinfo == NULL)
+  if (stabsec->sec_info_type != SEC_INFO_TYPE_STABS)
     return offset;
 
   if (offset >= stabsec->rawsize)