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: "Maciej W. Rozycki" <macro at linux-mips dot org>
- To: Mark Kettenis <mark dot kettenis at xs4all dot nl>
- Cc: drow at false dot org, binutils at sources dot redhat dot com
- Date: Mon, 23 May 2005 21:35:31 +0100 (BST)
- 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><200505172255.j4HMtc5J008824@elgar.sibelius.xs4all.nl><Pine.LNX.4.61L.0505181157111.19170@blysk.ds.pg.gda.pl>
On Wed, 18 May 2005, Maciej W. Rozycki wrote:
> > 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.
>
> It hasn't really fallen -- it's just my lack of time, sigh... Thanks for
> looking into it -- I'll see if I can test it before 2.16.1.
Well, I've had a look at the patch and I found out just returning a
failure is inadequate for these functions. For
_bfd_mips_elf_section_processing() it's simply ignored. For
_bfd_mips_elf_section_from_shdr() it leads to such a damaged object being
completely rejected, which prevents doing `objdump' or fixing it with
another run of `strip --only-keep-debug' and is probably an overkill. In
neither case any useful diagnostics is available. Therefore I've
rewritten these changes to provide some diagnostics and attempt to
continue anyway.
For _bfd_mips_elf_fake_sections() I agree appropriate handling of all
special sections is desirable.
This has been checked not to cause any regressions in the test suite run
for mipsel-linux-gnu natively.
2005-05-23 Mark Kettenis <kettenis@gnu.org>
Maciej W. Rozycki <macro@linux-mips.org>
* elfxx-mips.c (_bfd_mips_elf_section_processing): Warn and
stop processing of options if one of invalid size is
encountered.
(_bfd_mips_elf_section_from_shdr): Likewise.
(_bfd_mips_elf_fake_sections): Reset the type of empty special
sections.
OK to apply? Since it fixes a fatal problem, I'm asking for permission
for 2.16.1, too.
Maciej
binutils-2.16-mips-fake-sections.patch
diff -up --recursive --new-file binutils-2.16.macro/bfd/elfxx-mips.c binutils-2.16/bfd/elfxx-mips.c
--- binutils-2.16.macro/bfd/elfxx-mips.c 2005-04-19 18:37:04.000000000 +0000
+++ binutils-2.16/bfd/elfxx-mips.c 2005-05-22 06:08:02.000000000 +0000
@@ -4990,6 +4990,13 @@ _bfd_mips_elf_section_processing (bfd *a
bfd_mips_elf_swap_options_in (abfd, (Elf_External_Options *) l,
&intopt);
+ if (intopt.size < sizeof (Elf_External_Options))
+ {
+ (*_bfd_error_handler)
+ (_("%B: Warning: bad `%s' option size %u smaller than its header"),
+ abfd, MIPS_ELF_OPTIONS_SECTION_NAME (abfd), intopt.size);
+ break;
+ }
if (ABI_64_P (abfd) && intopt.kind == ODK_REGINFO)
{
bfd_byte buf[8];
@@ -5202,6 +5209,13 @@ _bfd_mips_elf_section_from_shdr (bfd *ab
bfd_mips_elf_swap_options_in (abfd, (Elf_External_Options *) l,
&intopt);
+ if (intopt.size < sizeof (Elf_External_Options))
+ {
+ (*_bfd_error_handler)
+ (_("%B: Warning: bad `%s' option size %u smaller than its header"),
+ abfd, MIPS_ELF_OPTIONS_SECTION_NAME (abfd), intopt.size);
+ break;
+ }
if (ABI_64_P (abfd) && intopt.kind == ODK_REGINFO)
{
Elf64_Internal_RegInfo intreg;
@@ -5240,8 +5254,10 @@ bfd_boolean
_bfd_mips_elf_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr, asection *sec)
{
register const char *name;
+ unsigned int sh_type;
name = bfd_get_section_name (abfd, sec);
+ sh_type = hdr->sh_type;
if (strcmp (name, ".liblist") == 0)
{
@@ -5343,6 +5359,12 @@ _bfd_mips_elf_fake_sections (bfd *abfd,
hdr->sh_entsize = 8;
}
+ /* In the unlikely event a special section is empty it has to lose its
+ special meaning. This may happen e.g. when using `strip' with the
+ "--only-keep-debug" option. */
+ if (sec->size > 0 && !(sec->flags & SEC_HAS_CONTENTS))
+ hdr->sh_type = sh_type;
+
/* The generic elf_fake_sections will set up REL_HDR using the default
kind of relocations. We used to set up a second header for the
non-default kind of relocations here, but only NewABI would use