public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@bigpond.net.au>
To: binutils@sourceware.org
Subject: Re: ld lma assignment
Date: Tue, 22 Aug 2006 11:51:00 -0000	[thread overview]
Message-ID: <20060822073344.GB23819@bubble.grove.modra.org> (raw)
In-Reply-To: <20060726050914.GK6872@bubble.grove.modra.org>

On Wed, Jul 26, 2006 at 02:39:14PM +0930, Alan Modra wrote:
> While playing with overlays recently, I noticed an annoying linker
> script requirement.  An output section following an overlay must have
> its lma specified (with AT or AT>).  As must any section following one
> with an lma adjustment, because ld defaults to setting lma equal to
> vma and this may cause lma overlap.

Fixes doco for this change, and warns on backward movement of VMA
unless accompanied with an explicit LMA assignment.  I guess I should
have added the news item when I committed the first patch to raise
awareness of the change in default lma.  Apologies for that, I wasn't
trying to slip a change in under the radar!  I still feel it's a good
change for 2.18, one that shouldn't affect too many scripts, and those
that it does are easily fixed.

	* NEWS: Mention LMA default change.
	* ld.texinfo (Output Section LMA): Update default description.
	(Location Counter): Clarify backward movement.
	* ldlang.c (lang_size_sections_1): Leave non-alloc sections with
	default lma equal to vma.  Warn on backward movement of dot.

Index: ld/NEWS
===================================================================
RCS file: /cvs/src/src/ld/NEWS,v
retrieving revision 1.66
diff -u -p -r1.66 NEWS
--- ld/NEWS	4 Aug 2006 14:53:26 -0000	1.66
+++ ld/NEWS	22 Aug 2006 04:39:19 -0000
@@ -1,4 +1,10 @@
 -*- text -*-
+* The default output section LMA has changed for allocatable sections from
+  being equal to VMA, to keeping the difference between LMA and VMA the same as
+  the previous output section in the same region.  This is a more useful
+  default when using overlays and other cases where you specify an LMA
+  differing from the VMA for some sections.
+
 * New switch: --print-gc-sections to list any sections removed by garabge
   collection.
 
Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.171
diff -u -p -r1.171 ld.texinfo
--- ld/ld.texinfo	4 Aug 2006 14:53:26 -0000	1.171
+++ ld/ld.texinfo	22 Aug 2006 04:39:24 -0000
@@ -3764,15 +3764,20 @@ Every section has a virtual address (VMA
 an output section description sets the VMA (@pxref{Output Section
 Address}).
 
-The linker will normally set the LMA equal to the VMA.  You can change
-that by using the @code{AT} keyword.  The expression @var{lma} that
-follows the @code{AT} keyword specifies the load address of the
-section.
+The expression @var{lma} that follows the @code{AT} keyword specifies
+the load address of the section.
 
 Alternatively, with @samp{AT>@var{lma_region}} expression, you may
 specify a memory region for the section's load address. @xref{MEMORY}.
 Note that if the section has not had a VMA assigned to it then the
 linker will use the @var{lma_region} as the VMA region as well.
+
+If neither @code{AT} nor @code{AT>} is specified for an allocatable
+section, the linker will set the LMA such that the difference between
+VMA and LMA for the section is the same as the preceding output
+section in the same region.  If there is no preceding output section
+or the section is not allocatable, the linker will set the LMA equal
+to the VMA.
 @xref{Output Section Region}.
 
 @cindex ROM initialized data
@@ -4586,7 +4591,9 @@ anywhere that an ordinary symbol is allo
 @cindex holes
 Assigning a value to @code{.} will cause the location counter to be
 moved.  This may be used to create holes in the output section.  The
-location counter may never be moved backwards.
+location counter may not be moved backwards inside an output section,
+and may not be moved backwards outside of an output section if so
+doing creates areas with overlapping LMAs.
 
 @smallexample
 SECTIONS
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.234
diff -u -p -r1.234 ldlang.c
--- ld/ldlang.c	16 Aug 2006 08:31:45 -0000	1.234
+++ ld/ldlang.c	22 Aug 2006 04:39:28 -0000
@@ -4400,16 +4400,30 @@ lang_size_sections_1
 		  lma = align_power (lma, os->section_alignment);
 		os->bfd_section->lma = lma;
 	      }
-	    else if (r->last_os != NULL)
+	    else if (r->last_os != NULL
+		     && (os->bfd_section->flags & SEC_ALLOC) != 0)
 	      {
 		bfd_vma lma;
 		asection *last;
 
 		last = r->last_os->output_section_statement.bfd_section;
-		/* If dot moved backwards (which is invalid according
-		   to ld docs) then leave lma equal to vma.  This
-		   keeps users of buggy ld scripts happy.  */
-		if (dot >= last->vma)
+
+		/* A backwards move of dot should be accompanied by
+		   an explicit assignment to the section LMA (ie.
+		   os->load_base set) because backwards moves normally
+		   create overlapping LMAs.  */
+		if (dot < last->vma)
+		  {
+		    einfo (_("%P: warning: dot moved backwards before `%s'\n"),
+			   os->name);
+
+		    /* If dot moved backwards then leave lma equal to
+		       vma.  This is the old default lma, which might
+		       just happen to work when the backwards move is
+		       sufficiently large.  Nag anyway, so people fix
+		       their linker scripts.  */
+		  }
+		else
 		  {
 		    /* If the current vma overlaps the previous section,
 		       then set the current lma to that at the end of
@@ -4440,9 +4454,16 @@ lang_size_sections_1
 	       lma region.  We use this to set the lma for
 	       following sections.  Overlays or other linker
 	       script assignment to lma might mean that the
-	       default lma == vma is incorrect.  */
+	       default lma == vma is incorrect.
+	       To avoid warnings about dot moving backwards when using
+	       -Ttext, don't start tracking sections until we find one
+	       of non-zero size or with lma set differently to vma.  */
 	    if (((os->bfd_section->flags & SEC_HAS_CONTENTS) != 0
 		 || (os->bfd_section->flags & SEC_THREAD_LOCAL) == 0)
+		&& (os->bfd_section->flags & SEC_ALLOC) != 0
+		&& (os->bfd_section->size != 0
+		    || os->bfd_section->vma != os->bfd_section->lma
+		    || r->last_os != NULL)
 		&& os->lma_region == NULL
 		&& !link_info.relocatable)
 	      r->last_os = s;

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

  reply	other threads:[~2006-08-22  7:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-26  5:09 Alan Modra
2006-08-22 11:51 ` Alan Modra [this message]
2006-08-22 18:46   ` H. J. Lu
2006-08-23  1:55     ` Alan Modra
2006-08-23  3:47       ` H. J. Lu
2006-08-23  1:34   ` H. J. Lu
2006-08-23  2:58     ` Alan Modra
2006-08-23  3:36       ` H. J. Lu
2006-08-23  5:08         ` PATCH: ld lma assignment test failure H. J. Lu
2006-08-23 10:25           ` Alan Modra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060822073344.GB23819@bubble.grove.modra.org \
    --to=amodra@bigpond.net.au \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).