This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PowerPC64 toc edit segfault
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