From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: Re: Add section caches to coff_data_type
Date: Thu, 18 May 2023 18:16:14 +0930 [thread overview]
Message-ID: <ZGXl1p9lWaR0Ji4d@squeak.grove.modra.org> (raw)
In-Reply-To: <ZGWTY4avxfRTfaEa@squeak.grove.modra.org>
On Thu, May 18, 2023 at 12:24:27PM +0930, Alan Modra wrote:
> NULL. Well, yes, the hash table isn't initialised for the output bfd.
> mkobject_hook is the wrong place to do that.
One other reason why it's the wrong place to call htab_create is that
any memory malloc'd in an object_p function should result in the
object_p returning a bfd_cleanup function that frees the memory.
bfd_alloc memory is fine in object_p, as alloc'd memory handled by
bfd_check_format_matches.
Another thing, section target_index is renumbered in
coff_compute_section_file_positions and _bfd_xcoff_bfd_final_link. I
don't know that there is currently any way that the output bfd
section_by_target_index could be populated before this point but
clear them out so no one need worry about it.
* coffcode.h (coff_compute_section_file_positions): Clear
section_by_target_index hash table when changing target_index.
(_bfd_xcoff_bfd_final_link): Likewise.
diff --git a/bfd/coffcode.h b/bfd/coffcode.h
index 777515e82e1..2d429828822 100644
--- a/bfd/coffcode.h
+++ b/bfd/coffcode.h
@@ -3067,6 +3067,9 @@ coff_compute_section_file_positions (bfd * abfd)
sofar += bfd_coff_scnhsz (abfd);
#endif
+ if (coff_data (abfd)->section_by_target_index)
+ htab_empty (coff_data (abfd)->section_by_target_index);
+
#ifdef COFF_IMAGE_WITH_PE
{
/* PE requires the sections to be in memory order when listed in
diff --git a/bfd/xcofflink.c b/bfd/xcofflink.c
index b57ed21afb9..a27721301dd 100644
--- a/bfd/xcofflink.c
+++ b/bfd/xcofflink.c
@@ -7076,6 +7076,8 @@ _bfd_xcoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
/* Reset the section indices after inserting the new
sections. */
+ if (xcoff_data (abfd)->coff.section_by_target_index)
+ htab_empty (xcoff_data (abfd)->coff.section_by_target_index);
indx = 0;
for (o = abfd->sections; o != NULL; o = o->next)
{
--
Alan Modra
Australia Development Lab, IBM
prev parent reply other threads:[~2023-05-18 8:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-18 2:54 Alan Modra
2023-05-18 8:46 ` Alan Modra [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZGXl1p9lWaR0Ji4d@squeak.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).