Improve readelf's display of RELR relocs.
[binutils-gdb.git] / ld / ldgram.y
blob0d531fddfa1c3a9ee15b4806729406e8fbf6968f
1 /* A YACC grammar to parse a superset of the AT&T linker scripting language.
2 Copyright (C) 1991-2024 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 "libiberty.h"
31 #include "bfd.h"
32 #include "bfdlink.h"
33 #include "ctf-api.h"
34 #include "ld.h"
35 #include "ldexp.h"
36 #include "ldver.h"
37 #include "ldlang.h"
38 #include "ldfile.h"
39 #include "ldemul.h"
40 #include "ldmisc.h"
41 #include "ldmain.h"
42 #include "mri.h"
43 #include "ldctor.h"
44 #include "ldlex.h"
46 #ifndef YYDEBUG
47 #define YYDEBUG 1
48 #endif
50 static enum section_type sectype;
51 static etree_type *sectype_value;
52 static lang_memory_region_type *region;
54 static bool ldgram_had_keep = false;
55 static char *ldgram_vers_current_lang = NULL;
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--;
63 static void yyerror (const char *);
65 %union {
66 bfd_vma integer;
67 struct big_int
69 bfd_vma integer;
70 char *str;
71 } bigint;
72 fill_type *fill;
73 char *name;
74 const char *cname;
75 struct wildcard_spec wildcard;
76 struct wildcard_list *wildcard_list;
77 struct name_list *name_list;
78 struct flag_info_list *flag_info_list;
79 struct flag_info *flag_info;
80 int token;
81 union etree_union *etree;
82 struct phdr_info
84 bool filehdr;
85 bool phdrs;
86 union etree_union *at;
87 union etree_union *flags;
88 } phdr;
89 struct lang_nocrossref *nocrossref;
90 struct lang_output_section_phdr_list *section_phdr;
91 struct bfd_elf_version_deps *deflist;
92 struct bfd_elf_version_expr *versyms;
93 struct bfd_elf_version_tree *versnode;
96 %type <etree> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val
97 %type <etree> opt_exp_without_type opt_subalign opt_align
98 %type <fill> fill_opt fill_exp
99 %type <name_list> exclude_name_list
100 %type <wildcard_list> section_name_list
101 %type <flag_info_list> sect_flag_list
102 %type <flag_info> sect_flags
103 %type <name> memspec_opt memspec_at_opt paren_script_name casesymlist
104 %type <cname> wildcard_name
105 %type <wildcard> section_name_spec filename_spec wildcard_maybe_exclude wildcard_maybe_reverse
106 %token <bigint> INT
107 %token <name> NAME LNAME
108 %type <integer> length
109 %type <phdr> phdr_qualifiers
110 %type <nocrossref> nocrossref_list
111 %type <section_phdr> phdr_opt
112 %type <integer> opt_nocrossrefs
114 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ XOREQ
115 %right <token> '?' ':'
116 %left <token> OROR
117 %left <token> ANDAND
118 %left <token> '|'
119 %left <token> '^'
120 %left <token> '&'
121 %left <token> EQ NE
122 %left <token> '<' '>' LE GE
123 %left <token> LSHIFT RSHIFT
125 %left <token> '+' '-'
126 %left <token> '*' '/' '%'
128 %right UNARY
129 %token END
130 %left <token> '('
131 %token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE ASCIZ
132 %token SECTIONS PHDRS INSERT_K AFTER BEFORE LINKER_VERSION
133 %token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
134 %token SORT_BY_NAME SORT_BY_ALIGNMENT SORT_NONE
135 %token SORT_BY_INIT_PRIORITY REVERSE
136 %token '{' '}'
137 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
138 %token INHIBIT_COMMON_ALLOCATION FORCE_GROUP_ALLOCATION
139 %token SEGMENT_START
140 %token INCLUDE
141 %token MEMORY
142 %token REGION_ALIAS
143 %token LD_FEATURE
144 %token NOLOAD DSECT COPY INFO OVERLAY
145 %token READONLY
146 %token TYPE
147 %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY
148 %token <integer> NEXT
149 %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K
150 %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS NOCROSSREFS_TO
151 %token ORIGIN FILL
152 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
153 %token ALIGNMOD AT SUBALIGN HIDDEN PROVIDE PROVIDE_HIDDEN AS_NEEDED
154 %type <token> assign_op atype attributes_opt sect_constraint opt_align_with_input
155 %type <name> filename
156 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
157 %token LOG2CEIL FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
158 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
159 %token <name> VERS_TAG VERS_IDENTIFIER
160 %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
161 %token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL INPUT_SECTION_FLAGS ALIGN_WITH_INPUT
162 %token EXCLUDE_FILE
163 %token CONSTANT
164 %type <versyms> vers_defns
165 %type <versnode> vers_tag
166 %type <deflist> verdep
167 %token INPUT_DYNAMIC_LIST
171 file:
172 INPUT_SCRIPT script_file
173 | INPUT_MRI_SCRIPT mri_script_file
174 | INPUT_VERSION_SCRIPT version_script_file
175 | INPUT_DYNAMIC_LIST dynamic_list_file
176 | INPUT_DEFSYM defsym_expr
180 filename: NAME;
183 defsym_expr:
184 { ldlex_expression(); }
185 assignment
186 { ldlex_popstate(); }
189 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
190 mri_script_file:
192 ldlex_mri_script ();
193 PUSH_ERROR (_("MRI style script"));
195 mri_script_lines
197 ldlex_popstate ();
198 mri_draw_tree ();
199 POP_ERROR ();
203 mri_script_lines:
204 mri_script_lines mri_script_command NEWLINE
208 mri_script_command:
209 CHIP exp
210 | CHIP exp ',' exp
211 | NAME {
212 einfo(_("%F%P: unrecognised keyword in MRI style script '%s'\n"),$1);
214 | LIST {
215 config.map_filename = "-";
217 | ORDER ordernamelist
218 | ENDWORD
219 | PUBLIC NAME '=' exp
220 { mri_public($2, $4); }
221 | PUBLIC NAME ',' exp
222 { mri_public($2, $4); }
223 | PUBLIC NAME exp
224 { mri_public($2, $3); }
225 | FORMAT NAME
226 { mri_format($2); }
227 | SECT NAME ',' exp
228 { mri_output_section($2, $4);}
229 | SECT NAME exp
230 { mri_output_section($2, $3);}
231 | SECT NAME '=' exp
232 { mri_output_section($2, $4);}
233 | ALIGN_K NAME '=' exp
234 { mri_align($2,$4); }
235 | ALIGN_K NAME ',' exp
236 { mri_align($2,$4); }
237 | ALIGNMOD NAME '=' exp
238 { mri_alignmod($2,$4); }
239 | ALIGNMOD NAME ',' exp
240 { mri_alignmod($2,$4); }
241 | ABSOLUTE mri_abs_name_list
242 | LOAD mri_load_name_list
243 | NAMEWORD NAME
244 { mri_name($2); }
245 | ALIAS NAME ',' NAME
246 { mri_alias($2,$4,0);}
247 | ALIAS NAME ',' INT
248 { mri_alias ($2, 0, (int) $4.integer); }
249 | BASE exp
250 { mri_base($2); }
251 | TRUNCATE INT
252 { mri_truncate ((unsigned int) $2.integer); }
253 | CASE casesymlist
254 | EXTERN extern_name_list
255 | INCLUDE filename
256 { ldfile_open_command_file ($2); }
257 mri_script_lines END
258 | START NAME
259 { lang_add_entry ($2, false); }
263 ordernamelist:
264 ordernamelist ',' NAME { mri_order($3); }
265 | ordernamelist NAME { mri_order($2); }
269 mri_load_name_list:
270 NAME
271 { mri_load($1); }
272 | mri_load_name_list ',' NAME { mri_load($3); }
275 mri_abs_name_list:
276 NAME
277 { mri_only_load($1); }
278 | mri_abs_name_list ',' NAME
279 { mri_only_load($3); }
282 casesymlist:
283 /* empty */ { $$ = NULL; }
284 | NAME
285 | casesymlist ',' NAME
288 extern_name_list:
289 NAME
290 { ldlang_add_undef ($1, false); }
291 | extern_name_list NAME
292 { ldlang_add_undef ($2, false); }
293 | extern_name_list ',' NAME
294 { ldlang_add_undef ($3, false); }
297 script_file:
298 { ldlex_script (); }
299 ifile_list
300 { ldlex_popstate (); }
303 ifile_list:
304 ifile_list ifile_p1
309 ifile_p1:
310 memory
311 | sections
312 | phdrs
313 | startup
314 | high_level_library
315 | low_level_library
316 | floating_point_support
317 | statement_anywhere
318 | version
319 | ';'
320 | TARGET_K '(' NAME ')'
321 { lang_add_target($3); }
322 | SEARCH_DIR '(' filename ')'
323 { ldfile_add_library_path ($3, false); }
324 | OUTPUT '(' filename ')'
325 { lang_add_output($3, 1); }
326 | OUTPUT_FORMAT '(' NAME ')'
327 { lang_add_output_format ($3, (char *) NULL,
328 (char *) NULL, 1); }
329 | OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')'
330 { lang_add_output_format ($3, $5, $7, 1); }
331 | OUTPUT_ARCH '(' NAME ')'
332 { ldfile_set_output_arch ($3, bfd_arch_unknown); }
333 | FORCE_COMMON_ALLOCATION
334 { command_line.force_common_definition = true ; }
335 | FORCE_GROUP_ALLOCATION
336 { command_line.force_group_allocation = true ; }
337 | INHIBIT_COMMON_ALLOCATION
338 { link_info.inhibit_common_definition = true ; }
339 | INPUT '(' input_list ')'
340 | GROUP
341 { lang_enter_group (); }
342 '(' input_list ')'
343 { lang_leave_group (); }
344 | MAP '(' filename ')'
345 { lang_add_map($3); }
346 | INCLUDE filename
347 { ldfile_open_command_file ($2); }
348 ifile_list END
349 | NOCROSSREFS '(' nocrossref_list ')'
351 lang_add_nocrossref ($3);
353 | NOCROSSREFS_TO '(' nocrossref_list ')'
355 lang_add_nocrossref_to ($3);
357 | EXTERN '(' { ldlex_expression (); } extern_name_list ')'
358 { ldlex_popstate (); }
359 | INSERT_K AFTER NAME
360 { lang_add_insert ($3, 0); }
361 | INSERT_K BEFORE NAME
362 { lang_add_insert ($3, 1); }
363 | REGION_ALIAS '(' NAME ',' NAME ')'
364 { lang_memory_region_alias ($3, $5); }
365 | LD_FEATURE '(' NAME ')'
366 { lang_ld_feature ($3); }
369 input_list:
370 { ldlex_inputlist(); }
371 input_list1
372 { ldlex_popstate(); }
374 input_list1:
375 NAME
376 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
377 (char *)NULL); }
378 | input_list1 ',' NAME
379 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
380 (char *)NULL); }
381 | input_list1 NAME
382 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
383 (char *)NULL); }
384 | LNAME
385 { lang_add_input_file($1,lang_input_file_is_l_enum,
386 (char *)NULL); }
387 | input_list1 ',' LNAME
388 { lang_add_input_file($3,lang_input_file_is_l_enum,
389 (char *)NULL); }
390 | input_list1 LNAME
391 { lang_add_input_file($2,lang_input_file_is_l_enum,
392 (char *)NULL); }
393 | AS_NEEDED '('
394 { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
395 input_flags.add_DT_NEEDED_for_regular = true; }
396 input_list1 ')'
397 { input_flags.add_DT_NEEDED_for_regular = $<integer>3; }
398 | input_list1 ',' AS_NEEDED '('
399 { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
400 input_flags.add_DT_NEEDED_for_regular = true; }
401 input_list1 ')'
402 { input_flags.add_DT_NEEDED_for_regular = $<integer>5; }
403 | input_list1 AS_NEEDED '('
404 { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
405 input_flags.add_DT_NEEDED_for_regular = true; }
406 input_list1 ')'
407 { input_flags.add_DT_NEEDED_for_regular = $<integer>4; }
410 sections:
411 SECTIONS '{' sec_or_group_p1 '}'
414 sec_or_group_p1:
415 sec_or_group_p1 section
416 | sec_or_group_p1 statement_anywhere
420 statement_anywhere:
421 ENTRY '(' NAME ')'
422 { lang_add_entry ($3, false); }
423 | assignment separator
424 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')'
425 { ldlex_popstate ();
426 lang_add_assignment (exp_assert ($4, $6)); }
429 wildcard_name:
430 NAME
432 $$ = $1;
436 wildcard_maybe_exclude:
437 wildcard_name
439 $$.name = $1;
440 $$.sorted = none;
441 $$.exclude_name_list = NULL;
442 $$.section_flag_list = NULL;
443 $$.reversed = false;
445 | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
447 $$.name = $5;
448 $$.sorted = none;
449 $$.exclude_name_list = $3;
450 $$.section_flag_list = NULL;
451 $$.reversed = false;
455 wildcard_maybe_reverse:
456 wildcard_maybe_exclude
457 | REVERSE '(' wildcard_maybe_exclude ')'
459 $$ = $3;
460 $$.reversed = true;
461 $$.sorted = by_name;
465 filename_spec:
466 wildcard_maybe_reverse
467 | SORT_BY_NAME '(' wildcard_maybe_reverse ')'
469 $$ = $3;
470 $$.sorted = by_name;
472 | SORT_NONE '(' wildcard_maybe_reverse ')'
474 $$ = $3;
475 $$.sorted = by_none;
476 $$.reversed = false;
478 | REVERSE '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')'
480 $$ = $5;
481 $$.sorted = by_name;
482 $$.reversed = true;
486 section_name_spec:
487 wildcard_maybe_reverse
488 | SORT_BY_NAME '(' wildcard_maybe_reverse ')'
490 $$ = $3;
491 $$.sorted = by_name;
493 | SORT_BY_ALIGNMENT '(' wildcard_maybe_reverse ')'
495 $$ = $3;
496 $$.sorted = by_alignment;
498 | SORT_NONE '(' wildcard_maybe_reverse ')'
500 $$ = $3;
501 $$.sorted = by_none;
503 | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_reverse ')' ')'
505 $$ = $5;
506 $$.sorted = by_name_alignment;
508 | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_maybe_reverse ')' ')'
510 $$ = $5;
511 $$.sorted = by_name;
513 | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_maybe_reverse ')' ')'
515 $$ = $5;
516 $$.sorted = by_alignment_name;
518 | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_reverse ')' ')'
520 $$ = $5;
521 $$.sorted = by_alignment;
523 | SORT_BY_INIT_PRIORITY '(' wildcard_maybe_reverse ')'
525 $$ = $3;
526 $$.sorted = by_init_priority;
528 | REVERSE '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')'
530 $$ = $5;
531 $$.sorted = by_name;
532 $$.reversed = true;
534 | REVERSE '(' SORT_BY_INIT_PRIORITY '(' wildcard_maybe_exclude ')' ')'
536 $$ = $5;
537 $$.sorted = by_init_priority;
538 $$.reversed = true;
542 sect_flag_list: NAME
544 struct flag_info_list *n;
545 n = ((struct flag_info_list *) xmalloc (sizeof *n));
546 if ($1[0] == '!')
548 n->with = without_flags;
549 n->name = &$1[1];
551 else
553 n->with = with_flags;
554 n->name = $1;
556 n->valid = false;
557 n->next = NULL;
558 $$ = n;
560 | sect_flag_list '&' NAME
562 struct flag_info_list *n;
563 n = ((struct flag_info_list *) xmalloc (sizeof *n));
564 if ($3[0] == '!')
566 n->with = without_flags;
567 n->name = &$3[1];
569 else
571 n->with = with_flags;
572 n->name = $3;
574 n->valid = false;
575 n->next = $1;
576 $$ = n;
580 sect_flags:
581 INPUT_SECTION_FLAGS '(' sect_flag_list ')'
583 struct flag_info *n;
584 n = ((struct flag_info *) xmalloc (sizeof *n));
585 n->flag_list = $3;
586 n->flags_initialized = false;
587 n->not_with_flags = 0;
588 n->only_with_flags = 0;
589 $$ = n;
593 exclude_name_list:
594 exclude_name_list wildcard_name
596 struct name_list *tmp;
597 tmp = (struct name_list *) xmalloc (sizeof *tmp);
598 tmp->name = $2;
599 tmp->next = $1;
600 $$ = tmp;
603 wildcard_name
605 struct name_list *tmp;
606 tmp = (struct name_list *) xmalloc (sizeof *tmp);
607 tmp->name = $1;
608 tmp->next = NULL;
609 $$ = tmp;
613 section_name_list:
614 section_name_list opt_comma section_name_spec
616 struct wildcard_list *tmp;
617 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
618 tmp->next = $1;
619 tmp->spec = $3;
620 $$ = tmp;
623 section_name_spec
625 struct wildcard_list *tmp;
626 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
627 tmp->next = NULL;
628 tmp->spec = $1;
629 $$ = tmp;
633 input_section_spec_no_keep:
634 NAME
636 struct wildcard_spec tmp;
637 tmp.name = $1;
638 tmp.exclude_name_list = NULL;
639 tmp.sorted = none;
640 tmp.section_flag_list = NULL;
641 lang_add_wild (&tmp, NULL, ldgram_had_keep);
643 | sect_flags NAME
645 struct wildcard_spec tmp;
646 tmp.name = $2;
647 tmp.exclude_name_list = NULL;
648 tmp.sorted = none;
649 tmp.section_flag_list = $1;
650 lang_add_wild (&tmp, NULL, ldgram_had_keep);
652 | '[' section_name_list ']'
654 lang_add_wild (NULL, $2, ldgram_had_keep);
656 | sect_flags '[' section_name_list ']'
658 struct wildcard_spec tmp;
659 tmp.name = NULL;
660 tmp.exclude_name_list = NULL;
661 tmp.sorted = none;
662 tmp.section_flag_list = $1;
663 lang_add_wild (&tmp, $3, ldgram_had_keep);
665 | filename_spec '(' section_name_list ')'
667 lang_add_wild (&$1, $3, ldgram_had_keep);
669 | sect_flags filename_spec '(' section_name_list ')'
671 $2.section_flag_list = $1;
672 lang_add_wild (&$2, $4, ldgram_had_keep);
676 input_section_spec:
677 input_section_spec_no_keep
678 | KEEP '('
679 { ldgram_had_keep = true; }
680 input_section_spec_no_keep ')'
681 { ldgram_had_keep = false; }
684 statement:
686 | assignment separator
687 | CREATE_OBJECT_SYMBOLS
689 lang_add_attribute (lang_object_symbols_statement_enum);
691 | CONSTRUCTORS
693 lang_add_attribute (lang_constructors_statement_enum);
695 | SORT_BY_NAME '(' CONSTRUCTORS ')'
697 constructors_sorted = true;
698 lang_add_attribute (lang_constructors_statement_enum);
700 | input_section_spec
701 | length '(' mustbe_exp ')'
703 lang_add_data ((int) $1, $3);
705 | ASCIZ NAME
707 lang_add_string ($2);
709 | FILL '(' fill_exp ')'
711 lang_add_fill ($3);
713 | LINKER_VERSION
715 lang_add_version_string ();
717 | ASSERT_K
718 { ldlex_expression (); }
719 '(' exp ',' NAME ')' separator
721 ldlex_popstate ();
722 lang_add_assignment (exp_assert ($4, $6));
724 | INCLUDE filename
726 ldfile_open_command_file ($2);
728 statement_list_opt END
731 statement_list:
732 statement_list statement
733 | statement
736 statement_list_opt:
737 /* empty */
738 | statement_list
741 length:
742 QUAD
743 { $$ = $1; }
744 | SQUAD
745 { $$ = $1; }
746 | LONG
747 { $$ = $1; }
748 | SHORT
749 { $$ = $1; }
750 | BYTE
751 { $$ = $1; }
754 fill_exp:
755 mustbe_exp
757 $$ = exp_get_fill ($1, 0, _("fill value"));
761 fill_opt:
762 '=' fill_exp
763 { $$ = $2; }
764 | { $$ = (fill_type *) 0; }
767 assign_op:
768 PLUSEQ
769 { $$ = '+'; }
770 | MINUSEQ
771 { $$ = '-'; }
772 | MULTEQ
773 { $$ = '*'; }
774 | DIVEQ
775 { $$ = '/'; }
776 | LSHIFTEQ
777 { $$ = LSHIFT; }
778 | RSHIFTEQ
779 { $$ = RSHIFT; }
780 | ANDEQ
781 { $$ = '&'; }
782 | OREQ
783 { $$ = '|'; }
784 | XOREQ
785 { $$ = '^'; }
789 separator: ';' | ','
793 assignment:
794 NAME '=' mustbe_exp
796 lang_add_assignment (exp_assign ($1, $3, false));
798 | NAME assign_op mustbe_exp
800 lang_add_assignment (exp_assign ($1,
801 exp_binop ($2,
802 exp_nameop (NAME,
803 $1),
804 $3), false));
806 | HIDDEN '(' NAME '=' mustbe_exp ')'
808 lang_add_assignment (exp_assign ($3, $5, true));
810 | PROVIDE '(' NAME '=' mustbe_exp ')'
812 lang_add_assignment (exp_provide ($3, $5, false));
814 | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
816 lang_add_assignment (exp_provide ($3, $5, true));
821 opt_comma:
822 ',' | ;
825 memory:
826 MEMORY '{' memory_spec_list_opt '}'
829 memory_spec_list_opt: memory_spec_list | ;
831 memory_spec_list:
832 memory_spec_list opt_comma memory_spec
833 | memory_spec
837 memory_spec: NAME
838 { region = lang_memory_region_lookup ($1, true); }
839 attributes_opt ':'
840 origin_spec opt_comma length_spec
842 | INCLUDE filename
843 { ldfile_open_command_file ($2); }
844 memory_spec_list_opt END
847 origin_spec:
848 ORIGIN '=' mustbe_exp
850 region->origin_exp = $3;
854 length_spec:
855 LENGTH '=' mustbe_exp
857 if (yychar == NAME)
859 yyclearin;
860 ldlex_backup ();
862 region->length_exp = $3;
866 attributes_opt:
867 /* empty */
868 { /* dummy action to avoid bison 1.25 error message */ }
869 | '(' attributes_list ')'
872 attributes_list:
873 attributes_string
874 | attributes_list attributes_string
877 attributes_string:
878 NAME
879 { lang_set_flags (region, $1, 0); }
880 | '!' NAME
881 { lang_set_flags (region, $2, 1); }
884 startup:
885 STARTUP '(' filename ')'
886 { lang_startup($3); }
889 high_level_library:
890 HLL '(' high_level_library_NAME_list ')'
891 | HLL '(' ')'
892 { ldemul_hll((char *)NULL); }
895 high_level_library_NAME_list:
896 high_level_library_NAME_list opt_comma filename
897 { ldemul_hll($3); }
898 | filename
899 { ldemul_hll($1); }
902 low_level_library:
903 SYSLIB '(' low_level_library_NAME_list ')'
906 low_level_library_NAME_list:
907 low_level_library_NAME_list opt_comma filename
908 { ldemul_syslib($3); }
912 floating_point_support:
913 FLOAT
914 { lang_float(true); }
915 | NOFLOAT
916 { lang_float(false); }
919 nocrossref_list:
920 /* empty */
922 $$ = NULL;
924 | NAME nocrossref_list
926 struct lang_nocrossref *n;
928 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
929 n->name = $1;
930 n->next = $2;
931 $$ = n;
933 | NAME ',' nocrossref_list
935 struct lang_nocrossref *n;
937 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
938 n->name = $1;
939 n->next = $3;
940 $$ = n;
944 paren_script_name: { ldlex_script (); }
945 '(' NAME ')'
946 { ldlex_popstate (); $$ = $3; }
948 mustbe_exp: { ldlex_expression (); }
950 { ldlex_popstate (); $$ = $2; }
953 exp :
954 '-' exp %prec UNARY
955 { $$ = exp_unop ('-', $2); }
956 | '(' exp ')'
957 { $$ = $2; }
958 | NEXT '(' exp ')' %prec UNARY
959 { $$ = exp_unop ((int) $1,$3); }
960 | '!' exp %prec UNARY
961 { $$ = exp_unop ('!', $2); }
962 | '+' exp %prec UNARY
963 { $$ = $2; }
964 | '~' exp %prec UNARY
965 { $$ = exp_unop ('~', $2);}
967 | exp '*' exp
968 { $$ = exp_binop ('*', $1, $3); }
969 | exp '/' exp
970 { $$ = exp_binop ('/', $1, $3); }
971 | exp '%' exp
972 { $$ = exp_binop ('%', $1, $3); }
973 | exp '+' exp
974 { $$ = exp_binop ('+', $1, $3); }
975 | exp '-' exp
976 { $$ = exp_binop ('-' , $1, $3); }
977 | exp LSHIFT exp
978 { $$ = exp_binop (LSHIFT , $1, $3); }
979 | exp RSHIFT exp
980 { $$ = exp_binop (RSHIFT , $1, $3); }
981 | exp EQ exp
982 { $$ = exp_binop (EQ , $1, $3); }
983 | exp NE exp
984 { $$ = exp_binop (NE , $1, $3); }
985 | exp LE exp
986 { $$ = exp_binop (LE , $1, $3); }
987 | exp GE exp
988 { $$ = exp_binop (GE , $1, $3); }
989 | exp '<' exp
990 { $$ = exp_binop ('<' , $1, $3); }
991 | exp '>' exp
992 { $$ = exp_binop ('>' , $1, $3); }
993 | exp '&' exp
994 { $$ = exp_binop ('&' , $1, $3); }
995 | exp '^' exp
996 { $$ = exp_binop ('^' , $1, $3); }
997 | exp '|' exp
998 { $$ = exp_binop ('|' , $1, $3); }
999 | exp '?' exp ':' exp
1000 { $$ = exp_trinop ('?' , $1, $3, $5); }
1001 | exp ANDAND exp
1002 { $$ = exp_binop (ANDAND , $1, $3); }
1003 | exp OROR exp
1004 { $$ = exp_binop (OROR , $1, $3); }
1005 | DEFINED '(' NAME ')'
1006 { $$ = exp_nameop (DEFINED, $3); }
1007 | INT
1008 { $$ = exp_bigintop ($1.integer, $1.str); }
1009 | SIZEOF_HEADERS
1010 { $$ = exp_nameop (SIZEOF_HEADERS,0); }
1012 | ALIGNOF paren_script_name
1013 { $$ = exp_nameop (ALIGNOF, $2); }
1014 | SIZEOF paren_script_name
1015 { $$ = exp_nameop (SIZEOF, $2); }
1016 | ADDR paren_script_name
1017 { $$ = exp_nameop (ADDR, $2); }
1018 | LOADADDR paren_script_name
1019 { $$ = exp_nameop (LOADADDR, $2); }
1020 | CONSTANT '(' NAME ')'
1021 { $$ = exp_nameop (CONSTANT,$3); }
1022 | ABSOLUTE '(' exp ')'
1023 { $$ = exp_unop (ABSOLUTE, $3); }
1024 | ALIGN_K '(' exp ')'
1025 { $$ = exp_unop (ALIGN_K,$3); }
1026 | ALIGN_K '(' exp ',' exp ')'
1027 { $$ = exp_binop (ALIGN_K,$3,$5); }
1028 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
1029 { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
1030 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
1031 { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
1032 | DATA_SEGMENT_END '(' exp ')'
1033 { $$ = exp_unop (DATA_SEGMENT_END, $3); }
1034 | SEGMENT_START { ldlex_script (); } '(' NAME
1035 { ldlex_popstate (); } ',' exp ')'
1036 { /* The operands to the expression node are
1037 placed in the opposite order from the way
1038 in which they appear in the script as
1039 that allows us to reuse more code in
1040 fold_binary. */
1041 $$ = exp_binop (SEGMENT_START,
1043 exp_nameop (NAME, $4)); }
1044 | BLOCK '(' exp ')'
1045 { $$ = exp_unop (ALIGN_K,$3); }
1046 | NAME
1047 { $$ = exp_nameop (NAME,$1); }
1048 | MAX_K '(' exp ',' exp ')'
1049 { $$ = exp_binop (MAX_K, $3, $5 ); }
1050 | MIN_K '(' exp ',' exp ')'
1051 { $$ = exp_binop (MIN_K, $3, $5 ); }
1052 | ASSERT_K '(' exp ',' NAME ')'
1053 { $$ = exp_assert ($3, $5); }
1054 | ORIGIN paren_script_name
1055 { $$ = exp_nameop (ORIGIN, $2); }
1056 | LENGTH paren_script_name
1057 { $$ = exp_nameop (LENGTH, $2); }
1058 | LOG2CEIL '(' exp ')'
1059 { $$ = exp_unop (LOG2CEIL, $3); }
1063 memspec_at_opt:
1064 AT '>' NAME { $$ = $3; }
1065 | { $$ = 0; }
1068 opt_at:
1069 AT '(' exp ')' { $$ = $3; }
1070 | { $$ = 0; }
1073 opt_align:
1074 ALIGN_K '(' exp ')' { $$ = $3; }
1075 | { $$ = 0; }
1078 opt_align_with_input:
1079 ALIGN_WITH_INPUT { $$ = ALIGN_WITH_INPUT; }
1080 | { $$ = 0; }
1083 opt_subalign:
1084 SUBALIGN '(' exp ')' { $$ = $3; }
1085 | { $$ = 0; }
1088 sect_constraint:
1089 ONLY_IF_RO { $$ = ONLY_IF_RO; }
1090 | ONLY_IF_RW { $$ = ONLY_IF_RW; }
1091 | SPECIAL { $$ = SPECIAL; }
1092 | { $$ = 0; }
1095 section: NAME
1096 { ldlex_expression(); }
1097 opt_exp_with_type
1098 opt_at
1099 opt_align
1100 opt_align_with_input
1101 opt_subalign
1102 sect_constraint
1104 ldlex_popstate ();
1105 ldlex_wild ();
1106 lang_enter_output_section_statement ($1, $3, sectype,
1107 sectype_value, $5, $7, $4, $8, $6);
1110 statement_list_opt
1112 { ldlex_popstate (); }
1113 memspec_opt memspec_at_opt phdr_opt fill_opt
1115 /* fill_opt may have switched the lexer into
1116 expression state, and back again, but in
1117 order to find the end of the fill
1118 expression the parser must look ahead one
1119 token. If it is a NAME, throw it away as
1120 it will have been lexed in the wrong
1121 state. */
1122 if (yychar == NAME)
1124 yyclearin;
1125 ldlex_backup ();
1127 lang_leave_output_section_statement ($17, $14,
1128 $16, $15);
1130 opt_comma
1131 | OVERLAY
1132 { ldlex_expression (); }
1133 opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
1134 { ldlex_popstate (); }
1137 lang_enter_overlay ($3, $6);
1139 overlay_section
1141 memspec_opt memspec_at_opt phdr_opt fill_opt
1143 if (yychar == NAME)
1145 yyclearin;
1146 ldlex_backup ();
1148 lang_leave_overlay ($5, (int) $4,
1149 $15, $12, $14, $13);
1151 opt_comma
1152 | /* The GROUP case is just enough to support the gcc
1153 svr3.ifile script. It is not intended to be full
1154 support. I'm not even sure what GROUP is supposed
1155 to mean. */
1156 GROUP
1157 { ldlex_expression (); }
1158 opt_exp_with_type
1160 ldlex_popstate ();
1161 lang_add_assignment (exp_assign (".", $3, false));
1163 '{' sec_or_group_p1 '}'
1164 | INCLUDE filename
1166 ldfile_open_command_file ($2);
1168 sec_or_group_p1 END
1171 type:
1172 NOLOAD { sectype = noload_section; }
1173 | DSECT { sectype = noalloc_section; }
1174 | COPY { sectype = noalloc_section; }
1175 | INFO { sectype = noalloc_section; }
1176 | OVERLAY { sectype = noalloc_section; }
1177 | READONLY '(' TYPE '=' exp ')' { sectype = typed_readonly_section; sectype_value = $5; }
1178 | READONLY { sectype = readonly_section; }
1179 | TYPE '=' exp { sectype = type_section; sectype_value = $3; }
1182 atype:
1183 '(' type ')'
1184 | /* EMPTY */ { sectype = normal_section; }
1185 | '(' ')' { sectype = normal_section; }
1188 opt_exp_with_type:
1189 exp atype ':' { $$ = $1; }
1190 | atype ':' { $$ = (etree_type *)NULL; }
1191 | /* The BIND cases are to support the gcc svr3.ifile
1192 script. They aren't intended to implement full
1193 support for the BIND keyword. I'm not even sure
1194 what BIND is supposed to mean. */
1195 BIND '(' exp ')' atype ':' { $$ = $3; }
1196 | BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
1197 { $$ = $3; }
1200 opt_exp_without_type:
1201 exp ':' { $$ = $1; }
1202 | ':' { $$ = (etree_type *) NULL; }
1205 opt_nocrossrefs:
1206 /* empty */
1207 { $$ = 0; }
1208 | NOCROSSREFS
1209 { $$ = 1; }
1212 memspec_opt:
1213 '>' NAME
1214 { $$ = $2; }
1215 | { $$ = DEFAULT_MEMORY_REGION; }
1218 phdr_opt:
1219 /* empty */
1221 $$ = NULL;
1223 | phdr_opt ':' NAME
1225 struct lang_output_section_phdr_list *n;
1227 n = ((struct lang_output_section_phdr_list *)
1228 xmalloc (sizeof *n));
1229 n->name = $3;
1230 n->used = false;
1231 n->next = $1;
1232 $$ = n;
1236 overlay_section:
1237 /* empty */
1238 | overlay_section
1239 NAME
1241 ldlex_wild ();
1242 lang_enter_overlay_section ($2);
1245 statement_list_opt
1247 { ldlex_popstate (); }
1248 phdr_opt fill_opt
1250 if (yychar == NAME)
1252 yyclearin;
1253 ldlex_backup ();
1255 lang_leave_overlay_section ($9, $8);
1257 opt_comma
1260 phdrs:
1261 PHDRS '{' phdr_list '}'
1264 phdr_list:
1265 /* empty */
1266 | phdr_list phdr
1269 phdr:
1270 NAME { ldlex_expression (); }
1271 phdr_type phdr_qualifiers { ldlex_popstate (); }
1274 lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1275 $4.flags);
1279 phdr_type:
1282 $$ = $1;
1284 if ($1->type.node_class == etree_name
1285 && $1->type.node_code == NAME)
1287 const char *s;
1288 unsigned int i;
1289 static const char * const phdr_types[] =
1291 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1292 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
1293 "PT_PHDR", "PT_TLS"
1296 s = $1->name.name;
1297 for (i = 0;
1298 i < sizeof phdr_types / sizeof phdr_types[0];
1299 i++)
1300 if (strcmp (s, phdr_types[i]) == 0)
1302 $$ = exp_intop (i);
1303 break;
1305 if (i == sizeof phdr_types / sizeof phdr_types[0])
1307 if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1308 $$ = exp_intop (0x6474e550);
1309 else if (strcmp (s, "PT_GNU_STACK") == 0)
1310 $$ = exp_intop (0x6474e551);
1311 else if (strcmp (s, "PT_GNU_RELRO") == 0)
1312 $$ = exp_intop (0x6474e552);
1313 else if (strcmp (s, "PT_GNU_PROPERTY") == 0)
1314 $$ = exp_intop (0x6474e553);
1315 else
1317 einfo (_("\
1318 %X%P:%pS: unknown phdr type `%s' (try integer literal)\n"),
1319 NULL, s);
1320 $$ = exp_intop (0);
1327 phdr_qualifiers:
1328 /* empty */
1330 memset (&$$, 0, sizeof (struct phdr_info));
1332 | NAME phdr_val phdr_qualifiers
1334 $$ = $3;
1335 if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
1336 $$.filehdr = true;
1337 else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
1338 $$.phdrs = true;
1339 else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1340 $$.flags = $2;
1341 else
1342 einfo (_("%X%P:%pS: PHDRS syntax error at `%s'\n"),
1343 NULL, $1);
1345 | AT '(' exp ')' phdr_qualifiers
1347 $$ = $5;
1348 $$.at = $3;
1352 phdr_val:
1353 /* empty */
1355 $$ = NULL;
1357 | '(' exp ')'
1359 $$ = $2;
1363 dynamic_list_file:
1365 ldlex_version_file ();
1366 PUSH_ERROR (_("dynamic list"));
1368 dynamic_list_nodes
1370 ldlex_popstate ();
1371 POP_ERROR ();
1375 dynamic_list_nodes:
1376 dynamic_list_node
1377 | dynamic_list_nodes dynamic_list_node
1380 dynamic_list_node:
1381 '{' dynamic_list_tag '}' ';'
1384 dynamic_list_tag:
1385 vers_defns ';'
1387 lang_append_dynamic_list (current_dynamic_list_p, $1);
1391 /* This syntax is used within an external version script file. */
1393 version_script_file:
1395 ldlex_version_file ();
1396 PUSH_ERROR (_("VERSION script"));
1398 vers_nodes
1400 ldlex_popstate ();
1401 POP_ERROR ();
1405 /* This is used within a normal linker script file. */
1407 version:
1409 ldlex_version_script ();
1411 VERSIONK '{' vers_nodes '}'
1413 ldlex_popstate ();
1417 vers_nodes:
1418 vers_node
1419 | vers_nodes vers_node
1422 vers_node:
1423 '{' vers_tag '}' ';'
1425 lang_register_vers_node (NULL, $2, NULL);
1427 | VERS_TAG '{' vers_tag '}' ';'
1429 lang_register_vers_node ($1, $3, NULL);
1431 | VERS_TAG '{' vers_tag '}' verdep ';'
1433 lang_register_vers_node ($1, $3, $5);
1437 verdep:
1438 VERS_TAG
1440 $$ = lang_add_vers_depend (NULL, $1);
1442 | verdep VERS_TAG
1444 $$ = lang_add_vers_depend ($1, $2);
1448 vers_tag:
1449 /* empty */
1451 $$ = lang_new_vers_node (NULL, NULL);
1453 | vers_defns ';'
1455 $$ = lang_new_vers_node ($1, NULL);
1457 | GLOBAL ':' vers_defns ';'
1459 $$ = lang_new_vers_node ($3, NULL);
1461 | LOCAL ':' vers_defns ';'
1463 $$ = lang_new_vers_node (NULL, $3);
1465 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1467 $$ = lang_new_vers_node ($3, $7);
1471 vers_defns:
1472 VERS_IDENTIFIER
1474 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, false);
1476 | NAME
1478 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, true);
1480 | vers_defns ';' VERS_IDENTIFIER
1482 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, false);
1484 | vers_defns ';' NAME
1486 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, true);
1488 | vers_defns ';' EXTERN NAME '{'
1490 $<name>$ = ldgram_vers_current_lang;
1491 ldgram_vers_current_lang = $4;
1493 vers_defns opt_semicolon '}'
1495 struct bfd_elf_version_expr *pat;
1496 for (pat = $7; pat->next != NULL; pat = pat->next);
1497 pat->next = $1;
1498 $$ = $7;
1499 ldgram_vers_current_lang = $<name>6;
1501 | EXTERN NAME '{'
1503 $<name>$ = ldgram_vers_current_lang;
1504 ldgram_vers_current_lang = $2;
1506 vers_defns opt_semicolon '}'
1508 $$ = $5;
1509 ldgram_vers_current_lang = $<name>4;
1511 | GLOBAL
1513 $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, false);
1515 | vers_defns ';' GLOBAL
1517 $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, false);
1519 | LOCAL
1521 $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, false);
1523 | vers_defns ';' LOCAL
1525 $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, false);
1527 | EXTERN
1529 $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, false);
1531 | vers_defns ';' EXTERN
1533 $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, false);
1537 opt_semicolon:
1538 /* empty */
1539 | ';'
1543 static void
1544 yyerror (const char *arg)
1546 if (ldfile_assumed_script)
1547 einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
1548 ldlex_filename ());
1549 if (error_index > 0 && error_index < ERROR_NAME_MAX)
1550 einfo (_("%F%P:%pS: %s in %s\n"), NULL, arg, error_names[error_index - 1]);
1551 else
1552 einfo ("%F%P:%pS: %s\n", NULL, arg);