* opncls.c (bfd_zalloc): Document this function.
[deliverable/binutils-gdb.git] / ld / ldgram.y
index bdfdcd5ddd65d7dd3ab934de53d7422ed5234e79..23151d8f6b09f4a53974390f1b14bb87b21779f8 100644 (file)
@@ -1,23 +1,23 @@
 /* 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 Free Software Foundation, Inc.
+   2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
 
-This file is part of GNU ld.
+   This file is part of GNU ld.
 
-This program 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 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.
+   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.  */
+   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.  */
 
 %{
 /*
@@ -134,6 +134,7 @@ static int error_index;
 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
 %token INHIBIT_COMMON_ALLOCATION
 %token SIZEOF_HEADERS
+%token SEGMENT_START
 %token INCLUDE
 %token MEMORY DEFSYMEND
 %token NOLOAD DSECT COPY INFO OVERLAY
@@ -143,7 +144,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 SUBALIGN PROVIDE
+%token ALIGNMOD AT SUBALIGN PROVIDE AS_NEEDED
 %type <token> assign_op atype attributes_opt sect_constraint
 %type <name>  filename
 %token CHIP LIST SECT ABSOLUTE  LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
@@ -371,6 +372,18 @@ input_list:
        |       input_list LNAME
                { lang_add_input_file($2,lang_input_file_is_l_enum,
                                 (char *)NULL); }
+       |       AS_NEEDED '('
+                 { $<integer>$ = as_needed; as_needed = TRUE; }
+                    input_list ')'
+                 { as_needed = $<integer>3; }
+       |       input_list ',' AS_NEEDED '('
+                 { $<integer>$ = as_needed; as_needed = TRUE; }
+                    input_list ')'
+                 { as_needed = $<integer>5; }
+       |       input_list AS_NEEDED '('
+                 { $<integer>$ = as_needed; as_needed = TRUE; }
+                    input_list ')'
+                 { as_needed = $<integer>4; }
        ;
 
 sections:
@@ -761,98 +774,111 @@ nocrossref_list:
                }
        ;
 
-mustbe_exp:             { ldlex_expression(); }
+mustbe_exp:             { ldlex_expression (); }
                exp
-                        { ldlex_popstate(); $$=$2;}
+                        { ldlex_popstate (); $$=$2;}
        ;
 
 exp    :
                '-' exp %prec UNARY
-                       { $$ = exp_unop('-', $2); }
+                       { $$ = exp_unop ('-', $2); }
        |       '(' exp ')'
                        { $$ = $2; }
        |       NEXT '(' exp ')' %prec UNARY
-                       { $$ = exp_unop((int) $1,$3); }
+                       { $$ = exp_unop ((int) $1,$3); }
        |       '!' exp %prec UNARY
-                       { $$ = exp_unop('!', $2); }
+                       { $$ = exp_unop ('!', $2); }
        |       '+' exp %prec UNARY
                        { $$ = $2; }
        |       '~' exp %prec UNARY
-                       { $$ = exp_unop('~', $2);}
+                       { $$ = exp_unop ('~', $2);}
 
        |       exp '*' exp
-                       { $$ = exp_binop('*', $1, $3); }
+                       { $$ = exp_binop ('*', $1, $3); }
        |       exp '/' exp
-                       { $$ = exp_binop('/', $1, $3); }
+                       { $$ = exp_binop ('/', $1, $3); }
        |       exp '%' exp
-                       { $$ = exp_binop('%', $1, $3); }
+                       { $$ = exp_binop ('%', $1, $3); }
        |       exp '+' exp
-                       { $$ = exp_binop('+', $1, $3); }
+                       { $$ = exp_binop ('+', $1, $3); }
        |       exp '-' exp
-                       { $$ = exp_binop('-' , $1, $3); }
+                       { $$ = exp_binop ('-' , $1, $3); }
        |       exp LSHIFT exp
-                       { $$ = exp_binop(LSHIFT , $1, $3); }
+                       { $$ = exp_binop (LSHIFT , $1, $3); }
        |       exp RSHIFT exp
-                       { $$ = exp_binop(RSHIFT , $1, $3); }
+                       { $$ = exp_binop (RSHIFT , $1, $3); }
        |       exp EQ exp
-                       { $$ = exp_binop(EQ , $1, $3); }
+                       { $$ = exp_binop (EQ , $1, $3); }
        |       exp NE exp
-                       { $$ = exp_binop(NE , $1, $3); }
+                       { $$ = exp_binop (NE , $1, $3); }
        |       exp LE exp
-                       { $$ = exp_binop(LE , $1, $3); }
+                       { $$ = exp_binop (LE , $1, $3); }
        |       exp GE exp
-                       { $$ = exp_binop(GE , $1, $3); }
+                       { $$ = exp_binop (GE , $1, $3); }
        |       exp '<' exp
-                       { $$ = exp_binop('<' , $1, $3); }
+                       { $$ = exp_binop ('<' , $1, $3); }
        |       exp '>' exp
-                       { $$ = exp_binop('>' , $1, $3); }
+                       { $$ = exp_binop ('>' , $1, $3); }
        |       exp '&' exp
-                       { $$ = exp_binop('&' , $1, $3); }
+                       { $$ = exp_binop ('&' , $1, $3); }
        |       exp '^' exp
-                       { $$ = exp_binop('^' , $1, $3); }
+                       { $$ = exp_binop ('^' , $1, $3); }
        |       exp '|' exp
-                       { $$ = exp_binop('|' , $1, $3); }
+                       { $$ = exp_binop ('|' , $1, $3); }
        |       exp '?' exp ':' exp
-                       { $$ = exp_trinop('?' , $1, $3, $5); }
+                       { $$ = exp_trinop ('?' , $1, $3, $5); }
        |       exp ANDAND exp
-                       { $$ = exp_binop(ANDAND , $1, $3); }
+                       { $$ = exp_binop (ANDAND , $1, $3); }
        |       exp OROR exp
-                       { $$ = exp_binop(OROR , $1, $3); }
+                       { $$ = exp_binop (OROR , $1, $3); }
        |       DEFINED '(' NAME ')'
-                       { $$ = exp_nameop(DEFINED, $3); }
+                       { $$ = exp_nameop (DEFINED, $3); }
        |       INT
                        { $$ = exp_bigintop ($1.integer, $1.str); }
         |      SIZEOF_HEADERS
-                       { $$ = exp_nameop(SIZEOF_HEADERS,0); }
+                       { $$ = exp_nameop (SIZEOF_HEADERS,0); }
 
        |       SIZEOF '(' NAME ')'
-                       { $$ = exp_nameop(SIZEOF,$3); }
+                       { $$ = exp_nameop (SIZEOF,$3); }
        |       ADDR '(' NAME ')'
-                       { $$ = exp_nameop(ADDR,$3); }
+                       { $$ = exp_nameop (ADDR,$3); }
        |       LOADADDR '(' NAME ')'
-                       { $$ = exp_nameop(LOADADDR,$3); }
+                       { $$ = exp_nameop (LOADADDR,$3); }
        |       ABSOLUTE '(' exp ')'
-                       { $$ = exp_unop(ABSOLUTE, $3); }
+                       { $$ = exp_unop (ABSOLUTE, $3); }
        |       ALIGN_K '(' exp ')'
-                       { $$ = exp_unop(ALIGN_K,$3); }
+                       { $$ = exp_unop (ALIGN_K,$3); }
        |       ALIGN_K '(' exp ',' exp ')'
-                       { $$ = exp_binop(ALIGN_K,$3,$5); }
+                       { $$ = exp_binop (ALIGN_K,$3,$5); }
        |       DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
                        { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
        |       DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
                        { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
        |       DATA_SEGMENT_END '(' exp ')'
-                       { $$ = exp_unop(DATA_SEGMENT_END, $3); }
+                       { $$ = exp_unop (DATA_SEGMENT_END, $3); }
+        |       SEGMENT_START '(' NAME ',' exp ')'
+                        { /* The operands to the expression node are
+                            placed in the opposite order from the way
+                            in which they appear in the script as
+                            that allows us to reuse more code in
+                            fold_binary.  */
+                         $$ = exp_binop (SEGMENT_START,
+                                         $5,
+                                         exp_nameop (NAME, $3)); }
        |       BLOCK '(' exp ')'
-                       { $$ = exp_unop(ALIGN_K,$3); }
+                       { $$ = exp_unop (ALIGN_K,$3); }
        |       NAME
-                       { $$ = exp_nameop(NAME,$1); }
+                       { $$ = exp_nameop (NAME,$1); }
        |       MAX_K '(' exp ',' exp ')'
                        { $$ = exp_binop (MAX_K, $3, $5 ); }
        |       MIN_K '(' exp ',' exp ')'
                        { $$ = exp_binop (MIN_K, $3, $5 ); }
        |       ASSERT_K '(' exp ',' NAME ')'
                        { $$ = exp_assert ($3, $5); }
+       |       ORIGIN '(' NAME ')'
+                       { $$ = exp_nameop (ORIGIN, $3); }
+       |       LENGTH '(' NAME ')'
+                       { $$ = exp_nameop (LENGTH, $3); }
        ;
 
 
This page took 0.027642 seconds and 4 git commands to generate.