From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1989 invoked by alias); 14 Apr 2007 01:42:28 -0000 Received: (qmail 1766 invoked by uid 22791); 14 Apr 2007 01:42:27 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 14 Apr 2007 02:42:25 +0100 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id l3E1mp2O022446 for ; Sat, 14 Apr 2007 03:48:51 +0200 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id l3E1mp4e022441 for binutils@sources.redhat.com; Sat, 14 Apr 2007 03:48:51 +0200 Date: Sat, 14 Apr 2007 05:25:00 -0000 From: Jakub Jelinek To: binutils@sources.redhat.com Subject: [PATCH] Fix ld segfault with MALLOC_PERTURB_=36 Message-ID: <20070414014850.GJ1826@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i 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: 2007-04/txt/msg00188.txt.bz2 Hi! echo 'SECTIONS { foo : { *(.data) } }' > x.lds MALLOC_PERTURB_=36 ld -m elf_i386 -r --format binary --oformat elf32-i386 -T x.lds x.lds -o x.o crashes, as info->input_bfds is binary flavour, not elf and therefore *elf_tdata (sub) contains unrelated garbage. The following patch fixes that. Ok to commit? I wonder whether the following hunk in bfd_elf_size_dynamic_sections doesn't need the same treatment: for (sub = info->input_bfds; sub != NULL; sub = sub->link_next) for (o = sub->sections; o != NULL; o = o->next) if (elf_section_data (o)->this_hdr.sh_type == SHT_PREINIT_ARRAY) 2007-04-13 Jakub Jelinek * elflink.c (bfd_elf_final_link): Don't free symbuf if input bfd is not elf. --- bfd/elflink.c.jj 2007-04-07 10:19:03.000000000 +0200 +++ bfd/elflink.c 2007-04-14 02:58:02.000000000 +0200 @@ -9533,7 +9533,8 @@ bfd_elf_final_link (bfd *abfd, struct bf if (!info->reduce_memory_overheads) { for (sub = info->input_bfds; sub != NULL; sub = sub->link_next) - if (elf_tdata (sub)->symbuf) + if (bfd_get_flavour (sub) == bfd_target_elf_flavour + && elf_tdata (sub)->symbuf) { free (elf_tdata (sub)->symbuf); elf_tdata (sub)->symbuf = NULL; Jakub