This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: MIPS, strip --only-keep-debug & an infinite loop
- From: Mark Kettenis <mark dot kettenis at xs4all dot nl>
- To: macro at linux-mips dot org
- Cc: drow at false dot org, binutils at sources dot redhat dot com
- Date: Wed, 18 May 2005 00:55:38 +0200 (CEST)
- Subject: Re: MIPS, strip --only-keep-debug & an infinite loop
- References: <200504282014.j3SKEO8G001654@elgar.sibelius.xs4all.nl><Pine.LNX.4.61L.0504291249500.32392 at blysk.ds.pg.gda.pl><20050429121900.GD1621@hattusa.textio> <Pine.LNX.4.61L.0504291326090.32392@blysk.ds.pg.gda.pl><20050429130154.GE1621@hattusa.textio> <20050429130646.GA19824@nevyn.them.org><Pine.LNX.4.61L.0504291413340.32392@blysk.ds.pg.gda.pl><20050429135107.GA21441@nevyn.them.org> <Pine.LNX.4.61L.0504291458240.32392@blysk.ds.pg.gda.pl>
Date: Fri, 29 Apr 2005 16:16:27 +0100 (BST)
From: "Maciej W. Rozycki" <macro@linux-mips.org>
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 <kettenis@gnu.org>
* 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;