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