public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@linux-mips.org>
To: Mark Kettenis <mark.kettenis@xs4all.nl>
Cc: drow@false.org, binutils@sources.redhat.com
Subject: Re: MIPS, strip --only-keep-debug & an infinite loop
Date: Mon, 23 May 2005 20:51:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.61L.0505232051440.4541@blysk.ds.pg.gda.pl> (raw)
In-Reply-To: <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

  parent reply	other threads:[~2005-05-23 20:36 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-28 23:02 Mark Kettenis
2005-04-29 12:30 ` Maciej W. Rozycki
2005-04-29 13:02   ` Thiemo Seufer
2005-04-29 13:06     ` Maciej W. Rozycki
2005-04-29 13:47       ` Thiemo Seufer
2005-04-29 13:51         ` Daniel Jacobowitz
2005-04-29 14:06           ` Maciej W. Rozycki
2005-04-29 14:07             ` Daniel Jacobowitz
2005-04-29 16:13               ` Maciej W. Rozycki
2005-05-01  1:50                 ` Daniel Jacobowitz
2005-05-01 16:16                   ` Maciej W. Rozycki
2005-05-01 16:17                     ` Daniel Jacobowitz
2005-05-17 23:20                 ` Mark Kettenis
2005-05-18 13:36                   ` Maciej W. Rozycki
2005-05-18 17:32                     ` Mark Kettenis
2005-05-23 20:51                     ` Maciej W. Rozycki [this message]
2005-05-25 23:35                       ` Mark Kettenis
2005-05-26 16:27                       ` Eric Christopher
2005-04-29 15:16   ` Mark Kettenis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.61L.0505232051440.4541@blysk.ds.pg.gda.pl \
    --to=macro@linux-mips.org \
    --cc=binutils@sources.redhat.com \
    --cc=drow@false.org \
    --cc=mark.kettenis@xs4all.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).