This is the mail archive of the binutils@sources.redhat.com 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]

MRI ld feature


MRI ld allows alignment of input sections to be forced.  This patch
makes the underlying support in GNU ld generally available via a new
linker keyword.  Probably not hugely exciting for most people, but
someone I know wanted this feature.  In the process of describing to him
where he'd need to hack ld, I discovered existing code..

	* ld.texinfo: Typo fixes.  Document SUBALIGN.
	* ldgram.y (opt_subalign): Add.
	* ldlex.l (SUBALIGN): Recognize.
	* ldlang.c (overlay_subalign): New var.
	(lang_enter_overlay): Add subalign param.
	(lang_enter_overlay_section): Pass overlay_subalign to
	lang_enter_output_section_statement.
	* ldlang.h (lang_enter_overlay): Update.

Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.95
diff -u -p -r1.95 ld.texinfo
--- ld/ld.texinfo	25 Jun 2003 06:40:26 -0000	1.95
+++ ld/ld.texinfo	26 Jul 2003 14:38:32 -0000
@@ -1217,7 +1217,7 @@ this option overrides it.  @xref{BFD}.
 Create a position independent executable.  This is currently only supported on
 ELF platforms.  Position independent executables are similar to shared
 libraries in that they are relocated by the dynamic linker to the virtual
-address OS chooses for them (which can varry between invocations), like
+address the OS chooses for them (which can vary between invocations).  Like
 normal dynamically linked executables they can be executed and symbols
 defined in the executable cannot be overridden by shared libraries.
 
@@ -2686,7 +2686,8 @@ in the first input file.  The first sect
 The full description of an output section looks like this:
 @smallexample
 @group
-@var{section} [@var{address}] [(@var{type})] : [AT(@var{lma})]
+@var{section} [@var{address}] [(@var{type})] :
+  [AT(@var{lma})] [SUBALIGN(@var{subsection_align})]
   @{
     @var{output-section-command}
     @var{output-section-command}
@@ -3207,7 +3208,8 @@ We showed above that the full descriptio
 like this:
 @smallexample
 @group
-@var{section} [@var{address}] [(@var{type})] : [AT(@var{lma})]
+@var{section} [@var{address}] [(@var{type})] :
+  [AT(@var{lma})] [SUBALIGN(@var{subsection_align})]
   @{
     @var{output-section-command}
     @var{output-section-command}
@@ -3222,6 +3224,7 @@ remaining section attributes.
 @menu
 * Output Section Type::		Output section type
 * Output Section LMA::		Output section LMA
+* Forced Input Alignment::	Forced Input Alignment
 * Output Section Region::	Output section region
 * Output Section Phdr::		Output section phdr
 * Output Section Fill::		Output section fill
@@ -3328,6 +3331,15 @@ for (dst = &_bstart; dst< &_bend; dst++)
   *dst = 0;
 @end group
 @end smallexample
+
+@node Forced Input Alignment
+@subsubsection Forced Input Alignment
+@kindex SUBALIGN(@var{subsection_align})
+@cindex forcing input section alignment
+@cindex input section alignment
+You can force input section alignment within an output section by using
+SUBALIGN.  The value specified overrides any alignment given by input
+sections, whether larger or smaller.
 
 @node Output Section Region
 @subsubsection Output Section Region
Index: ld/ldgram.y
===================================================================
RCS file: /cvs/src/src/ld/ldgram.y,v
retrieving revision 1.26
diff -u -p -r1.26 ldgram.y
--- ld/ldgram.y	3 Jun 2003 22:27:24 -0000	1.26
+++ ld/ldgram.y	26 Jul 2003 14:38:33 -0000
@@ -94,7 +94,7 @@ static int error_index;
 }
 
 %type <etree> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val
-%type <etree> opt_exp_without_type
+%type <etree> opt_exp_without_type opt_subalign
 %type <fill> fill_opt fill_exp
 %type <name_list> exclude_name_list
 %type <wildcard_list> file_NAME_list
@@ -142,7 +142,7 @@ static int error_index;
 %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS
 %token ORIGIN FILL
 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
-%token ALIGNMOD AT PROVIDE
+%token ALIGNMOD AT SUBALIGN PROVIDE
 %type <token> assign_op atype attributes_opt
 %type <name>  filename
 %token CHIP LIST SECT ABSOLUTE  LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
@@ -828,31 +828,37 @@ opt_at:
 	|	{ $$ = 0; }
 	;
 
+opt_subalign:
+		SUBALIGN '(' exp ')' { $$ = $3; }
+	|	{ $$ = 0; }
+	;
+
 section:	NAME 		{ ldlex_expression(); }
 		opt_exp_with_type
-		opt_at   	{ ldlex_popstate (); ldlex_script (); }
+		opt_at
+		opt_subalign	{ ldlex_popstate (); ldlex_script (); }
 		'{'
 			{
 			  lang_enter_output_section_statement($1, $3,
 							      sectype,
-							      0, 0, 0, $4);
+							      0, 0, $5, $4);
 			}
 		statement_list_opt
  		'}' { ldlex_popstate (); ldlex_expression (); }
 		memspec_opt memspec_at_opt phdr_opt fill_opt
 		{
 		  ldlex_popstate ();
-		  lang_leave_output_section_statement ($14, $11, $13, $12);
+		  lang_leave_output_section_statement ($15, $12, $14, $13);
 		}
 		opt_comma
 		{}
 	|	OVERLAY
 			{ ldlex_expression (); }
-		opt_exp_without_type opt_nocrossrefs opt_at
+		opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
 			{ ldlex_popstate (); ldlex_script (); }
 		'{'
 			{
-			  lang_enter_overlay ($3);
+			  lang_enter_overlay ($3, $6);
 			}
 		overlay_section
 		'}'
@@ -861,7 +867,7 @@ section:	NAME 		{ ldlex_expression(); }
 			{
 			  ldlex_popstate ();
 			  lang_leave_overlay ($5, (int) $4,
-					      $15, $12, $14, $13);
+					      $16, $13, $15, $14);
 			}
 		opt_comma
 	|	/* The GROUP case is just enough to support the gcc
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.116
diff -u -p -r1.116 ldlang.c
--- ld/ldlang.c	28 Jun 2003 05:28:54 -0000	1.116
+++ ld/ldlang.c	26 Jul 2003 14:38:35 -0000
@@ -4649,6 +4649,8 @@ lang_add_nocrossref (struct lang_nocross
 
 /* The overlay virtual address.  */
 static etree_type *overlay_vma;
+/* And subsection alignment.  */
+static etree_type *overlay_subalign;
 
 /* An expression for the maximum section size seen so far.  */
 static etree_type *overlay_max;
@@ -4665,12 +4667,15 @@ static struct overlay_list *overlay_list
 /* Start handling an overlay.  */
 
 void
-lang_enter_overlay (etree_type *vma_expr)
+lang_enter_overlay (etree_type *vma_expr, etree_type *subalign)
 {
   /* The grammar should prevent nested overlays from occurring.  */
-  ASSERT (overlay_vma == NULL && overlay_max == NULL);
+  ASSERT (overlay_vma == NULL
+	  && overlay_subalign == NULL
+	  && overlay_max == NULL);
 
   overlay_vma = vma_expr;
+  overlay_subalign = subalign;
 }
 
 /* Start a section in an overlay.  We handle this by calling
@@ -4684,7 +4689,7 @@ lang_enter_overlay_section (const char *
   etree_type *size;
 
   lang_enter_output_section_statement (name, overlay_vma, normal_section,
-				       0, 0, 0, 0);
+				       0, 0, overlay_subalign, 0);
 
   /* If this is the first section, then base the VMA of future
      sections on this one.  This will work correctly even if `.' is
Index: ld/ldlang.h
===================================================================
RCS file: /cvs/src/src/ld/ldlang.h,v
retrieving revision 1.28
diff -u -p -r1.28 ldlang.h
--- ld/ldlang.h	28 Jun 2003 05:28:54 -0000	1.28
+++ ld/ldlang.h	26 Jul 2003 14:38:36 -0000
@@ -492,7 +492,7 @@ extern void lang_new_phdr
 extern void lang_add_nocrossref
   (struct lang_nocrossref *);
 extern void lang_enter_overlay
-  (etree_type *);
+  (etree_type *, etree_type *);
 extern void lang_enter_overlay_section
   (const char *);
 extern void lang_leave_overlay_section
Index: ld/ldlex.l
===================================================================
RCS file: /cvs/src/src/ld/ldlex.l,v
retrieving revision 1.20
diff -u -p -r1.20 ldlex.l
--- ld/ldlex.l	28 Jun 2003 05:28:54 -0000	1.20
+++ ld/ldlex.l	26 Jul 2003 14:38:36 -0000
@@ -306,6 +306,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^]([*?
 <BOTH,SCRIPT>"INCLUDE"			{ RTOKEN(INCLUDE);}
 <BOTH,SCRIPT>"PHDRS"			{ RTOKEN (PHDRS); }
 <EXPRESSION,BOTH,SCRIPT>"AT"			{ RTOKEN(AT);}
+<EXPRESSION,BOTH,SCRIPT>"SUBALIGN"		{ RTOKEN(SUBALIGN);}
 <EXPRESSION,BOTH,SCRIPT>"PROVIDE"		{ RTOKEN(PROVIDE); }
 <EXPRESSION,BOTH,SCRIPT>"KEEP"		{ RTOKEN(KEEP); }
 <EXPRESSION,BOTH,SCRIPT>"EXCLUDE_FILE"        { RTOKEN(EXCLUDE_FILE); }

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