[gdb/tui] Replace macro HELP_ATTRIBUTE_MODE with std::string
[binutils-gdb.git] / ld / ldgram.y
blob081176ba0f133658e4dec7c9e7b6a76bba0e90b3
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).
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 ASCIZ
129 %token SECTIONS PHDRS INSERT_K AFTER BEFORE LINKER_VERSION
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);
671 | ASCIZ NAME
673 lang_add_string ($2);
675 | FILL '(' fill_exp ')'
677 lang_add_fill ($3);
679 | LINKER_VERSION
681 lang_add_version_string ();
683 | ASSERT_K
684 { ldlex_expression (); }
685 '(' exp ',' NAME ')' separator
687 ldlex_popstate ();
688 lang_add_assignment (exp_assert ($4, $6));
690 | INCLUDE filename
692 ldfile_open_command_file ($2);
694 statement_list_opt END
697 statement_list:
698 statement_list statement
699 | statement
702 statement_list_opt:
703 /* empty */
704 | statement_list
707 length:
708 QUAD
709 { $$ = $1; }
710 | SQUAD
711 { $$ = $1; }
712 | LONG
713 { $$ = $1; }
714 | SHORT
715 { $$ = $1; }
716 | BYTE
717 { $$ = $1; }
720 fill_exp:
721 mustbe_exp
723 $$ = exp_get_fill ($1, 0, _("fill value"));
727 fill_opt:
728 '=' fill_exp
729 { $$ = $2; }
730 | { $$ = (fill_type *) 0; }
733 assign_op:
734 PLUSEQ
735 { $$ = '+'; }
736 | MINUSEQ
737 { $$ = '-'; }
738 | MULTEQ
739 { $$ = '*'; }
740 | DIVEQ
741 { $$ = '/'; }
742 | LSHIFTEQ
743 { $$ = LSHIFT; }
744 | RSHIFTEQ
745 { $$ = RSHIFT; }
746 | ANDEQ
747 { $$ = '&'; }
748 | OREQ
749 { $$ = '|'; }
753 separator: ';' | ','
757 assignment:
758 NAME '=' mustbe_exp
760 lang_add_assignment (exp_assign ($1, $3, false));
762 | NAME assign_op mustbe_exp
764 lang_add_assignment (exp_assign ($1,
765 exp_binop ($2,
766 exp_nameop (NAME,
767 $1),
768 $3), false));
770 | HIDDEN '(' NAME '=' mustbe_exp ')'
772 lang_add_assignment (exp_assign ($3, $5, true));
774 | PROVIDE '(' NAME '=' mustbe_exp ')'
776 lang_add_assignment (exp_provide ($3, $5, false));
778 | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
780 lang_add_assignment (exp_provide ($3, $5, true));
785 opt_comma:
786 ',' | ;
789 memory:
790 MEMORY '{' memory_spec_list_opt '}'
793 memory_spec_list_opt: memory_spec_list | ;
795 memory_spec_list:
796 memory_spec_list opt_comma memory_spec
797 | memory_spec
801 memory_spec: NAME
802 { region = lang_memory_region_lookup ($1, true); }
803 attributes_opt ':'
804 origin_spec opt_comma length_spec
806 | INCLUDE filename
807 { ldfile_open_command_file ($2); }
808 memory_spec_list_opt END
811 origin_spec:
812 ORIGIN '=' mustbe_exp
814 region->origin_exp = $3;
818 length_spec:
819 LENGTH '=' mustbe_exp
821 if (yychar == NAME)
823 yyclearin;
824 ldlex_backup ();
826 region->length_exp = $3;
830 attributes_opt:
831 /* empty */
832 { /* dummy action to avoid bison 1.25 error message */ }
833 | '(' attributes_list ')'
836 attributes_list:
837 attributes_string
838 | attributes_list attributes_string
841 attributes_string:
842 NAME
843 { lang_set_flags (region, $1, 0); }
844 | '!' NAME
845 { lang_set_flags (region, $2, 1); }
848 startup:
849 STARTUP '(' filename ')'
850 { lang_startup($3); }
853 high_level_library:
854 HLL '(' high_level_library_NAME_list ')'
855 | HLL '(' ')'
856 { ldemul_hll((char *)NULL); }
859 high_level_library_NAME_list:
860 high_level_library_NAME_list opt_comma filename
861 { ldemul_hll($3); }
862 | filename
863 { ldemul_hll($1); }
866 low_level_library:
867 SYSLIB '(' low_level_library_NAME_list ')'
870 low_level_library_NAME_list:
871 low_level_library_NAME_list opt_comma filename
872 { ldemul_syslib($3); }
876 floating_point_support:
877 FLOAT
878 { lang_float(true); }
879 | NOFLOAT
880 { lang_float(false); }
883 nocrossref_list:
884 /* empty */
886 $$ = NULL;
888 | NAME nocrossref_list
890 struct lang_nocrossref *n;
892 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
893 n->name = $1;
894 n->next = $2;
895 $$ = n;
897 | NAME ',' nocrossref_list
899 struct lang_nocrossref *n;
901 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
902 n->name = $1;
903 n->next = $3;
904 $$ = n;
908 paren_script_name: { ldlex_script (); }
909 '(' NAME ')'
910 { ldlex_popstate (); $$ = $3; }
912 mustbe_exp: { ldlex_expression (); }
914 { ldlex_popstate (); $$ = $2; }
917 exp :
918 '-' exp %prec UNARY
919 { $$ = exp_unop ('-', $2); }
920 | '(' exp ')'
921 { $$ = $2; }
922 | NEXT '(' exp ')' %prec UNARY
923 { $$ = exp_unop ((int) $1,$3); }
924 | '!' exp %prec UNARY
925 { $$ = exp_unop ('!', $2); }
926 | '+' exp %prec UNARY
927 { $$ = $2; }
928 | '~' exp %prec UNARY
929 { $$ = exp_unop ('~', $2);}
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 '-' exp
940 { $$ = exp_binop ('-' , $1, $3); }
941 | exp LSHIFT exp
942 { $$ = exp_binop (LSHIFT , $1, $3); }
943 | exp RSHIFT exp
944 { $$ = exp_binop (RSHIFT , $1, $3); }
945 | exp EQ exp
946 { $$ = exp_binop (EQ , $1, $3); }
947 | exp NE exp
948 { $$ = exp_binop (NE , $1, $3); }
949 | exp LE exp
950 { $$ = exp_binop (LE , $1, $3); }
951 | exp GE exp
952 { $$ = exp_binop (GE , $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
962 { $$ = exp_binop ('|' , $1, $3); }
963 | exp '?' exp ':' exp
964 { $$ = exp_trinop ('?' , $1, $3, $5); }
965 | exp ANDAND exp
966 { $$ = exp_binop (ANDAND , $1, $3); }
967 | exp OROR exp
968 { $$ = exp_binop (OROR , $1, $3); }
969 | DEFINED '(' NAME ')'
970 { $$ = exp_nameop (DEFINED, $3); }
971 | INT
972 { $$ = exp_bigintop ($1.integer, $1.str); }
973 | SIZEOF_HEADERS
974 { $$ = exp_nameop (SIZEOF_HEADERS,0); }
976 | ALIGNOF paren_script_name
977 { $$ = exp_nameop (ALIGNOF, $2); }
978 | SIZEOF paren_script_name
979 { $$ = exp_nameop (SIZEOF, $2); }
980 | ADDR paren_script_name
981 { $$ = exp_nameop (ADDR, $2); }
982 | LOADADDR paren_script_name
983 { $$ = exp_nameop (LOADADDR, $2); }
984 | CONSTANT '(' NAME ')'
985 { $$ = exp_nameop (CONSTANT,$3); }
986 | ABSOLUTE '(' exp ')'
987 { $$ = exp_unop (ABSOLUTE, $3); }
988 | ALIGN_K '(' exp ')'
989 { $$ = exp_unop (ALIGN_K,$3); }
990 | ALIGN_K '(' exp ',' exp ')'
991 { $$ = exp_binop (ALIGN_K,$3,$5); }
992 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
993 { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
994 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
995 { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
996 | DATA_SEGMENT_END '(' exp ')'
997 { $$ = exp_unop (DATA_SEGMENT_END, $3); }
998 | SEGMENT_START { ldlex_script (); } '(' NAME
999 { ldlex_popstate (); } ',' exp ')'
1000 { /* The operands to the expression node are
1001 placed in the opposite order from the way
1002 in which they appear in the script as
1003 that allows us to reuse more code in
1004 fold_binary. */
1005 $$ = exp_binop (SEGMENT_START,
1007 exp_nameop (NAME, $4)); }
1008 | BLOCK '(' exp ')'
1009 { $$ = exp_unop (ALIGN_K,$3); }
1010 | NAME
1011 { $$ = exp_nameop (NAME,$1); }
1012 | MAX_K '(' exp ',' exp ')'
1013 { $$ = exp_binop (MAX_K, $3, $5 ); }
1014 | MIN_K '(' exp ',' exp ')'
1015 { $$ = exp_binop (MIN_K, $3, $5 ); }
1016 | ASSERT_K '(' exp ',' NAME ')'
1017 { $$ = exp_assert ($3, $5); }
1018 | ORIGIN paren_script_name
1019 { $$ = exp_nameop (ORIGIN, $2); }
1020 | LENGTH paren_script_name
1021 { $$ = exp_nameop (LENGTH, $2); }
1022 | LOG2CEIL '(' exp ')'
1023 { $$ = exp_unop (LOG2CEIL, $3); }
1027 memspec_at_opt:
1028 AT '>' NAME { $$ = $3; }
1029 | { $$ = 0; }
1032 opt_at:
1033 AT '(' exp ')' { $$ = $3; }
1034 | { $$ = 0; }
1037 opt_align:
1038 ALIGN_K '(' exp ')' { $$ = $3; }
1039 | { $$ = 0; }
1042 opt_align_with_input:
1043 ALIGN_WITH_INPUT { $$ = ALIGN_WITH_INPUT; }
1044 | { $$ = 0; }
1047 opt_subalign:
1048 SUBALIGN '(' exp ')' { $$ = $3; }
1049 | { $$ = 0; }
1052 sect_constraint:
1053 ONLY_IF_RO { $$ = ONLY_IF_RO; }
1054 | ONLY_IF_RW { $$ = ONLY_IF_RW; }
1055 | SPECIAL { $$ = SPECIAL; }
1056 | { $$ = 0; }
1059 section: NAME
1060 { ldlex_expression(); }
1061 opt_exp_with_type
1062 opt_at
1063 opt_align
1064 opt_align_with_input
1065 opt_subalign
1066 sect_constraint
1068 ldlex_popstate ();
1069 ldlex_wild ();
1070 lang_enter_output_section_statement ($1, $3, sectype,
1071 sectype_value, $5, $7, $4, $8, $6);
1074 statement_list_opt
1076 { ldlex_popstate (); }
1077 memspec_opt memspec_at_opt phdr_opt fill_opt
1079 /* fill_opt may have switched the lexer into
1080 expression state, and back again, but in
1081 order to find the end of the fill
1082 expression the parser must look ahead one
1083 token. If it is a NAME, throw it away as
1084 it will have been lexed in the wrong
1085 state. */
1086 if (yychar == NAME)
1088 yyclearin;
1089 ldlex_backup ();
1091 lang_leave_output_section_statement ($17, $14,
1092 $16, $15);
1094 opt_comma
1095 | OVERLAY
1096 { ldlex_expression (); }
1097 opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
1098 { ldlex_popstate (); }
1101 lang_enter_overlay ($3, $6);
1103 overlay_section
1105 memspec_opt memspec_at_opt phdr_opt fill_opt
1107 if (yychar == NAME)
1109 yyclearin;
1110 ldlex_backup ();
1112 lang_leave_overlay ($5, (int) $4,
1113 $15, $12, $14, $13);
1115 opt_comma
1116 | /* The GROUP case is just enough to support the gcc
1117 svr3.ifile script. It is not intended to be full
1118 support. I'm not even sure what GROUP is supposed
1119 to mean. */
1120 GROUP
1121 { ldlex_expression (); }
1122 opt_exp_with_type
1124 ldlex_popstate ();
1125 lang_add_assignment (exp_assign (".", $3, false));
1127 '{' sec_or_group_p1 '}'
1128 | INCLUDE filename
1130 ldfile_open_command_file ($2);
1132 sec_or_group_p1 END
1135 type:
1136 NOLOAD { sectype = noload_section; }
1137 | DSECT { sectype = noalloc_section; }
1138 | COPY { sectype = noalloc_section; }
1139 | INFO { sectype = noalloc_section; }
1140 | OVERLAY { sectype = noalloc_section; }
1141 | READONLY '(' TYPE '=' exp ')' { sectype = typed_readonly_section; sectype_value = $5; }
1142 | READONLY { sectype = readonly_section; }
1143 | TYPE '=' exp { sectype = type_section; sectype_value = $3; }
1146 atype:
1147 '(' type ')'
1148 | /* EMPTY */ { sectype = normal_section; }
1149 | '(' ')' { sectype = normal_section; }
1152 opt_exp_with_type:
1153 exp atype ':' { $$ = $1; }
1154 | atype ':' { $$ = (etree_type *)NULL; }
1155 | /* The BIND cases are to support the gcc svr3.ifile
1156 script. They aren't intended to implement full
1157 support for the BIND keyword. I'm not even sure
1158 what BIND is supposed to mean. */
1159 BIND '(' exp ')' atype ':' { $$ = $3; }
1160 | BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
1161 { $$ = $3; }
1164 opt_exp_without_type:
1165 exp ':' { $$ = $1; }
1166 | ':' { $$ = (etree_type *) NULL; }
1169 opt_nocrossrefs:
1170 /* empty */
1171 { $$ = 0; }
1172 | NOCROSSREFS
1173 { $$ = 1; }
1176 memspec_opt:
1177 '>' NAME
1178 { $$ = $2; }
1179 | { $$ = DEFAULT_MEMORY_REGION; }
1182 phdr_opt:
1183 /* empty */
1185 $$ = NULL;
1187 | phdr_opt ':' NAME
1189 struct lang_output_section_phdr_list *n;
1191 n = ((struct lang_output_section_phdr_list *)
1192 xmalloc (sizeof *n));
1193 n->name = $3;
1194 n->used = false;
1195 n->next = $1;
1196 $$ = n;
1200 overlay_section:
1201 /* empty */
1202 | overlay_section
1203 NAME
1205 ldlex_wild ();
1206 lang_enter_overlay_section ($2);
1209 statement_list_opt
1211 { ldlex_popstate (); }
1212 phdr_opt fill_opt
1214 if (yychar == NAME)
1216 yyclearin;
1217 ldlex_backup ();
1219 lang_leave_overlay_section ($9, $8);
1221 opt_comma
1224 phdrs:
1225 PHDRS '{' phdr_list '}'
1228 phdr_list:
1229 /* empty */
1230 | phdr_list phdr
1233 phdr:
1234 NAME { ldlex_expression (); }
1235 phdr_type phdr_qualifiers { ldlex_popstate (); }
1238 lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1239 $4.flags);
1243 phdr_type:
1246 $$ = $1;
1248 if ($1->type.node_class == etree_name
1249 && $1->type.node_code == NAME)
1251 const char *s;
1252 unsigned int i;
1253 static const char * const phdr_types[] =
1255 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1256 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
1257 "PT_PHDR", "PT_TLS"
1260 s = $1->name.name;
1261 for (i = 0;
1262 i < sizeof phdr_types / sizeof phdr_types[0];
1263 i++)
1264 if (strcmp (s, phdr_types[i]) == 0)
1266 $$ = exp_intop (i);
1267 break;
1269 if (i == sizeof phdr_types / sizeof phdr_types[0])
1271 if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1272 $$ = exp_intop (0x6474e550);
1273 else if (strcmp (s, "PT_GNU_STACK") == 0)
1274 $$ = exp_intop (0x6474e551);
1275 else if (strcmp (s, "PT_GNU_RELRO") == 0)
1276 $$ = exp_intop (0x6474e552);
1277 else if (strcmp (s, "PT_GNU_PROPERTY") == 0)
1278 $$ = exp_intop (0x6474e553);
1279 else
1281 einfo (_("\
1282 %X%P:%pS: unknown phdr type `%s' (try integer literal)\n"),
1283 NULL, s);
1284 $$ = exp_intop (0);
1291 phdr_qualifiers:
1292 /* empty */
1294 memset (&$$, 0, sizeof (struct phdr_info));
1296 | NAME phdr_val phdr_qualifiers
1298 $$ = $3;
1299 if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
1300 $$.filehdr = true;
1301 else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
1302 $$.phdrs = true;
1303 else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1304 $$.flags = $2;
1305 else
1306 einfo (_("%X%P:%pS: PHDRS syntax error at `%s'\n"),
1307 NULL, $1);
1309 | AT '(' exp ')' phdr_qualifiers
1311 $$ = $5;
1312 $$.at = $3;
1316 phdr_val:
1317 /* empty */
1319 $$ = NULL;
1321 | '(' exp ')'
1323 $$ = $2;
1327 dynamic_list_file:
1329 ldlex_version_file ();
1330 PUSH_ERROR (_("dynamic list"));
1332 dynamic_list_nodes
1334 ldlex_popstate ();
1335 POP_ERROR ();
1339 dynamic_list_nodes:
1340 dynamic_list_node
1341 | dynamic_list_nodes dynamic_list_node
1344 dynamic_list_node:
1345 '{' dynamic_list_tag '}' ';'
1348 dynamic_list_tag:
1349 vers_defns ';'
1351 lang_append_dynamic_list (current_dynamic_list_p, $1);
1355 /* This syntax is used within an external version script file. */
1357 version_script_file:
1359 ldlex_version_file ();
1360 PUSH_ERROR (_("VERSION script"));
1362 vers_nodes
1364 ldlex_popstate ();
1365 POP_ERROR ();
1369 /* This is used within a normal linker script file. */
1371 version:
1373 ldlex_version_script ();
1375 VERSIONK '{' vers_nodes '}'
1377 ldlex_popstate ();
1381 vers_nodes:
1382 vers_node
1383 | vers_nodes vers_node
1386 vers_node:
1387 '{' vers_tag '}' ';'
1389 lang_register_vers_node (NULL, $2, NULL);
1391 | VERS_TAG '{' vers_tag '}' ';'
1393 lang_register_vers_node ($1, $3, NULL);
1395 | VERS_TAG '{' vers_tag '}' verdep ';'
1397 lang_register_vers_node ($1, $3, $5);
1401 verdep:
1402 VERS_TAG
1404 $$ = lang_add_vers_depend (NULL, $1);
1406 | verdep VERS_TAG
1408 $$ = lang_add_vers_depend ($1, $2);
1412 vers_tag:
1413 /* empty */
1415 $$ = lang_new_vers_node (NULL, NULL);
1417 | vers_defns ';'
1419 $$ = lang_new_vers_node ($1, NULL);
1421 | GLOBAL ':' vers_defns ';'
1423 $$ = lang_new_vers_node ($3, NULL);
1425 | LOCAL ':' vers_defns ';'
1427 $$ = lang_new_vers_node (NULL, $3);
1429 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1431 $$ = lang_new_vers_node ($3, $7);
1435 vers_defns:
1436 VERS_IDENTIFIER
1438 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, false);
1440 | NAME
1442 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, true);
1444 | vers_defns ';' VERS_IDENTIFIER
1446 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, false);
1448 | vers_defns ';' NAME
1450 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, true);
1452 | vers_defns ';' EXTERN NAME '{'
1454 $<name>$ = ldgram_vers_current_lang;
1455 ldgram_vers_current_lang = $4;
1457 vers_defns opt_semicolon '}'
1459 struct bfd_elf_version_expr *pat;
1460 for (pat = $7; pat->next != NULL; pat = pat->next);
1461 pat->next = $1;
1462 $$ = $7;
1463 ldgram_vers_current_lang = $<name>6;
1465 | EXTERN NAME '{'
1467 $<name>$ = ldgram_vers_current_lang;
1468 ldgram_vers_current_lang = $2;
1470 vers_defns opt_semicolon '}'
1472 $$ = $5;
1473 ldgram_vers_current_lang = $<name>4;
1475 | GLOBAL
1477 $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, false);
1479 | vers_defns ';' GLOBAL
1481 $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, false);
1483 | LOCAL
1485 $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, false);
1487 | vers_defns ';' LOCAL
1489 $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, false);
1491 | EXTERN
1493 $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, false);
1495 | vers_defns ';' EXTERN
1497 $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, false);
1501 opt_semicolon:
1502 /* empty */
1503 | ';'
1507 void
1508 yyerror(arg)
1509 const char *arg;
1511 if (ldfile_assumed_script)
1512 einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
1513 ldlex_filename ());
1514 if (error_index > 0 && error_index < ERROR_NAME_MAX)
1515 einfo (_("%F%P:%pS: %s in %s\n"), NULL, arg, error_names[error_index - 1]);
1516 else
1517 einfo ("%F%P:%pS: %s\n", NULL, arg);