From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28227 invoked by alias); 15 Feb 2011 04:00:23 -0000 Received: (qmail 28216 invoked by uid 22791); 15 Feb 2011 04:00:23 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-yx0-f169.google.com (HELO mail-yx0-f169.google.com) (209.85.213.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 15 Feb 2011 04:00:18 +0000 Received: by yxl31 with SMTP id 31so2670697yxl.0 for ; Mon, 14 Feb 2011 20:00:16 -0800 (PST) Received: by 10.236.110.6 with SMTP id t6mr194737yhg.49.1297742416865; Mon, 14 Feb 2011 20:00:16 -0800 (PST) Received: from bubble.grove.modra.org ([115.187.252.19]) by mx.google.com with ESMTPS id c7sm736745yhh.41.2011.02.14.20.00.13 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 14 Feb 2011 20:00:15 -0800 (PST) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id EDA3E16DE62A; Tue, 15 Feb 2011 14:30:08 +1030 (CST) Date: Tue, 15 Feb 2011 04:00:00 -0000 From: Alan Modra To: binutils@sourceware.org Subject: Re: PowerPC64 toc edit segfault Message-ID: <20110215040008.GW7651@bubble.grove.modra.org> Mail-Followup-To: binutils@sourceware.org References: <20110208030151.GM9489@bubble.grove.modra.org> <20110209082028.GA7651@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110209082028.GA7651@bubble.grove.modra.org> User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2011-02/txt/msg00161.txt.bz2 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