This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: MIPS, strip --only-keep-debug & an infinite loop


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]