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