bfd/
[external/binutils.git] / ld / ldgram.y
1 /* A YACC grammar to parse a superset of the AT&T linker scripting language.
2    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3    2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4    Free Software Foundation, Inc.
5    Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
6
7    This file is part of the GNU Binutils.
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22    MA 02110-1301, USA.  */
23
24 %{
25 /*
26
27  */
28
29 #define DONTDECLARE_MALLOC
30
31 #include "sysdep.h"
32 #include "bfd.h"
33 #include "bfdlink.h"
34 #include "ld.h"
35 #include "ldexp.h"
36 #include "ldver.h"
37 #include "ldlang.h"
38 #include "ldfile.h"
39 #include "ldemul.h"
40 #include "ldmisc.h"
41 #include "ldmain.h"
42 #include "mri.h"
43 #include "ldctor.h"
44 #include "ldlex.h"
45
46 #ifndef YYDEBUG
47 #define YYDEBUG 1
48 #endif
49
50 static enum section_type sectype;
51 static lang_memory_region_type *region;
52
53 bfd_boolean ldgram_had_keep = FALSE;
54 char *ldgram_vers_current_lang = NULL;
55
56 #define ERROR_NAME_MAX 20
57 static char *error_names[ERROR_NAME_MAX];
58 static int error_index;
59 #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
60 #define POP_ERROR()   error_index--;
61 %}
62 %union {
63   bfd_vma integer;
64   struct big_int
65     {
66       bfd_vma integer;
67       char *str;
68     } bigint;
69   fill_type *fill;
70   char *name;
71   const char *cname;
72   struct wildcard_spec wildcard;
73   struct wildcard_list *wildcard_list;
74   struct name_list *name_list;
75   struct flag_info_list *flag_info_list;
76   struct flag_info *flag_info;
77   int token;
78   union etree_union *etree;
79   struct phdr_info
80     {
81       bfd_boolean filehdr;
82       bfd_boolean phdrs;
83       union etree_union *at;
84       union etree_union *flags;
85     } phdr;
86   struct lang_nocrossref *nocrossref;
87   struct lang_output_section_phdr_list *section_phdr;
88   struct bfd_elf_version_deps *deflist;
89   struct bfd_elf_version_expr *versyms;
90   struct bfd_elf_version_tree *versnode;
91 }
92
93 %type <etree> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val
94 %type <etree> opt_exp_without_type opt_subalign opt_align
95 %type <fill> fill_opt fill_exp
96 %type <name_list> exclude_name_list
97 %type <wildcard_list> file_NAME_list
98 %type <flag_info_list> sect_flag_list
99 %type <flag_info> sect_flags
100 %type <name> memspec_opt casesymlist
101 %type <name> memspec_at_opt
102 %type <cname> wildcard_name
103 %type <wildcard> wildcard_spec
104 %token <bigint> INT
105 %token <name> NAME LNAME
106 %type <integer> length
107 %type <phdr> phdr_qualifiers
108 %type <nocrossref> nocrossref_list
109 %type <section_phdr> phdr_opt
110 %type <integer> opt_nocrossrefs
111
112 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ  '=' LSHIFTEQ RSHIFTEQ   ANDEQ OREQ
113 %right <token> '?' ':'
114 %left <token> OROR
115 %left <token>  ANDAND
116 %left <token> '|'
117 %left <token>  '^'
118 %left  <token> '&'
119 %left <token>  EQ NE
120 %left  <token> '<' '>' LE GE
121 %left  <token> LSHIFT RSHIFT
122
123 %left  <token> '+' '-'
124 %left  <token> '*' '/' '%'
125
126 %right UNARY
127 %token END
128 %left <token> '('
129 %token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
130 %token SECTIONS PHDRS INSERT_K AFTER BEFORE
131 %token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
132 %token SORT_BY_NAME SORT_BY_ALIGNMENT SORT_NONE
133 %token SORT_BY_INIT_PRIORITY
134 %token '{' '}'
135 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
136 %token INHIBIT_COMMON_ALLOCATION
137 %token SEGMENT_START
138 %token INCLUDE
139 %token MEMORY
140 %token REGION_ALIAS
141 %token LD_FEATURE
142 %token NOLOAD DSECT COPY INFO OVERLAY
143 %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY
144 %token <integer> NEXT
145 %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K
146 %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS
147 %token ORIGIN FILL
148 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
149 %token ALIGNMOD AT SUBALIGN HIDDEN PROVIDE PROVIDE_HIDDEN AS_NEEDED
150 %type <token> assign_op atype attributes_opt sect_constraint
151 %type <name>  filename
152 %token CHIP LIST SECT ABSOLUTE  LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
153 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
154 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
155 %token <name> VERS_TAG VERS_IDENTIFIER
156 %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
157 %token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL INPUT_SECTION_FLAGS
158 %token EXCLUDE_FILE
159 %token CONSTANT
160 %type <versyms> vers_defns
161 %type <versnode> vers_tag
162 %type <deflist> verdep
163 %token INPUT_DYNAMIC_LIST
164
165 %%
166
167 file:
168                 INPUT_SCRIPT script_file
169         |       INPUT_MRI_SCRIPT mri_script_file
170         |       INPUT_VERSION_SCRIPT version_script_file
171         |       INPUT_DYNAMIC_LIST dynamic_list_file
172         |       INPUT_DEFSYM defsym_expr
173         ;
174
175
176 filename:  NAME;
177
178
179 defsym_expr:
180                 { ldlex_defsym(); }
181                 NAME '=' exp
182                 {
183                   ldlex_popstate();
184                   lang_add_assignment (exp_defsym ($2, $4));
185                 }
186         ;
187
188 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
189 mri_script_file:
190                 {
191                   ldlex_mri_script ();
192                   PUSH_ERROR (_("MRI style script"));
193                 }
194              mri_script_lines
195                 {
196                   ldlex_popstate ();
197                   mri_draw_tree ();
198                   POP_ERROR ();
199                 }
200         ;
201
202 mri_script_lines:
203                 mri_script_lines mri_script_command NEWLINE
204           |
205         ;
206
207 mri_script_command:
208                 CHIP  exp
209         |       CHIP  exp ',' exp
210         |       NAME    {
211                         einfo(_("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1);
212                         }
213         |       LIST    {
214                         config.map_filename = "-";
215                         }
216         |       ORDER ordernamelist
217         |       ENDWORD
218         |       PUBLIC NAME '=' exp
219                         { mri_public($2, $4); }
220         |       PUBLIC NAME ',' exp
221                         { mri_public($2, $4); }
222         |       PUBLIC NAME  exp
223                         { mri_public($2, $3); }
224         |       FORMAT NAME
225                         { mri_format($2); }
226         |       SECT NAME ',' exp
227                         { mri_output_section($2, $4);}
228         |       SECT NAME  exp
229                         { mri_output_section($2, $3);}
230         |       SECT NAME '=' exp
231                         { mri_output_section($2, $4);}
232         |       ALIGN_K NAME '=' exp
233                         { mri_align($2,$4); }
234         |       ALIGN_K NAME ',' exp
235                         { mri_align($2,$4); }
236         |       ALIGNMOD NAME '=' exp
237                         { mri_alignmod($2,$4); }
238         |       ALIGNMOD NAME ',' exp
239                         { mri_alignmod($2,$4); }
240         |       ABSOLUTE mri_abs_name_list
241         |       LOAD     mri_load_name_list
242         |       NAMEWORD NAME
243                         { mri_name($2); }
244         |       ALIAS NAME ',' NAME
245                         { mri_alias($2,$4,0);}
246         |       ALIAS NAME ',' INT
247                         { mri_alias ($2, 0, (int) $4.integer); }
248         |       BASE     exp
249                         { mri_base($2); }
250         |       TRUNCATE INT
251                 { mri_truncate ((unsigned int) $2.integer); }
252         |       CASE casesymlist
253         |       EXTERN extern_name_list
254         |       INCLUDE filename
255                 { ldlex_script (); ldfile_open_command_file($2); }
256                 mri_script_lines END
257                 { ldlex_popstate (); }
258         |       START NAME
259                 { lang_add_entry ($2, FALSE); }
260         |
261         ;
262
263 ordernamelist:
264               ordernamelist ',' NAME         { mri_order($3); }
265         |     ordernamelist  NAME         { mri_order($2); }
266         |
267         ;
268
269 mri_load_name_list:
270                 NAME
271                         { mri_load($1); }
272         |       mri_load_name_list ',' NAME { mri_load($3); }
273         ;
274
275 mri_abs_name_list:
276                 NAME
277                         { mri_only_load($1); }
278         |       mri_abs_name_list ','  NAME
279                         { mri_only_load($3); }
280         ;
281
282 casesymlist:
283           /* empty */ { $$ = NULL; }
284         | NAME
285         | casesymlist ',' NAME
286         ;
287
288 /* Parsed as expressions so that commas separate entries */
289 extern_name_list:
290         { ldlex_expression (); }
291         extern_name_list_body
292         { ldlex_popstate (); }
293
294 extern_name_list_body:
295           NAME
296                         { ldlang_add_undef ($1, FALSE); }
297         | extern_name_list_body NAME
298                         { ldlang_add_undef ($2, FALSE); }
299         | extern_name_list_body ',' NAME
300                         { ldlang_add_undef ($3, FALSE); }
301         ;
302
303 script_file:
304         { ldlex_both(); }
305         ifile_list
306         { ldlex_popstate(); }
307         ;
308
309 ifile_list:
310         ifile_list ifile_p1
311         |
312         ;
313
314
315 ifile_p1:
316                 memory
317         |       sections
318         |       phdrs
319         |       startup
320         |       high_level_library
321         |       low_level_library
322         |       floating_point_support
323         |       statement_anywhere
324         |       version
325         |        ';'
326         |       TARGET_K '(' NAME ')'
327                 { lang_add_target($3); }
328         |       SEARCH_DIR '(' filename ')'
329                 { ldfile_add_library_path ($3, FALSE); }
330         |       OUTPUT '(' filename ')'
331                 { lang_add_output($3, 1); }
332         |       OUTPUT_FORMAT '(' NAME ')'
333                   { lang_add_output_format ($3, (char *) NULL,
334                                             (char *) NULL, 1); }
335         |       OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')'
336                   { lang_add_output_format ($3, $5, $7, 1); }
337         |       OUTPUT_ARCH '(' NAME ')'
338                   { ldfile_set_output_arch ($3, bfd_arch_unknown); }
339         |       FORCE_COMMON_ALLOCATION
340                 { command_line.force_common_definition = TRUE ; }
341         |       INHIBIT_COMMON_ALLOCATION
342                 { command_line.inhibit_common_definition = TRUE ; }
343         |       INPUT '(' input_list ')'
344         |       GROUP
345                   { lang_enter_group (); }
346                     '(' input_list ')'
347                   { lang_leave_group (); }
348         |       MAP '(' filename ')'
349                 { lang_add_map($3); }
350         |       INCLUDE filename
351                 { ldlex_script (); ldfile_open_command_file($2); }
352                 ifile_list END
353                 { ldlex_popstate (); }
354         |       NOCROSSREFS '(' nocrossref_list ')'
355                 {
356                   lang_add_nocrossref ($3);
357                 }
358         |       EXTERN '(' extern_name_list ')'
359         |       INSERT_K AFTER NAME
360                 { lang_add_insert ($3, 0); }
361         |       INSERT_K BEFORE NAME
362                 { lang_add_insert ($3, 1); }
363         |       REGION_ALIAS '(' NAME ',' NAME ')'
364                 { lang_memory_region_alias ($3, $5); }
365         |       LD_FEATURE '(' NAME ')'
366                 { lang_ld_feature ($3); }
367         ;
368
369 input_list:
370                 NAME
371                 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
372                                  (char *)NULL); }
373         |       input_list ',' NAME
374                 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
375                                  (char *)NULL); }
376         |       input_list NAME
377                 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
378                                  (char *)NULL); }
379         |       LNAME
380                 { lang_add_input_file($1,lang_input_file_is_l_enum,
381                                  (char *)NULL); }
382         |       input_list ',' LNAME
383                 { lang_add_input_file($3,lang_input_file_is_l_enum,
384                                  (char *)NULL); }
385         |       input_list LNAME
386                 { lang_add_input_file($2,lang_input_file_is_l_enum,
387                                  (char *)NULL); }
388         |       AS_NEEDED '('
389                   { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
390                     input_flags.add_DT_NEEDED_for_regular = TRUE; }
391                      input_list ')'
392                   { input_flags.add_DT_NEEDED_for_regular = $<integer>3; }
393         |       input_list ',' AS_NEEDED '('
394                   { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
395                     input_flags.add_DT_NEEDED_for_regular = TRUE; }
396                      input_list ')'
397                   { input_flags.add_DT_NEEDED_for_regular = $<integer>5; }
398         |       input_list AS_NEEDED '('
399                   { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
400                     input_flags.add_DT_NEEDED_for_regular = TRUE; }
401                      input_list ')'
402                   { input_flags.add_DT_NEEDED_for_regular = $<integer>4; }
403         ;
404
405 sections:
406                 SECTIONS '{' sec_or_group_p1 '}'
407         ;
408
409 sec_or_group_p1:
410                 sec_or_group_p1 section
411         |       sec_or_group_p1 statement_anywhere
412         |
413         ;
414
415 statement_anywhere:
416                 ENTRY '(' NAME ')'
417                 { lang_add_entry ($3, FALSE); }
418         |       assignment end
419         |       ASSERT_K  {ldlex_expression ();} '(' exp ',' NAME ')'
420                 { ldlex_popstate ();
421                   lang_add_assignment (exp_assert ($4, $6)); }
422         ;
423
424 /* The '*' and '?' cases are there because the lexer returns them as
425    separate tokens rather than as NAME.  */
426 wildcard_name:
427                 NAME
428                         {
429                           $$ = $1;
430                         }
431         |       '*'
432                         {
433                           $$ = "*";
434                         }
435         |       '?'
436                         {
437                           $$ = "?";
438                         }
439         ;
440
441 wildcard_spec:
442                 wildcard_name
443                         {
444                           $$.name = $1;
445                           $$.sorted = none;
446                           $$.exclude_name_list = NULL;
447                           $$.section_flag_list = NULL;
448                         }
449         |       EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
450                         {
451                           $$.name = $5;
452                           $$.sorted = none;
453                           $$.exclude_name_list = $3;
454                           $$.section_flag_list = NULL;
455                         }
456         |       SORT_BY_NAME '(' wildcard_name ')'
457                         {
458                           $$.name = $3;
459                           $$.sorted = by_name;
460                           $$.exclude_name_list = NULL;
461                           $$.section_flag_list = NULL;
462                         }
463         |       SORT_BY_ALIGNMENT '(' wildcard_name ')'
464                         {
465                           $$.name = $3;
466                           $$.sorted = by_alignment;
467                           $$.exclude_name_list = NULL;
468                           $$.section_flag_list = NULL;
469                         }
470         |       SORT_NONE '(' wildcard_name ')'
471                         {
472                           $$.name = $3;
473                           $$.sorted = by_none;
474                           $$.exclude_name_list = NULL;
475                           $$.section_flag_list = NULL;
476                         }
477         |       SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
478                         {
479                           $$.name = $5;
480                           $$.sorted = by_name_alignment;
481                           $$.exclude_name_list = NULL;
482                           $$.section_flag_list = NULL;
483                         }
484         |       SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_name ')' ')'
485                         {
486                           $$.name = $5;
487                           $$.sorted = by_name;
488                           $$.exclude_name_list = NULL;
489                           $$.section_flag_list = NULL;
490                         }
491         |       SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_name ')' ')'
492                         {
493                           $$.name = $5;
494                           $$.sorted = by_alignment_name;
495                           $$.exclude_name_list = NULL;
496                           $$.section_flag_list = NULL;
497                         }
498         |       SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
499                         {
500                           $$.name = $5;
501                           $$.sorted = by_alignment;
502                           $$.exclude_name_list = NULL;
503                           $$.section_flag_list = NULL;
504                         }
505         |       SORT_BY_NAME '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')'
506                         {
507                           $$.name = $7;
508                           $$.sorted = by_name;
509                           $$.exclude_name_list = $5;
510                           $$.section_flag_list = NULL;
511                         }
512         |       SORT_BY_INIT_PRIORITY '(' wildcard_name ')'
513                         {
514                           $$.name = $3;
515                           $$.sorted = by_init_priority;
516                           $$.exclude_name_list = NULL;
517                           $$.section_flag_list = NULL;
518                         }
519         ;
520
521 sect_flag_list: NAME
522                         {
523                           struct flag_info_list *n;
524                           n = ((struct flag_info_list *) xmalloc (sizeof *n));
525                           if ($1[0] == '!')
526                             {
527                               n->with = without_flags;
528                               n->name = &$1[1];
529                             }
530                           else
531                             {
532                               n->with = with_flags;
533                               n->name = $1;
534                             }
535                           n->valid = FALSE;
536                           n->next = NULL;
537                           $$ = n;
538                         }
539         |       sect_flag_list '&' NAME
540                         {
541                           struct flag_info_list *n;
542                           n = ((struct flag_info_list *) xmalloc (sizeof *n));
543                           if ($3[0] == '!')
544                             {
545                               n->with = without_flags;
546                               n->name = &$3[1];
547                             }
548                           else
549                             {
550                               n->with = with_flags;
551                               n->name = $3;
552                             }
553                           n->valid = FALSE;
554                           n->next = $1;
555                           $$ = n;
556                         }
557         ;
558
559 sect_flags:
560                 INPUT_SECTION_FLAGS '(' sect_flag_list ')'
561                         {
562                           struct flag_info *n;
563                           n = ((struct flag_info *) xmalloc (sizeof *n));
564                           n->flag_list = $3;
565                           n->flags_initialized = FALSE;
566                           n->not_with_flags = 0;
567                           n->only_with_flags = 0;
568                           $$ = n;
569                         }
570         ;
571
572 exclude_name_list:
573                 exclude_name_list wildcard_name
574                         {
575                           struct name_list *tmp;
576                           tmp = (struct name_list *) xmalloc (sizeof *tmp);
577                           tmp->name = $2;
578                           tmp->next = $1;
579                           $$ = tmp;
580                         }
581         |
582                 wildcard_name
583                         {
584                           struct name_list *tmp;
585                           tmp = (struct name_list *) xmalloc (sizeof *tmp);
586                           tmp->name = $1;
587                           tmp->next = NULL;
588                           $$ = tmp;
589                         }
590         ;
591
592 file_NAME_list:
593                 file_NAME_list opt_comma wildcard_spec
594                         {
595                           struct wildcard_list *tmp;
596                           tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
597                           tmp->next = $1;
598                           tmp->spec = $3;
599                           $$ = tmp;
600                         }
601         |
602                 wildcard_spec
603                         {
604                           struct wildcard_list *tmp;
605                           tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
606                           tmp->next = NULL;
607                           tmp->spec = $1;
608                           $$ = tmp;
609                         }
610         ;
611
612 input_section_spec_no_keep:
613                 NAME
614                         {
615                           struct wildcard_spec tmp;
616                           tmp.name = $1;
617                           tmp.exclude_name_list = NULL;
618                           tmp.sorted = none;
619                           tmp.section_flag_list = NULL;
620                           lang_add_wild (&tmp, NULL, ldgram_had_keep);
621                         }
622         |       sect_flags NAME
623                         {
624                           struct wildcard_spec tmp;
625                           tmp.name = $2;
626                           tmp.exclude_name_list = NULL;
627                           tmp.sorted = none;
628                           tmp.section_flag_list = $1;
629                           lang_add_wild (&tmp, NULL, ldgram_had_keep);
630                         }
631         |       '[' file_NAME_list ']'
632                         {
633                           lang_add_wild (NULL, $2, ldgram_had_keep);
634                         }
635         |       sect_flags '[' file_NAME_list ']'
636                         {
637                           struct wildcard_spec tmp;
638                           tmp.name = NULL;
639                           tmp.exclude_name_list = NULL;
640                           tmp.sorted = none;
641                           tmp.section_flag_list = $1;
642                           lang_add_wild (&tmp, $3, ldgram_had_keep);
643                         }
644         |       wildcard_spec '(' file_NAME_list ')'
645                         {
646                           lang_add_wild (&$1, $3, ldgram_had_keep);
647                         }
648         |       sect_flags wildcard_spec '(' file_NAME_list ')'
649                         {
650                           $2.section_flag_list = $1;
651                           lang_add_wild (&$2, $4, ldgram_had_keep);
652                         }
653         ;
654
655 input_section_spec:
656                 input_section_spec_no_keep
657         |       KEEP '('
658                         { ldgram_had_keep = TRUE; }
659                 input_section_spec_no_keep ')'
660                         { ldgram_had_keep = FALSE; }
661         ;
662
663 statement:
664                 assignment end
665         |       CREATE_OBJECT_SYMBOLS
666                 {
667                 lang_add_attribute(lang_object_symbols_statement_enum);
668                 }
669         |       ';'
670         |       CONSTRUCTORS
671                 {
672
673                   lang_add_attribute(lang_constructors_statement_enum);
674                 }
675         | SORT_BY_NAME '(' CONSTRUCTORS ')'
676                 {
677                   constructors_sorted = TRUE;
678                   lang_add_attribute (lang_constructors_statement_enum);
679                 }
680         | input_section_spec
681         | length '(' mustbe_exp ')'
682                         {
683                           lang_add_data ((int) $1, $3);
684                         }
685
686         | FILL '(' fill_exp ')'
687                         {
688                           lang_add_fill ($3);
689                         }
690         | ASSERT_K  {ldlex_expression ();} '(' exp ',' NAME ')' end
691                         { ldlex_popstate ();
692                           lang_add_assignment (exp_assert ($4, $6)); }
693         | INCLUDE filename
694                 { ldlex_script (); ldfile_open_command_file($2); }
695                 statement_list_opt END
696                 { ldlex_popstate (); }
697         ;
698
699 statement_list:
700                 statement_list statement
701         |       statement
702         ;
703
704 statement_list_opt:
705                 /* empty */
706         |       statement_list
707         ;
708
709 length:
710                 QUAD
711                         { $$ = $1; }
712         |       SQUAD
713                         { $$ = $1; }
714         |       LONG
715                         { $$ = $1; }
716         |       SHORT
717                         { $$ = $1; }
718         |       BYTE
719                         { $$ = $1; }
720         ;
721
722 fill_exp:
723         mustbe_exp
724                 {
725                   $$ = exp_get_fill ($1, 0, "fill value");
726                 }
727         ;
728
729 fill_opt:
730           '=' fill_exp
731                 { $$ = $2; }
732         |       { $$ = (fill_type *) 0; }
733         ;
734
735 assign_op:
736                 PLUSEQ
737                         { $$ = '+'; }
738         |       MINUSEQ
739                         { $$ = '-'; }
740         |       MULTEQ
741                         { $$ = '*'; }
742         |       DIVEQ
743                         { $$ = '/'; }
744         |       LSHIFTEQ
745                         { $$ = LSHIFT; }
746         |       RSHIFTEQ
747                         { $$ = RSHIFT; }
748         |       ANDEQ
749                         { $$ = '&'; }
750         |       OREQ
751                         { $$ = '|'; }
752
753         ;
754
755 end:    ';' | ','
756         ;
757
758
759 assignment:
760                 NAME '=' mustbe_exp
761                 {
762                   lang_add_assignment (exp_assign ($1, $3, FALSE));
763                 }
764         |       NAME assign_op mustbe_exp
765                 {
766                   lang_add_assignment (exp_assign ($1,
767                                                    exp_binop ($2,
768                                                               exp_nameop (NAME,
769                                                                           $1),
770                                                               $3), FALSE));
771                 }
772         |       HIDDEN '(' NAME '=' mustbe_exp ')'
773                 {
774                   lang_add_assignment (exp_assign ($3, $5, TRUE));
775                 }
776         |       PROVIDE '(' NAME '=' mustbe_exp ')'
777                 {
778                   lang_add_assignment (exp_provide ($3, $5, FALSE));
779                 }
780         |       PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
781                 {
782                   lang_add_assignment (exp_provide ($3, $5, TRUE));
783                 }
784         ;
785
786
787 opt_comma:
788                 ','     |       ;
789
790
791 memory:
792                 MEMORY '{' memory_spec_list_opt '}'
793         ;
794
795 memory_spec_list_opt: memory_spec_list | ;
796
797 memory_spec_list:
798                 memory_spec_list opt_comma memory_spec
799         |       memory_spec
800         ;
801
802
803 memory_spec:    NAME
804                 { region = lang_memory_region_lookup ($1, TRUE); }
805                 attributes_opt ':'
806                 origin_spec opt_comma length_spec
807                 {}
808         |       INCLUDE filename
809                 { ldlex_script (); ldfile_open_command_file($2); }
810                 memory_spec_list_opt END
811                 { ldlex_popstate (); }
812         ;
813
814 origin_spec:
815         ORIGIN '=' mustbe_exp
816                 {
817                   region->origin = exp_get_vma ($3, 0, "origin");
818                   region->current = region->origin;
819                 }
820         ;
821
822 length_spec:
823              LENGTH '=' mustbe_exp
824                 {
825                   region->length = exp_get_vma ($3, -1, "length");
826                 }
827         ;
828
829 attributes_opt:
830                 /* empty */
831                   { /* dummy action to avoid bison 1.25 error message */ }
832         |       '(' attributes_list ')'
833         ;
834
835 attributes_list:
836                 attributes_string
837         |       attributes_list attributes_string
838         ;
839
840 attributes_string:
841                 NAME
842                   { lang_set_flags (region, $1, 0); }
843         |       '!' NAME
844                   { lang_set_flags (region, $2, 1); }
845         ;
846
847 startup:
848         STARTUP '(' filename ')'
849                 { lang_startup($3); }
850         ;
851
852 high_level_library:
853                 HLL '(' high_level_library_NAME_list ')'
854         |       HLL '(' ')'
855                         { ldemul_hll((char *)NULL); }
856         ;
857
858 high_level_library_NAME_list:
859                 high_level_library_NAME_list opt_comma filename
860                         { ldemul_hll($3); }
861         |       filename
862                         { ldemul_hll($1); }
863
864         ;
865
866 low_level_library:
867         SYSLIB '(' low_level_library_NAME_list ')'
868         ; low_level_library_NAME_list:
869                 low_level_library_NAME_list opt_comma filename
870                         { ldemul_syslib($3); }
871         |
872         ;
873
874 floating_point_support:
875                 FLOAT
876                         { lang_float(TRUE); }
877         |       NOFLOAT
878                         { lang_float(FALSE); }
879         ;
880
881 nocrossref_list:
882                 /* empty */
883                 {
884                   $$ = NULL;
885                 }
886         |       NAME nocrossref_list
887                 {
888                   struct lang_nocrossref *n;
889
890                   n = (struct lang_nocrossref *) xmalloc (sizeof *n);
891                   n->name = $1;
892                   n->next = $2;
893                   $$ = n;
894                 }
895         |       NAME ',' nocrossref_list
896                 {
897                   struct lang_nocrossref *n;
898
899                   n = (struct lang_nocrossref *) xmalloc (sizeof *n);
900                   n->name = $1;
901                   n->next = $3;
902                   $$ = n;
903                 }
904         ;
905
906 mustbe_exp:              { ldlex_expression (); }
907                 exp
908                          { ldlex_popstate (); $$=$2;}
909         ;
910
911 exp     :
912                 '-' exp %prec UNARY
913                         { $$ = exp_unop ('-', $2); }
914         |       '(' exp ')'
915                         { $$ = $2; }
916         |       NEXT '(' exp ')' %prec UNARY
917                         { $$ = exp_unop ((int) $1,$3); }
918         |       '!' exp %prec UNARY
919                         { $$ = exp_unop ('!', $2); }
920         |       '+' exp %prec UNARY
921                         { $$ = $2; }
922         |       '~' exp %prec UNARY
923                         { $$ = exp_unop ('~', $2);}
924
925         |       exp '*' exp
926                         { $$ = exp_binop ('*', $1, $3); }
927         |       exp '/' exp
928                         { $$ = exp_binop ('/', $1, $3); }
929         |       exp '%' exp
930                         { $$ = exp_binop ('%', $1, $3); }
931         |       exp '+' exp
932                         { $$ = exp_binop ('+', $1, $3); }
933         |       exp '-' exp
934                         { $$ = exp_binop ('-' , $1, $3); }
935         |       exp LSHIFT exp
936                         { $$ = exp_binop (LSHIFT , $1, $3); }
937         |       exp RSHIFT exp
938                         { $$ = exp_binop (RSHIFT , $1, $3); }
939         |       exp EQ exp
940                         { $$ = exp_binop (EQ , $1, $3); }
941         |       exp NE exp
942                         { $$ = exp_binop (NE , $1, $3); }
943         |       exp LE exp
944                         { $$ = exp_binop (LE , $1, $3); }
945         |       exp GE exp
946                         { $$ = exp_binop (GE , $1, $3); }
947         |       exp '<' exp
948                         { $$ = exp_binop ('<' , $1, $3); }
949         |       exp '>' exp
950                         { $$ = exp_binop ('>' , $1, $3); }
951         |       exp '&' exp
952                         { $$ = exp_binop ('&' , $1, $3); }
953         |       exp '^' exp
954                         { $$ = exp_binop ('^' , $1, $3); }
955         |       exp '|' exp
956                         { $$ = exp_binop ('|' , $1, $3); }
957         |       exp '?' exp ':' exp
958                         { $$ = exp_trinop ('?' , $1, $3, $5); }
959         |       exp ANDAND exp
960                         { $$ = exp_binop (ANDAND , $1, $3); }
961         |       exp OROR exp
962                         { $$ = exp_binop (OROR , $1, $3); }
963         |       DEFINED '(' NAME ')'
964                         { $$ = exp_nameop (DEFINED, $3); }
965         |       INT
966                         { $$ = exp_bigintop ($1.integer, $1.str); }
967         |       SIZEOF_HEADERS
968                         { $$ = exp_nameop (SIZEOF_HEADERS,0); }
969
970         |       ALIGNOF '(' NAME ')'
971                         { $$ = exp_nameop (ALIGNOF,$3); }
972         |       SIZEOF '(' NAME ')'
973                         { $$ = exp_nameop (SIZEOF,$3); }
974         |       ADDR '(' NAME ')'
975                         { $$ = exp_nameop (ADDR,$3); }
976         |       LOADADDR '(' NAME ')'
977                         { $$ = exp_nameop (LOADADDR,$3); }
978         |       CONSTANT '(' NAME ')'
979                         { $$ = exp_nameop (CONSTANT,$3); }
980         |       ABSOLUTE '(' exp ')'
981                         { $$ = exp_unop (ABSOLUTE, $3); }
982         |       ALIGN_K '(' exp ')'
983                         { $$ = exp_unop (ALIGN_K,$3); }
984         |       ALIGN_K '(' exp ',' exp ')'
985                         { $$ = exp_binop (ALIGN_K,$3,$5); }
986         |       DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
987                         { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
988         |       DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
989                         { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
990         |       DATA_SEGMENT_END '(' exp ')'
991                         { $$ = exp_unop (DATA_SEGMENT_END, $3); }
992         |       SEGMENT_START '(' NAME ',' exp ')'
993                         { /* The operands to the expression node are
994                              placed in the opposite order from the way
995                              in which they appear in the script as
996                              that allows us to reuse more code in
997                              fold_binary.  */
998                           $$ = exp_binop (SEGMENT_START,
999                                           $5,
1000                                           exp_nameop (NAME, $3)); }
1001         |       BLOCK '(' exp ')'
1002                         { $$ = exp_unop (ALIGN_K,$3); }
1003         |       NAME
1004                         { $$ = exp_nameop (NAME,$1); }
1005         |       MAX_K '(' exp ',' exp ')'
1006                         { $$ = exp_binop (MAX_K, $3, $5 ); }
1007         |       MIN_K '(' exp ',' exp ')'
1008                         { $$ = exp_binop (MIN_K, $3, $5 ); }
1009         |       ASSERT_K '(' exp ',' NAME ')'
1010                         { $$ = exp_assert ($3, $5); }
1011         |       ORIGIN '(' NAME ')'
1012                         { $$ = exp_nameop (ORIGIN, $3); }
1013         |       LENGTH '(' NAME ')'
1014                         { $$ = exp_nameop (LENGTH, $3); }
1015         ;
1016
1017
1018 memspec_at_opt:
1019                 AT '>' NAME { $$ = $3; }
1020         |       { $$ = 0; }
1021         ;
1022
1023 opt_at:
1024                 AT '(' exp ')' { $$ = $3; }
1025         |       { $$ = 0; }
1026         ;
1027
1028 opt_align:
1029                 ALIGN_K '(' exp ')' { $$ = $3; }
1030         |       { $$ = 0; }
1031         ;
1032
1033 opt_subalign:
1034                 SUBALIGN '(' exp ')' { $$ = $3; }
1035         |       { $$ = 0; }
1036         ;
1037
1038 sect_constraint:
1039                 ONLY_IF_RO { $$ = ONLY_IF_RO; }
1040         |       ONLY_IF_RW { $$ = ONLY_IF_RW; }
1041         |       SPECIAL { $$ = SPECIAL; }
1042         |       { $$ = 0; }
1043         ;
1044
1045 section:        NAME            { ldlex_expression(); }
1046                 opt_exp_with_type
1047                 opt_at
1048                 opt_align
1049                 opt_subalign    { ldlex_popstate (); ldlex_script (); }
1050                 sect_constraint
1051                 '{'
1052                         {
1053                           lang_enter_output_section_statement($1, $3,
1054                                                               sectype,
1055                                                               $5, $6, $4, $8);
1056                         }
1057                 statement_list_opt
1058                 '}' { ldlex_popstate (); ldlex_expression (); }
1059                 memspec_opt memspec_at_opt phdr_opt fill_opt
1060                 {
1061                   ldlex_popstate ();
1062                   lang_leave_output_section_statement ($17, $14, $16, $15);
1063                 }
1064                 opt_comma
1065                 {}
1066         |       OVERLAY
1067                         { ldlex_expression (); }
1068                 opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
1069                         { ldlex_popstate (); ldlex_script (); }
1070                 '{'
1071                         {
1072                           lang_enter_overlay ($3, $6);
1073                         }
1074                 overlay_section
1075                 '}'
1076                         { ldlex_popstate (); ldlex_expression (); }
1077                 memspec_opt memspec_at_opt phdr_opt fill_opt
1078                         {
1079                           ldlex_popstate ();
1080                           lang_leave_overlay ($5, (int) $4,
1081                                               $16, $13, $15, $14);
1082                         }
1083                 opt_comma
1084         |       /* The GROUP case is just enough to support the gcc
1085                    svr3.ifile script.  It is not intended to be full
1086                    support.  I'm not even sure what GROUP is supposed
1087                    to mean.  */
1088                 GROUP { ldlex_expression (); }
1089                 opt_exp_with_type
1090                 {
1091                   ldlex_popstate ();
1092                   lang_add_assignment (exp_assign (".", $3, FALSE));
1093                 }
1094                 '{' sec_or_group_p1 '}'
1095         |       INCLUDE filename
1096                 { ldlex_script (); ldfile_open_command_file($2); }
1097                 sec_or_group_p1 END
1098                 { ldlex_popstate (); }
1099         ;
1100
1101 type:
1102            NOLOAD  { sectype = noload_section; }
1103         |  DSECT   { sectype = noalloc_section; }
1104         |  COPY    { sectype = noalloc_section; }
1105         |  INFO    { sectype = noalloc_section; }
1106         |  OVERLAY { sectype = noalloc_section; }
1107         ;
1108
1109 atype:
1110                 '(' type ')'
1111         |       /* EMPTY */ { sectype = normal_section; }
1112         |       '(' ')' { sectype = normal_section; }
1113         ;
1114
1115 opt_exp_with_type:
1116                 exp atype ':'           { $$ = $1; }
1117         |       atype ':'               { $$ = (etree_type *)NULL;  }
1118         |       /* The BIND cases are to support the gcc svr3.ifile
1119                    script.  They aren't intended to implement full
1120                    support for the BIND keyword.  I'm not even sure
1121                    what BIND is supposed to mean.  */
1122                 BIND '(' exp ')' atype ':' { $$ = $3; }
1123         |       BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
1124                 { $$ = $3; }
1125         ;
1126
1127 opt_exp_without_type:
1128                 exp ':'         { $$ = $1; }
1129         |       ':'             { $$ = (etree_type *) NULL;  }
1130         ;
1131
1132 opt_nocrossrefs:
1133                 /* empty */
1134                         { $$ = 0; }
1135         |       NOCROSSREFS
1136                         { $$ = 1; }
1137         ;
1138
1139 memspec_opt:
1140                 '>' NAME
1141                 { $$ = $2; }
1142         |       { $$ = DEFAULT_MEMORY_REGION; }
1143         ;
1144
1145 phdr_opt:
1146                 /* empty */
1147                 {
1148                   $$ = NULL;
1149                 }
1150         |       phdr_opt ':' NAME
1151                 {
1152                   struct lang_output_section_phdr_list *n;
1153
1154                   n = ((struct lang_output_section_phdr_list *)
1155                        xmalloc (sizeof *n));
1156                   n->name = $3;
1157                   n->used = FALSE;
1158                   n->next = $1;
1159                   $$ = n;
1160                 }
1161         ;
1162
1163 overlay_section:
1164                 /* empty */
1165         |       overlay_section
1166                 NAME
1167                         {
1168                           ldlex_script ();
1169                           lang_enter_overlay_section ($2);
1170                         }
1171                 '{' statement_list_opt '}'
1172                         { ldlex_popstate (); ldlex_expression (); }
1173                 phdr_opt fill_opt
1174                         {
1175                           ldlex_popstate ();
1176                           lang_leave_overlay_section ($9, $8);
1177                         }
1178                 opt_comma
1179         ;
1180
1181 phdrs:
1182                 PHDRS '{' phdr_list '}'
1183         ;
1184
1185 phdr_list:
1186                 /* empty */
1187         |       phdr_list phdr
1188         ;
1189
1190 phdr:
1191                 NAME { ldlex_expression (); }
1192                   phdr_type phdr_qualifiers { ldlex_popstate (); }
1193                   ';'
1194                 {
1195                   lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1196                                  $4.flags);
1197                 }
1198         ;
1199
1200 phdr_type:
1201                 exp
1202                 {
1203                   $$ = $1;
1204
1205                   if ($1->type.node_class == etree_name
1206                       && $1->type.node_code == NAME)
1207                     {
1208                       const char *s;
1209                       unsigned int i;
1210                       static const char * const phdr_types[] =
1211                         {
1212                           "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1213                           "PT_INTERP", "PT_NOTE", "PT_SHLIB",
1214                           "PT_PHDR", "PT_TLS"
1215                         };
1216
1217                       s = $1->name.name;
1218                       for (i = 0;
1219                            i < sizeof phdr_types / sizeof phdr_types[0];
1220                            i++)
1221                         if (strcmp (s, phdr_types[i]) == 0)
1222                           {
1223                             $$ = exp_intop (i);
1224                             break;
1225                           }
1226                       if (i == sizeof phdr_types / sizeof phdr_types[0])
1227                         {
1228                           if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1229                             $$ = exp_intop (0x6474e550);
1230                           else if (strcmp (s, "PT_GNU_STACK") == 0)
1231                             $$ = exp_intop (0x6474e551);
1232                           else
1233                             {
1234                               einfo (_("\
1235 %X%P:%S: unknown phdr type `%s' (try integer literal)\n"),
1236                                      NULL, s);
1237                               $$ = exp_intop (0);
1238                             }
1239                         }
1240                     }
1241                 }
1242         ;
1243
1244 phdr_qualifiers:
1245                 /* empty */
1246                 {
1247                   memset (&$$, 0, sizeof (struct phdr_info));
1248                 }
1249         |       NAME phdr_val phdr_qualifiers
1250                 {
1251                   $$ = $3;
1252                   if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
1253                     $$.filehdr = TRUE;
1254                   else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
1255                     $$.phdrs = TRUE;
1256                   else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1257                     $$.flags = $2;
1258                   else
1259                     einfo (_("%X%P:%S: PHDRS syntax error at `%s'\n"),
1260                            NULL, $1);
1261                 }
1262         |       AT '(' exp ')' phdr_qualifiers
1263                 {
1264                   $$ = $5;
1265                   $$.at = $3;
1266                 }
1267         ;
1268
1269 phdr_val:
1270                 /* empty */
1271                 {
1272                   $$ = NULL;
1273                 }
1274         | '(' exp ')'
1275                 {
1276                   $$ = $2;
1277                 }
1278         ;
1279
1280 dynamic_list_file:
1281                 {
1282                   ldlex_version_file ();
1283                   PUSH_ERROR (_("dynamic list"));
1284                 }
1285                 dynamic_list_nodes
1286                 {
1287                   ldlex_popstate ();
1288                   POP_ERROR ();
1289                 }
1290         ;
1291
1292 dynamic_list_nodes:
1293                 dynamic_list_node
1294         |       dynamic_list_nodes dynamic_list_node
1295         ;
1296
1297 dynamic_list_node:
1298                 '{' dynamic_list_tag '}' ';'
1299         ;
1300
1301 dynamic_list_tag:
1302                 vers_defns ';'
1303                 {
1304                   lang_append_dynamic_list ($1);
1305                 }
1306         ;
1307
1308 /* This syntax is used within an external version script file.  */
1309
1310 version_script_file:
1311                 {
1312                   ldlex_version_file ();
1313                   PUSH_ERROR (_("VERSION script"));
1314                 }
1315                 vers_nodes
1316                 {
1317                   ldlex_popstate ();
1318                   POP_ERROR ();
1319                 }
1320         ;
1321
1322 /* This is used within a normal linker script file.  */
1323
1324 version:
1325                 {
1326                   ldlex_version_script ();
1327                 }
1328                 VERSIONK '{' vers_nodes '}'
1329                 {
1330                   ldlex_popstate ();
1331                 }
1332         ;
1333
1334 vers_nodes:
1335                 vers_node
1336         |       vers_nodes vers_node
1337         ;
1338
1339 vers_node:
1340                 '{' vers_tag '}' ';'
1341                 {
1342                   lang_register_vers_node (NULL, $2, NULL);
1343                 }
1344         |       VERS_TAG '{' vers_tag '}' ';'
1345                 {
1346                   lang_register_vers_node ($1, $3, NULL);
1347                 }
1348         |       VERS_TAG '{' vers_tag '}' verdep ';'
1349                 {
1350                   lang_register_vers_node ($1, $3, $5);
1351                 }
1352         ;
1353
1354 verdep:
1355                 VERS_TAG
1356                 {
1357                   $$ = lang_add_vers_depend (NULL, $1);
1358                 }
1359         |       verdep VERS_TAG
1360                 {
1361                   $$ = lang_add_vers_depend ($1, $2);
1362                 }
1363         ;
1364
1365 vers_tag:
1366                 /* empty */
1367                 {
1368                   $$ = lang_new_vers_node (NULL, NULL);
1369                 }
1370         |       vers_defns ';'
1371                 {
1372                   $$ = lang_new_vers_node ($1, NULL);
1373                 }
1374         |       GLOBAL ':' vers_defns ';'
1375                 {
1376                   $$ = lang_new_vers_node ($3, NULL);
1377                 }
1378         |       LOCAL ':' vers_defns ';'
1379                 {
1380                   $$ = lang_new_vers_node (NULL, $3);
1381                 }
1382         |       GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1383                 {
1384                   $$ = lang_new_vers_node ($3, $7);
1385                 }
1386         ;
1387
1388 vers_defns:
1389                 VERS_IDENTIFIER
1390                 {
1391                   $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, FALSE);
1392                 }
1393         |       NAME
1394                 {
1395                   $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, TRUE);
1396                 }
1397         |       vers_defns ';' VERS_IDENTIFIER
1398                 {
1399                   $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, FALSE);
1400                 }
1401         |       vers_defns ';' NAME
1402                 {
1403                   $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, TRUE);
1404                 }
1405         |       vers_defns ';' EXTERN NAME '{'
1406                         {
1407                           $<name>$ = ldgram_vers_current_lang;
1408                           ldgram_vers_current_lang = $4;
1409                         }
1410                 vers_defns opt_semicolon '}'
1411                         {
1412                           struct bfd_elf_version_expr *pat;
1413                           for (pat = $7; pat->next != NULL; pat = pat->next);
1414                           pat->next = $1;
1415                           $$ = $7;
1416                           ldgram_vers_current_lang = $<name>6;
1417                         }
1418         |       EXTERN NAME '{'
1419                         {
1420                           $<name>$ = ldgram_vers_current_lang;
1421                           ldgram_vers_current_lang = $2;
1422                         }
1423                 vers_defns opt_semicolon '}'
1424                         {
1425                           $$ = $5;
1426                           ldgram_vers_current_lang = $<name>4;
1427                         }
1428         |       GLOBAL
1429                 {
1430                   $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, FALSE);
1431                 }
1432         |       vers_defns ';' GLOBAL
1433                 {
1434                   $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, FALSE);
1435                 }
1436         |       LOCAL
1437                 {
1438                   $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, FALSE);
1439                 }
1440         |       vers_defns ';' LOCAL
1441                 {
1442                   $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, FALSE);
1443                 }
1444         |       EXTERN
1445                 {
1446                   $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, FALSE);
1447                 }
1448         |       vers_defns ';' EXTERN
1449                 {
1450                   $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, FALSE);
1451                 }
1452         ;
1453
1454 opt_semicolon:
1455                 /* empty */
1456         |       ';'
1457         ;
1458
1459 %%
1460 void
1461 yyerror(arg)
1462      const char *arg;
1463 {
1464   if (ldfile_assumed_script)
1465     einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
1466            ldlex_filename ());
1467   if (error_index > 0 && error_index < ERROR_NAME_MAX)
1468     einfo ("%P%F:%S: %s in %s\n", NULL, arg, error_names[error_index - 1]);
1469   else
1470     einfo ("%P%F:%S: %s\n", NULL, arg);
1471 }