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:41:52PM +1030, Alan Modra wrote:
> 	(lang_size_sections_1): Consolidate alignment code.  Warn if section
> 	alignment affects start address when explicit address given.

This wasn't a good idea.  The ld documentation is clear that if an
address is given for an output section, then that is where it starts,
regardless of input section alignment.  It was unspecified what happens
if both output section alignment and output section address were given,
but the old code applied alignment on top of the address.

I also noticed that the section alignment warning message uses %lu,
which isn't provided by einfo.

ld/ChangeLog
	* ldlang.c (lang_size_sections_1): Revert 2005-11-16 functional
	changes to section alignment.
	* ldmisc.c (vfinfo): Handle %ld and %lu.

Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.207
diff -u -p -r1.207 ldlang.c
--- ld/ldlang.c	17 Nov 2005 00:10:05 -0000	1.207
+++ ld/ldlang.c	18 Nov 2005 04:04:11 -0000
@@ -4137,7 +4137,7 @@ lang_size_sections_1
 	      }
 	    else
 	      {
-		bfd_vma savedot;
+		int align;
 
 		if (os->addr_tree == NULL)
 		  {
@@ -4188,20 +4188,25 @@ lang_size_sections_1
 		      }
 
 		    newdot = os->region->current;
+		    align = os->bfd_section->alignment_power;
 		  }
+		else
+		  align = 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));
+		if (align > 0)
+		  {
+		    bfd_vma savedot = newdot;
+		    newdot = align_power (newdot, align);
+
+		    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);
 
Index: ld/ldmisc.c
===================================================================
RCS file: /cvs/src/src/ld/ldmisc.c,v
retrieving revision 1.27
diff -u -p -r1.27 ldmisc.c
--- ld/ldmisc.c	5 Oct 2005 16:12:17 -0000	1.27
+++ ld/ldmisc.c	18 Nov 2005 04:04:11 -0000
@@ -55,6 +55,8 @@
  %W hex bfd_vma with 0x with no leading zeros taking up 8 spaces
  %X no object output, fail return
  %d integer, like printf
+ %ld long, like printf
+ %lu unsigned long, like printf
  %s arbitrary string, like printf
  %u integer, like printf
  %v hex bfd_vma, no leading zeros
@@ -78,10 +80,6 @@ vfinfo (FILE *fp, const char *fmt, va_li
 	  fmt++;
 	  switch (*fmt++)
 	    {
-	    default:
-	      fprintf (fp, "%%%c", fmt[-1]);
-	      break;
-
 	    case '%':
 	      /* literal % */
 	      putc ('%', fp);
@@ -407,6 +405,25 @@ vfinfo (FILE *fp, const char *fmt, va_li
 	      /* unsigned integer, like printf */
 	      fprintf (fp, "%u", va_arg (arg, unsigned int));
 	      break;
+
+	    case 'l':
+	      if (*fmt == 'd')
+		{
+		  fprintf (fp, "%ld", va_arg (arg, long));
+		  ++fmt;
+		  break;
+		}
+	      else if (*fmt == 'u')
+		{
+		  fprintf (fp, "%lu", va_arg (arg, unsigned long));
+		  ++fmt;
+		  break;
+		}
+	      /* Fall thru */
+
+	    default:
+	      fprintf (fp, "%%%c", fmt[-1]);
+	      break;
 	    }
 	}
     }

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