This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Two operand ALIGN
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: binutils at sources dot redhat dot com
- Date: Fri, 20 Feb 2004 13:53:04 +0000
- Subject: Two operand ALIGN
- Organization: Codesourcery LLC
Hi,
I kept writing (<expr> + ${ALIGN} - 1) & (${ALIGN} - 1) in a linker script,
and thought a two operand ALIGN (expr, align) builtin might be useful. With
this, ALIGN (expr) and ALIGN (., expr) are equivalent.
Here it is, tested on i686-pc-linux-gnu, ok?
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2004-02-20 Nathan Sidwell <nathan@codesourcery.com>
* ldgram.y (exp): Add two operand ALIGN.
* ldexp.c (fold_binary): Add ALIGN_K case.
* ld.texinfo (ALIGN): Document two operand version.
* ld-scripts/align.{s,t,exp}: New.
Index: ld/ldexp.c
===================================================================
RCS file: /cvs/src/src/ld/ldexp.c,v
retrieving revision 1.27
diff -c -3 -p -r1.27 ldexp.c
*** ld/ldexp.c 3 Jan 2004 12:39:07 -0000 1.27
--- ld/ldexp.c 20 Feb 2004 13:47:00 -0000
*************** fold_binary (etree_type *tree,
*** 394,399 ****
--- 394,403 ----
result = other;
break;
+ case ALIGN_K:
+ result.value = align_n (result.value, other.value);
+ break;
+
case DATA_SEGMENT_ALIGN:
if (allocation_done != lang_first_phase_enum
&& current_section == abs_output_section
Index: ld/ldgram.y
===================================================================
RCS file: /cvs/src/src/ld/ldgram.y,v
retrieving revision 1.31
diff -c -3 -p -r1.31 ldgram.y
*** ld/ldgram.y 18 Feb 2004 16:37:20 -0000 1.31
--- ld/ldgram.y 20 Feb 2004 13:47:01 -0000
*************** exp :
*** 804,809 ****
--- 804,811 ----
{ $$ = exp_unop(ABSOLUTE, $3); }
| ALIGN_K '(' exp ')'
{ $$ = exp_unop(ALIGN_K,$3); }
+ | ALIGN_K '(' exp ',' exp ')'
+ { $$ = exp_binop(ALIGN_K,$3,$5); }
| DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
{ $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
| DATA_SEGMENT_END '(' exp ')'
Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.104
diff -c -3 -p -r1.104 ld.texinfo
*** ld/ld.texinfo 20 Jan 2004 21:08:16 -0000 1.104
--- ld/ld.texinfo 20 Feb 2004 13:47:16 -0000
*************** SECTIONS @{ @dots{}
*** 4383,4399 ****
@end group
@end smallexample
! @item ALIGN(@var{exp})
! @kindex ALIGN(@var{exp})
@cindex round up location counter
@cindex align location counter
! Return the location counter (@code{.}) aligned to the next @var{exp}
! boundary.
! @code{ALIGN} doesn't change the value of the location counter---it just
! does arithmetic on it. Here is an example which aligns the output
! @code{.data} section to the next @code{0x2000} byte boundary after the
! preceding section and sets a variable within the section to the next
! @code{0x8000} boundary after the input sections:
@smallexample
@group
SECTIONS @{ @dots{}
--- 4383,4407 ----
@end group
@end smallexample
! @item ALIGN(@var{align})
! @itemx ALIGN(@var{exp},@var{align})
! @kindex ALIGN(@var{align})
! @kindex ALIGN(@var{exp},@var{align})
@cindex round up location counter
@cindex align location counter
! @cindex round up expression
! @cindex align expression
! Return the location counter (@code{.}) or arbitrary expression aligned
! to the next @var{align} boundary. The single operand @code{ALIGN}
! doesn't change the value of the location counter---it just does
! arithmetic on it. The two operand @code{ALIGN} allows an arbitrary
! expression to be aligned upwards (@code{ALIGN(@var{align})} is
! equivalent to @code{ALIGN(., @var{align})}).
!
! Here is an example which aligns the output @code{.data} section to the
! next @code{0x2000} byte boundary after the preceding section and sets a
! variable within the section to the next @code{0x8000} boundary after the
! input sections:
@smallexample
@group
SECTIONS @{ @dots{}
Index: ld/testsuite/ld-scripts/align.exp
===================================================================
RCS file: ld/testsuite/ld-scripts/align.exp
diff -N ld/testsuite/ld-scripts/align.exp
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/align.exp 20 Feb 2004 13:47:16 -0000
***************
*** 0 ****
--- 1,31 ----
+ # Test ALIGN in a linker script.
+ # By Nathan Sidwell, CodeSourcery LLC
+ # Copyright 2004
+ # Free Software Foundation, Inc.
+ #
+ # This file is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU General Public License as published by
+ # the Free Software Foundation; either version 2 of the License, or
+ # (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+ # along with this program; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ set testname "ALIGN"
+
+ if ![ld_assemble $as $srcdir/$subdir/align.s tmpdir/align.o] {
+ unresolved $testname
+ return
+ }
+
+ if ![ld_simple_link $ld tmpdir/align "-T $srcdir/$subdir/align.t tmpdir/align.o"] {
+ fail $testname
+ } else {
+ pass $testname
+ }
Index: ld/testsuite/ld-scripts/align.s
===================================================================
RCS file: ld/testsuite/ld-scripts/align.s
diff -N ld/testsuite/ld-scripts/align.s
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/align.s 20 Feb 2004 13:47:16 -0000
***************
*** 0 ****
--- 1,2 ----
+ .text
+ .long 0
Index: ld/testsuite/ld-scripts/align.t
===================================================================
RCS file: ld/testsuite/ld-scripts/align.t
diff -N ld/testsuite/ld-scripts/align.t
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/align.t 20 Feb 2004 13:47:16 -0000
***************
*** 0 ****
--- 1,8 ----
+ SECTIONS
+ {
+ .text : {*(.text)}
+ .data ALIGN(0x40) : AT (ALIGN (LOADADDR (.text) + SIZEOF (.text), 0x80))
+ {}
+ ASSERT (LOADADDR(.data) == 0x80, "dyadic ALIGN broken")
+ ASSERT (ADDR(.data) == 0x40, "monadic ALIGN broken")
+ }