From: Jan Beulich Date: Fri, 24 Oct 2025 13:10:35 +0000 (+0200) Subject: bfd: simplify _bfd_{link,write,discard}_section_stabs() interface X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e1701c4d81a50183875d9431587790ff0acfc8a;p=thirdparty%2Fbinutils-gdb.git bfd: simplify _bfd_{link,write,discard}_section_stabs() interface ... 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. --- diff --git a/bfd/coff-bfd.h b/bfd/coff-bfd.h index 9b2f2b7ae91..ebcc934c7e8 100644 --- a/bfd/coff-bfd.h +++ b/bfd/coff-bfd.h @@ -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; }; diff --git a/bfd/cofflink.c b/bfd/cofflink.c index 38278e230da..2ce5a0273ae 100644 --- a/bfd/cofflink.c +++ b/bfd/cofflink.c @@ -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; } } diff --git a/bfd/elf.c b/bfd/elf.c index 9999b09a9eb..56a5857e29e 100644 --- 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); diff --git a/bfd/elflink.c b/bfd/elflink.c index b7380ef34e3..2dd121de4a7 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -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; diff --git a/bfd/libbfd.h b/bfd/libbfd.h index 3e1f1ec0fea..9c3c98e04cb 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -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 diff --git a/bfd/stabs.c b/bfd/stabs.c index a7c99daf383..f1b866bf7dd 100644 --- a/bfd/stabs.c +++ b/bfd/stabs.c @@ -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)