From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22946 invoked by alias); 17 May 2005 22:56:00 -0000 Mailing-List: contact binutils-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sources.redhat.com Received: (qmail 22823 invoked from network); 17 May 2005 22:55:50 -0000 Received: from unknown (HELO sibelius.xs4all.nl) (82.92.89.47) by sourceware.org with SMTP; 17 May 2005 22:55:50 -0000 Received: from elgar.sibelius.xs4all.nl (root@elgar.sibelius.xs4all.nl [192.168.0.2]) by sibelius.xs4all.nl (8.13.0/8.13.0) with ESMTP id j4HMtc8P011268; Wed, 18 May 2005 00:55:38 +0200 (CEST) Received: from elgar.sibelius.xs4all.nl (kettenis@localhost.sibelius.xs4all.nl [127.0.0.1]) by elgar.sibelius.xs4all.nl (8.13.4/8.13.3) with ESMTP id j4HMtclQ027322; Wed, 18 May 2005 00:55:38 +0200 (CEST) Received: (from kettenis@localhost) by elgar.sibelius.xs4all.nl (8.13.4/8.13.4/Submit) id j4HMtc5J008824; Wed, 18 May 2005 00:55:38 +0200 (CEST) Date: Tue, 17 May 2005 23:20:00 -0000 Message-Id: <200505172255.j4HMtc5J008824@elgar.sibelius.xs4all.nl> From: Mark Kettenis To: macro@linux-mips.org CC: drow@false.org, binutils@sources.redhat.com In-reply-to: (macro@linux-mips.org) Subject: Re: MIPS, strip --only-keep-debug & an infinite loop References: <200504282014.j3SKEO8G001654@elgar.sibelius.xs4all.nl> <20050429121900.GD1621@hattusa.textio> <20050429130154.GE1621@hattusa.textio> <20050429130646.GA19824@nevyn.them.org> <20050429135107.GA21441@nevyn.them.org> X-SW-Source: 2005-05/txt/msg00555.txt.bz2 Date: Fri, 29 Apr 2005 16:16:27 +0100 (BST) From: "Maciej W. Rozycki" On Fri, 29 Apr 2005, Daniel Jacobowitz wrote: > > But I've tried with a different target and the result is weird -- all > > non-debugging sections are merged to overlap starting from the same file > > offset, keeping their sizes, VMA, etc. intact... Program headers, if > > present, get adjusted accordingly. > > You missed the vital bit. They all become NOBITS sections. The > original file still has their original contents; they are only in this > file because .symtab will have contents, and it references section > numbers. That makes sense. And with readelf I can see the problem now -- ".MIPS.options" is left marked as SHT_MIPS_OPTIONS as opposed to SHT_NOBITS. Since that section no longer contains anything relevant, it should be considered a bug. Hmm, this seems to have fallen between the cracks. Anyway, here is a patch that seems to work for me. It seems to fix objcopy/strip --only-keep-debug and avoids the infinite loop. However, I do think the SEC_HAS_CONTENTS check should probably be applied to other faked sections too. Mark Index: ChangeLog from Mark Kettenis * elfxx-mips.c (_bfd_mips_elf_section_processing): Return FALSE if option size is zero. (_bfd_mips_elf_section_from_shdr): Likewise. (_bfd_mips_elf_fake_sections): Only fake SHT_MIPS_OPTIONS if the section has contents. Index: elfxx-mips.c =================================================================== RCS file: /cvs/src/src/bfd/elfxx-mips.c,v retrieving revision 1.138 diff -u -p -r1.138 elfxx-mips.c --- elfxx-mips.c 7 May 2005 13:22:55 -0000 1.138 +++ elfxx-mips.c 17 May 2005 22:53:29 -0000 @@ -5017,6 +5017,8 @@ _bfd_mips_elf_section_processing (bfd *a if (bfd_bwrite (buf, 4, abfd) != 4) return FALSE; } + if (intopt.size == 0) + return FALSE; l += intopt.size; } } @@ -5223,6 +5225,8 @@ _bfd_mips_elf_section_from_shdr (bfd *ab &intreg); elf_gp (abfd) = intreg.ri_gp_value; } + if (intopt.size == 0) + return FALSE; l += intopt.size; } free (contents); @@ -5313,7 +5317,8 @@ _bfd_mips_elf_fake_sections (bfd *abfd, hdr->sh_flags |= SHF_MIPS_NOSTRIP; /* The sh_info field is set in final_write_processing. */ } - else if (MIPS_ELF_OPTIONS_SECTION_NAME_P (name)) + else if (MIPS_ELF_OPTIONS_SECTION_NAME_P (name) + && (sec->flags & SEC_HAS_CONTENTS)) { hdr->sh_type = SHT_MIPS_OPTIONS; hdr->sh_entsize = 1;