This is the mail archive of the binutils@sourceware.org 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: No error for Linker Section Overlapping


On Tue, Apr 17, 2007 at 04:41:48PM +0530, Deepen Mantri wrote:
> >> The changes to lma assignment made using overlays considerably 	
> >> simpler.  In particular, sections following an overlay area now	
> >> don't need their LMAs set.	
> 
> Yes, this is correct. However, it now seems to me that keyword 	
> "OVERLAY" has become redundant.

It always has been redundant.  See the "syntactic sugar" comment in
the ld info doc.

> Even if you do not use or intend 	
> to use it, the sections having overlapped VMAs are going to be 	
> considered as overlay sections.	

Well, yes.  After all, an overlapping VMA is the only difference
between an "overlay" section and a "normal" section as far as the
linker is concerned.  Prior to my change to LMA assignment, you
needed to specify the LMA on all overlay sections (or use the OVERLAY
keyword which did this for you), and all following sections (which the
OVERLAY keyword did not do).  Now you need to specify the LMA as well
if you specify VMA and *don't* want overlays, but see below.

> But can't we add an additional check, whether the sections having 	
> overlapped VMAs are overlay or not, before changing their LMAs?

Hmm, we could, by making the OVERLAY keyword affect the section type.
This should bring back the old behaviour for you but still give most
of the ease of use improvement for overlays.

ld/
	* ldlang.h (enum section_type): Add overlay_section.
	* ldlang.c (lang_add_section): Handle flags for overlay_section
	as per normal_section.
	(lang_size_sections_1): When setting lma, detect overlays by
	os->sectype rather than by looking for overlapping vmas.
	(lang_enter_overlay_section): Use overlay_section type.
	(lang_leave_overlay): Set first overlay section to normal.
ld/testsuite/
	* ld-spu/ovl.lnk: Use OVERLAY keyword.

Index: ld/ldlang.h
===================================================================
RCS file: /cvs/src/src/ld/ldlang.h,v
retrieving revision 1.72
diff -u -p -r1.72 ldlang.h
--- ld/ldlang.h	26 Mar 2007 11:10:44 -0000	1.72
+++ ld/ldlang.h	18 Apr 2007 02:10:00 -0000
@@ -108,6 +108,7 @@ typedef struct lang_output_statement_str
 enum section_type
 {
   normal_section,
+  overlay_section,
   noload_section,
   noalloc_section
 };
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.257
diff -u -p -r1.257 ldlang.c
--- ld/ldlang.c	10 Apr 2007 18:00:26 -0000	1.257
+++ ld/ldlang.c	18 Apr 2007 02:09:59 -0000
@@ -2040,6 +2040,7 @@ lang_add_section (lang_statement_list_ty
       switch (output->sectype)
 	{
 	case normal_section:
+	case overlay_section:
 	  break;
 	case noalloc_section:
 	  flags &= ~SEC_ALLOC;
@@ -4438,14 +4439,9 @@ lang_size_sections_1
 		  }
 		else
 		  {
-		    /* If the current vma overlaps the previous section,
-		       then set the current lma to that at the end of
-		       the previous section.  The previous section was
-		       probably an overlay.  */
-		    if ((dot >= last->vma
-			 && dot < last->vma + last->size)
-			|| (last->vma >= dot
-			    && last->vma < dot + os->bfd_section->size))
+		    /* If this is an overlay, set the current lma to that
+		       at the end of the previous section.  */
+		    if (os->sectype == overlay_section)
 		      lma = last->lma + last->size;
 
 		    /* Otherwise, keep the same lma to vma relationship
@@ -6392,7 +6388,7 @@ lang_enter_overlay_section (const char *
   struct overlay_list *n;
   etree_type *size;
 
-  lang_enter_output_section_statement (name, overlay_vma, normal_section,
+  lang_enter_output_section_statement (name, overlay_vma, overlay_section,
 				       0, overlay_subalign, 0, 0);
 
   /* If this is the first section, then base the VMA of future
@@ -6506,7 +6502,10 @@ lang_leave_overlay (etree_type *lma_expr
 	 The base address is not needed (and should be null) if
 	 an LMA region was specified.  */
       if (l->next == 0)
-	l->os->load_base = lma_expr;
+	{
+	  l->os->load_base = lma_expr;
+	  l->os->sectype = normal_section;
+	}
       if (phdrs != NULL && l->os->phdrs == NULL)
 	l->os->phdrs = phdrs;
 
Index: ld/testsuite/ld-spu/ovl.lnk
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-spu/ovl.lnk,v
retrieving revision 1.1
diff -u -p -r1.1 ovl.lnk
--- ld/testsuite/ld-spu/ovl.lnk	25 Oct 2006 06:49:21 -0000	1.1
+++ ld/testsuite/ld-spu/ovl.lnk	18 Apr 2007 02:10:03 -0000
@@ -3,10 +3,11 @@ SECTIONS
   . = SIZEOF_HEADERS;
   .text : { *(.text) *(.stub) }
 
-  . = 0x400;
-  .ov_a1 : { *(.ov_a1) }
-  .ov_a2 ADDR (.ov_a1) : { *(.ov_a2) }
-  . = ADDR (.ov_a1) + MAX (SIZEOF (.ov_a1), SIZEOF (.ov_a2));
+  OVERLAY 0x400 :
+  {
+    .ov_a1 { *(.ov_a1) }
+    .ov_a2 { *(.ov_a2) }
+  }
 
   .data : { *(.data) *(.ovtab) }
   .bss : { *(.bss) }

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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