public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Patch to fix section overlap tests in linker
@ 1999-11-22  7:48 Nick Clifton
  0 siblings, 0 replies; only message in thread
From: Nick Clifton @ 1999-11-22  7:48 UTC (permalink / raw)
  To: binutils

Hi Guys,

  The patch below fixes a bug in the linker's code to check for
  section overlaps.  The linker was checking sections with the NOLOAD
  attribute when they really should be ignored.

  Is it OK to apply this patch ?

Cheers
	Nick


1999-11-22  Nick Clifton  <nickc@cygnus.com>

	* ldlang.c (lang_check_section_addresses): Fix test to determine
	if a section should be tested.
	(IGNORE_SECTION): New macro.

Index: ld/ldlang.c
===================================================================
RCS file: /cvs/binutils/binutils/ld/ldlang.c,v
retrieving revision 1.14
diff -p -r1.14 ldlang.c
*** ldlang.c	1999/11/01 23:37:48	1.14
--- ldlang.c	1999/11/22 15:46:53
*************** size_input_section (this_ptr, output_sec
*** 2608,2613 ****
--- 2608,2617 ----
    return dot;
  }
  
+ #define IGNORE_SECTION(bfd, s) \
+   (((bfd_get_section_flags (bfd, s) & (SEC_ALLOC | SEC_LOAD)) == 0) \
+    || bfd_section_size (bfd, s) == 0)
+ 
  /* Check to see if any allocated sections overlap with other allocated
     sections.  This can happen when the linker script specifically specifies
     the output section addresses of the two sections.  */
*************** lang_check_section_addresses ()
*** 2618,2666 ****
  
    /* Scan all sections in the output list.  */
    for (s = output_bfd->sections; s != NULL; s = s->next)
!     /* Ignore sections which are not loaded or which have no contents.  */
!     if ((bfd_get_section_flags (output_bfd, s) & (SEC_ALLOC | SEC_LOAD))
! 	&& bfd_section_size (output_bfd, s) != 0)
!       {
! 	asection * os;
! 
! 	/* Once we reach section 's' stop our seach.  This prevents two
! 	   warning messages from being produced, one for 'section A overlaps
! 	   section B' and one for 'section B overlaps section A'.  */
! 	for (os = output_bfd->sections; os != s; os = os->next)
! 	  {
! 	    bfd_vma s_start;
! 	    bfd_vma s_end;
! 	    bfd_vma os_start;
! 	    bfd_vma os_end;
! 
! 	    /* Only consider loadable sections with real contents.  */
! 	    if (((bfd_get_section_flags (output_bfd, os)
! 		  & (SEC_ALLOC | SEC_LOAD)) == 0)
! 		|| bfd_section_size (output_bfd, os) == 0)
! 	      continue;
! 
! 	    /* We must check the sections' LMA addresses not their
! 	       VMA addresses because overlay sections can have
! 	       overlapping VMAs but they must have distinct LMAs.  */
! 	    s_start  = bfd_section_lma (output_bfd, s);
! 	    os_start = bfd_section_lma (output_bfd, os);
! 	    s_end    = s_start  + bfd_section_size (output_bfd, s) - 1;
! 	    os_end   = os_start + bfd_section_size (output_bfd, os) - 1;
! 
! 	    /* Look for an overlap.  */
! 	    if ((s_end < os_start) || (s_start > os_end))
! 	      continue;
! 	    
! 	    einfo (
  _("%X%P: section %s [%V -> %V] overlaps section %s [%V -> %V]\n"),
! 		   s->name, s_start, s_end, os->name, os_start, os_end);
! 
! 	    /* Once we have found one overlap for this section,
! 	       stop looking for others.  */
! 	    break;
! 	  }
!       }
  }
  
  /* This variable indicates whether bfd_relax_section should be called
--- 2622,2669 ----
  
    /* Scan all sections in the output list.  */
    for (s = output_bfd->sections; s != NULL; s = s->next)
!     {
!       asection * os;
!       
!       /* Ignore sections which are not loaded or which have no contents.  */
!       if (IGNORE_SECTION (output_bfd, s))
! 	continue;
!       
!       /* Once we reach section 's' stop our seach.  This prevents two
! 	 warning messages from being produced, one for 'section A overlaps
! 	 section B' and one for 'section B overlaps section A'.  */
!       for (os = output_bfd->sections; os != s; os = os->next)
! 	{
! 	  bfd_vma s_start;
! 	  bfd_vma s_end;
! 	  bfd_vma os_start;
! 	  bfd_vma os_end;
! 	  
! 	  /* Only consider loadable sections with real contents.  */
! 	  if (IGNORE_SECTION (output_bfd, os))
! 	    continue;
! 
! 	  /* We must check the sections' LMA addresses not their
! 	     VMA addresses because overlay sections can have
! 	     overlapping VMAs but they must have distinct LMAs.  */
! 	  s_start  = bfd_section_lma (output_bfd, s);
! 	  os_start = bfd_section_lma (output_bfd, os);
! 	  s_end    = s_start  + bfd_section_size (output_bfd, s) - 1;
! 	  os_end   = os_start + bfd_section_size (output_bfd, os) - 1;
! 	  
! 	  /* Look for an overlap.  */
! 	  if ((s_end < os_start) || (s_start > os_end))
! 	    continue;
! 	  
! 	  einfo (
  _("%X%P: section %s [%V -> %V] overlaps section %s [%V -> %V]\n"),
! 		 s->name, s_start, s_end, os->name, os_start, os_end);
! 	  
! 	  /* Once we have found one overlap for this section,
! 	     stop looking for others.  */
! 	  break;
! 	}
!     }
  }
  
  /* This variable indicates whether bfd_relax_section should be called

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-11-22  7:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-22  7:48 Patch to fix section overlap tests in linker Nick Clifton

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).