* ldfile.c (ldfile_set_output_arch): Add defarch param.
[binutils-gdb.git] / ld / ldgram.y
index 2df9756aa619eb3e03292d7a69c6a4cbf0aa6c72..17717fbbbb3dd8130f26ddfceac461ab7a77144e 100644 (file)
@@ -1,6 +1,6 @@
 /* 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 Free Software Foundation, Inc.
+   2001, 2002, 2003 Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
 
 This file is part of GNU ld.
@@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "bfd.h"
 #include "sysdep.h"
 #include "bfdlink.h"
-#include "ld.h"    
+#include "ld.h"
 #include "ldexp.h"
 #include "ldver.h"
 #include "ldlang.h"
@@ -49,13 +49,13 @@ static enum section_type sectype;
 
 lang_memory_region_type *region;
 
-boolean ldgram_want_filename = true;
-FILE *  saved_script_handle = NULL;
-boolean force_make_executable = false;
+bfd_boolean ldgram_want_filename = TRUE;
+FILE *saved_script_handle = NULL;
+bfd_boolean force_make_executable = FALSE;
 
-boolean ldgram_in_script = false;
-boolean ldgram_had_equals = false;
-boolean ldgram_had_keep = false;
+bfd_boolean ldgram_in_script = FALSE;
+bfd_boolean ldgram_had_equals = FALSE;
+bfd_boolean ldgram_had_keep = FALSE;
 char *ldgram_vers_current_lang = NULL;
 
 #define ERROR_NAME_MAX 20
@@ -66,6 +66,12 @@ static int error_index;
 %}
 %union {
   bfd_vma integer;
+  struct big_int
+    {
+      bfd_vma integer;
+      char *str;
+    } bigint;
+  fill_type *fill;
   char *name;
   const char *cname;
   struct wildcard_spec wildcard;
@@ -75,8 +81,8 @@ static int error_index;
   union etree_union *etree;
   struct phdr_info
     {
-      boolean filehdr;
-      boolean phdrs;
+      bfd_boolean filehdr;
+      bfd_boolean phdrs;
       union etree_union *at;
       union etree_union *flags;
     } phdr;
@@ -88,15 +94,15 @@ 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 <integer> fill_opt
+%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
 %type <name> memspec_opt casesymlist
 %type <name> memspec_at_opt
 %type <cname> wildcard_name
 %type <wildcard> wildcard_spec
-%token <integer> INT  
+%token <bigint> INT
 %token <name> NAME LNAME
 %type <integer> length
 %type <phdr> phdr_qualifiers
@@ -104,7 +110,7 @@ static int error_index;
 %type <section_phdr> phdr_opt
 %type <integer> opt_nocrossrefs
 
-%right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ  '=' LSHIFTEQ RSHIFTEQ   ANDEQ OREQ 
+%right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ  '=' LSHIFTEQ RSHIFTEQ   ANDEQ OREQ
 %right <token> '?' ':'
 %left <token> OROR
 %left <token>  ANDAND
@@ -119,7 +125,7 @@ static int error_index;
 %left  <token> '*' '/' '%'
 
 %right UNARY
-%token END 
+%token END
 %left <token> '('
 %token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
 %token SECTIONS PHDRS SORT DATA_SEGMENT_ALIGN DATA_SEGMENT_END
@@ -136,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
@@ -152,7 +158,7 @@ static int error_index;
 
 %%
 
-file:  
+file:
                INPUT_SCRIPT script_file
        |       INPUT_MRI_SCRIPT mri_script_file
        |       INPUT_VERSION_SCRIPT version_script_file
@@ -170,8 +176,9 @@ defsym_expr:
                  ldlex_popstate();
                  lang_add_assignment(exp_assop($3,$2,$4));
                }
+       ;
 
-/* SYNTAX WITHIN AN MRI SCRIPT FILE */  
+/* SYNTAX WITHIN AN MRI SCRIPT FILE */
 mri_script_file:
                {
                  ldlex_mri_script ();
@@ -191,7 +198,7 @@ mri_script_lines:
        ;
 
 mri_script_command:
-               CHIP  exp 
+               CHIP  exp
        |       CHIP  exp ',' exp
        |       NAME    {
                        einfo(_("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1);
@@ -200,12 +207,12 @@ mri_script_command:
                        config.map_filename = "-";
                        }
         |       ORDER ordernamelist
-       |       ENDWORD 
+       |       ENDWORD
         |       PUBLIC NAME '=' exp
                        { mri_public($2, $4); }
         |       PUBLIC NAME ',' exp
                        { mri_public($2, $4); }
-        |       PUBLIC NAME  exp 
+        |       PUBLIC NAME  exp
                        { mri_public($2, $3); }
        |       FORMAT NAME
                        { mri_format($2); }
@@ -225,16 +232,16 @@ mri_script_command:
                        { mri_alignmod($2,$4); }
        |       ABSOLUTE mri_abs_name_list
        |       LOAD     mri_load_name_list
-       |       NAMEWORD NAME 
-                       { mri_name($2); }   
+       |       NAMEWORD NAME
+                       { mri_name($2); }
        |       ALIAS NAME ',' NAME
                        { mri_alias($2,$4,0);}
        |       ALIAS NAME ',' INT
-                       { mri_alias($2,0,(int) $4);}
+                       { mri_alias ($2, 0, (int) $4.integer); }
        |       BASE     exp
                        { mri_base($2); }
-        |       TRUNCATE INT
-               {  mri_truncate((unsigned int) $2); }
+       |       TRUNCATE INT
+               { mri_truncate ((unsigned int) $2.integer); }
        |       CASE casesymlist
        |       EXTERN extern_name_list
        |       INCLUDE filename
@@ -242,7 +249,7 @@ mri_script_command:
                mri_script_lines END
                { ldlex_popstate (); }
        |       START NAME
-               { lang_add_entry ($2, false); }
+               { lang_add_entry ($2, FALSE); }
         |
        ;
 
@@ -312,7 +319,7 @@ ifile_p1:
        |       TARGET_K '(' NAME ')'
                { lang_add_target($3); }
        |       SEARCH_DIR '(' filename ')'
-               { ldfile_add_library_path ($3, false); }
+               { ldfile_add_library_path ($3, FALSE); }
        |       OUTPUT '(' filename ')'
                { lang_add_output($3, 1); }
         |      OUTPUT_FORMAT '(' NAME ')'
@@ -321,11 +328,11 @@ ifile_p1:
        |       OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')'
                  { lang_add_output_format ($3, $5, $7, 1); }
         |      OUTPUT_ARCH '(' NAME ')'
-                 { ldfile_set_output_arch($3); }
+                 { ldfile_set_output_arch ($3, bfd_arch_unknown); }
        |       FORCE_COMMON_ALLOCATION
-               { command_line.force_common_definition = true ; }
+               { command_line.force_common_definition = TRUE ; }
        |       INHIBIT_COMMON_ALLOCATION
-               { command_line.inhibit_common_definition = true ; }
+               { command_line.inhibit_common_definition = TRUE ; }
        |       INPUT '(' input_list ')'
        |       GROUP
                  { lang_enter_group (); }
@@ -333,7 +340,7 @@ ifile_p1:
                  { lang_leave_group (); }
        |       MAP '(' filename ')'
                { lang_add_map($3); }
-       |       INCLUDE filename 
+       |       INCLUDE filename
                { ldlex_script (); ldfile_open_command_file($2); }
                ifile_list END
                { ldlex_popstate (); }
@@ -377,7 +384,7 @@ sec_or_group_p1:
 
 statement_anywhere:
                ENTRY '(' NAME ')'
-               { lang_add_entry ($3, false); }
+               { lang_add_entry ($3, FALSE); }
        |       assignment end
        ;
 
@@ -402,25 +409,25 @@ wildcard_spec:
                wildcard_name
                        {
                          $$.name = $1;
-                         $$.sorted = false;
+                         $$.sorted = FALSE;
                          $$.exclude_name_list = NULL;
                        }
        |       EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
                        {
                          $$.name = $5;
-                         $$.sorted = false;
+                         $$.sorted = FALSE;
                          $$.exclude_name_list = $3;
                        }
        |       SORT '(' wildcard_name ')'
                        {
                          $$.name = $3;
-                         $$.sorted = true;
+                         $$.sorted = TRUE;
                          $$.exclude_name_list = NULL;
                        }
        |       SORT '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')'
                        {
                          $$.name = $7;
-                         $$.sorted = true;
+                         $$.sorted = TRUE;
                          $$.exclude_name_list = $5;
                        }
        ;
@@ -432,7 +439,7 @@ exclude_name_list:
                          tmp = (struct name_list *) xmalloc (sizeof *tmp);
                          tmp->name = $2;
                          tmp->next = $1;
-                         $$ = tmp;     
+                         $$ = tmp;
                        }
        |
                wildcard_name
@@ -471,7 +478,7 @@ input_section_spec_no_keep:
                          struct wildcard_spec tmp;
                          tmp.name = $1;
                          tmp.exclude_name_list = NULL;
-                         tmp.sorted = false;
+                         tmp.sorted = FALSE;
                          lang_add_wild (&tmp, NULL, ldgram_had_keep);
                        }
         |      '[' file_NAME_list ']'
@@ -487,41 +494,37 @@ input_section_spec_no_keep:
 input_section_spec:
                input_section_spec_no_keep
        |       KEEP '('
-                       { ldgram_had_keep = true; }
+                       { ldgram_had_keep = TRUE; }
                input_section_spec_no_keep ')'
-                       { ldgram_had_keep = false; }
+                       { ldgram_had_keep = FALSE; }
        ;
 
 statement:
                assignment end
        |       CREATE_OBJECT_SYMBOLS
                {
-               lang_add_attribute(lang_object_symbols_statement_enum); 
+               lang_add_attribute(lang_object_symbols_statement_enum);
                }
         |      ';'
         |      CONSTRUCTORS
                {
-               
-                 lang_add_attribute(lang_constructors_statement_enum); 
+
+                 lang_add_attribute(lang_constructors_statement_enum);
                }
        | SORT '(' CONSTRUCTORS ')'
                {
-                 constructors_sorted = true;
+                 constructors_sorted = TRUE;
                  lang_add_attribute (lang_constructors_statement_enum);
                }
        | input_section_spec
         | length '(' mustbe_exp ')'
                        {
-                       lang_add_data((int) $1,$3);
+                         lang_add_data ((int) $1, $3);
                        }
-  
-       | FILL '(' mustbe_exp ')'
+
+       | FILL '(' fill_exp ')'
                        {
-                         lang_add_fill
-                           (exp_get_value_int($3,
-                                              0,
-                                              "fill value",
-                                              lang_first_phase_enum));
+                         lang_add_fill ($3);
                        }
        ;
 
@@ -529,7 +532,7 @@ statement_list:
                statement_list statement
        |       statement
        ;
-  
+
 statement_list_opt:
                /* empty */
        |       statement_list
@@ -548,18 +551,21 @@ length:
                        { $$ = $1; }
        ;
 
-fill_opt:
-          '=' mustbe_exp
+fill_exp:
+       mustbe_exp
                {
-                 $$ =   exp_get_value_int($2,
-                                          0,
-                                          "fill value",
-                                          lang_first_phase_enum);
+                 $$ = exp_get_fill ($1,
+                                    0,
+                                    "fill value",
+                                    lang_first_phase_enum);
                }
-       |       { $$ = 0; }
        ;
 
-               
+fill_opt:
+         '=' fill_exp
+               { $$ = $2; }
+       |       { $$ = (fill_type *) 0; }
+       ;
 
 assign_op:
                PLUSEQ
@@ -620,11 +626,11 @@ memory_spec_list:
        ;
 
 
-memory_spec:           NAME
-                       { region = lang_memory_region_lookup($1); }
+memory_spec:   NAME
+               { region = lang_memory_region_lookup ($1, TRUE); }
                attributes_opt ':'
                origin_spec opt_comma length_spec
-
+               {}
        ;
 
 origin_spec:
@@ -691,11 +697,11 @@ low_level_library:
 
 floating_point_support:
                FLOAT
-                       { lang_float(true); }
+                       { lang_float(TRUE); }
        |       NOFLOAT
-                       { lang_float(false); }
+                       { lang_float(FALSE); }
        ;
-               
+
 nocrossref_list:
                /* empty */
                {
@@ -781,7 +787,7 @@ exp :
        |       DEFINED '(' NAME ')'
                        { $$ = exp_nameop(DEFINED, $3); }
        |       INT
-                       { $$ = exp_intop($1); }
+                       { $$ = exp_bigintop ($1.integer, $1.str); }
         |      SIZEOF_HEADERS
                        { $$ = exp_nameop(SIZEOF_HEADERS,0); }
 
@@ -814,7 +820,7 @@ exp :
 
 memspec_at_opt:
                 AT '>' NAME { $$ = $3; }
-        |       { $$ = "*default*"; }
+        |       { $$ = 0; }
         ;
 
 opt_at:
@@ -822,30 +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_exp_with_type
+               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      
+               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, $5, (int) $4);
+                         lang_enter_overlay ($3, $6);
                        }
                overlay_section
                '}'
@@ -853,7 +866,8 @@ section:    NAME            { ldlex_expression(); }
                memspec_opt memspec_at_opt phdr_opt fill_opt
                        {
                          ldlex_popstate ();
-                         lang_leave_overlay ($15, $12, $14, $13);
+                         lang_leave_overlay ($5, (int) $4,
+                                             $16, $13, $15, $14);
                        }
                opt_comma
        |       /* The GROUP case is just enough to support the gcc
@@ -910,7 +924,7 @@ opt_nocrossrefs:
 memspec_opt:
                '>' NAME
                { $$ = $2; }
-       |       { $$ = "*default*"; }
+       |       { $$ = DEFAULT_MEMORY_REGION; }
        ;
 
 phdr_opt:
@@ -925,7 +939,7 @@ phdr_opt:
                  n = ((struct lang_output_section_phdr_list *)
                       xmalloc (sizeof *n));
                  n->name = $3;
-                 n->used = false;
+                 n->used = FALSE;
                  n->next = $1;
                  $$ = n;
                }
@@ -982,7 +996,7 @@ phdr_type:
                        {
                          "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
                          "PT_INTERP", "PT_NOTE", "PT_SHLIB",
-                         "PT_PHDR"
+                         "PT_PHDR", "PT_TLS"
                        };
 
                      s = $1->name.name;
@@ -994,6 +1008,20 @@ phdr_type:
                            $$ = exp_intop (i);
                            break;
                          }
+                     if (i == sizeof phdr_types / sizeof phdr_types[0])
+                       {
+                         if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
+                           $$ = exp_intop (0x6474e550);
+                         else if (strcmp (s, "PT_GNU_STACK") == 0)
+                           $$ = exp_intop (0x6474e551);
+                         else
+                           {
+                             einfo (_("\
+%X%P:%S: unknown phdr type `%s' (try integer literal)\n"),
+                                    s);
+                             $$ = exp_intop (0);
+                           }
+                       }
                    }
                }
        ;
@@ -1007,9 +1035,9 @@ phdr_qualifiers:
                {
                  $$ = $3;
                  if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
-                   $$.filehdr = true;
+                   $$.filehdr = TRUE;
                  else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
-                   $$.phdrs = true;
+                   $$.phdrs = TRUE;
                  else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
                    $$.flags = $2;
                  else
@@ -1122,23 +1150,38 @@ vers_defns:
                {
                  $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang);
                }
+       |       vers_defns ';' EXTERN NAME '{'
+                       {
+                         $<name>$ = ldgram_vers_current_lang;
+                         ldgram_vers_current_lang = $4;
+                       }
+               vers_defns opt_semicolon '}'
+                       {
+                         $$ = $7;
+                         ldgram_vers_current_lang = $<name>6;
+                       }
        |       EXTERN NAME '{'
                        {
                          $<name>$ = ldgram_vers_current_lang;
                          ldgram_vers_current_lang = $2;
                        }
-               vers_defns '}'
+               vers_defns opt_semicolon '}'
                        {
                          $$ = $5;
                          ldgram_vers_current_lang = $<name>4;
                        }
        ;
 
+opt_semicolon:
+               /* empty */
+       |       ';'
+       ;
+
 %%
 void
-yyerror(arg) 
+yyerror(arg)
      const char *arg;
-{ 
+{
   if (ldfile_assumed_script)
     einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
           ldfile_input_filename);