Automatic date update in version.in
[binutils-gdb.git] / ld / ldgram.y
blob3a904e39482640d62fda6fa3db01a52980c48191
1 /* A YACC grammar to parse a superset of the AT&T linker scripting language.
2 Copyright (C) 1991-2022 Free Software Foundation, Inc.
3 Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
5 This file is part of the GNU Binutils.
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.
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.
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. */
27 #define DONTDECLARE_MALLOC
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"
45 #ifndef YYDEBUG
46 #define YYDEBUG 1
47 #endif
49 static enum section_type sectype;
50 static etree_type *sectype_value;
51 static lang_memory_region_type *region;
53 static bool ldgram_had_keep = false;
54 static char *ldgram_vers_current_lang = NULL;
56 #define ERROR_NAME_MAX 20
57 static char *error_names[ERROR_NAME_MAX];
58 static int error_index;
59 #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
60 #define POP_ERROR() error_index--;
62 %union {
63 bfd_vma integer;
64 struct big_int
66 bfd_vma integer;
67 char *str;
68 } bigint;
69 fill_type *fill;
70 char *name;
71 const char *cname;
72 struct wildcard_spec wildcard;
73 struct wildcard_list *wildcard_list;
74 struct name_list *name_list;
75 struct flag_info_list *flag_info_list;
76 struct flag_info *flag_info;
77 int token;
78 union etree_union *etree;
79 struct phdr_info
81 bool filehdr;
82 bool phdrs;
83 union etree_union *at;
84 union etree_union *flags;
85 } phdr;
86 struct lang_nocrossref *nocrossref;
87 struct lang_output_section_phdr_list *section_phdr;
88 struct bfd_elf_version_deps *deflist;
89 struct bfd_elf_version_expr *versyms;
90 struct bfd_elf_version_tree *versnode;
93 %type <etree> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val
94 %type <etree> opt_exp_without_type opt_subalign opt_align
95 %type <fill> fill_opt fill_exp
96 %type <name_list> exclude_name_list
97 %type <wildcard_list> section_name_list
98 %type <flag_info_list> sect_flag_list
99 %type <flag_info> sect_flags
100 %type <name> memspec_opt memspec_at_opt paren_script_name casesymlist
101 %type <cname> wildcard_name
102 %type <wildcard> section_name_spec filename_spec wildcard_maybe_exclude
103 %token <bigint> INT
104 %token <name> NAME LNAME
105 %type <integer> length
106 %type <phdr> phdr_qualifiers
107 %type <nocrossref> nocrossref_list
108 %type <section_phdr> phdr_opt
109 %type <integer> opt_nocrossrefs
111 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
112 %right <token> '?' ':'
113 %left <token> OROR
114 %left <token> ANDAND
115 %left <token> '|'
116 %left <token> '^'
117 %left <token> '&'
118 %left <token> EQ NE
119 %left <token> '<' '>' LE GE
120 %left <token> LSHIFT RSHIFT
122 %left <token> '+' '-'
123 %left <token> '*' '/' '%'
125 %right UNARY
126 %token END
127 %left <token> '('
128 %token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
129 %token SECTIONS PHDRS INSERT_K AFTER BEFORE
130 %token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
131 %token SORT_BY_NAME SORT_BY_ALIGNMENT SORT_NONE
132 %token SORT_BY_INIT_PRIORITY
133 %token '{' '}'
134 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
135 %token INHIBIT_COMMON_ALLOCATION FORCE_GROUP_ALLOCATION
136 %token SEGMENT_START
137 %token INCLUDE
138 %token MEMORY
139 %token REGION_ALIAS
140 %token LD_FEATURE
141 %token NOLOAD DSECT COPY INFO OVERLAY
142 %token READONLY
143 %token TYPE
144 %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY
145 %token <integer> NEXT
146 %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K
147 %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS NOCROSSREFS_TO
148 %token ORIGIN FILL
149 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
150 %token ALIGNMOD AT SUBALIGN HIDDEN PROVIDE PROVIDE_HIDDEN AS_NEEDED
151 %type <token> assign_op atype attributes_opt sect_constraint opt_align_with_input
152 %type <name> filename
153 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
154 %token LOG2CEIL FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
155 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
156 %token <name> VERS_TAG VERS_IDENTIFIER
157 %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
158 %token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL INPUT_SECTION_FLAGS ALIGN_WITH_INPUT
159 %token EXCLUDE_FILE
160 %token CONSTANT
161 %type <versyms> vers_defns
162 %type <versnode> vers_tag
163 %type <deflist> verdep
164 %token INPUT_DYNAMIC_LIST
168 file:
169 INPUT_SCRIPT script_file
170 | INPUT_MRI_SCRIPT mri_script_file
171 | INPUT_VERSION_SCRIPT version_script_file
172 | INPUT_DYNAMIC_LIST dynamic_list_file
173 | INPUT_DEFSYM defsym_expr
177 filename: NAME;
180 defsym_expr:
181 { ldlex_expression(); }
182 assignment
183 { ldlex_popstate(); }
186 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
187 mri_script_file:
189 ldlex_mri_script ();
190 PUSH_ERROR (_("MRI style script"));
192 mri_script_lines
194 ldlex_popstate ();
195 mri_draw_tree ();
196 POP_ERROR ();
200 mri_script_lines:
201 mri_script_lines mri_script_command NEWLINE
205 mri_script_command:
206 CHIP exp
207 | CHIP exp ',' exp
208 | NAME {
209 einfo(_("%F%P: unrecognised keyword in MRI style script '%s'\n"),$1);
211 | LIST {
212 config.map_filename = "-";
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 { ldfile_open_command_file ($2); }
254 mri_script_lines END
255 | START NAME
256 { lang_add_entry ($2, false); }
260 ordernamelist:
261 ordernamelist ',' NAME { mri_order($3); }
262 | ordernamelist NAME { mri_order($2); }
266 mri_load_name_list:
267 NAME
268 { mri_load($1); }
269 | mri_load_name_list ',' NAME { mri_load($3); }
272 mri_abs_name_list:
273 NAME
274 { mri_only_load($1); }
275 | mri_abs_name_list ',' NAME
276 { mri_only_load($3); }
279 casesymlist:
280 /* empty */ { $$ = NULL; }
281 | NAME
282 | casesymlist ',' NAME
285 extern_name_list:
286 NAME
287 { ldlang_add_undef ($1, false); }
288 | extern_name_list NAME
289 { ldlang_add_undef ($2, false); }
290 | extern_name_list ',' NAME
291 { ldlang_add_undef ($3, false); }
294 script_file:
295 { ldlex_script (); }
296 ifile_list
297 { ldlex_popstate (); }
300 ifile_list:
301 ifile_list ifile_p1
306 ifile_p1:
307 memory
308 | sections
309 | phdrs
310 | startup
311 | high_level_library
312 | low_level_library
313 | floating_point_support
314 | statement_anywhere
315 | version
316 | ';'
317 | TARGET_K '(' NAME ')'
318 { lang_add_target($3); }
319 | SEARCH_DIR '(' filename ')'
320 { ldfile_add_library_path ($3, false); }
321 | OUTPUT '(' filename ')'
322 { lang_add_output($3, 1); }
323 | OUTPUT_FORMAT '(' NAME ')'
324 { lang_add_output_format ($3, (char *) NULL,
325 (char *) NULL, 1); }
326 | OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')'
327 { lang_add_output_format ($3, $5, $7, 1); }
328 | OUTPUT_ARCH '(' NAME ')'
329 { ldfile_set_output_arch ($3, bfd_arch_unknown); }
330 | FORCE_COMMON_ALLOCATION
331 { command_line.force_common_definition = true ; }
332 | FORCE_GROUP_ALLOCATION
333 { command_line.force_group_allocation = true ; }
334 | INHIBIT_COMMON_ALLOCATION
335 { link_info.inhibit_common_definition = true ; }
336 | INPUT '(' input_list ')'
337 | GROUP
338 { lang_enter_group (); }
339 '(' input_list ')'
340 { lang_leave_group (); }
341 | MAP '(' filename ')'
342 { lang_add_map($3); }
343 | INCLUDE filename
344 { ldfile_open_command_file ($2); }
345 ifile_list END
346 | NOCROSSREFS '(' nocrossref_list ')'
348 lang_add_nocrossref ($3);
350 | NOCROSSREFS_TO '(' nocrossref_list ')'
352 lang_add_nocrossref_to ($3);
354 | EXTERN '(' { ldlex_expression (); } extern_name_list ')'
355 { ldlex_popstate (); }
356 | INSERT_K AFTER NAME
357 { lang_add_insert ($3, 0); }
358 | INSERT_K BEFORE NAME
359 { lang_add_insert ($3, 1); }
360 | REGION_ALIAS '(' NAME ',' NAME ')'
361 { lang_memory_region_alias ($3, $5); }
362 | LD_FEATURE '(' NAME ')'
363 { lang_ld_feature ($3); }
366 input_list:
367 { ldlex_inputlist(); }
368 input_list1
369 { ldlex_popstate(); }
371 input_list1:
372 NAME
373 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
374 (char *)NULL); }
375 | input_list1 ',' NAME
376 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
377 (char *)NULL); }
378 | input_list1 NAME
379 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
380 (char *)NULL); }
381 | LNAME
382 { lang_add_input_file($1,lang_input_file_is_l_enum,
383 (char *)NULL); }
384 | input_list1 ',' LNAME
385 { lang_add_input_file($3,lang_input_file_is_l_enum,
386 (char *)NULL); }
387 | input_list1 LNAME
388 { lang_add_input_file($2,lang_input_file_is_l_enum,
389 (char *)NULL); }
390 | AS_NEEDED '('
391 { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
392 input_flags.add_DT_NEEDED_for_regular = true; }
393 input_list1 ')'
394 { input_flags.add_DT_NEEDED_for_regular = $<integer>3; }
395 | input_list1 ',' AS_NEEDED '('
396 { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
397 input_flags.add_DT_NEEDED_for_regular = true; }
398 input_list1 ')'
399 { input_flags.add_DT_NEEDED_for_regular = $<integer>5; }
400 | input_list1 AS_NEEDED '('
401 { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
402 input_flags.add_DT_NEEDED_for_regular = true; }
403 input_list1 ')'
404 { input_flags.add_DT_NEEDED_for_regular = $<integer>4; }
407 sections:
408 SECTIONS '{' sec_or_group_p1 '}'
411 sec_or_group_p1:
412 sec_or_group_p1 section
413 | sec_or_group_p1 statement_anywhere
417 statement_anywhere:
418 ENTRY '(' NAME ')'
419 { lang_add_entry ($3, false); }
420 | assignment separator
421 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')'
422 { ldlex_popstate ();
423 lang_add_assignment (exp_assert ($4, $6)); }
426 wildcard_name:
427 NAME
429 $$ = $1;
433 wildcard_maybe_exclude:
434 wildcard_name
436 $$.name = $1;
437 $$.sorted = none;
438 $$.exclude_name_list = NULL;
439 $$.section_flag_list = NULL;
441 | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
443 $$.name = $5;
444 $$.sorted = none;
445 $$.exclude_name_list = $3;
446 $$.section_flag_list = NULL;
450 filename_spec:
451 wildcard_maybe_exclude
452 | SORT_BY_NAME '(' wildcard_maybe_exclude ')'
454 $$ = $3;
455 $$.sorted = by_name;
457 | SORT_NONE '(' wildcard_maybe_exclude ')'
459 $$ = $3;
460 $$.sorted = by_none;
464 section_name_spec:
465 wildcard_maybe_exclude
466 | SORT_BY_NAME '(' wildcard_maybe_exclude ')'
468 $$ = $3;
469 $$.sorted = by_name;
471 | SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')'
473 $$ = $3;
474 $$.sorted = by_alignment;
476 | SORT_NONE '(' wildcard_maybe_exclude ')'
478 $$ = $3;
479 $$.sorted = by_none;
481 | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')'
483 $$ = $5;
484 $$.sorted = by_name_alignment;
486 | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')'
488 $$ = $5;
489 $$.sorted = by_name;
491 | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')'
493 $$ = $5;
494 $$.sorted = by_alignment_name;
496 | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')'
498 $$ = $5;
499 $$.sorted = by_alignment;
501 | SORT_BY_INIT_PRIORITY '(' wildcard_maybe_exclude ')'
503 $$ = $3;
504 $$.sorted = by_init_priority;
508 sect_flag_list: NAME
510 struct flag_info_list *n;
511 n = ((struct flag_info_list *) xmalloc (sizeof *n));
512 if ($1[0] == '!')
514 n->with = without_flags;
515 n->name = &$1[1];
517 else
519 n->with = with_flags;
520 n->name = $1;
522 n->valid = false;
523 n->next = NULL;
524 $$ = n;
526 | sect_flag_list '&' NAME
528 struct flag_info_list *n;
529 n = ((struct flag_info_list *) xmalloc (sizeof *n));
530 if ($3[0] == '!')
532 n->with = without_flags;
533 n->name = &$3[1];
535 else
537 n->with = with_flags;
538 n->name = $3;
540 n->valid = false;
541 n->next = $1;
542 $$ = n;
546 sect_flags:
547 INPUT_SECTION_FLAGS '(' sect_flag_list ')'
549 struct flag_info *n;
550 n = ((struct flag_info *) xmalloc (sizeof *n));
551 n->flag_list = $3;
552 n->flags_initialized = false;
553 n->not_with_flags = 0;
554 n->only_with_flags = 0;
555 $$ = n;
559 exclude_name_list:
560 exclude_name_list wildcard_name
562 struct name_list *tmp;
563 tmp = (struct name_list *) xmalloc (sizeof *tmp);
564 tmp->name = $2;
565 tmp->next = $1;
566 $$ = tmp;
569 wildcard_name
571 struct name_list *tmp;
572 tmp = (struct name_list *) xmalloc (sizeof *tmp);
573 tmp->name = $1;
574 tmp->next = NULL;
575 $$ = tmp;
579 section_name_list:
580 section_name_list opt_comma section_name_spec
582 struct wildcard_list *tmp;
583 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
584 tmp->next = $1;
585 tmp->spec = $3;
586 $$ = tmp;
589 section_name_spec
591 struct wildcard_list *tmp;
592 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
593 tmp->next = NULL;
594 tmp->spec = $1;
595 $$ = tmp;
599 input_section_spec_no_keep:
600 NAME
602 struct wildcard_spec tmp;
603 tmp.name = $1;
604 tmp.exclude_name_list = NULL;
605 tmp.sorted = none;
606 tmp.section_flag_list = NULL;
607 lang_add_wild (&tmp, NULL, ldgram_had_keep);
609 | sect_flags NAME
611 struct wildcard_spec tmp;
612 tmp.name = $2;
613 tmp.exclude_name_list = NULL;
614 tmp.sorted = none;
615 tmp.section_flag_list = $1;
616 lang_add_wild (&tmp, NULL, ldgram_had_keep);
618 | '[' section_name_list ']'
620 lang_add_wild (NULL, $2, ldgram_had_keep);
622 | sect_flags '[' section_name_list ']'
624 struct wildcard_spec tmp;
625 tmp.name = NULL;
626 tmp.exclude_name_list = NULL;
627 tmp.sorted = none;
628 tmp.section_flag_list = $1;
629 lang_add_wild (&tmp, $3, ldgram_had_keep);
631 | filename_spec '(' section_name_list ')'
633 lang_add_wild (&$1, $3, ldgram_had_keep);
635 | sect_flags filename_spec '(' section_name_list ')'
637 $2.section_flag_list = $1;
638 lang_add_wild (&$2, $4, ldgram_had_keep);
642 input_section_spec:
643 input_section_spec_no_keep
644 | KEEP '('
645 { ldgram_had_keep = true; }
646 input_section_spec_no_keep ')'
647 { ldgram_had_keep = false; }
650 statement:
652 | assignment separator
653 | CREATE_OBJECT_SYMBOLS
655 lang_add_attribute (lang_object_symbols_statement_enum);
657 | CONSTRUCTORS
659 lang_add_attribute (lang_constructors_statement_enum);
661 | SORT_BY_NAME '(' CONSTRUCTORS ')'
663 constructors_sorted = true;
664 lang_add_attribute (lang_constructors_statement_enum);
666 | input_section_spec
667 | length '(' mustbe_exp ')'
669 lang_add_data ((int) $1, $3);
672 | FILL '(' fill_exp ')'
674 lang_add_fill ($3);
676 | ASSERT_K
677 { ldlex_expression (); }
678 '(' exp ',' NAME ')' separator
680 ldlex_popstate ();
681 lang_add_assignment (exp_assert ($4, $6));
683 | INCLUDE filename
685 ldfile_open_command_file ($2);
687 statement_list_opt END
690 statement_list:
691 statement_list statement
692 | statement
695 statement_list_opt:
696 /* empty */
697 | statement_list
700 length:
701 QUAD
702 { $$ = $1; }
703 | SQUAD
704 { $$ = $1; }
705 | LONG
706 { $$ = $1; }
707 | SHORT
708 { $$ = $1; }
709 | BYTE
710 { $$ = $1; }
713 fill_exp:
714 mustbe_exp
716 $$ = exp_get_fill ($1, 0, "fill value");
720 fill_opt:
721 '=' fill_exp
722 { $$ = $2; }
723 | { $$ = (fill_type *) 0; }
726 assign_op:
727 PLUSEQ
728 { $$ = '+'; }
729 | MINUSEQ
730 { $$ = '-'; }
731 | MULTEQ
732 { $$ = '*'; }
733 | DIVEQ
734 { $$ = '/'; }
735 | LSHIFTEQ
736 { $$ = LSHIFT; }
737 | RSHIFTEQ
738 { $$ = RSHIFT; }
739 | ANDEQ
740 { $$ = '&'; }
741 | OREQ
742 { $$ = '|'; }
746 separator: ';' | ','
750 assignment:
751 NAME '=' mustbe_exp
753 lang_add_assignment (exp_assign ($1, $3, false));
755 | NAME assign_op mustbe_exp
757 lang_add_assignment (exp_assign ($1,
758 exp_binop ($2,
759 exp_nameop (NAME,
760 $1),
761 $3), false));
763 | HIDDEN '(' NAME '=' mustbe_exp ')'
765 lang_add_assignment (exp_assign ($3, $5, true));
767 | PROVIDE '(' NAME '=' mustbe_exp ')'
769 lang_add_assignment (exp_provide ($3, $5, false));
771 | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
773 lang_add_assignment (exp_provide ($3, $5, true));
778 opt_comma:
779 ',' | ;
782 memory:
783 MEMORY '{' memory_spec_list_opt '}'
786 memory_spec_list_opt: memory_spec_list | ;
788 memory_spec_list:
789 memory_spec_list opt_comma memory_spec
790 | memory_spec
794 memory_spec: NAME
795 { region = lang_memory_region_lookup ($1, true); }
796 attributes_opt ':'
797 origin_spec opt_comma length_spec
799 | INCLUDE filename
800 { ldfile_open_command_file ($2); }
801 memory_spec_list_opt END
804 origin_spec:
805 ORIGIN '=' mustbe_exp
807 region->origin_exp = $3;
811 length_spec:
812 LENGTH '=' mustbe_exp
814 if (yychar == NAME)
816 yyclearin;
817 ldlex_backup ();
819 region->length_exp = $3;
823 attributes_opt:
824 /* empty */
825 { /* dummy action to avoid bison 1.25 error message */ }
826 | '(' attributes_list ')'
829 attributes_list:
830 attributes_string
831 | attributes_list attributes_string
834 attributes_string:
835 NAME
836 { lang_set_flags (region, $1, 0); }
837 | '!' NAME
838 { lang_set_flags (region, $2, 1); }
841 startup:
842 STARTUP '(' filename ')'
843 { lang_startup($3); }
846 high_level_library:
847 HLL '(' high_level_library_NAME_list ')'
848 | HLL '(' ')'
849 { ldemul_hll((char *)NULL); }
852 high_level_library_NAME_list:
853 high_level_library_NAME_list opt_comma filename
854 { ldemul_hll($3); }
855 | filename
856 { ldemul_hll($1); }
859 low_level_library:
860 SYSLIB '(' low_level_library_NAME_list ')'
863 low_level_library_NAME_list:
864 low_level_library_NAME_list opt_comma filename
865 { ldemul_syslib($3); }
869 floating_point_support:
870 FLOAT
871 { lang_float(true); }
872 | NOFLOAT
873 { lang_float(false); }
876 nocrossref_list:
877 /* empty */
879 $$ = NULL;
881 | NAME nocrossref_list
883 struct lang_nocrossref *n;
885 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
886 n->name = $1;
887 n->next = $2;
888 $$ = n;
890 | NAME ',' nocrossref_list
892 struct lang_nocrossref *n;
894 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
895 n->name = $1;
896 n->next = $3;
897 $$ = n;
901 paren_script_name: { ldlex_script (); }
902 '(' NAME ')'
903 { ldlex_popstate (); $$ = $3; }
905 mustbe_exp: { ldlex_expression (); }
907 { ldlex_popstate (); $$ = $2; }
910 exp :
911 '-' exp %prec UNARY
912 { $$ = exp_unop ('-', $2); }
913 | '(' exp ')'
914 { $$ = $2; }
915 | NEXT '(' exp ')' %prec UNARY
916 { $$ = exp_unop ((int) $1,$3); }
917 | '!' exp %prec UNARY
918 { $$ = exp_unop ('!', $2); }
919 | '+' exp %prec UNARY
920 { $$ = $2; }
921 | '~' exp %prec UNARY
922 { $$ = exp_unop ('~', $2);}
924 | exp '*' exp
925 { $$ = exp_binop ('*', $1, $3); }
926 | exp '/' exp
927 { $$ = exp_binop ('/', $1, $3); }
928 | exp '%' exp
929 { $$ = exp_binop ('%', $1, $3); }
930 | exp '+' exp
931 { $$ = exp_binop ('+', $1, $3); }
932 | exp '-' exp
933 { $$ = exp_binop ('-' , $1, $3); }
934 | exp LSHIFT exp
935 { $$ = exp_binop (LSHIFT , $1, $3); }
936 | exp RSHIFT exp
937 { $$ = exp_binop (RSHIFT , $1, $3); }
938 | exp EQ exp
939 { $$ = exp_binop (EQ , $1, $3); }
940 | exp NE exp
941 { $$ = exp_binop (NE , $1, $3); }
942 | exp LE exp
943 { $$ = exp_binop (LE , $1, $3); }
944 | exp GE exp
945 { $$ = exp_binop (GE , $1, $3); }
946 | exp '<' exp
947 { $$ = exp_binop ('<' , $1, $3); }
948 | exp '>' exp
949 { $$ = exp_binop ('>' , $1, $3); }
950 | exp '&' exp
951 { $$ = exp_binop ('&' , $1, $3); }
952 | exp '^' exp
953 { $$ = exp_binop ('^' , $1, $3); }
954 | exp '|' exp
955 { $$ = exp_binop ('|' , $1, $3); }
956 | exp '?' exp ':' exp
957 { $$ = exp_trinop ('?' , $1, $3, $5); }
958 | exp ANDAND exp
959 { $$ = exp_binop (ANDAND , $1, $3); }
960 | exp OROR exp
961 { $$ = exp_binop (OROR , $1, $3); }
962 | DEFINED '(' NAME ')'
963 { $$ = exp_nameop (DEFINED, $3); }
964 | INT
965 { $$ = exp_bigintop ($1.integer, $1.str); }
966 | SIZEOF_HEADERS
967 { $$ = exp_nameop (SIZEOF_HEADERS,0); }
969 | ALIGNOF paren_script_name
970 { $$ = exp_nameop (ALIGNOF, $2); }
971 | SIZEOF paren_script_name
972 { $$ = exp_nameop (SIZEOF, $2); }
973 | ADDR paren_script_name
974 { $$ = exp_nameop (ADDR, $2); }
975 | LOADADDR paren_script_name
976 { $$ = exp_nameop (LOADADDR, $2); }
977 | CONSTANT '(' NAME ')'
978 { $$ = exp_nameop (CONSTANT,$3); }
979 | ABSOLUTE '(' exp ')'
980 { $$ = exp_unop (ABSOLUTE, $3); }
981 | ALIGN_K '(' exp ')'
982 { $$ = exp_unop (ALIGN_K,$3); }
983 | ALIGN_K '(' exp ',' exp ')'
984 { $$ = exp_binop (ALIGN_K,$3,$5); }
985 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
986 { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
987 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
988 { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
989 | DATA_SEGMENT_END '(' exp ')'
990 { $$ = exp_unop (DATA_SEGMENT_END, $3); }
991 | SEGMENT_START { ldlex_script (); } '(' NAME
992 { ldlex_popstate (); } ',' exp ')'
993 { /* The operands to the expression node are
994 placed in the opposite order from the way
995 in which they appear in the script as
996 that allows us to reuse more code in
997 fold_binary. */
998 $$ = exp_binop (SEGMENT_START,
1000 exp_nameop (NAME, $4)); }
1001 | BLOCK '(' exp ')'
1002 { $$ = exp_unop (ALIGN_K,$3); }
1003 | NAME
1004 { $$ = exp_nameop (NAME,$1); }
1005 | MAX_K '(' exp ',' exp ')'
1006 { $$ = exp_binop (MAX_K, $3, $5 ); }
1007 | MIN_K '(' exp ',' exp ')'
1008 { $$ = exp_binop (MIN_K, $3, $5 ); }
1009 | ASSERT_K '(' exp ',' NAME ')'
1010 { $$ = exp_assert ($3, $5); }
1011 | ORIGIN paren_script_name
1012 { $$ = exp_nameop (ORIGIN, $2); }
1013 | LENGTH paren_script_name
1014 { $$ = exp_nameop (LENGTH, $2); }
1015 | LOG2CEIL '(' exp ')'
1016 { $$ = exp_unop (LOG2CEIL, $3); }
1020 memspec_at_opt:
1021 AT '>' NAME { $$ = $3; }
1022 | { $$ = 0; }
1025 opt_at:
1026 AT '(' exp ')' { $$ = $3; }
1027 | { $$ = 0; }
1030 opt_align:
1031 ALIGN_K '(' exp ')' { $$ = $3; }
1032 | { $$ = 0; }
1035 opt_align_with_input:
1036 ALIGN_WITH_INPUT { $$ = ALIGN_WITH_INPUT; }
1037 | { $$ = 0; }
1040 opt_subalign:
1041 SUBALIGN '(' exp ')' { $$ = $3; }
1042 | { $$ = 0; }
1045 sect_constraint:
1046 ONLY_IF_RO { $$ = ONLY_IF_RO; }
1047 | ONLY_IF_RW { $$ = ONLY_IF_RW; }
1048 | SPECIAL { $$ = SPECIAL; }
1049 | { $$ = 0; }
1052 section: NAME
1053 { ldlex_expression(); }
1054 opt_exp_with_type
1055 opt_at
1056 opt_align
1057 opt_align_with_input
1058 opt_subalign
1059 sect_constraint
1061 ldlex_popstate ();
1062 ldlex_wild ();
1063 lang_enter_output_section_statement ($1, $3, sectype,
1064 sectype_value, $5, $7, $4, $8, $6);
1067 statement_list_opt
1069 { ldlex_popstate (); }
1070 memspec_opt memspec_at_opt phdr_opt fill_opt
1072 /* fill_opt may have switched the lexer into
1073 expression state, and back again, but in
1074 order to find the end of the fill
1075 expression the parser must look ahead one
1076 token. If it is a NAME, throw it away as
1077 it will have been lexed in the wrong
1078 state. */
1079 if (yychar == NAME)
1081 yyclearin;
1082 ldlex_backup ();
1084 lang_leave_output_section_statement ($17, $14,
1085 $16, $15);
1087 opt_comma
1088 | OVERLAY
1089 { ldlex_expression (); }
1090 opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
1091 { ldlex_popstate (); }
1094 lang_enter_overlay ($3, $6);
1096 overlay_section
1098 memspec_opt memspec_at_opt phdr_opt fill_opt
1100 if (yychar == NAME)
1102 yyclearin;
1103 ldlex_backup ();
1105 lang_leave_overlay ($5, (int) $4,
1106 $15, $12, $14, $13);
1108 opt_comma
1109 | /* The GROUP case is just enough to support the gcc
1110 svr3.ifile script. It is not intended to be full
1111 support. I'm not even sure what GROUP is supposed
1112 to mean. */
1113 GROUP
1114 { ldlex_expression (); }
1115 opt_exp_with_type
1117 ldlex_popstate ();
1118 lang_add_assignment (exp_assign (".", $3, false));
1120 '{' sec_or_group_p1 '}'
1121 | INCLUDE filename
1123 ldfile_open_command_file ($2);
1125 sec_or_group_p1 END
1128 type:
1129 NOLOAD { sectype = noload_section; }
1130 | DSECT { sectype = noalloc_section; }
1131 | COPY { sectype = noalloc_section; }
1132 | INFO { sectype = noalloc_section; }
1133 | OVERLAY { sectype = noalloc_section; }
1134 | READONLY '(' TYPE '=' exp ')' { sectype = typed_readonly_section; sectype_value = $5; }
1135 | READONLY { sectype = readonly_section; }
1136 | TYPE '=' exp { sectype = type_section; sectype_value = $3; }
1139 atype:
1140 '(' type ')'
1141 | /* EMPTY */ { sectype = normal_section; }
1142 | '(' ')' { sectype = normal_section; }
1145 opt_exp_with_type:
1146 exp atype ':' { $$ = $1; }
1147 | atype ':' { $$ = (etree_type *)NULL; }
1148 | /* The BIND cases are to support the gcc svr3.ifile
1149 script. They aren't intended to implement full
1150 support for the BIND keyword. I'm not even sure
1151 what BIND is supposed to mean. */
1152 BIND '(' exp ')' atype ':' { $$ = $3; }
1153 | BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
1154 { $$ = $3; }
1157 opt_exp_without_type:
1158 exp ':' { $$ = $1; }
1159 | ':' { $$ = (etree_type *) NULL; }
1162 opt_nocrossrefs:
1163 /* empty */
1164 { $$ = 0; }
1165 | NOCROSSREFS
1166 { $$ = 1; }
1169 memspec_opt:
1170 '>' NAME
1171 { $$ = $2; }
1172 | { $$ = DEFAULT_MEMORY_REGION; }
1175 phdr_opt:
1176 /* empty */
1178 $$ = NULL;
1180 | phdr_opt ':' NAME
1182 struct lang_output_section_phdr_list *n;
1184 n = ((struct lang_output_section_phdr_list *)
1185 xmalloc (sizeof *n));
1186 n->name = $3;
1187 n->used = false;
1188 n->next = $1;
1189 $$ = n;
1193 overlay_section:
1194 /* empty */
1195 | overlay_section
1196 NAME
1198 ldlex_wild ();
1199 lang_enter_overlay_section ($2);
1202 statement_list_opt
1204 { ldlex_popstate (); }
1205 phdr_opt fill_opt
1207 if (yychar == NAME)
1209 yyclearin;
1210 ldlex_backup ();
1212 lang_leave_overlay_section ($9, $8);
1214 opt_comma
1217 phdrs:
1218 PHDRS '{' phdr_list '}'
1221 phdr_list:
1222 /* empty */
1223 | phdr_list phdr
1226 phdr:
1227 NAME { ldlex_expression (); }
1228 phdr_type phdr_qualifiers { ldlex_popstate (); }
1231 lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1232 $4.flags);
1236 phdr_type:
1239 $$ = $1;
1241 if ($1->type.node_class == etree_name
1242 && $1->type.node_code == NAME)
1244 const char *s;
1245 unsigned int i;
1246 static const char * const phdr_types[] =
1248 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1249 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
1250 "PT_PHDR", "PT_TLS"
1253 s = $1->name.name;
1254 for (i = 0;
1255 i < sizeof phdr_types / sizeof phdr_types[0];
1256 i++)
1257 if (strcmp (s, phdr_types[i]) == 0)
1259 $$ = exp_intop (i);
1260 break;
1262 if (i == sizeof phdr_types / sizeof phdr_types[0])
1264 if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1265 $$ = exp_intop (0x6474e550);
1266 else if (strcmp (s, "PT_GNU_STACK") == 0)
1267 $$ = exp_intop (0x6474e551);
1268 else if (strcmp (s, "PT_GNU_RELRO") == 0)
1269 $$ = exp_intop (0x6474e552);
1270 else if (strcmp (s, "PT_GNU_PROPERTY") == 0)
1271 $$ = exp_intop (0x6474e553);
1272 else
1274 einfo (_("\
1275 %X%P:%pS: unknown phdr type `%s' (try integer literal)\n"),
1276 NULL, s);
1277 $$ = exp_intop (0);
1284 phdr_qualifiers:
1285 /* empty */
1287 memset (&$$, 0, sizeof (struct phdr_info));
1289 | NAME phdr_val phdr_qualifiers
1291 $$ = $3;
1292 if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
1293 $$.filehdr = true;
1294 else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
1295 $$.phdrs = true;
1296 else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1297 $$.flags = $2;
1298 else
1299 einfo (_("%X%P:%pS: PHDRS syntax error at `%s'\n"),
1300 NULL, $1);
1302 | AT '(' exp ')' phdr_qualifiers
1304 $$ = $5;
1305 $$.at = $3;
1309 phdr_val:
1310 /* empty */
1312 $$ = NULL;
1314 | '(' exp ')'
1316 $$ = $2;
1320 dynamic_list_file:
1322 ldlex_version_file ();
1323 PUSH_ERROR (_("dynamic list"));
1325 dynamic_list_nodes
1327 ldlex_popstate ();
1328 POP_ERROR ();
1332 dynamic_list_nodes:
1333 dynamic_list_node
1334 | dynamic_list_nodes dynamic_list_node
1337 dynamic_list_node:
1338 '{' dynamic_list_tag '}' ';'
1341 dynamic_list_tag:
1342 vers_defns ';'
1344 lang_append_dynamic_list (current_dynamic_list_p, $1);
1348 /* This syntax is used within an external version script file. */
1350 version_script_file:
1352 ldlex_version_file ();
1353 PUSH_ERROR (_("VERSION script"));
1355 vers_nodes
1357 ldlex_popstate ();
1358 POP_ERROR ();
1362 /* This is used within a normal linker script file. */
1364 version:
1366 ldlex_version_script ();
1368 VERSIONK '{' vers_nodes '}'
1370 ldlex_popstate ();
1374 vers_nodes:
1375 vers_node
1376 | vers_nodes vers_node
1379 vers_node:
1380 '{' vers_tag '}' ';'
1382 lang_register_vers_node (NULL, $2, NULL);
1384 | VERS_TAG '{' vers_tag '}' ';'
1386 lang_register_vers_node ($1, $3, NULL);
1388 | VERS_TAG '{' vers_tag '}' verdep ';'
1390 lang_register_vers_node ($1, $3, $5);
1394 verdep:
1395 VERS_TAG
1397 $$ = lang_add_vers_depend (NULL, $1);
1399 | verdep VERS_TAG
1401 $$ = lang_add_vers_depend ($1, $2);
1405 vers_tag:
1406 /* empty */
1408 $$ = lang_new_vers_node (NULL, NULL);
1410 | vers_defns ';'
1412 $$ = lang_new_vers_node ($1, NULL);
1414 | GLOBAL ':' vers_defns ';'
1416 $$ = lang_new_vers_node ($3, NULL);
1418 | LOCAL ':' vers_defns ';'
1420 $$ = lang_new_vers_node (NULL, $3);
1422 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1424 $$ = lang_new_vers_node ($3, $7);
1428 vers_defns:
1429 VERS_IDENTIFIER
1431 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, false);
1433 | NAME
1435 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, true);
1437 | vers_defns ';' VERS_IDENTIFIER
1439 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, false);
1441 | vers_defns ';' NAME
1443 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, true);
1445 | vers_defns ';' EXTERN NAME '{'
1447 $<name>$ = ldgram_vers_current_lang;
1448 ldgram_vers_current_lang = $4;
1450 vers_defns opt_semicolon '}'
1452 struct bfd_elf_version_expr *pat;
1453 for (pat = $7; pat->next != NULL; pat = pat->next);
1454 pat->next = $1;
1455 $$ = $7;
1456 ldgram_vers_current_lang = $<name>6;
1458 | EXTERN NAME '{'
1460 $<name>$ = ldgram_vers_current_lang;
1461 ldgram_vers_current_lang = $2;
1463 vers_defns opt_semicolon '}'
1465 $$ = $5;
1466 ldgram_vers_current_lang = $<name>4;
1468 | GLOBAL
1470 $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, false);
1472 | vers_defns ';' GLOBAL
1474 $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, false);
1476 | LOCAL
1478 $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, false);
1480 | vers_defns ';' LOCAL
1482 $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, false);
1484 | EXTERN
1486 $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, false);
1488 | vers_defns ';' EXTERN
1490 $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, false);
1494 opt_semicolon:
1495 /* empty */
1496 | ';'
1500 void
1501 yyerror(arg)
1502 const char *arg;
1504 if (ldfile_assumed_script)
1505 einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
1506 ldlex_filename ());
1507 if (error_index > 0 && error_index < ERROR_NAME_MAX)
1508 einfo ("%F%P:%pS: %s in %s\n", NULL, arg, error_names[error_index - 1]);
1509 else
1510 einfo ("%F%P:%pS: %s\n", NULL, arg);