[BFD][AARCH64]Disallow R_AARCH64_ABS32(LP64) & R_AARCH64_ABS16 in const section of...
[external/binutils.git] / ld / ldgram.y
1 /* A YACC grammar to parse a superset of the AT&T linker scripting language.
2    Copyright (C) 1991-2017 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 static bfd_boolean ldgram_had_keep = FALSE;
52 static 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> section_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> section_name_spec filename_spec wildcard_maybe_exclude
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 FORCE_GROUP_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 NOCROSSREFS_TO
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         |       FORCE_GROUP_ALLOCATION
340                 { command_line.force_group_allocation = TRUE ; }
341         |       INHIBIT_COMMON_ALLOCATION
342                 { link_info.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         |       NOCROSSREFS_TO '(' nocrossref_list ')'
359                 {
360                   lang_add_nocrossref_to ($3);
361                 }
362         |       EXTERN '(' extern_name_list ')'
363         |       INSERT_K AFTER NAME
364                 { lang_add_insert ($3, 0); }
365         |       INSERT_K BEFORE NAME
366                 { lang_add_insert ($3, 1); }
367         |       REGION_ALIAS '(' NAME ',' NAME ')'
368                 { lang_memory_region_alias ($3, $5); }
369         |       LD_FEATURE '(' NAME ')'
370                 { lang_ld_feature ($3); }
371         ;
372
373 input_list:
374                 { ldlex_inputlist(); }
375                 input_list1
376                 { ldlex_popstate(); }
377
378 input_list1:
379                 NAME
380                 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
381                                  (char *)NULL); }
382         |       input_list1 ',' NAME
383                 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
384                                  (char *)NULL); }
385         |       input_list1 NAME
386                 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
387                                  (char *)NULL); }
388         |       LNAME
389                 { lang_add_input_file($1,lang_input_file_is_l_enum,
390                                  (char *)NULL); }
391         |       input_list1 ',' LNAME
392                 { lang_add_input_file($3,lang_input_file_is_l_enum,
393                                  (char *)NULL); }
394         |       input_list1 LNAME
395                 { lang_add_input_file($2,lang_input_file_is_l_enum,
396                                  (char *)NULL); }
397         |       AS_NEEDED '('
398                   { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
399                     input_flags.add_DT_NEEDED_for_regular = TRUE; }
400                      input_list1 ')'
401                   { input_flags.add_DT_NEEDED_for_regular = $<integer>3; }
402         |       input_list1 ',' AS_NEEDED '('
403                   { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
404                     input_flags.add_DT_NEEDED_for_regular = TRUE; }
405                      input_list1 ')'
406                   { input_flags.add_DT_NEEDED_for_regular = $<integer>5; }
407         |       input_list1 AS_NEEDED '('
408                   { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
409                     input_flags.add_DT_NEEDED_for_regular = TRUE; }
410                      input_list1 ')'
411                   { input_flags.add_DT_NEEDED_for_regular = $<integer>4; }
412         ;
413
414 sections:
415                 SECTIONS '{' sec_or_group_p1 '}'
416         ;
417
418 sec_or_group_p1:
419                 sec_or_group_p1 section
420         |       sec_or_group_p1 statement_anywhere
421         |
422         ;
423
424 statement_anywhere:
425                 ENTRY '(' NAME ')'
426                 { lang_add_entry ($3, FALSE); }
427         |       assignment end
428         |       ASSERT_K  {ldlex_expression ();} '(' exp ',' NAME ')'
429                 { ldlex_popstate ();
430                   lang_add_assignment (exp_assert ($4, $6)); }
431         ;
432
433 /* The '*' and '?' cases are there because the lexer returns them as
434    separate tokens rather than as NAME.  */
435 wildcard_name:
436                 NAME
437                         {
438                           $$ = $1;
439                         }
440         |       '*'
441                         {
442                           $$ = "*";
443                         }
444         |       '?'
445                         {
446                           $$ = "?";
447                         }
448         ;
449
450 wildcard_maybe_exclude:
451                 wildcard_name
452                         {
453                           $$.name = $1;
454                           $$.sorted = none;
455                           $$.exclude_name_list = NULL;
456                           $$.section_flag_list = NULL;
457                         }
458         |       EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
459                         {
460                           $$.name = $5;
461                           $$.sorted = none;
462                           $$.exclude_name_list = $3;
463                           $$.section_flag_list = NULL;
464                         }
465         ;
466
467 filename_spec:
468                 wildcard_maybe_exclude
469         |       SORT_BY_NAME '(' wildcard_maybe_exclude ')'
470                         {
471                           $$ = $3;
472                           $$.sorted = by_name;
473                         }
474         |       SORT_NONE '(' wildcard_maybe_exclude ')'
475                         {
476                           $$ = $3;
477                           $$.sorted = by_none;
478                         }
479         ;
480
481 section_name_spec:
482                 wildcard_maybe_exclude
483         |       SORT_BY_NAME '(' wildcard_maybe_exclude ')'
484                         {
485                           $$ = $3;
486                           $$.sorted = by_name;
487                         }
488         |       SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')'
489                         {
490                           $$ = $3;
491                           $$.sorted = by_alignment;
492                         }
493         |       SORT_NONE '(' wildcard_maybe_exclude ')'
494                         {
495                           $$ = $3;
496                           $$.sorted = by_none;
497                         }
498         |       SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')'
499                         {
500                           $$ = $5;
501                           $$.sorted = by_name_alignment;
502                         }
503         |       SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')'
504                         {
505                           $$ = $5;
506                           $$.sorted = by_name;
507                         }
508         |       SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')'
509                         {
510                           $$ = $5;
511                           $$.sorted = by_alignment_name;
512                         }
513         |       SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')'
514                         {
515                           $$ = $5;
516                           $$.sorted = by_alignment;
517                         }
518         |       SORT_BY_INIT_PRIORITY '(' wildcard_maybe_exclude ')'
519                         {
520                           $$ = $3;
521                           $$.sorted = by_init_priority;
522                         }
523         ;
524
525 sect_flag_list: NAME
526                         {
527                           struct flag_info_list *n;
528                           n = ((struct flag_info_list *) xmalloc (sizeof *n));
529                           if ($1[0] == '!')
530                             {
531                               n->with = without_flags;
532                               n->name = &$1[1];
533                             }
534                           else
535                             {
536                               n->with = with_flags;
537                               n->name = $1;
538                             }
539                           n->valid = FALSE;
540                           n->next = NULL;
541                           $$ = n;
542                         }
543         |       sect_flag_list '&' NAME
544                         {
545                           struct flag_info_list *n;
546                           n = ((struct flag_info_list *) xmalloc (sizeof *n));
547                           if ($3[0] == '!')
548                             {
549                               n->with = without_flags;
550                               n->name = &$3[1];
551                             }
552                           else
553                             {
554                               n->with = with_flags;
555                               n->name = $3;
556                             }
557                           n->valid = FALSE;
558                           n->next = $1;
559                           $$ = n;
560                         }
561         ;
562
563 sect_flags:
564                 INPUT_SECTION_FLAGS '(' sect_flag_list ')'
565                         {
566                           struct flag_info *n;
567                           n = ((struct flag_info *) xmalloc (sizeof *n));
568                           n->flag_list = $3;
569                           n->flags_initialized = FALSE;
570                           n->not_with_flags = 0;
571                           n->only_with_flags = 0;
572                           $$ = n;
573                         }
574         ;
575
576 exclude_name_list:
577                 exclude_name_list wildcard_name
578                         {
579                           struct name_list *tmp;
580                           tmp = (struct name_list *) xmalloc (sizeof *tmp);
581                           tmp->name = $2;
582                           tmp->next = $1;
583                           $$ = tmp;
584                         }
585         |
586                 wildcard_name
587                         {
588                           struct name_list *tmp;
589                           tmp = (struct name_list *) xmalloc (sizeof *tmp);
590                           tmp->name = $1;
591                           tmp->next = NULL;
592                           $$ = tmp;
593                         }
594         ;
595
596 section_name_list:
597                 section_name_list opt_comma section_name_spec
598                         {
599                           struct wildcard_list *tmp;
600                           tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
601                           tmp->next = $1;
602                           tmp->spec = $3;
603                           $$ = tmp;
604                         }
605         |
606                 section_name_spec
607                         {
608                           struct wildcard_list *tmp;
609                           tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
610                           tmp->next = NULL;
611                           tmp->spec = $1;
612                           $$ = tmp;
613                         }
614         ;
615
616 input_section_spec_no_keep:
617                 NAME
618                         {
619                           struct wildcard_spec tmp;
620                           tmp.name = $1;
621                           tmp.exclude_name_list = NULL;
622                           tmp.sorted = none;
623                           tmp.section_flag_list = NULL;
624                           lang_add_wild (&tmp, NULL, ldgram_had_keep);
625                         }
626         |       sect_flags NAME
627                         {
628                           struct wildcard_spec tmp;
629                           tmp.name = $2;
630                           tmp.exclude_name_list = NULL;
631                           tmp.sorted = none;
632                           tmp.section_flag_list = $1;
633                           lang_add_wild (&tmp, NULL, ldgram_had_keep);
634                         }
635         |       '[' section_name_list ']'
636                         {
637                           lang_add_wild (NULL, $2, ldgram_had_keep);
638                         }
639         |       sect_flags '[' section_name_list ']'
640                         {
641                           struct wildcard_spec tmp;
642                           tmp.name = NULL;
643                           tmp.exclude_name_list = NULL;
644                           tmp.sorted = none;
645                           tmp.section_flag_list = $1;
646                           lang_add_wild (&tmp, $3, ldgram_had_keep);
647                         }
648         |       filename_spec '(' section_name_list ')'
649                         {
650                           lang_add_wild (&$1, $3, ldgram_had_keep);
651                         }
652         |       sect_flags filename_spec '(' section_name_list ')'
653                         {
654                           $2.section_flag_list = $1;
655                           lang_add_wild (&$2, $4, ldgram_had_keep);
656                         }
657         ;
658
659 input_section_spec:
660                 input_section_spec_no_keep
661         |       KEEP '('
662                         { ldgram_had_keep = TRUE; }
663                 input_section_spec_no_keep ')'
664                         { ldgram_had_keep = FALSE; }
665         ;
666
667 statement:
668                 assignment end
669         |       CREATE_OBJECT_SYMBOLS
670                 {
671                 lang_add_attribute(lang_object_symbols_statement_enum);
672                 }
673         |       ';'
674         |       CONSTRUCTORS
675                 {
676
677                   lang_add_attribute(lang_constructors_statement_enum);
678                 }
679         | SORT_BY_NAME '(' CONSTRUCTORS ')'
680                 {
681                   constructors_sorted = TRUE;
682                   lang_add_attribute (lang_constructors_statement_enum);
683                 }
684         | input_section_spec
685         | length '(' mustbe_exp ')'
686                 {
687                   lang_add_data ((int) $1, $3);
688                 }
689
690         | FILL '(' fill_exp ')'
691                 {
692                   lang_add_fill ($3);
693                 }
694         | ASSERT_K  {ldlex_expression ();} '(' exp ',' NAME ')' end
695                         { ldlex_popstate ();
696                           lang_add_assignment (exp_assert ($4, $6)); }
697         | INCLUDE filename
698                 { ldlex_script (); ldfile_open_command_file($2); }
699                 statement_list_opt END
700                 { ldlex_popstate (); }
701         ;
702
703 statement_list:
704                 statement_list statement
705         |       statement
706         ;
707
708 statement_list_opt:
709                 /* empty */
710         |       statement_list
711         ;
712
713 length:
714                 QUAD
715                         { $$ = $1; }
716         |       SQUAD
717                         { $$ = $1; }
718         |       LONG
719                         { $$ = $1; }
720         |       SHORT
721                         { $$ = $1; }
722         |       BYTE
723                         { $$ = $1; }
724         ;
725
726 fill_exp:
727         mustbe_exp
728                 {
729                   $$ = exp_get_fill ($1, 0, "fill value");
730                 }
731         ;
732
733 fill_opt:
734           '=' fill_exp
735                 { $$ = $2; }
736         |       { $$ = (fill_type *) 0; }
737         ;
738
739 assign_op:
740                 PLUSEQ
741                         { $$ = '+'; }
742         |       MINUSEQ
743                         { $$ = '-'; }
744         |       MULTEQ
745                         { $$ = '*'; }
746         |       DIVEQ
747                         { $$ = '/'; }
748         |       LSHIFTEQ
749                         { $$ = LSHIFT; }
750         |       RSHIFTEQ
751                         { $$ = RSHIFT; }
752         |       ANDEQ
753                         { $$ = '&'; }
754         |       OREQ
755                         { $$ = '|'; }
756
757         ;
758
759 end:    ';' | ','
760         ;
761
762
763 assignment:
764                 NAME '=' mustbe_exp
765                 {
766                   lang_add_assignment (exp_assign ($1, $3, FALSE));
767                 }
768         |       NAME assign_op mustbe_exp
769                 {
770                   lang_add_assignment (exp_assign ($1,
771                                                    exp_binop ($2,
772                                                               exp_nameop (NAME,
773                                                                           $1),
774                                                               $3), FALSE));
775                 }
776         |       HIDDEN '(' NAME '=' mustbe_exp ')'
777                 {
778                   lang_add_assignment (exp_assign ($3, $5, TRUE));
779                 }
780         |       PROVIDE '(' NAME '=' mustbe_exp ')'
781                 {
782                   lang_add_assignment (exp_provide ($3, $5, FALSE));
783                 }
784         |       PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
785                 {
786                   lang_add_assignment (exp_provide ($3, $5, TRUE));
787                 }
788         ;
789
790
791 opt_comma:
792                 ','     |       ;
793
794
795 memory:
796                 MEMORY '{' memory_spec_list_opt '}'
797         ;
798
799 memory_spec_list_opt: memory_spec_list | ;
800
801 memory_spec_list:
802                 memory_spec_list opt_comma memory_spec
803         |       memory_spec
804         ;
805
806
807 memory_spec:    NAME
808                 { region = lang_memory_region_lookup ($1, TRUE); }
809                 attributes_opt ':'
810                 origin_spec opt_comma length_spec
811                 {}
812         |       INCLUDE filename
813                 { ldlex_script (); ldfile_open_command_file($2); }
814                 memory_spec_list_opt END
815                 { ldlex_popstate (); }
816         ;
817
818 origin_spec:
819         ORIGIN '=' mustbe_exp
820                 {
821                   region->origin_exp = $3;
822                   region->current = region->origin;
823                 }
824         ;
825
826 length_spec:
827              LENGTH '=' mustbe_exp
828                 {
829                   region->length_exp = $3;
830                 }
831         ;
832
833 attributes_opt:
834                 /* empty */
835                   { /* dummy action to avoid bison 1.25 error message */ }
836         |       '(' attributes_list ')'
837         ;
838
839 attributes_list:
840                 attributes_string
841         |       attributes_list attributes_string
842         ;
843
844 attributes_string:
845                 NAME
846                   { lang_set_flags (region, $1, 0); }
847         |       '!' NAME
848                   { lang_set_flags (region, $2, 1); }
849         ;
850
851 startup:
852         STARTUP '(' filename ')'
853                 { lang_startup($3); }
854         ;
855
856 high_level_library:
857                 HLL '(' high_level_library_NAME_list ')'
858         |       HLL '(' ')'
859                         { ldemul_hll((char *)NULL); }
860         ;
861
862 high_level_library_NAME_list:
863                 high_level_library_NAME_list opt_comma filename
864                         { ldemul_hll($3); }
865         |       filename
866                         { ldemul_hll($1); }
867
868         ;
869
870 low_level_library:
871         SYSLIB '(' low_level_library_NAME_list ')'
872         ; low_level_library_NAME_list:
873                 low_level_library_NAME_list opt_comma filename
874                         { ldemul_syslib($3); }
875         |
876         ;
877
878 floating_point_support:
879                 FLOAT
880                         { lang_float(TRUE); }
881         |       NOFLOAT
882                         { lang_float(FALSE); }
883         ;
884
885 nocrossref_list:
886                 /* empty */
887                 {
888                   $$ = NULL;
889                 }
890         |       NAME nocrossref_list
891                 {
892                   struct lang_nocrossref *n;
893
894                   n = (struct lang_nocrossref *) xmalloc (sizeof *n);
895                   n->name = $1;
896                   n->next = $2;
897                   $$ = n;
898                 }
899         |       NAME ',' nocrossref_list
900                 {
901                   struct lang_nocrossref *n;
902
903                   n = (struct lang_nocrossref *) xmalloc (sizeof *n);
904                   n->name = $1;
905                   n->next = $3;
906                   $$ = n;
907                 }
908         ;
909
910 mustbe_exp:              { ldlex_expression (); }
911                 exp
912                          { ldlex_popstate (); $$=$2;}
913         ;
914
915 exp     :
916                 '-' exp %prec UNARY
917                         { $$ = exp_unop ('-', $2); }
918         |       '(' exp ')'
919                         { $$ = $2; }
920         |       NEXT '(' exp ')' %prec UNARY
921                         { $$ = exp_unop ((int) $1,$3); }
922         |       '!' exp %prec UNARY
923                         { $$ = exp_unop ('!', $2); }
924         |       '+' exp %prec UNARY
925                         { $$ = $2; }
926         |       '~' exp %prec UNARY
927                         { $$ = exp_unop ('~', $2);}
928
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 '+' exp
936                         { $$ = exp_binop ('+', $1, $3); }
937         |       exp '-' exp
938                         { $$ = exp_binop ('-' , $1, $3); }
939         |       exp LSHIFT exp
940                         { $$ = exp_binop (LSHIFT , $1, $3); }
941         |       exp RSHIFT exp
942                         { $$ = exp_binop (RSHIFT , $1, $3); }
943         |       exp EQ exp
944                         { $$ = exp_binop (EQ , $1, $3); }
945         |       exp NE exp
946                         { $$ = exp_binop (NE , $1, $3); }
947         |       exp LE exp
948                         { $$ = exp_binop (LE , $1, $3); }
949         |       exp GE exp
950                         { $$ = exp_binop (GE , $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
958                         { $$ = exp_binop ('^' , $1, $3); }
959         |       exp '|' exp
960                         { $$ = exp_binop ('|' , $1, $3); }
961         |       exp '?' exp ':' exp
962                         { $$ = exp_trinop ('?' , $1, $3, $5); }
963         |       exp ANDAND exp
964                         { $$ = exp_binop (ANDAND , $1, $3); }
965         |       exp OROR exp
966                         { $$ = exp_binop (OROR , $1, $3); }
967         |       DEFINED '(' NAME ')'
968                         { $$ = exp_nameop (DEFINED, $3); }
969         |       INT
970                         { $$ = exp_bigintop ($1.integer, $1.str); }
971         |       SIZEOF_HEADERS
972                         { $$ = exp_nameop (SIZEOF_HEADERS,0); }
973
974         |       ALIGNOF '(' NAME ')'
975                         { $$ = exp_nameop (ALIGNOF,$3); }
976         |       SIZEOF '(' NAME ')'
977                         { $$ = exp_nameop (SIZEOF,$3); }
978         |       ADDR '(' NAME ')'
979                         { $$ = exp_nameop (ADDR,$3); }
980         |       LOADADDR '(' NAME ')'
981                         { $$ = exp_nameop (LOADADDR,$3); }
982         |       CONSTANT '(' NAME ')'
983                         { $$ = exp_nameop (CONSTANT,$3); }
984         |       ABSOLUTE '(' exp ')'
985                         { $$ = exp_unop (ABSOLUTE, $3); }
986         |       ALIGN_K '(' exp ')'
987                         { $$ = exp_unop (ALIGN_K,$3); }
988         |       ALIGN_K '(' exp ',' exp ')'
989                         { $$ = exp_binop (ALIGN_K,$3,$5); }
990         |       DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
991                         { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
992         |       DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
993                         { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
994         |       DATA_SEGMENT_END '(' exp ')'
995                         { $$ = exp_unop (DATA_SEGMENT_END, $3); }
996         |       SEGMENT_START '(' NAME ',' exp ')'
997                         { /* The operands to the expression node are
998                              placed in the opposite order from the way
999                              in which they appear in the script as
1000                              that allows us to reuse more code in
1001                              fold_binary.  */
1002                           $$ = exp_binop (SEGMENT_START,
1003                                           $5,
1004                                           exp_nameop (NAME, $3)); }
1005         |       BLOCK '(' exp ')'
1006                         { $$ = exp_unop (ALIGN_K,$3); }
1007         |       NAME
1008                         { $$ = exp_nameop (NAME,$1); }
1009         |       MAX_K '(' exp ',' exp ')'
1010                         { $$ = exp_binop (MAX_K, $3, $5 ); }
1011         |       MIN_K '(' exp ',' exp ')'
1012                         { $$ = exp_binop (MIN_K, $3, $5 ); }
1013         |       ASSERT_K '(' exp ',' NAME ')'
1014                         { $$ = exp_assert ($3, $5); }
1015         |       ORIGIN '(' NAME ')'
1016                         { $$ = exp_nameop (ORIGIN, $3); }
1017         |       LENGTH '(' NAME ')'
1018                         { $$ = exp_nameop (LENGTH, $3); }
1019         |       LOG2CEIL '(' exp ')'
1020                         { $$ = exp_unop (LOG2CEIL, $3); }
1021         ;
1022
1023
1024 memspec_at_opt:
1025                 AT '>' NAME { $$ = $3; }
1026         |       { $$ = 0; }
1027         ;
1028
1029 opt_at:
1030                 AT '(' exp ')' { $$ = $3; }
1031         |       { $$ = 0; }
1032         ;
1033
1034 opt_align:
1035                 ALIGN_K '(' exp ')' { $$ = $3; }
1036         |       { $$ = 0; }
1037         ;
1038
1039 opt_align_with_input:
1040                 ALIGN_WITH_INPUT { $$ = ALIGN_WITH_INPUT; }
1041         |       { $$ = 0; }
1042         ;
1043
1044 opt_subalign:
1045                 SUBALIGN '(' exp ')' { $$ = $3; }
1046         |       { $$ = 0; }
1047         ;
1048
1049 sect_constraint:
1050                 ONLY_IF_RO { $$ = ONLY_IF_RO; }
1051         |       ONLY_IF_RW { $$ = ONLY_IF_RW; }
1052         |       SPECIAL { $$ = SPECIAL; }
1053         |       { $$ = 0; }
1054         ;
1055
1056 section:        NAME            { ldlex_expression(); }
1057                 opt_exp_with_type
1058                 opt_at
1059                 opt_align
1060                 opt_align_with_input
1061                 opt_subalign    { ldlex_popstate (); ldlex_script (); }
1062                 sect_constraint
1063                 '{'
1064                         {
1065                           lang_enter_output_section_statement($1, $3,
1066                                                               sectype,
1067                                                               $5, $7, $4, $9, $6);
1068                         }
1069                 statement_list_opt
1070                 '}' { ldlex_popstate (); ldlex_expression (); }
1071                 memspec_opt memspec_at_opt phdr_opt fill_opt
1072                 {
1073                   ldlex_popstate ();
1074                   lang_leave_output_section_statement ($18, $15, $17, $16);
1075                 }
1076                 opt_comma
1077                 {}
1078         |       OVERLAY
1079                         { ldlex_expression (); }
1080                 opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
1081                         { ldlex_popstate (); ldlex_script (); }
1082                 '{'
1083                         {
1084                           lang_enter_overlay ($3, $6);
1085                         }
1086                 overlay_section
1087                 '}'
1088                         { ldlex_popstate (); ldlex_expression (); }
1089                 memspec_opt memspec_at_opt phdr_opt fill_opt
1090                         {
1091                           ldlex_popstate ();
1092                           lang_leave_overlay ($5, (int) $4,
1093                                               $16, $13, $15, $14);
1094                         }
1095                 opt_comma
1096         |       /* The GROUP case is just enough to support the gcc
1097                    svr3.ifile script.  It is not intended to be full
1098                    support.  I'm not even sure what GROUP is supposed
1099                    to mean.  */
1100                 GROUP { ldlex_expression (); }
1101                 opt_exp_with_type
1102                 {
1103                   ldlex_popstate ();
1104                   lang_add_assignment (exp_assign (".", $3, FALSE));
1105                 }
1106                 '{' sec_or_group_p1 '}'
1107         |       INCLUDE filename
1108                 { ldlex_script (); ldfile_open_command_file($2); }
1109                 sec_or_group_p1 END
1110                 { ldlex_popstate (); }
1111         ;
1112
1113 type:
1114            NOLOAD  { sectype = noload_section; }
1115         |  DSECT   { sectype = noalloc_section; }
1116         |  COPY    { sectype = noalloc_section; }
1117         |  INFO    { sectype = noalloc_section; }
1118         |  OVERLAY { sectype = noalloc_section; }
1119         ;
1120
1121 atype:
1122                 '(' type ')'
1123         |       /* EMPTY */ { sectype = normal_section; }
1124         |       '(' ')' { sectype = normal_section; }
1125         ;
1126
1127 opt_exp_with_type:
1128                 exp atype ':'           { $$ = $1; }
1129         |       atype ':'               { $$ = (etree_type *)NULL;  }
1130         |       /* The BIND cases are to support the gcc svr3.ifile
1131                    script.  They aren't intended to implement full
1132                    support for the BIND keyword.  I'm not even sure
1133                    what BIND is supposed to mean.  */
1134                 BIND '(' exp ')' atype ':' { $$ = $3; }
1135         |       BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
1136                 { $$ = $3; }
1137         ;
1138
1139 opt_exp_without_type:
1140                 exp ':'         { $$ = $1; }
1141         |       ':'             { $$ = (etree_type *) NULL;  }
1142         ;
1143
1144 opt_nocrossrefs:
1145                 /* empty */
1146                         { $$ = 0; }
1147         |       NOCROSSREFS
1148                         { $$ = 1; }
1149         ;
1150
1151 memspec_opt:
1152                 '>' NAME
1153                 { $$ = $2; }
1154         |       { $$ = DEFAULT_MEMORY_REGION; }
1155         ;
1156
1157 phdr_opt:
1158                 /* empty */
1159                 {
1160                   $$ = NULL;
1161                 }
1162         |       phdr_opt ':' NAME
1163                 {
1164                   struct lang_output_section_phdr_list *n;
1165
1166                   n = ((struct lang_output_section_phdr_list *)
1167                        xmalloc (sizeof *n));
1168                   n->name = $3;
1169                   n->used = FALSE;
1170                   n->next = $1;
1171                   $$ = n;
1172                 }
1173         ;
1174
1175 overlay_section:
1176                 /* empty */
1177         |       overlay_section
1178                 NAME
1179                         {
1180                           ldlex_script ();
1181                           lang_enter_overlay_section ($2);
1182                         }
1183                 '{' statement_list_opt '}'
1184                         { ldlex_popstate (); ldlex_expression (); }
1185                 phdr_opt fill_opt
1186                         {
1187                           ldlex_popstate ();
1188                           lang_leave_overlay_section ($9, $8);
1189                         }
1190                 opt_comma
1191         ;
1192
1193 phdrs:
1194                 PHDRS '{' phdr_list '}'
1195         ;
1196
1197 phdr_list:
1198                 /* empty */
1199         |       phdr_list phdr
1200         ;
1201
1202 phdr:
1203                 NAME { ldlex_expression (); }
1204                   phdr_type phdr_qualifiers { ldlex_popstate (); }
1205                   ';'
1206                 {
1207                   lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1208                                  $4.flags);
1209                 }
1210         ;
1211
1212 phdr_type:
1213                 exp
1214                 {
1215                   $$ = $1;
1216
1217                   if ($1->type.node_class == etree_name
1218                       && $1->type.node_code == NAME)
1219                     {
1220                       const char *s;
1221                       unsigned int i;
1222                       static const char * const phdr_types[] =
1223                         {
1224                           "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1225                           "PT_INTERP", "PT_NOTE", "PT_SHLIB",
1226                           "PT_PHDR", "PT_TLS"
1227                         };
1228
1229                       s = $1->name.name;
1230                       for (i = 0;
1231                            i < sizeof phdr_types / sizeof phdr_types[0];
1232                            i++)
1233                         if (strcmp (s, phdr_types[i]) == 0)
1234                           {
1235                             $$ = exp_intop (i);
1236                             break;
1237                           }
1238                       if (i == sizeof phdr_types / sizeof phdr_types[0])
1239                         {
1240                           if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1241                             $$ = exp_intop (0x6474e550);
1242                           else if (strcmp (s, "PT_GNU_STACK") == 0)
1243                             $$ = exp_intop (0x6474e551);
1244                           else
1245                             {
1246                               einfo (_("\
1247 %X%P:%S: unknown phdr type `%s' (try integer literal)\n"),
1248                                      NULL, s);
1249                               $$ = exp_intop (0);
1250                             }
1251                         }
1252                     }
1253                 }
1254         ;
1255
1256 phdr_qualifiers:
1257                 /* empty */
1258                 {
1259                   memset (&$$, 0, sizeof (struct phdr_info));
1260                 }
1261         |       NAME phdr_val phdr_qualifiers
1262                 {
1263                   $$ = $3;
1264                   if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
1265                     $$.filehdr = TRUE;
1266                   else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
1267                     $$.phdrs = TRUE;
1268                   else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1269                     $$.flags = $2;
1270                   else
1271                     einfo (_("%X%P:%S: PHDRS syntax error at `%s'\n"),
1272                            NULL, $1);
1273                 }
1274         |       AT '(' exp ')' phdr_qualifiers
1275                 {
1276                   $$ = $5;
1277                   $$.at = $3;
1278                 }
1279         ;
1280
1281 phdr_val:
1282                 /* empty */
1283                 {
1284                   $$ = NULL;
1285                 }
1286         | '(' exp ')'
1287                 {
1288                   $$ = $2;
1289                 }
1290         ;
1291
1292 dynamic_list_file:
1293                 {
1294                   ldlex_version_file ();
1295                   PUSH_ERROR (_("dynamic list"));
1296                 }
1297                 dynamic_list_nodes
1298                 {
1299                   ldlex_popstate ();
1300                   POP_ERROR ();
1301                 }
1302         ;
1303
1304 dynamic_list_nodes:
1305                 dynamic_list_node
1306         |       dynamic_list_nodes dynamic_list_node
1307         ;
1308
1309 dynamic_list_node:
1310                 '{' dynamic_list_tag '}' ';'
1311         ;
1312
1313 dynamic_list_tag:
1314                 vers_defns ';'
1315                 {
1316                   lang_append_dynamic_list ($1);
1317                 }
1318         ;
1319
1320 /* This syntax is used within an external version script file.  */
1321
1322 version_script_file:
1323                 {
1324                   ldlex_version_file ();
1325                   PUSH_ERROR (_("VERSION script"));
1326                 }
1327                 vers_nodes
1328                 {
1329                   ldlex_popstate ();
1330                   POP_ERROR ();
1331                 }
1332         ;
1333
1334 /* This is used within a normal linker script file.  */
1335
1336 version:
1337                 {
1338                   ldlex_version_script ();
1339                 }
1340                 VERSIONK '{' vers_nodes '}'
1341                 {
1342                   ldlex_popstate ();
1343                 }
1344         ;
1345
1346 vers_nodes:
1347                 vers_node
1348         |       vers_nodes vers_node
1349         ;
1350
1351 vers_node:
1352                 '{' vers_tag '}' ';'
1353                 {
1354                   lang_register_vers_node (NULL, $2, NULL);
1355                 }
1356         |       VERS_TAG '{' vers_tag '}' ';'
1357                 {
1358                   lang_register_vers_node ($1, $3, NULL);
1359                 }
1360         |       VERS_TAG '{' vers_tag '}' verdep ';'
1361                 {
1362                   lang_register_vers_node ($1, $3, $5);
1363                 }
1364         ;
1365
1366 verdep:
1367                 VERS_TAG
1368                 {
1369                   $$ = lang_add_vers_depend (NULL, $1);
1370                 }
1371         |       verdep VERS_TAG
1372                 {
1373                   $$ = lang_add_vers_depend ($1, $2);
1374                 }
1375         ;
1376
1377 vers_tag:
1378                 /* empty */
1379                 {
1380                   $$ = lang_new_vers_node (NULL, NULL);
1381                 }
1382         |       vers_defns ';'
1383                 {
1384                   $$ = lang_new_vers_node ($1, NULL);
1385                 }
1386         |       GLOBAL ':' vers_defns ';'
1387                 {
1388                   $$ = lang_new_vers_node ($3, NULL);
1389                 }
1390         |       LOCAL ':' vers_defns ';'
1391                 {
1392                   $$ = lang_new_vers_node (NULL, $3);
1393                 }
1394         |       GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1395                 {
1396                   $$ = lang_new_vers_node ($3, $7);
1397                 }
1398         ;
1399
1400 vers_defns:
1401                 VERS_IDENTIFIER
1402                 {
1403                   $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, FALSE);
1404                 }
1405         |       NAME
1406                 {
1407                   $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, TRUE);
1408                 }
1409         |       vers_defns ';' VERS_IDENTIFIER
1410                 {
1411                   $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, FALSE);
1412                 }
1413         |       vers_defns ';' NAME
1414                 {
1415                   $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, TRUE);
1416                 }
1417         |       vers_defns ';' EXTERN NAME '{'
1418                         {
1419                           $<name>$ = ldgram_vers_current_lang;
1420                           ldgram_vers_current_lang = $4;
1421                         }
1422                 vers_defns opt_semicolon '}'
1423                         {
1424                           struct bfd_elf_version_expr *pat;
1425                           for (pat = $7; pat->next != NULL; pat = pat->next);
1426                           pat->next = $1;
1427                           $$ = $7;
1428                           ldgram_vers_current_lang = $<name>6;
1429                         }
1430         |       EXTERN NAME '{'
1431                         {
1432                           $<name>$ = ldgram_vers_current_lang;
1433                           ldgram_vers_current_lang = $2;
1434                         }
1435                 vers_defns opt_semicolon '}'
1436                         {
1437                           $$ = $5;
1438                           ldgram_vers_current_lang = $<name>4;
1439                         }
1440         |       GLOBAL
1441                 {
1442                   $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, FALSE);
1443                 }
1444         |       vers_defns ';' GLOBAL
1445                 {
1446                   $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, FALSE);
1447                 }
1448         |       LOCAL
1449                 {
1450                   $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, FALSE);
1451                 }
1452         |       vers_defns ';' LOCAL
1453                 {
1454                   $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, FALSE);
1455                 }
1456         |       EXTERN
1457                 {
1458                   $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, FALSE);
1459                 }
1460         |       vers_defns ';' EXTERN
1461                 {
1462                   $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, FALSE);
1463                 }
1464         ;
1465
1466 opt_semicolon:
1467                 /* empty */
1468         |       ';'
1469         ;
1470
1471 %%
1472 void
1473 yyerror(arg)
1474      const char *arg;
1475 {
1476   if (ldfile_assumed_script)
1477     einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
1478            ldlex_filename ());
1479   if (error_index > 0 && error_index < ERROR_NAME_MAX)
1480     einfo ("%P%F:%S: %s in %s\n", NULL, arg, error_names[error_index - 1]);
1481   else
1482     einfo ("%P%F:%S: %s\n", NULL, arg);
1483 }