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: output section ALIGN and relocatable links


On Wed, Nov 16, 2005 at 05:00:40PM +1030, Alan Modra wrote:
> On Tue, Nov 15, 2005 at 10:36:39AM -0800, Sterling Augustine wrote:
> > The output section's alignment is only copied to the output bfd's 
> > alignment in lang_add_section, which is only called when an input 
> > section goes into the output section.
> 
> I'll look into it.  The right place to set the alignment is in init_os.
> Hmm, I also think HJ's patch should have made this sort of ALIGN 
> set the minimum output section alignment, not override input sections.

	* ld.texinfo (Forced Output Alignment): Specify that this is an
	alignment increase, not an override.
	* ldlang.c (init_os): Set output section alignment here..
	(lang_add_section): ..rather than here.
	(lang_size_sections_1): Consolidate alignment code.  Warn if section
	alignment affects start address when explicit address given.

Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.151
diff -u -p -r1.151 ld.texinfo
--- ld/ld.texinfo	24 Oct 2005 23:07:12 -0000	1.151
+++ ld/ld.texinfo	16 Nov 2005 07:03:54 -0000
@@ -3775,9 +3775,7 @@ for (dst = &_bstart; dst< &_bend; dst++)
 @kindex ALIGN(@var{section_align})
 @cindex forcing output section alignment
 @cindex output section alignment
-You can force an output section alignment by using ALIGN.  The value
-specified overrides any alignment given by input sections, whether
-larger or smaller.
+You can increase an output section's alignment by using ALIGN.
 
 @node Forced Input Alignment
 @subsubsection Forced Input Alignment
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.204
diff -u -p -r1.204 ldlang.c
--- ld/ldlang.c	4 Nov 2005 13:26:53 -0000	1.204
+++ ld/ldlang.c	16 Nov 2005 07:03:57 -0000
@@ -1720,6 +1720,10 @@ init_os (lang_output_section_statement_t
   if (s->load_base != NULL)
     exp_init_os (s->load_base);
 
+  /* If supplied an alignment, set it.  */
+  if (s->section_alignment != -1)
+    s->bfd_section->alignment_power = s->section_alignment;
+
   if (isec)
     bfd_init_private_section_data (isec->owner, isec,
 				   output_bfd, s->bfd_section,
@@ -1941,10 +1945,6 @@ lang_add_section (lang_statement_list_ty
       if (section->alignment_power > output->bfd_section->alignment_power)
 	output->bfd_section->alignment_power = section->alignment_power;
 
-      /* If supplied an alignment, then force it.  */
-      if (output->section_alignment != -1)
-	output->bfd_section->alignment_power = output->section_alignment;
-
       if (bfd_get_arch (section->owner) == bfd_arch_tic54x
 	  && (section->flags & SEC_TIC54X_BLOCK) != 0)
 	{
@@ -4144,6 +4144,8 @@ lang_size_sections_1
 	      }
 	    else
 	      {
+		bfd_vma savedot;
+
 		if (os->addr_tree == NULL)
 		  {
 		    /* No address specified for this section, get one
@@ -4193,27 +4195,20 @@ lang_size_sections_1
 		      }
 
 		    newdot = os->region->current;
-
-		    if (os->section_alignment == -1)
-		      {
-			bfd_vma savedot = newdot;
-			newdot = align_power (newdot,
-					      os->bfd_section->alignment_power);
-
-			if (newdot != savedot
-			    && config.warn_section_align
-			    && expld.phase != lang_mark_phase_enum)
-			  einfo (_("%P: warning: changing start of section"
-				   " %s by %lu bytes\n"),
-				 os->name, (unsigned long) (newdot - savedot));
-		      }
 		  }
 
-		/* The section starts here.
-		   First, align to what the section needs.  */
-
-		if (os->section_alignment != -1)
-		  newdot = align_power (newdot, os->section_alignment);
+		/* Align to what the section needs.  */
+		savedot = newdot;
+		newdot = align_power (newdot,
+				      os->bfd_section->alignment_power);
+
+		if (newdot != savedot
+		    && (config.warn_section_align
+			|| os->addr_tree != NULL)
+		    && expld.phase != lang_mark_phase_enum)
+		  einfo (_("%P: warning: changing start of section"
+			   " %s by %lu bytes\n"),
+			 os->name, (unsigned long) (newdot - savedot));
 
 		bfd_set_section_vma (0, os->bfd_section, newdot);
 

-- 
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]