daily update
[binutils.git] / ld / ldgram.y
blob49d9ff1bc3a658a6cb7ccc0c75ccbaa89984a120
1 /* A YACC grammar to parse a superset of the AT&T linker scripting language.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
5 Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
7 This file is part of the GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
29 #define DONTDECLARE_MALLOC
31 #include "sysdep.h"
32 #include "bfd.h"
33 #include "bfdlink.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 lang_memory_region_type *region;
53 bfd_boolean ldgram_had_keep = FALSE;
54 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 int token;
76 union etree_union *etree;
77 struct phdr_info
79 bfd_boolean filehdr;
80 bfd_boolean phdrs;
81 union etree_union *at;
82 union etree_union *flags;
83 } phdr;
84 struct lang_nocrossref *nocrossref;
85 struct lang_output_section_phdr_list *section_phdr;
86 struct bfd_elf_version_deps *deflist;
87 struct bfd_elf_version_expr *versyms;
88 struct bfd_elf_version_tree *versnode;
91 %type <etree> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val
92 %type <etree> opt_exp_without_type opt_subalign opt_align
93 %type <fill> fill_opt fill_exp
94 %type <name_list> exclude_name_list
95 %type <wildcard_list> file_NAME_list
96 %type <name> memspec_opt casesymlist
97 %type <name> memspec_at_opt
98 %type <cname> wildcard_name
99 %type <wildcard> wildcard_spec
100 %token <bigint> INT
101 %token <name> NAME LNAME
102 %type <integer> length
103 %type <phdr> phdr_qualifiers
104 %type <nocrossref> nocrossref_list
105 %type <section_phdr> phdr_opt
106 %type <integer> opt_nocrossrefs
108 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
109 %right <token> '?' ':'
110 %left <token> OROR
111 %left <token> ANDAND
112 %left <token> '|'
113 %left <token> '^'
114 %left <token> '&'
115 %left <token> EQ NE
116 %left <token> '<' '>' LE GE
117 %left <token> LSHIFT RSHIFT
119 %left <token> '+' '-'
120 %left <token> '*' '/' '%'
122 %right UNARY
123 %token END
124 %left <token> '('
125 %token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
126 %token SECTIONS PHDRS INSERT_K AFTER BEFORE
127 %token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
128 %token SORT_BY_NAME SORT_BY_ALIGNMENT
129 %token '{' '}'
130 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
131 %token INHIBIT_COMMON_ALLOCATION
132 %token SEGMENT_START
133 %token INCLUDE
134 %token MEMORY
135 %token REGION_ALIAS
136 %token NOLOAD DSECT COPY INFO OVERLAY
137 %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY
138 %token <integer> NEXT
139 %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K
140 %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS
141 %token ORIGIN FILL
142 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
143 %token ALIGNMOD AT SUBALIGN PROVIDE PROVIDE_HIDDEN AS_NEEDED
144 %type <token> assign_op atype attributes_opt sect_constraint
145 %type <name> filename
146 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
147 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
148 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
149 %token <name> VERS_TAG VERS_IDENTIFIER
150 %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
151 %token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL
152 %token EXCLUDE_FILE
153 %token CONSTANT
154 %type <versyms> vers_defns
155 %type <versnode> vers_tag
156 %type <deflist> verdep
157 %token INPUT_DYNAMIC_LIST
161 file:
162 INPUT_SCRIPT script_file
163 | INPUT_MRI_SCRIPT mri_script_file
164 | INPUT_VERSION_SCRIPT version_script_file
165 | INPUT_DYNAMIC_LIST dynamic_list_file
166 | INPUT_DEFSYM defsym_expr
170 filename: NAME;
173 defsym_expr:
174 { ldlex_defsym(); }
175 NAME '=' exp
177 ldlex_popstate();
178 lang_add_assignment(exp_assop($3,$2,$4));
182 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
183 mri_script_file:
185 ldlex_mri_script ();
186 PUSH_ERROR (_("MRI style script"));
188 mri_script_lines
190 ldlex_popstate ();
191 mri_draw_tree ();
192 POP_ERROR ();
196 mri_script_lines:
197 mri_script_lines mri_script_command NEWLINE
201 mri_script_command:
202 CHIP exp
203 | CHIP exp ',' exp
204 | NAME {
205 einfo(_("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1);
207 | LIST {
208 config.map_filename = "-";
210 | ORDER ordernamelist
211 | ENDWORD
212 | PUBLIC NAME '=' exp
213 { mri_public($2, $4); }
214 | PUBLIC NAME ',' exp
215 { mri_public($2, $4); }
216 | PUBLIC NAME exp
217 { mri_public($2, $3); }
218 | FORMAT NAME
219 { mri_format($2); }
220 | SECT NAME ',' exp
221 { mri_output_section($2, $4);}
222 | SECT NAME exp
223 { mri_output_section($2, $3);}
224 | SECT NAME '=' exp
225 { mri_output_section($2, $4);}
226 | ALIGN_K NAME '=' exp
227 { mri_align($2,$4); }
228 | ALIGN_K NAME ',' exp
229 { mri_align($2,$4); }
230 | ALIGNMOD NAME '=' exp
231 { mri_alignmod($2,$4); }
232 | ALIGNMOD NAME ',' exp
233 { mri_alignmod($2,$4); }
234 | ABSOLUTE mri_abs_name_list
235 | LOAD mri_load_name_list
236 | NAMEWORD NAME
237 { mri_name($2); }
238 | ALIAS NAME ',' NAME
239 { mri_alias($2,$4,0);}
240 | ALIAS NAME ',' INT
241 { mri_alias ($2, 0, (int) $4.integer); }
242 | BASE exp
243 { mri_base($2); }
244 | TRUNCATE INT
245 { mri_truncate ((unsigned int) $2.integer); }
246 | CASE casesymlist
247 | EXTERN extern_name_list
248 | INCLUDE filename
249 { ldlex_script (); ldfile_open_command_file($2); }
250 mri_script_lines END
251 { ldlex_popstate (); }
252 | START NAME
253 { lang_add_entry ($2, FALSE); }
257 ordernamelist:
258 ordernamelist ',' NAME { mri_order($3); }
259 | ordernamelist NAME { mri_order($2); }
263 mri_load_name_list:
264 NAME
265 { mri_load($1); }
266 | mri_load_name_list ',' NAME { mri_load($3); }
269 mri_abs_name_list:
270 NAME
271 { mri_only_load($1); }
272 | mri_abs_name_list ',' NAME
273 { mri_only_load($3); }
276 casesymlist:
277 /* empty */ { $$ = NULL; }
278 | NAME
279 | casesymlist ',' NAME
282 /* Parsed as expressions so that commas separate entries */
283 extern_name_list:
284 { ldlex_expression (); }
285 extern_name_list_body
286 { ldlex_popstate (); }
288 extern_name_list_body:
289 NAME
290 { ldlang_add_undef ($1); }
291 | extern_name_list_body NAME
292 { ldlang_add_undef ($2); }
293 | extern_name_list_body ',' NAME
294 { ldlang_add_undef ($3); }
297 script_file:
298 { ldlex_both(); }
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 | INHIBIT_COMMON_ALLOCATION
336 { command_line.inhibit_common_definition = TRUE ; }
337 | INPUT '(' input_list ')'
338 | GROUP
339 { lang_enter_group (); }
340 '(' input_list ')'
341 { lang_leave_group (); }
342 | MAP '(' filename ')'
343 { lang_add_map($3); }
344 | INCLUDE filename
345 { ldlex_script (); ldfile_open_command_file($2); }
346 ifile_list END
347 { ldlex_popstate (); }
348 | NOCROSSREFS '(' nocrossref_list ')'
350 lang_add_nocrossref ($3);
352 | EXTERN '(' extern_name_list ')'
353 | INSERT_K AFTER NAME
354 { lang_add_insert ($3, 0); }
355 | INSERT_K BEFORE NAME
356 { lang_add_insert ($3, 1); }
357 | REGION_ALIAS '(' NAME ',' NAME ')'
358 { lang_memory_region_alias ($3, $5); }
361 input_list:
362 NAME
363 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
364 (char *)NULL); }
365 | input_list ',' NAME
366 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
367 (char *)NULL); }
368 | input_list NAME
369 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
370 (char *)NULL); }
371 | LNAME
372 { lang_add_input_file($1,lang_input_file_is_l_enum,
373 (char *)NULL); }
374 | input_list ',' LNAME
375 { lang_add_input_file($3,lang_input_file_is_l_enum,
376 (char *)NULL); }
377 | input_list LNAME
378 { lang_add_input_file($2,lang_input_file_is_l_enum,
379 (char *)NULL); }
380 | AS_NEEDED '('
381 { $<integer>$ = add_DT_NEEDED_for_regular; add_DT_NEEDED_for_regular = TRUE; }
382 input_list ')'
383 { add_DT_NEEDED_for_regular = $<integer>3; }
384 | input_list ',' AS_NEEDED '('
385 { $<integer>$ = add_DT_NEEDED_for_regular; add_DT_NEEDED_for_regular = TRUE; }
386 input_list ')'
387 { add_DT_NEEDED_for_regular = $<integer>5; }
388 | input_list AS_NEEDED '('
389 { $<integer>$ = add_DT_NEEDED_for_regular; add_DT_NEEDED_for_regular = TRUE; }
390 input_list ')'
391 { add_DT_NEEDED_for_regular = $<integer>4; }
394 sections:
395 SECTIONS '{' sec_or_group_p1 '}'
398 sec_or_group_p1:
399 sec_or_group_p1 section
400 | sec_or_group_p1 statement_anywhere
404 statement_anywhere:
405 ENTRY '(' NAME ')'
406 { lang_add_entry ($3, FALSE); }
407 | assignment end
408 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')'
409 { ldlex_popstate ();
410 lang_add_assignment (exp_assert ($4, $6)); }
413 /* The '*' and '?' cases are there because the lexer returns them as
414 separate tokens rather than as NAME. */
415 wildcard_name:
416 NAME
418 $$ = $1;
420 | '*'
422 $$ = "*";
424 | '?'
426 $$ = "?";
430 wildcard_spec:
431 wildcard_name
433 $$.name = $1;
434 $$.sorted = none;
435 $$.exclude_name_list = NULL;
437 | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
439 $$.name = $5;
440 $$.sorted = none;
441 $$.exclude_name_list = $3;
443 | SORT_BY_NAME '(' wildcard_name ')'
445 $$.name = $3;
446 $$.sorted = by_name;
447 $$.exclude_name_list = NULL;
449 | SORT_BY_ALIGNMENT '(' wildcard_name ')'
451 $$.name = $3;
452 $$.sorted = by_alignment;
453 $$.exclude_name_list = NULL;
455 | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
457 $$.name = $5;
458 $$.sorted = by_name_alignment;
459 $$.exclude_name_list = NULL;
461 | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_name ')' ')'
463 $$.name = $5;
464 $$.sorted = by_name;
465 $$.exclude_name_list = NULL;
467 | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_name ')' ')'
469 $$.name = $5;
470 $$.sorted = by_alignment_name;
471 $$.exclude_name_list = NULL;
473 | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
475 $$.name = $5;
476 $$.sorted = by_alignment;
477 $$.exclude_name_list = NULL;
479 | SORT_BY_NAME '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')'
481 $$.name = $7;
482 $$.sorted = by_name;
483 $$.exclude_name_list = $5;
487 exclude_name_list:
488 exclude_name_list wildcard_name
490 struct name_list *tmp;
491 tmp = (struct name_list *) xmalloc (sizeof *tmp);
492 tmp->name = $2;
493 tmp->next = $1;
494 $$ = tmp;
497 wildcard_name
499 struct name_list *tmp;
500 tmp = (struct name_list *) xmalloc (sizeof *tmp);
501 tmp->name = $1;
502 tmp->next = NULL;
503 $$ = tmp;
507 file_NAME_list:
508 file_NAME_list opt_comma wildcard_spec
510 struct wildcard_list *tmp;
511 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
512 tmp->next = $1;
513 tmp->spec = $3;
514 $$ = tmp;
517 wildcard_spec
519 struct wildcard_list *tmp;
520 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
521 tmp->next = NULL;
522 tmp->spec = $1;
523 $$ = tmp;
527 input_section_spec_no_keep:
528 NAME
530 struct wildcard_spec tmp;
531 tmp.name = $1;
532 tmp.exclude_name_list = NULL;
533 tmp.sorted = none;
534 lang_add_wild (&tmp, NULL, ldgram_had_keep);
536 | '[' file_NAME_list ']'
538 lang_add_wild (NULL, $2, ldgram_had_keep);
540 | wildcard_spec '(' file_NAME_list ')'
542 lang_add_wild (&$1, $3, ldgram_had_keep);
546 input_section_spec:
547 input_section_spec_no_keep
548 | KEEP '('
549 { ldgram_had_keep = TRUE; }
550 input_section_spec_no_keep ')'
551 { ldgram_had_keep = FALSE; }
554 statement:
555 assignment end
556 | CREATE_OBJECT_SYMBOLS
558 lang_add_attribute(lang_object_symbols_statement_enum);
560 | ';'
561 | CONSTRUCTORS
564 lang_add_attribute(lang_constructors_statement_enum);
566 | SORT_BY_NAME '(' CONSTRUCTORS ')'
568 constructors_sorted = TRUE;
569 lang_add_attribute (lang_constructors_statement_enum);
571 | input_section_spec
572 | length '(' mustbe_exp ')'
574 lang_add_data ((int) $1, $3);
577 | FILL '(' fill_exp ')'
579 lang_add_fill ($3);
581 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')' end
582 { ldlex_popstate ();
583 lang_add_assignment (exp_assert ($4, $6)); }
584 | INCLUDE filename
585 { ldlex_script (); ldfile_open_command_file($2); }
586 statement_list_opt END
587 { ldlex_popstate (); }
590 statement_list:
591 statement_list statement
592 | statement
595 statement_list_opt:
596 /* empty */
597 | statement_list
600 length:
601 QUAD
602 { $$ = $1; }
603 | SQUAD
604 { $$ = $1; }
605 | LONG
606 { $$ = $1; }
607 | SHORT
608 { $$ = $1; }
609 | BYTE
610 { $$ = $1; }
613 fill_exp:
614 mustbe_exp
616 $$ = exp_get_fill ($1, 0, "fill value");
620 fill_opt:
621 '=' fill_exp
622 { $$ = $2; }
623 | { $$ = (fill_type *) 0; }
626 assign_op:
627 PLUSEQ
628 { $$ = '+'; }
629 | MINUSEQ
630 { $$ = '-'; }
631 | MULTEQ
632 { $$ = '*'; }
633 | DIVEQ
634 { $$ = '/'; }
635 | LSHIFTEQ
636 { $$ = LSHIFT; }
637 | RSHIFTEQ
638 { $$ = RSHIFT; }
639 | ANDEQ
640 { $$ = '&'; }
641 | OREQ
642 { $$ = '|'; }
646 end: ';' | ','
650 assignment:
651 NAME '=' mustbe_exp
653 lang_add_assignment (exp_assop ($2, $1, $3));
655 | NAME assign_op mustbe_exp
657 lang_add_assignment (exp_assop ('=', $1,
658 exp_binop ($2,
659 exp_nameop (NAME,
660 $1),
661 $3)));
663 | PROVIDE '(' NAME '=' mustbe_exp ')'
665 lang_add_assignment (exp_provide ($3, $5, FALSE));
667 | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
669 lang_add_assignment (exp_provide ($3, $5, TRUE));
674 opt_comma:
675 ',' | ;
678 memory:
679 MEMORY '{' memory_spec_list_opt '}'
682 memory_spec_list_opt: memory_spec_list | ;
684 memory_spec_list:
685 memory_spec_list opt_comma memory_spec
686 | memory_spec
690 memory_spec: NAME
691 { region = lang_memory_region_lookup ($1, TRUE); }
692 attributes_opt ':'
693 origin_spec opt_comma length_spec
695 | INCLUDE filename
696 { ldlex_script (); ldfile_open_command_file($2); }
697 memory_spec_list_opt END
698 { ldlex_popstate (); }
701 origin_spec:
702 ORIGIN '=' mustbe_exp
704 region->origin = exp_get_vma ($3, 0, "origin");
705 region->current = region->origin;
709 length_spec:
710 LENGTH '=' mustbe_exp
712 region->length = exp_get_vma ($3, -1, "length");
716 attributes_opt:
717 /* empty */
718 { /* dummy action to avoid bison 1.25 error message */ }
719 | '(' attributes_list ')'
722 attributes_list:
723 attributes_string
724 | attributes_list attributes_string
727 attributes_string:
728 NAME
729 { lang_set_flags (region, $1, 0); }
730 | '!' NAME
731 { lang_set_flags (region, $2, 1); }
734 startup:
735 STARTUP '(' filename ')'
736 { lang_startup($3); }
739 high_level_library:
740 HLL '(' high_level_library_NAME_list ')'
741 | HLL '(' ')'
742 { ldemul_hll((char *)NULL); }
745 high_level_library_NAME_list:
746 high_level_library_NAME_list opt_comma filename
747 { ldemul_hll($3); }
748 | filename
749 { ldemul_hll($1); }
753 low_level_library:
754 SYSLIB '(' low_level_library_NAME_list ')'
755 ; low_level_library_NAME_list:
756 low_level_library_NAME_list opt_comma filename
757 { ldemul_syslib($3); }
761 floating_point_support:
762 FLOAT
763 { lang_float(TRUE); }
764 | NOFLOAT
765 { lang_float(FALSE); }
768 nocrossref_list:
769 /* empty */
771 $$ = NULL;
773 | NAME nocrossref_list
775 struct lang_nocrossref *n;
777 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
778 n->name = $1;
779 n->next = $2;
780 $$ = n;
782 | NAME ',' nocrossref_list
784 struct lang_nocrossref *n;
786 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
787 n->name = $1;
788 n->next = $3;
789 $$ = n;
793 mustbe_exp: { ldlex_expression (); }
795 { ldlex_popstate (); $$=$2;}
798 exp :
799 '-' exp %prec UNARY
800 { $$ = exp_unop ('-', $2); }
801 | '(' exp ')'
802 { $$ = $2; }
803 | NEXT '(' exp ')' %prec UNARY
804 { $$ = exp_unop ((int) $1,$3); }
805 | '!' exp %prec UNARY
806 { $$ = exp_unop ('!', $2); }
807 | '+' exp %prec UNARY
808 { $$ = $2; }
809 | '~' exp %prec UNARY
810 { $$ = exp_unop ('~', $2);}
812 | exp '*' exp
813 { $$ = exp_binop ('*', $1, $3); }
814 | exp '/' exp
815 { $$ = exp_binop ('/', $1, $3); }
816 | exp '%' exp
817 { $$ = exp_binop ('%', $1, $3); }
818 | exp '+' exp
819 { $$ = exp_binop ('+', $1, $3); }
820 | exp '-' exp
821 { $$ = exp_binop ('-' , $1, $3); }
822 | exp LSHIFT exp
823 { $$ = exp_binop (LSHIFT , $1, $3); }
824 | exp RSHIFT exp
825 { $$ = exp_binop (RSHIFT , $1, $3); }
826 | exp EQ exp
827 { $$ = exp_binop (EQ , $1, $3); }
828 | exp NE exp
829 { $$ = exp_binop (NE , $1, $3); }
830 | exp LE exp
831 { $$ = exp_binop (LE , $1, $3); }
832 | exp GE exp
833 { $$ = exp_binop (GE , $1, $3); }
834 | exp '<' exp
835 { $$ = exp_binop ('<' , $1, $3); }
836 | exp '>' exp
837 { $$ = exp_binop ('>' , $1, $3); }
838 | exp '&' exp
839 { $$ = exp_binop ('&' , $1, $3); }
840 | exp '^' exp
841 { $$ = exp_binop ('^' , $1, $3); }
842 | exp '|' exp
843 { $$ = exp_binop ('|' , $1, $3); }
844 | exp '?' exp ':' exp
845 { $$ = exp_trinop ('?' , $1, $3, $5); }
846 | exp ANDAND exp
847 { $$ = exp_binop (ANDAND , $1, $3); }
848 | exp OROR exp
849 { $$ = exp_binop (OROR , $1, $3); }
850 | DEFINED '(' NAME ')'
851 { $$ = exp_nameop (DEFINED, $3); }
852 | INT
853 { $$ = exp_bigintop ($1.integer, $1.str); }
854 | SIZEOF_HEADERS
855 { $$ = exp_nameop (SIZEOF_HEADERS,0); }
857 | ALIGNOF '(' NAME ')'
858 { $$ = exp_nameop (ALIGNOF,$3); }
859 | SIZEOF '(' NAME ')'
860 { $$ = exp_nameop (SIZEOF,$3); }
861 | ADDR '(' NAME ')'
862 { $$ = exp_nameop (ADDR,$3); }
863 | LOADADDR '(' NAME ')'
864 { $$ = exp_nameop (LOADADDR,$3); }
865 | CONSTANT '(' NAME ')'
866 { $$ = exp_nameop (CONSTANT,$3); }
867 | ABSOLUTE '(' exp ')'
868 { $$ = exp_unop (ABSOLUTE, $3); }
869 | ALIGN_K '(' exp ')'
870 { $$ = exp_unop (ALIGN_K,$3); }
871 | ALIGN_K '(' exp ',' exp ')'
872 { $$ = exp_binop (ALIGN_K,$3,$5); }
873 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
874 { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
875 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
876 { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
877 | DATA_SEGMENT_END '(' exp ')'
878 { $$ = exp_unop (DATA_SEGMENT_END, $3); }
879 | SEGMENT_START '(' NAME ',' exp ')'
880 { /* The operands to the expression node are
881 placed in the opposite order from the way
882 in which they appear in the script as
883 that allows us to reuse more code in
884 fold_binary. */
885 $$ = exp_binop (SEGMENT_START,
887 exp_nameop (NAME, $3)); }
888 | BLOCK '(' exp ')'
889 { $$ = exp_unop (ALIGN_K,$3); }
890 | NAME
891 { $$ = exp_nameop (NAME,$1); }
892 | MAX_K '(' exp ',' exp ')'
893 { $$ = exp_binop (MAX_K, $3, $5 ); }
894 | MIN_K '(' exp ',' exp ')'
895 { $$ = exp_binop (MIN_K, $3, $5 ); }
896 | ASSERT_K '(' exp ',' NAME ')'
897 { $$ = exp_assert ($3, $5); }
898 | ORIGIN '(' NAME ')'
899 { $$ = exp_nameop (ORIGIN, $3); }
900 | LENGTH '(' NAME ')'
901 { $$ = exp_nameop (LENGTH, $3); }
905 memspec_at_opt:
906 AT '>' NAME { $$ = $3; }
907 | { $$ = 0; }
910 opt_at:
911 AT '(' exp ')' { $$ = $3; }
912 | { $$ = 0; }
915 opt_align:
916 ALIGN_K '(' exp ')' { $$ = $3; }
917 | { $$ = 0; }
920 opt_subalign:
921 SUBALIGN '(' exp ')' { $$ = $3; }
922 | { $$ = 0; }
925 sect_constraint:
926 ONLY_IF_RO { $$ = ONLY_IF_RO; }
927 | ONLY_IF_RW { $$ = ONLY_IF_RW; }
928 | SPECIAL { $$ = SPECIAL; }
929 | { $$ = 0; }
932 section: NAME { ldlex_expression(); }
933 opt_exp_with_type
934 opt_at
935 opt_align
936 opt_subalign { ldlex_popstate (); ldlex_script (); }
937 sect_constraint
940 lang_enter_output_section_statement($1, $3,
941 sectype,
942 $5, $6, $4, $8);
944 statement_list_opt
945 '}' { ldlex_popstate (); ldlex_expression (); }
946 memspec_opt memspec_at_opt phdr_opt fill_opt
948 ldlex_popstate ();
949 lang_leave_output_section_statement ($17, $14, $16, $15);
951 opt_comma
953 | OVERLAY
954 { ldlex_expression (); }
955 opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
956 { ldlex_popstate (); ldlex_script (); }
959 lang_enter_overlay ($3, $6);
961 overlay_section
963 { ldlex_popstate (); ldlex_expression (); }
964 memspec_opt memspec_at_opt phdr_opt fill_opt
966 ldlex_popstate ();
967 lang_leave_overlay ($5, (int) $4,
968 $16, $13, $15, $14);
970 opt_comma
971 | /* The GROUP case is just enough to support the gcc
972 svr3.ifile script. It is not intended to be full
973 support. I'm not even sure what GROUP is supposed
974 to mean. */
975 GROUP { ldlex_expression (); }
976 opt_exp_with_type
978 ldlex_popstate ();
979 lang_add_assignment (exp_assop ('=', ".", $3));
981 '{' sec_or_group_p1 '}'
982 | INCLUDE filename
983 { ldlex_script (); ldfile_open_command_file($2); }
984 sec_or_group_p1 END
985 { ldlex_popstate (); }
988 type:
989 NOLOAD { sectype = noload_section; }
990 | DSECT { sectype = noalloc_section; }
991 | COPY { sectype = noalloc_section; }
992 | INFO { sectype = noalloc_section; }
993 | OVERLAY { sectype = noalloc_section; }
996 atype:
997 '(' type ')'
998 | /* EMPTY */ { sectype = normal_section; }
999 | '(' ')' { sectype = normal_section; }
1002 opt_exp_with_type:
1003 exp atype ':' { $$ = $1; }
1004 | atype ':' { $$ = (etree_type *)NULL; }
1005 | /* The BIND cases are to support the gcc svr3.ifile
1006 script. They aren't intended to implement full
1007 support for the BIND keyword. I'm not even sure
1008 what BIND is supposed to mean. */
1009 BIND '(' exp ')' atype ':' { $$ = $3; }
1010 | BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
1011 { $$ = $3; }
1014 opt_exp_without_type:
1015 exp ':' { $$ = $1; }
1016 | ':' { $$ = (etree_type *) NULL; }
1019 opt_nocrossrefs:
1020 /* empty */
1021 { $$ = 0; }
1022 | NOCROSSREFS
1023 { $$ = 1; }
1026 memspec_opt:
1027 '>' NAME
1028 { $$ = $2; }
1029 | { $$ = DEFAULT_MEMORY_REGION; }
1032 phdr_opt:
1033 /* empty */
1035 $$ = NULL;
1037 | phdr_opt ':' NAME
1039 struct lang_output_section_phdr_list *n;
1041 n = ((struct lang_output_section_phdr_list *)
1042 xmalloc (sizeof *n));
1043 n->name = $3;
1044 n->used = FALSE;
1045 n->next = $1;
1046 $$ = n;
1050 overlay_section:
1051 /* empty */
1052 | overlay_section
1053 NAME
1055 ldlex_script ();
1056 lang_enter_overlay_section ($2);
1058 '{' statement_list_opt '}'
1059 { ldlex_popstate (); ldlex_expression (); }
1060 phdr_opt fill_opt
1062 ldlex_popstate ();
1063 lang_leave_overlay_section ($9, $8);
1065 opt_comma
1068 phdrs:
1069 PHDRS '{' phdr_list '}'
1072 phdr_list:
1073 /* empty */
1074 | phdr_list phdr
1077 phdr:
1078 NAME { ldlex_expression (); }
1079 phdr_type phdr_qualifiers { ldlex_popstate (); }
1082 lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1083 $4.flags);
1087 phdr_type:
1090 $$ = $1;
1092 if ($1->type.node_class == etree_name
1093 && $1->type.node_code == NAME)
1095 const char *s;
1096 unsigned int i;
1097 static const char * const phdr_types[] =
1099 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1100 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
1101 "PT_PHDR", "PT_TLS"
1104 s = $1->name.name;
1105 for (i = 0;
1106 i < sizeof phdr_types / sizeof phdr_types[0];
1107 i++)
1108 if (strcmp (s, phdr_types[i]) == 0)
1110 $$ = exp_intop (i);
1111 break;
1113 if (i == sizeof phdr_types / sizeof phdr_types[0])
1115 if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1116 $$ = exp_intop (0x6474e550);
1117 else if (strcmp (s, "PT_GNU_STACK") == 0)
1118 $$ = exp_intop (0x6474e551);
1119 else
1121 einfo (_("\
1122 %X%P:%S: unknown phdr type `%s' (try integer literal)\n"),
1124 $$ = exp_intop (0);
1131 phdr_qualifiers:
1132 /* empty */
1134 memset (&$$, 0, sizeof (struct phdr_info));
1136 | NAME phdr_val phdr_qualifiers
1138 $$ = $3;
1139 if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
1140 $$.filehdr = TRUE;
1141 else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
1142 $$.phdrs = TRUE;
1143 else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1144 $$.flags = $2;
1145 else
1146 einfo (_("%X%P:%S: PHDRS syntax error at `%s'\n"), $1);
1148 | AT '(' exp ')' phdr_qualifiers
1150 $$ = $5;
1151 $$.at = $3;
1155 phdr_val:
1156 /* empty */
1158 $$ = NULL;
1160 | '(' exp ')'
1162 $$ = $2;
1166 dynamic_list_file:
1168 ldlex_version_file ();
1169 PUSH_ERROR (_("dynamic list"));
1171 dynamic_list_nodes
1173 ldlex_popstate ();
1174 POP_ERROR ();
1178 dynamic_list_nodes:
1179 dynamic_list_node
1180 | dynamic_list_nodes dynamic_list_node
1183 dynamic_list_node:
1184 '{' dynamic_list_tag '}' ';'
1187 dynamic_list_tag:
1188 vers_defns ';'
1190 lang_append_dynamic_list ($1);
1194 /* This syntax is used within an external version script file. */
1196 version_script_file:
1198 ldlex_version_file ();
1199 PUSH_ERROR (_("VERSION script"));
1201 vers_nodes
1203 ldlex_popstate ();
1204 POP_ERROR ();
1208 /* This is used within a normal linker script file. */
1210 version:
1212 ldlex_version_script ();
1214 VERSIONK '{' vers_nodes '}'
1216 ldlex_popstate ();
1220 vers_nodes:
1221 vers_node
1222 | vers_nodes vers_node
1225 vers_node:
1226 '{' vers_tag '}' ';'
1228 lang_register_vers_node (NULL, $2, NULL);
1230 | VERS_TAG '{' vers_tag '}' ';'
1232 lang_register_vers_node ($1, $3, NULL);
1234 | VERS_TAG '{' vers_tag '}' verdep ';'
1236 lang_register_vers_node ($1, $3, $5);
1240 verdep:
1241 VERS_TAG
1243 $$ = lang_add_vers_depend (NULL, $1);
1245 | verdep VERS_TAG
1247 $$ = lang_add_vers_depend ($1, $2);
1251 vers_tag:
1252 /* empty */
1254 $$ = lang_new_vers_node (NULL, NULL);
1256 | vers_defns ';'
1258 $$ = lang_new_vers_node ($1, NULL);
1260 | GLOBAL ':' vers_defns ';'
1262 $$ = lang_new_vers_node ($3, NULL);
1264 | LOCAL ':' vers_defns ';'
1266 $$ = lang_new_vers_node (NULL, $3);
1268 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1270 $$ = lang_new_vers_node ($3, $7);
1274 vers_defns:
1275 VERS_IDENTIFIER
1277 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, FALSE);
1279 | NAME
1281 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, TRUE);
1283 | vers_defns ';' VERS_IDENTIFIER
1285 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, FALSE);
1287 | vers_defns ';' NAME
1289 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, TRUE);
1291 | vers_defns ';' EXTERN NAME '{'
1293 $<name>$ = ldgram_vers_current_lang;
1294 ldgram_vers_current_lang = $4;
1296 vers_defns opt_semicolon '}'
1298 struct bfd_elf_version_expr *pat;
1299 for (pat = $7; pat->next != NULL; pat = pat->next);
1300 pat->next = $1;
1301 $$ = $7;
1302 ldgram_vers_current_lang = $<name>6;
1304 | EXTERN NAME '{'
1306 $<name>$ = ldgram_vers_current_lang;
1307 ldgram_vers_current_lang = $2;
1309 vers_defns opt_semicolon '}'
1311 $$ = $5;
1312 ldgram_vers_current_lang = $<name>4;
1314 | GLOBAL
1316 $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, FALSE);
1318 | vers_defns ';' GLOBAL
1320 $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, FALSE);
1322 | LOCAL
1324 $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, FALSE);
1326 | vers_defns ';' LOCAL
1328 $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, FALSE);
1330 | EXTERN
1332 $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, FALSE);
1334 | vers_defns ';' EXTERN
1336 $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, FALSE);
1340 opt_semicolon:
1341 /* empty */
1342 | ';'
1346 void
1347 yyerror(arg)
1348 const char *arg;
1350 if (ldfile_assumed_script)
1351 einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
1352 ldfile_input_filename);
1353 if (error_index > 0 && error_index < ERROR_NAME_MAX)
1354 einfo ("%P%F:%S: %s in %s\n", arg, error_names[error_index-1]);
1355 else
1356 einfo ("%P%F:%S: %s\n", arg);