public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PATCH: Fix empty sections with alignment
@ 2005-09-27  1:19 H. J. Lu
  2005-09-27  9:25 ` Alan Modra
  0 siblings, 1 reply; 5+ messages in thread
From: H. J. Lu @ 2005-09-27  1:19 UTC (permalink / raw)
  To: binutils; +Cc: amodra

This patch

http://sourceware.org/ml/binutils/2005-09/msg00215.html

breaks empty sections with alignment. The patch here works for me.


H.J.
----
2005-09-26  H.J. Lu  <hongjiu.lu@intel.com>

	* ldlang.c (lang_size_sections_1): Process alignment addr_tree
	later.

--- ld/ldlang.c.empty	2005-09-26 13:12:55.000000000 -0700
+++ ld/ldlang.c	2005-09-26 15:21:08.000000000 -0700
@@ -4044,7 +4044,9 @@ lang_size_sections_1
 	    lang_output_section_statement_type *os;
 
 	    os = &s->output_section_statement;
-	    if (os->addr_tree != NULL)
+	    if (os->addr_tree != NULL
+		&& !(os->addr_tree->type.node_class == etree_unary
+		     && os->addr_tree->type.node_code == ALIGN_K))
 	      {
 		os->processed = FALSE;
 		exp_fold_tree (os->addr_tree, bfd_abs_section_ptr, &dot);
@@ -4159,6 +4161,22 @@ lang_size_sections_1
 				 os->name, (unsigned long) (newdot - savedot));
 		      }
 		  }
+		else if (os->addr_tree->type.node_class == etree_unary
+			 && os->addr_tree->type.node_code == ALIGN_K)
+		  {
+		    newdot = dot;
+		    os->processed = FALSE;
+		    exp_fold_tree (os->addr_tree, bfd_abs_section_ptr,
+				   &newdot);
+
+		    if (!expld.result.valid_p
+			&& expld.phase != lang_mark_phase_enum)
+		      einfo (_("%F%S: non constant or forward reference"
+			       " address expression for section %s\n"),
+			     os->name);
+
+		    newdot = expld.result.value + expld.result.section->vma;
+		  }
 
 		/* The section starts here.
 		   First, align to what the section needs.  */

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: Fix empty sections with alignment
  2005-09-27  1:19 PATCH: Fix empty sections with alignment H. J. Lu
@ 2005-09-27  9:25 ` Alan Modra
  2005-09-27 18:34   ` H. J. Lu
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2005-09-27  9:25 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

On Mon, Sep 26, 2005 at 03:36:01PM -0700, H. J. Lu wrote:
> This patch
> 
> http://sourceware.org/ml/binutils/2005-09/msg00215.html
> 
> breaks empty sections with alignment. The patch here works for me.

It would be nice if you explained what was broken rather than leaving me
to deduce that from your patch.  In this case it's simple, but sometimes
I'm not clever enough to immediately deduce what you think is broken.

Before I OK this patch:  Do you know whether any linker scripts depend
on an address expression consisting of an ALIGN() being ignored like
this?  Besides those distributed with binutils, or prerelease linux
kernels, I mean.  The reason I ask is that I'm not really happy with the
direction this patch is leading.  We shouldn't be treating an ALIGN()
specially.  After all, ALIGN(x) as an address is supposed to be
eqivalent to ((.+x-1)/x)*x, and people could reasonably expect that both
expressions behave the same.  Which they won't after your patch.

Instead, I think we need some linker script construct that allows us to
increase the alignment of an output section over that specified by its
input sections, other than using ALIGN() as the address.  Perhaps an
ALIGN() after the semicolon.  lang_enter_output_section_statement
already supports an output section alignment.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: Fix empty sections with alignment
  2005-09-27  9:25 ` Alan Modra
@ 2005-09-27 18:34   ` H. J. Lu
  2005-09-27 21:21     ` H. J. Lu
  0 siblings, 1 reply; 5+ messages in thread
From: H. J. Lu @ 2005-09-27 18:34 UTC (permalink / raw)
  To: binutils

On Tue, Sep 27, 2005 at 12:03:15PM +0930, Alan Modra wrote:
> On Mon, Sep 26, 2005 at 03:36:01PM -0700, H. J. Lu wrote:
> > This patch
> > 
> > http://sourceware.org/ml/binutils/2005-09/msg00215.html
> > 
> > breaks empty sections with alignment. The patch here works for me.
> 
> It would be nice if you explained what was broken rather than leaving me
> to deduce that from your patch.  In this case it's simple, but sometimes
> I'm not clever enough to immediately deduce what you think is broken.
> 
> Before I OK this patch:  Do you know whether any linker scripts depend
> on an address expression consisting of an ALIGN() being ignored like
> this?  Besides those distributed with binutils, or prerelease linux

Yes, I do. That is how I noticed it. I am working for a sharable memory
project for clusters where the output sharable memory section should be
page aligned.

> kernels, I mean.  The reason I ask is that I'm not really happy with the
> direction this patch is leading.  We shouldn't be treating an ALIGN()
> specially.  After all, ALIGN(x) as an address is supposed to be
> eqivalent to ((.+x-1)/x)*x, and people could reasonably expect that both
> expressions behave the same.  Which they won't after your patch.
> 
> Instead, I think we need some linker script construct that allows us to
> increase the alignment of an output section over that specified by its
> input sections, other than using ALIGN() as the address.  Perhaps an
> ALIGN() after the semicolon.  lang_enter_output_section_statement
> already supports an output section alignment.

I will look into it.


H.J.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: Fix empty sections with alignment
  2005-09-27 18:34   ` H. J. Lu
@ 2005-09-27 21:21     ` H. J. Lu
  2005-09-28  8:39       ` Alan Modra
  0 siblings, 1 reply; 5+ messages in thread
From: H. J. Lu @ 2005-09-27 21:21 UTC (permalink / raw)
  To: binutils

On Tue, Sep 27, 2005 at 08:04:05AM -0700, H. J. Lu wrote:
> > 
> > Instead, I think we need some linker script construct that allows us to
> > increase the alignment of an output section over that specified by its
> > input sections, other than using ALIGN() as the address.  Perhaps an
> > ALIGN() after the semicolon.  lang_enter_output_section_statement
> > already supports an output section alignment.
> 
> I will look into it.
> 

Here is the patch to allow ALIGN to be used to force output section
alignment.


H.J.
----
2005-09-27  H.J. Lu  <hongjiu.lu@intel.com>

	* ld.texinfo (ALIGN): Document it as forcing output section
	alignment.

	* ldgram.y (ALIGN): Support it for forcing output section
	alignment.

--- ld/ld.texinfo.align	2005-09-26 13:12:55.000000000 -0700
+++ ld/ld.texinfo	2005-09-27 10:11:16.000000000 -0700
@@ -3067,7 +3067,7 @@ The full description of an output sectio
 @smallexample
 @group
 @var{section} [@var{address}] [(@var{type})] :
-  [AT(@var{lma})] [SUBALIGN(@var{subsection_align})]
+  [AT(@var{lma})] [ALIGN(@var{section_align})] [SUBALIGN(@var{subsection_align})]
   @{
     @var{output-section-command}
     @var{output-section-command}
@@ -3643,7 +3643,7 @@ like this:
 @smallexample
 @group
 @var{section} [@var{address}] [(@var{type})] :
-  [AT(@var{lma})] [SUBALIGN(@var{subsection_align})]
+  [AT(@var{lma})] [ALIGN(@var{section_align})] [SUBALIGN(@var{subsection_align})]
   @{
     @var{output-section-command}
     @var{output-section-command}
@@ -3658,6 +3658,7 @@ remaining section attributes.
 @menu
 * Output Section Type::		Output section type
 * Output Section LMA::		Output section LMA
+* Forced Output Alignment::	Forced Output Alignment
 * Forced Input Alignment::	Forced Input Alignment
 * Output Section Region::	Output section region
 * Output Section Phdr::		Output section phdr
@@ -3771,6 +3772,15 @@ for (dst = &_bstart; dst< &_bend; dst++)
 @end group
 @end smallexample
 
+@node Forced Output Alignment
+@subsubsection Forced Output Alignment
+@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.
+
 @node Forced Input Alignment
 @subsubsection Forced Input Alignment
 @kindex SUBALIGN(@var{subsection_align})
--- ld/ldgram.y.align	2005-09-26 13:12:55.000000000 -0700
+++ ld/ldgram.y	2005-09-27 10:04:14.000000000 -0700
@@ -92,7 +92,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 opt_subalign
+%type <etree> opt_exp_without_type opt_subalign opt_align
 %type <fill> fill_opt fill_exp
 %type <name_list> exclude_name_list
 %type <wildcard_list> file_NAME_list
@@ -892,6 +892,11 @@ opt_at:
 	|	{ $$ = 0; }
 	;
 
+opt_align:
+		ALIGN_K '(' exp ')' { $$ = $3; }
+	|	{ $$ = 0; }
+	;
+
 opt_subalign:
 		SUBALIGN '(' exp ')' { $$ = $3; }
 	|	{ $$ = 0; }
@@ -907,20 +912,21 @@ sect_constraint:
 section:	NAME 		{ ldlex_expression(); }
 		opt_exp_with_type
 		opt_at
+		opt_align
 		opt_subalign	{ ldlex_popstate (); ldlex_script (); }
 		sect_constraint
 		'{'
 			{
 			  lang_enter_output_section_statement($1, $3,
 							      sectype,
-							      0, $5, $4, $7);
+							      $5, $6, $4, $8);
 			}
 		statement_list_opt
  		'}' { ldlex_popstate (); ldlex_expression (); }
 		memspec_opt memspec_at_opt phdr_opt fill_opt
 		{
 		  ldlex_popstate ();
-		  lang_leave_output_section_statement ($16, $13, $15, $14);
+		  lang_leave_output_section_statement ($17, $14, $16, $15);
 		}
 		opt_comma
 		{}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: Fix empty sections with alignment
  2005-09-27 21:21     ` H. J. Lu
@ 2005-09-28  8:39       ` Alan Modra
  0 siblings, 0 replies; 5+ messages in thread
From: Alan Modra @ 2005-09-28  8:39 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

On Tue, Sep 27, 2005 at 12:12:15PM -0700, H. J. Lu wrote:
> 2005-09-27  H.J. Lu  <hongjiu.lu@intel.com>
> 
> 	* ld.texinfo (ALIGN): Document it as forcing output section
> 	alignment.
> 
> 	* ldgram.y (ALIGN): Support it for forcing output section
> 	alignment.

OK.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-09-27 23:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-27  1:19 PATCH: Fix empty sections with alignment H. J. Lu
2005-09-27  9:25 ` Alan Modra
2005-09-27 18:34   ` H. J. Lu
2005-09-27 21:21     ` H. J. Lu
2005-09-28  8:39       ` Alan Modra

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).