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

Mark Kettenis mark.kettenis@xs4all.nl
Tue May 17 23:20:00 GMT 2005


   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;



More information about the Binutils mailing list