* ldlang.c: Likewise.
	* ldlang.h: Likewise.
	* ldlex.l: Likewise.
	* mri.c: Likewise.
	* ld.texinfo: Document new feature.
	* NEWS: Mention new feature.
	* ld-scripts/script.exp: Run align with input test.
	* ld-scripts/align-with-input.t: New file.
	* ld-scripts/rgn-at8.d: Likewise.
	* ld-scripts/rgn-at8.t: Likewise.
+2013-07-19  Sebastian Huber  <sebastian.huber@embedded-brains.de>
+
+       * ldgram.y: Add ALIGN_WITH_INPUT output section attribute.
+       * ldlang.c: Likewise.
+       * ldlang.h: Likewise.
+       * ldlex.l: Likewise.
+       * mri.c: Likewise.
+       * ld.texinfo: Document new feature.
+       * NEWS: Mention new feature.
+
 2013-07-18  Roland McGrath  <mcgrathr@google.com>
 
        * emultempl/armelf.em (elf32_arm_add_stub_section): Take third
 
 
 * Remove linker support for MIPS ECOFF targets.
 
+* Add ALIGN_WITH_INPUT to the linker script language to force the alignment of
+  an output section to use the maximum alignment of all its input sections.
+
 Changes in 2.23:
 
 * Enable compressed debug section feature for x86/x86_64 pe-coff.
 
 @group
 @var{section} [@var{address}] [(@var{type})] :
   [AT(@var{lma})]
-  [ALIGN(@var{section_align})]
+  [ALIGN(@var{section_align}) | ALIGN_WITH_INPUT]
   [SUBALIGN(@var{subsection_align})]
   [@var{constraint}]
   @{
 @kindex ALIGN(@var{section_align})
 @cindex forcing output section alignment
 @cindex output section alignment
-You can increase an output section's alignment by using ALIGN.
+You can increase an output section's alignment by using ALIGN.  As an
+alternative you can force the output section alignment to the maximum alignment
+of all its input sections with ALIGN_WITH_INPUT.  The alignment forced by
+ALIGN_WITH_INPUT is used even in case the load and virtual memory regions are
+different.
 
 @node Forced Input Alignment
 @subsubsection Forced Input Alignment
 
 /* A YACC grammar to parse a superset of the AT&T linker scripting language.
-   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
-   Free Software Foundation, Inc.
+   Copyright 1991-2013 Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
 
    This file is part of the GNU Binutils.
 %token ORIGIN FILL
 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
 %token ALIGNMOD AT SUBALIGN HIDDEN PROVIDE PROVIDE_HIDDEN AS_NEEDED
-%type <token> assign_op atype attributes_opt sect_constraint
+%type <token> assign_op atype attributes_opt sect_constraint opt_align_with_input
 %type <name>  filename
 %token CHIP LIST SECT ABSOLUTE  LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
 %token <name> VERS_TAG VERS_IDENTIFIER
 %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
-%token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL INPUT_SECTION_FLAGS
+%token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL INPUT_SECTION_FLAGS ALIGN_WITH_INPUT
 %token EXCLUDE_FILE
 %token CONSTANT
 %type <versyms> vers_defns
        |       { $$ = 0; }
        ;
 
+opt_align_with_input:
+               ALIGN_WITH_INPUT { $$ = ALIGN_WITH_INPUT; }
+       |       { $$ = 0; }
+       ;
+
 opt_subalign:
                SUBALIGN '(' exp ')' { $$ = $3; }
        |       { $$ = 0; }
                opt_exp_with_type
                opt_at
                opt_align
+               opt_align_with_input
                opt_subalign    { ldlex_popstate (); ldlex_script (); }
                sect_constraint
                '{'
                        {
                          lang_enter_output_section_statement($1, $3,
                                                              sectype,
-                                                             $5, $6, $4, $8);
+                                                             $5, $7, $4, $9, $6);
                        }
                statement_list_opt
                '}' { ldlex_popstate (); ldlex_expression (); }
                memspec_opt memspec_at_opt phdr_opt fill_opt
                {
                  ldlex_popstate ();
-                 lang_leave_output_section_statement ($17, $14, $16, $15);
+                 lang_leave_output_section_statement ($18, $15, $17, $16);
                }
                opt_comma
                {}
 
 /* Linker command language support.
-   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
-   Free Software Foundation, Inc.
+   Copyright 1991-2013 Free Software Foundation, Inc.
 
    This file is part of the GNU Binutils.
 
   os_tail = ((lang_output_section_statement_type **)
             lang_output_section_statement.tail);
   os = lang_enter_output_section_statement (secname, address, normal_section,
-                                           NULL, NULL, NULL, constraint);
+                                           NULL, NULL, NULL, constraint, 0);
 
   ps = NULL;
   if (config.build_constructors && *os_tail == os)
                   as we did for the VMA, possibly including alignment
                   from the bfd section.  If a different region, then
                   only align according to the value in the output
-                  statement.  */
-               if (os->lma_region != os->region)
+                  statement unless specified otherwise.  */
+               if (os->lma_region != os->region && !os->align_lma_with_input)
                  section_alignment = os->section_alignment;
                if (section_alignment > 0)
                  lma = align_power (lma, section_alignment);
                                     etree_type *align,
                                     etree_type *subalign,
                                     etree_type *ebase,
-                                    int constraint)
+                                    int constraint,
+                                    int align_with_input)
 {
   lang_output_section_statement_type *os;
 
   /* Make next things chain into subchain of this.  */
   push_stat_ptr (&os->children);
 
+  os->align_lma_with_input = align_with_input == ALIGN_WITH_INPUT;
+  if (os->align_lma_with_input && align != NULL)
+    einfo (_("%F%P:%S: error: align with input and explicit align specified\n"), NULL);
+
   os->subsection_alignment =
     topower (exp_get_value_int (subalign, -1, "subsection alignment"));
   os->section_alignment =
   etree_type *size;
 
   lang_enter_output_section_statement (name, overlay_vma, overlay_section,
-                                      0, overlay_subalign, 0, 0);
+                                      0, overlay_subalign, 0, 0, 0);
 
   /* If this is the first section, then base the VMA of future
      sections on this one.  This will work correctly even if `.' is
 
 /* ldlang.h - linker command language support
-   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
-   Free Software Foundation, Inc.
+   Copyright 1991-2013 Free Software Foundation, Inc.
 
    This file is part of the GNU Binutils.
 
   unsigned int update_dot : 1;
   /* If this section is after assignment to _end.  */
   unsigned int after_end : 1;
+  /* If this section uses the alignment of its input sections.  */
+  unsigned int align_lma_with_input : 1;
 } lang_output_section_statement_type;
 
 typedef struct
 extern void lang_add_output
   (const char *, int from_script);
 extern lang_output_section_statement_type *lang_enter_output_section_statement
-  (const char *output_section_statement_name,
-   etree_type *address_exp,
-   enum section_type sectype,
-   etree_type *align,
-   etree_type *subalign,
-   etree_type *, int);
+  (const char *, etree_type *, enum section_type, etree_type *, etree_type *,
+   etree_type *, int, int);
 extern void lang_final
   (void);
 extern void lang_relax_sections
 
 
 %{
 
-/* Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
-   Free Software Foundation, Inc.
+/* Copyright 1991-2013 Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support.
 
    This file is part of the GNU Binutils.
 <EXPRESSION,BOTH,SCRIPT>"INCLUDE"      { RTOKEN(INCLUDE);}
 <BOTH,SCRIPT>"PHDRS"                   { RTOKEN (PHDRS); }
 <EXPRESSION,BOTH,SCRIPT>"AT"           { RTOKEN(AT);}
+<EXPRESSION,BOTH,SCRIPT>"ALIGN_WITH_INPUT"     { RTOKEN(ALIGN_WITH_INPUT);}
 <EXPRESSION,BOTH,SCRIPT>"SUBALIGN"     { RTOKEN(SUBALIGN);}
 <EXPRESSION,BOTH,SCRIPT>"HIDDEN"       { RTOKEN(HIDDEN); }
 <EXPRESSION,BOTH,SCRIPT>"PROVIDE"      { RTOKEN(PROVIDE); }
 
 
          lang_enter_output_section_statement (p->name, base,
                                               p->ok_to_load ? normal_section : noload_section,
-                                              align, subalign, NULL, 0);
+                                              align, subalign, NULL, 0, 0);
          base = 0;
          tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
          tmp->next = NULL;
 
+2013-07-19  Sebastian Huber  <sebastian.huber@embedded-brains.de>
+
+       * ld-scripts/script.exp: Run align with input test.
+       * ld-scripts/align-with-input.t: New file.
+       * ld-scripts/rgn-at8.d: Likewise.
+       * ld-scripts/rgn-at8.t: Likewise.
+
 2013-07-18  Terry Guo  <terry.guo@arm.com>
 
         * ld-arm/thumb-b-lks-sym.d: Updated to be more flexible.
 
--- /dev/null
+SECTIONS {
+  .abc : ALIGN(1) ALIGN_WITH_INPUT {
+    *(.abc)
+  }
+}
 
--- /dev/null
+#source: rgn-at6.s
+#ld: -T rgn-at8.t
+#objdump: -h --wide
+#xfail: rx-*-*
+# Test that lma is aligned when lma_region!=region and requested by script.
+
+#...
+.* 0+10000 +0+20000 .*
+.* 0+10100 +0+20100 .*
 
 # Test basic linker script functionality
 # By Ian Lance Taylor, Cygnus Support
-#   Copyright 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2009, 2010
-#   Free Software Foundation, Inc.
+#   Copyright 1999-2013 Free Software Foundation, Inc.
 #
 # This file is part of the GNU Binutils.
 #
         xpass "REGION_ALIAS: $testname"
     }
 }
+
+set testname "ALIGN_WITH_INPUT"
+
+if ![ld_simple_link $ld tmpdir/script "$flags -T $srcdir/$subdir/align-with-input.t tmpdir/script.o"] {
+    xfail $testname
+} else {
+    xpass $testname
+}