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]

simple bfd patch



Here's a simple bfd patch that causes binary_set_section_contents() to
ignore zero length sections. I was getting a bloated binary image on
a mips target because of a zero length section with an LMA that was
far removed from other ELF sections that were being copied to binary.

--Mark



2000-12-08  Mark Salter  <msalter@redhat.com>

	* binary.c (binary_set_section_contents): Ignore sections
	with zero size.

Index: binary.c
===================================================================
RCS file: /cvs/cvsfiles/devo/bfd/binary.c,v
retrieving revision 1.24
diff -p -5 -r1.24 binary.c
*** binary.c	1999/07/23 22:11:33	1.24
--- binary.c	2000/12/12 21:27:59
*************** binary_set_section_contents (abfd, sec, 
*** 253,262 ****
--- 253,265 ----
       asection *sec;
       PTR data;
       file_ptr offset;
       bfd_size_type size;
  {
+   if (size == 0)
+     return true;
+ 
    if (! abfd->output_has_begun)
      {
        boolean found_low;
        bfd_vma low;
        asection *s;
*************** binary_set_section_contents (abfd, sec, 
*** 268,277 ****
--- 271,281 ----
        low = 0;
        for (s = abfd->sections; s != NULL; s = s->next)
  	if (((s->flags
  	      & (SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC | SEC_NEVER_LOAD))
  	     == (SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC))
+ 	    && (s->_raw_size > 0)
  	    && (! found_low || s->lma < low))
  	  {
  	    low = s->lma;
  	    found_low = true;
  	  }
*************** binary_set_section_contents (abfd, sec, 
*** 282,292 ****
  
  	  /* Skip following warning check for sections that will not
  	     occupy file space.  */ 
  	  if ((s->flags
  	       & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_NEVER_LOAD))
! 	      != (SEC_HAS_CONTENTS | SEC_ALLOC))
  	    continue;
  
  	  /* If attempting to generate a binary file from a bfd with
  	     LMA's all over the place, huge (sparse?) binary files may
  	     result.  This condition attempts to detect this situation
--- 286,297 ----
  
  	  /* Skip following warning check for sections that will not
  	     occupy file space.  */ 
  	  if ((s->flags
  	       & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_NEVER_LOAD))
! 	      != (SEC_HAS_CONTENTS | SEC_ALLOC)
! 	      || (s->_raw_size == 0))
  	    continue;
  
  	  /* If attempting to generate a binary file from a bfd with
  	     LMA's all over the place, huge (sparse?) binary files may
  	     result.  This condition attempts to detect this situation

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