From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: Re: PowerPC64 toc edit segfault
Date: Tue, 15 Feb 2011 04:00:00 -0000 [thread overview]
Message-ID: <20110215040008.GW7651@bubble.grove.modra.org> (raw)
In-Reply-To: <20110209082028.GA7651@bubble.grove.modra.org>
On Wed, Feb 09, 2011 at 06:50:28PM +1030, Alan Modra wrote:
> This fixes two segfaults in ppc64_elf_edit_toc, found when simply
> @@ -8418,15 +8424,9 @@ ppc64_elf_edit_toc (struct bfd_link_info
> Elf_Internal_Rela *wrel;
> bfd_size_type sz;
>
> - /* Read toc relocs. */
> - relstart = _bfd_elf_link_read_relocs (ibfd, toc, NULL, NULL,
> - TRUE);
> - if (relstart == NULL)
> - goto error_ret;
> -
> /* Remove unused toc relocs, and adjust those we keep. */
> - wrel = relstart;
> - for (rel = relstart; rel < relstart + toc->reloc_count; ++rel)
> + wrel = toc_relocs;
> + for (rel = toc_relocs; rel < toc_relocs + toc->reloc_count; ++rel)
> if ((skip[rel->r_offset >> 3]
> & (ref_from_discarded | can_optimize)) == 0)
> {
Blah. Removing the above "Read toc relocs" caused a segfault when
linking -mcmodel=small code.
* elf64-ppc.c (ppc64_elf_edit_toc): Reinstate second read of
toc relocs. Fuss over free(NULL).
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.342
diff -u -p -r1.342 elf64-ppc.c
--- bfd/elf64-ppc.c 9 Feb 2011 08:16:00 -0000 1.342
+++ bfd/elf64-ppc.c 15 Feb 2011 03:54:10 -0000
@@ -8424,6 +8424,12 @@ ppc64_elf_edit_toc (struct bfd_link_info
bfd_size_type sz;
/* Remove unused toc relocs, and adjust those we keep. */
+ if (toc_relocs == NULL)
+ toc_relocs = _bfd_elf_link_read_relocs (ibfd, toc, NULL, NULL,
+ info->keep_memory);
+ if (toc_relocs == NULL)
+ goto error_ret;
+
wrel = toc_relocs;
for (rel = toc_relocs; rel < toc_relocs + toc->reloc_count; ++rel)
if ((skip[rel->r_offset >> 3]
@@ -8445,7 +8451,8 @@ ppc64_elf_edit_toc (struct bfd_link_info
rel_hdr->sh_size = toc->reloc_count * sz;
}
}
- else if (elf_section_data (toc)->relocs != toc_relocs)
+ else if (toc_relocs != NULL
+ && elf_section_data (toc)->relocs != toc_relocs)
free (toc_relocs);
if (local_syms != NULL
--
Alan Modra
Australia Development Lab, IBM
prev parent reply other threads:[~2011-02-15 4:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-08 3:02 Alan Modra
2011-02-09 8:20 ` Alan Modra
2011-02-15 4:00 ` 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=20110215040008.GW7651@bubble.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).