daily update
[binutils.git] / ld / ldgram.y
blob3795ffeb8f002d0ced6672613e2a4cae0e9f82a6
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, 2010, 2011
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 SORT_BY_INIT_PRIORITY
130 %token '{' '}'
131 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
132 %token INHIBIT_COMMON_ALLOCATION
133 %token SEGMENT_START
134 %token INCLUDE
135 %token MEMORY
136 %token REGION_ALIAS
137 %token LD_FEATURE
138 %token NOLOAD DSECT COPY INFO OVERLAY
139 %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY
140 %token <integer> NEXT
141 %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K
142 %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS
143 %token ORIGIN FILL
144 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
145 %token ALIGNMOD AT SUBALIGN PROVIDE PROVIDE_HIDDEN AS_NEEDED
146 %type <token> assign_op atype attributes_opt sect_constraint
147 %type <name> filename
148 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
149 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
150 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
151 %token <name> VERS_TAG VERS_IDENTIFIER
152 %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
153 %token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL
154 %token EXCLUDE_FILE
155 %token CONSTANT
156 %type <versyms> vers_defns
157 %type <versnode> vers_tag
158 %type <deflist> verdep
159 %token INPUT_DYNAMIC_LIST
163 file:
164 INPUT_SCRIPT script_file
165 | INPUT_MRI_SCRIPT mri_script_file
166 | INPUT_VERSION_SCRIPT version_script_file
167 | INPUT_DYNAMIC_LIST dynamic_list_file
168 | INPUT_DEFSYM defsym_expr
172 filename: NAME;
175 defsym_expr:
176 { ldlex_defsym(); }
177 NAME '=' exp
179 ldlex_popstate();
180 lang_add_assignment (exp_defsym ($2, $4));
184 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
185 mri_script_file:
187 ldlex_mri_script ();
188 PUSH_ERROR (_("MRI style script"));
190 mri_script_lines
192 ldlex_popstate ();
193 mri_draw_tree ();
194 POP_ERROR ();
198 mri_script_lines:
199 mri_script_lines mri_script_command NEWLINE
203 mri_script_command:
204 CHIP exp
205 | CHIP exp ',' exp
206 | NAME {
207 einfo(_("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1);
209 | LIST {
210 config.map_filename = "-";
212 | ORDER ordernamelist
213 | ENDWORD
214 | PUBLIC NAME '=' exp
215 { mri_public($2, $4); }
216 | PUBLIC NAME ',' exp
217 { mri_public($2, $4); }
218 | PUBLIC NAME exp
219 { mri_public($2, $3); }
220 | FORMAT NAME
221 { mri_format($2); }
222 | SECT NAME ',' exp
223 { mri_output_section($2, $4);}
224 | SECT NAME exp
225 { mri_output_section($2, $3);}
226 | SECT NAME '=' exp
227 { mri_output_section($2, $4);}
228 | ALIGN_K NAME '=' exp
229 { mri_align($2,$4); }
230 | ALIGN_K NAME ',' exp
231 { mri_align($2,$4); }
232 | ALIGNMOD NAME '=' exp
233 { mri_alignmod($2,$4); }
234 | ALIGNMOD NAME ',' exp
235 { mri_alignmod($2,$4); }
236 | ABSOLUTE mri_abs_name_list
237 | LOAD mri_load_name_list
238 | NAMEWORD NAME
239 { mri_name($2); }
240 | ALIAS NAME ',' NAME
241 { mri_alias($2,$4,0);}
242 | ALIAS NAME ',' INT
243 { mri_alias ($2, 0, (int) $4.integer); }
244 | BASE exp
245 { mri_base($2); }
246 | TRUNCATE INT
247 { mri_truncate ((unsigned int) $2.integer); }
248 | CASE casesymlist
249 | EXTERN extern_name_list
250 | INCLUDE filename
251 { ldlex_script (); ldfile_open_command_file($2); }
252 mri_script_lines END
253 { ldlex_popstate (); }
254 | START NAME
255 { lang_add_entry ($2, FALSE); }
259 ordernamelist:
260 ordernamelist ',' NAME { mri_order($3); }
261 | ordernamelist NAME { mri_order($2); }
265 mri_load_name_list:
266 NAME
267 { mri_load($1); }
268 | mri_load_name_list ',' NAME { mri_load($3); }
271 mri_abs_name_list:
272 NAME
273 { mri_only_load($1); }
274 | mri_abs_name_list ',' NAME
275 { mri_only_load($3); }
278 casesymlist:
279 /* empty */ { $$ = NULL; }
280 | NAME
281 | casesymlist ',' NAME
284 /* Parsed as expressions so that commas separate entries */
285 extern_name_list:
286 { ldlex_expression (); }
287 extern_name_list_body
288 { ldlex_popstate (); }
290 extern_name_list_body:
291 NAME
292 { ldlang_add_undef ($1, FALSE); }
293 | extern_name_list_body NAME
294 { ldlang_add_undef ($2, FALSE); }
295 | extern_name_list_body ',' NAME
296 { ldlang_add_undef ($3, FALSE); }
299 script_file:
300 { ldlex_both(); }
301 ifile_list
302 { ldlex_popstate(); }
305 ifile_list:
306 ifile_list ifile_p1
311 ifile_p1:
312 memory
313 | sections
314 | phdrs
315 | startup
316 | high_level_library
317 | low_level_library
318 | floating_point_support
319 | statement_anywhere
320 | version
321 | ';'
322 | TARGET_K '(' NAME ')'
323 { lang_add_target($3); }
324 | SEARCH_DIR '(' filename ')'
325 { ldfile_add_library_path ($3, FALSE); }
326 | OUTPUT '(' filename ')'
327 { lang_add_output($3, 1); }
328 | OUTPUT_FORMAT '(' NAME ')'
329 { lang_add_output_format ($3, (char *) NULL,
330 (char *) NULL, 1); }
331 | OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')'
332 { lang_add_output_format ($3, $5, $7, 1); }
333 | OUTPUT_ARCH '(' NAME ')'
334 { ldfile_set_output_arch ($3, bfd_arch_unknown); }
335 | FORCE_COMMON_ALLOCATION
336 { command_line.force_common_definition = TRUE ; }
337 | INHIBIT_COMMON_ALLOCATION
338 { command_line.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 { ldlex_script (); ldfile_open_command_file($2); }
348 ifile_list END
349 { ldlex_popstate (); }
350 | NOCROSSREFS '(' nocrossref_list ')'
352 lang_add_nocrossref ($3);
354 | EXTERN '(' extern_name_list ')'
355 | INSERT_K AFTER NAME
356 { lang_add_insert ($3, 0); }
357 | INSERT_K BEFORE NAME
358 { lang_add_insert ($3, 1); }
359 | REGION_ALIAS '(' NAME ',' NAME ')'
360 { lang_memory_region_alias ($3, $5); }
361 | LD_FEATURE '(' NAME ')'
362 { lang_ld_feature ($3); }
365 input_list:
366 NAME
367 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
368 (char *)NULL); }
369 | input_list ',' NAME
370 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
371 (char *)NULL); }
372 | input_list NAME
373 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
374 (char *)NULL); }
375 | LNAME
376 { lang_add_input_file($1,lang_input_file_is_l_enum,
377 (char *)NULL); }
378 | input_list ',' LNAME
379 { lang_add_input_file($3,lang_input_file_is_l_enum,
380 (char *)NULL); }
381 | input_list LNAME
382 { lang_add_input_file($2,lang_input_file_is_l_enum,
383 (char *)NULL); }
384 | 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>3; }
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>5; }
392 | input_list AS_NEEDED '('
393 { $<integer>$ = add_DT_NEEDED_for_regular; add_DT_NEEDED_for_regular = TRUE; }
394 input_list ')'
395 { add_DT_NEEDED_for_regular = $<integer>4; }
398 sections:
399 SECTIONS '{' sec_or_group_p1 '}'
402 sec_or_group_p1:
403 sec_or_group_p1 section
404 | sec_or_group_p1 statement_anywhere
408 statement_anywhere:
409 ENTRY '(' NAME ')'
410 { lang_add_entry ($3, FALSE); }
411 | assignment end
412 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')'
413 { ldlex_popstate ();
414 lang_add_assignment (exp_assert ($4, $6)); }
417 /* The '*' and '?' cases are there because the lexer returns them as
418 separate tokens rather than as NAME. */
419 wildcard_name:
420 NAME
422 $$ = $1;
424 | '*'
426 $$ = "*";
428 | '?'
430 $$ = "?";
434 wildcard_spec:
435 wildcard_name
437 $$.name = $1;
438 $$.sorted = none;
439 $$.exclude_name_list = NULL;
441 | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
443 $$.name = $5;
444 $$.sorted = none;
445 $$.exclude_name_list = $3;
447 | SORT_BY_NAME '(' wildcard_name ')'
449 $$.name = $3;
450 $$.sorted = by_name;
451 $$.exclude_name_list = NULL;
453 | SORT_BY_ALIGNMENT '(' wildcard_name ')'
455 $$.name = $3;
456 $$.sorted = by_alignment;
457 $$.exclude_name_list = NULL;
459 | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
461 $$.name = $5;
462 $$.sorted = by_name_alignment;
463 $$.exclude_name_list = NULL;
465 | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_name ')' ')'
467 $$.name = $5;
468 $$.sorted = by_name;
469 $$.exclude_name_list = NULL;
471 | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_name ')' ')'
473 $$.name = $5;
474 $$.sorted = by_alignment_name;
475 $$.exclude_name_list = NULL;
477 | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
479 $$.name = $5;
480 $$.sorted = by_alignment;
481 $$.exclude_name_list = NULL;
483 | SORT_BY_NAME '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')'
485 $$.name = $7;
486 $$.sorted = by_name;
487 $$.exclude_name_list = $5;
489 | SORT_BY_INIT_PRIORITY '(' wildcard_name ')'
491 $$.name = $3;
492 $$.sorted = by_init_priority;
493 $$.exclude_name_list = NULL;
497 exclude_name_list:
498 exclude_name_list wildcard_name
500 struct name_list *tmp;
501 tmp = (struct name_list *) xmalloc (sizeof *tmp);
502 tmp->name = $2;
503 tmp->next = $1;
504 $$ = tmp;
507 wildcard_name
509 struct name_list *tmp;
510 tmp = (struct name_list *) xmalloc (sizeof *tmp);
511 tmp->name = $1;
512 tmp->next = NULL;
513 $$ = tmp;
517 file_NAME_list:
518 file_NAME_list opt_comma wildcard_spec
520 struct wildcard_list *tmp;
521 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
522 tmp->next = $1;
523 tmp->spec = $3;
524 $$ = tmp;
527 wildcard_spec
529 struct wildcard_list *tmp;
530 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
531 tmp->next = NULL;
532 tmp->spec = $1;
533 $$ = tmp;
537 input_section_spec_no_keep:
538 NAME
540 struct wildcard_spec tmp;
541 tmp.name = $1;
542 tmp.exclude_name_list = NULL;
543 tmp.sorted = none;
544 lang_add_wild (&tmp, NULL, ldgram_had_keep);
546 | '[' file_NAME_list ']'
548 lang_add_wild (NULL, $2, ldgram_had_keep);
550 | wildcard_spec '(' file_NAME_list ')'
552 lang_add_wild (&$1, $3, ldgram_had_keep);
556 input_section_spec:
557 input_section_spec_no_keep
558 | KEEP '('
559 { ldgram_had_keep = TRUE; }
560 input_section_spec_no_keep ')'
561 { ldgram_had_keep = FALSE; }
564 statement:
565 assignment end
566 | CREATE_OBJECT_SYMBOLS
568 lang_add_attribute(lang_object_symbols_statement_enum);
570 | ';'
571 | CONSTRUCTORS
574 lang_add_attribute(lang_constructors_statement_enum);
576 | SORT_BY_NAME '(' CONSTRUCTORS ')'
578 constructors_sorted = TRUE;
579 lang_add_attribute (lang_constructors_statement_enum);
581 | input_section_spec
582 | length '(' mustbe_exp ')'
584 lang_add_data ((int) $1, $3);
587 | FILL '(' fill_exp ')'
589 lang_add_fill ($3);
591 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')' end
592 { ldlex_popstate ();
593 lang_add_assignment (exp_assert ($4, $6)); }
594 | INCLUDE filename
595 { ldlex_script (); ldfile_open_command_file($2); }
596 statement_list_opt END
597 { ldlex_popstate (); }
600 statement_list:
601 statement_list statement
602 | statement
605 statement_list_opt:
606 /* empty */
607 | statement_list
610 length:
611 QUAD
612 { $$ = $1; }
613 | SQUAD
614 { $$ = $1; }
615 | LONG
616 { $$ = $1; }
617 | SHORT
618 { $$ = $1; }
619 | BYTE
620 { $$ = $1; }
623 fill_exp:
624 mustbe_exp
626 $$ = exp_get_fill ($1, 0, "fill value");
630 fill_opt:
631 '=' fill_exp
632 { $$ = $2; }
633 | { $$ = (fill_type *) 0; }
636 assign_op:
637 PLUSEQ
638 { $$ = '+'; }
639 | MINUSEQ
640 { $$ = '-'; }
641 | MULTEQ
642 { $$ = '*'; }
643 | DIVEQ
644 { $$ = '/'; }
645 | LSHIFTEQ
646 { $$ = LSHIFT; }
647 | RSHIFTEQ
648 { $$ = RSHIFT; }
649 | ANDEQ
650 { $$ = '&'; }
651 | OREQ
652 { $$ = '|'; }
656 end: ';' | ','
660 assignment:
661 NAME '=' mustbe_exp
663 lang_add_assignment (exp_assign ($1, $3));
665 | NAME assign_op mustbe_exp
667 lang_add_assignment (exp_assign ($1,
668 exp_binop ($2,
669 exp_nameop (NAME,
670 $1),
671 $3)));
673 | PROVIDE '(' NAME '=' mustbe_exp ')'
675 lang_add_assignment (exp_provide ($3, $5, FALSE));
677 | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
679 lang_add_assignment (exp_provide ($3, $5, TRUE));
684 opt_comma:
685 ',' | ;
688 memory:
689 MEMORY '{' memory_spec_list_opt '}'
692 memory_spec_list_opt: memory_spec_list | ;
694 memory_spec_list:
695 memory_spec_list opt_comma memory_spec
696 | memory_spec
700 memory_spec: NAME
701 { region = lang_memory_region_lookup ($1, TRUE); }
702 attributes_opt ':'
703 origin_spec opt_comma length_spec
705 | INCLUDE filename
706 { ldlex_script (); ldfile_open_command_file($2); }
707 memory_spec_list_opt END
708 { ldlex_popstate (); }
711 origin_spec:
712 ORIGIN '=' mustbe_exp
714 region->origin = exp_get_vma ($3, 0, "origin");
715 region->current = region->origin;
719 length_spec:
720 LENGTH '=' mustbe_exp
722 region->length = exp_get_vma ($3, -1, "length");
726 attributes_opt:
727 /* empty */
728 { /* dummy action to avoid bison 1.25 error message */ }
729 | '(' attributes_list ')'
732 attributes_list:
733 attributes_string
734 | attributes_list attributes_string
737 attributes_string:
738 NAME
739 { lang_set_flags (region, $1, 0); }
740 | '!' NAME
741 { lang_set_flags (region, $2, 1); }
744 startup:
745 STARTUP '(' filename ')'
746 { lang_startup($3); }
749 high_level_library:
750 HLL '(' high_level_library_NAME_list ')'
751 | HLL '(' ')'
752 { ldemul_hll((char *)NULL); }
755 high_level_library_NAME_list:
756 high_level_library_NAME_list opt_comma filename
757 { ldemul_hll($3); }
758 | filename
759 { ldemul_hll($1); }
763 low_level_library:
764 SYSLIB '(' low_level_library_NAME_list ')'
765 ; low_level_library_NAME_list:
766 low_level_library_NAME_list opt_comma filename
767 { ldemul_syslib($3); }
771 floating_point_support:
772 FLOAT
773 { lang_float(TRUE); }
774 | NOFLOAT
775 { lang_float(FALSE); }
778 nocrossref_list:
779 /* empty */
781 $$ = NULL;
783 | NAME nocrossref_list
785 struct lang_nocrossref *n;
787 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
788 n->name = $1;
789 n->next = $2;
790 $$ = n;
792 | NAME ',' nocrossref_list
794 struct lang_nocrossref *n;
796 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
797 n->name = $1;
798 n->next = $3;
799 $$ = n;
803 mustbe_exp: { ldlex_expression (); }
805 { ldlex_popstate (); $$=$2;}
808 exp :
809 '-' exp %prec UNARY
810 { $$ = exp_unop ('-', $2); }
811 | '(' exp ')'
812 { $$ = $2; }
813 | NEXT '(' exp ')' %prec UNARY
814 { $$ = exp_unop ((int) $1,$3); }
815 | '!' exp %prec UNARY
816 { $$ = exp_unop ('!', $2); }
817 | '+' exp %prec UNARY
818 { $$ = $2; }
819 | '~' exp %prec UNARY
820 { $$ = exp_unop ('~', $2);}
822 | exp '*' exp
823 { $$ = exp_binop ('*', $1, $3); }
824 | exp '/' exp
825 { $$ = exp_binop ('/', $1, $3); }
826 | exp '%' exp
827 { $$ = exp_binop ('%', $1, $3); }
828 | exp '+' exp
829 { $$ = exp_binop ('+', $1, $3); }
830 | exp '-' exp
831 { $$ = exp_binop ('-' , $1, $3); }
832 | exp LSHIFT exp
833 { $$ = exp_binop (LSHIFT , $1, $3); }
834 | exp RSHIFT exp
835 { $$ = exp_binop (RSHIFT , $1, $3); }
836 | exp EQ exp
837 { $$ = exp_binop (EQ , $1, $3); }
838 | exp NE exp
839 { $$ = exp_binop (NE , $1, $3); }
840 | exp LE exp
841 { $$ = exp_binop (LE , $1, $3); }
842 | exp GE exp
843 { $$ = exp_binop (GE , $1, $3); }
844 | exp '<' exp
845 { $$ = exp_binop ('<' , $1, $3); }
846 | exp '>' exp
847 { $$ = exp_binop ('>' , $1, $3); }
848 | exp '&' exp
849 { $$ = exp_binop ('&' , $1, $3); }
850 | exp '^' exp
851 { $$ = exp_binop ('^' , $1, $3); }
852 | exp '|' exp
853 { $$ = exp_binop ('|' , $1, $3); }
854 | exp '?' exp ':' exp
855 { $$ = exp_trinop ('?' , $1, $3, $5); }
856 | exp ANDAND exp
857 { $$ = exp_binop (ANDAND , $1, $3); }
858 | exp OROR exp
859 { $$ = exp_binop (OROR , $1, $3); }
860 | DEFINED '(' NAME ')'
861 { $$ = exp_nameop (DEFINED, $3); }
862 | INT
863 { $$ = exp_bigintop ($1.integer, $1.str); }
864 | SIZEOF_HEADERS
865 { $$ = exp_nameop (SIZEOF_HEADERS,0); }
867 | ALIGNOF '(' NAME ')'
868 { $$ = exp_nameop (ALIGNOF,$3); }
869 | SIZEOF '(' NAME ')'
870 { $$ = exp_nameop (SIZEOF,$3); }
871 | ADDR '(' NAME ')'
872 { $$ = exp_nameop (ADDR,$3); }
873 | LOADADDR '(' NAME ')'
874 { $$ = exp_nameop (LOADADDR,$3); }
875 | CONSTANT '(' NAME ')'
876 { $$ = exp_nameop (CONSTANT,$3); }
877 | ABSOLUTE '(' exp ')'
878 { $$ = exp_unop (ABSOLUTE, $3); }
879 | ALIGN_K '(' exp ')'
880 { $$ = exp_unop (ALIGN_K,$3); }
881 | ALIGN_K '(' exp ',' exp ')'
882 { $$ = exp_binop (ALIGN_K,$3,$5); }
883 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
884 { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
885 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
886 { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
887 | DATA_SEGMENT_END '(' exp ')'
888 { $$ = exp_unop (DATA_SEGMENT_END, $3); }
889 | SEGMENT_START '(' NAME ',' exp ')'
890 { /* The operands to the expression node are
891 placed in the opposite order from the way
892 in which they appear in the script as
893 that allows us to reuse more code in
894 fold_binary. */
895 $$ = exp_binop (SEGMENT_START,
897 exp_nameop (NAME, $3)); }
898 | BLOCK '(' exp ')'
899 { $$ = exp_unop (ALIGN_K,$3); }
900 | NAME
901 { $$ = exp_nameop (NAME,$1); }
902 | MAX_K '(' exp ',' exp ')'
903 { $$ = exp_binop (MAX_K, $3, $5 ); }
904 | MIN_K '(' exp ',' exp ')'
905 { $$ = exp_binop (MIN_K, $3, $5 ); }
906 | ASSERT_K '(' exp ',' NAME ')'
907 { $$ = exp_assert ($3, $5); }
908 | ORIGIN '(' NAME ')'
909 { $$ = exp_nameop (ORIGIN, $3); }
910 | LENGTH '(' NAME ')'
911 { $$ = exp_nameop (LENGTH, $3); }
915 memspec_at_opt:
916 AT '>' NAME { $$ = $3; }
917 | { $$ = 0; }
920 opt_at:
921 AT '(' exp ')' { $$ = $3; }
922 | { $$ = 0; }
925 opt_align:
926 ALIGN_K '(' exp ')' { $$ = $3; }
927 | { $$ = 0; }
930 opt_subalign:
931 SUBALIGN '(' exp ')' { $$ = $3; }
932 | { $$ = 0; }
935 sect_constraint:
936 ONLY_IF_RO { $$ = ONLY_IF_RO; }
937 | ONLY_IF_RW { $$ = ONLY_IF_RW; }
938 | SPECIAL { $$ = SPECIAL; }
939 | { $$ = 0; }
942 section: NAME { ldlex_expression(); }
943 opt_exp_with_type
944 opt_at
945 opt_align
946 opt_subalign { ldlex_popstate (); ldlex_script (); }
947 sect_constraint
950 lang_enter_output_section_statement($1, $3,
951 sectype,
952 $5, $6, $4, $8);
954 statement_list_opt
955 '}' { ldlex_popstate (); ldlex_expression (); }
956 memspec_opt memspec_at_opt phdr_opt fill_opt
958 ldlex_popstate ();
959 lang_leave_output_section_statement ($17, $14, $16, $15);
961 opt_comma
963 | OVERLAY
964 { ldlex_expression (); }
965 opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
966 { ldlex_popstate (); ldlex_script (); }
969 lang_enter_overlay ($3, $6);
971 overlay_section
973 { ldlex_popstate (); ldlex_expression (); }
974 memspec_opt memspec_at_opt phdr_opt fill_opt
976 ldlex_popstate ();
977 lang_leave_overlay ($5, (int) $4,
978 $16, $13, $15, $14);
980 opt_comma
981 | /* The GROUP case is just enough to support the gcc
982 svr3.ifile script. It is not intended to be full
983 support. I'm not even sure what GROUP is supposed
984 to mean. */
985 GROUP { ldlex_expression (); }
986 opt_exp_with_type
988 ldlex_popstate ();
989 lang_add_assignment (exp_assign (".", $3));
991 '{' sec_or_group_p1 '}'
992 | INCLUDE filename
993 { ldlex_script (); ldfile_open_command_file($2); }
994 sec_or_group_p1 END
995 { ldlex_popstate (); }
998 type:
999 NOLOAD { sectype = noload_section; }
1000 | DSECT { sectype = noalloc_section; }
1001 | COPY { sectype = noalloc_section; }
1002 | INFO { sectype = noalloc_section; }
1003 | OVERLAY { sectype = noalloc_section; }
1006 atype:
1007 '(' type ')'
1008 | /* EMPTY */ { sectype = normal_section; }
1009 | '(' ')' { sectype = normal_section; }
1012 opt_exp_with_type:
1013 exp atype ':' { $$ = $1; }
1014 | atype ':' { $$ = (etree_type *)NULL; }
1015 | /* The BIND cases are to support the gcc svr3.ifile
1016 script. They aren't intended to implement full
1017 support for the BIND keyword. I'm not even sure
1018 what BIND is supposed to mean. */
1019 BIND '(' exp ')' atype ':' { $$ = $3; }
1020 | BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
1021 { $$ = $3; }
1024 opt_exp_without_type:
1025 exp ':' { $$ = $1; }
1026 | ':' { $$ = (etree_type *) NULL; }
1029 opt_nocrossrefs:
1030 /* empty */
1031 { $$ = 0; }
1032 | NOCROSSREFS
1033 { $$ = 1; }
1036 memspec_opt:
1037 '>' NAME
1038 { $$ = $2; }
1039 | { $$ = DEFAULT_MEMORY_REGION; }
1042 phdr_opt:
1043 /* empty */
1045 $$ = NULL;
1047 | phdr_opt ':' NAME
1049 struct lang_output_section_phdr_list *n;
1051 n = ((struct lang_output_section_phdr_list *)
1052 xmalloc (sizeof *n));
1053 n->name = $3;
1054 n->used = FALSE;
1055 n->next = $1;
1056 $$ = n;
1060 overlay_section:
1061 /* empty */
1062 | overlay_section
1063 NAME
1065 ldlex_script ();
1066 lang_enter_overlay_section ($2);
1068 '{' statement_list_opt '}'
1069 { ldlex_popstate (); ldlex_expression (); }
1070 phdr_opt fill_opt
1072 ldlex_popstate ();
1073 lang_leave_overlay_section ($9, $8);
1075 opt_comma
1078 phdrs:
1079 PHDRS '{' phdr_list '}'
1082 phdr_list:
1083 /* empty */
1084 | phdr_list phdr
1087 phdr:
1088 NAME { ldlex_expression (); }
1089 phdr_type phdr_qualifiers { ldlex_popstate (); }
1092 lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1093 $4.flags);
1097 phdr_type:
1100 $$ = $1;
1102 if ($1->type.node_class == etree_name
1103 && $1->type.node_code == NAME)
1105 const char *s;
1106 unsigned int i;
1107 static const char * const phdr_types[] =
1109 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1110 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
1111 "PT_PHDR", "PT_TLS"
1114 s = $1->name.name;
1115 for (i = 0;
1116 i < sizeof phdr_types / sizeof phdr_types[0];
1117 i++)
1118 if (strcmp (s, phdr_types[i]) == 0)
1120 $$ = exp_intop (i);
1121 break;
1123 if (i == sizeof phdr_types / sizeof phdr_types[0])
1125 if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1126 $$ = exp_intop (0x6474e550);
1127 else if (strcmp (s, "PT_GNU_STACK") == 0)
1128 $$ = exp_intop (0x6474e551);
1129 else
1131 einfo (_("\
1132 %X%P:%S: unknown phdr type `%s' (try integer literal)\n"),
1134 $$ = exp_intop (0);
1141 phdr_qualifiers:
1142 /* empty */
1144 memset (&$$, 0, sizeof (struct phdr_info));
1146 | NAME phdr_val phdr_qualifiers
1148 $$ = $3;
1149 if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
1150 $$.filehdr = TRUE;
1151 else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
1152 $$.phdrs = TRUE;
1153 else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1154 $$.flags = $2;
1155 else
1156 einfo (_("%X%P:%S: PHDRS syntax error at `%s'\n"), $1);
1158 | AT '(' exp ')' phdr_qualifiers
1160 $$ = $5;
1161 $$.at = $3;
1165 phdr_val:
1166 /* empty */
1168 $$ = NULL;
1170 | '(' exp ')'
1172 $$ = $2;
1176 dynamic_list_file:
1178 ldlex_version_file ();
1179 PUSH_ERROR (_("dynamic list"));
1181 dynamic_list_nodes
1183 ldlex_popstate ();
1184 POP_ERROR ();
1188 dynamic_list_nodes:
1189 dynamic_list_node
1190 | dynamic_list_nodes dynamic_list_node
1193 dynamic_list_node:
1194 '{' dynamic_list_tag '}' ';'
1197 dynamic_list_tag:
1198 vers_defns ';'
1200 lang_append_dynamic_list ($1);
1204 /* This syntax is used within an external version script file. */
1206 version_script_file:
1208 ldlex_version_file ();
1209 PUSH_ERROR (_("VERSION script"));
1211 vers_nodes
1213 ldlex_popstate ();
1214 POP_ERROR ();
1218 /* This is used within a normal linker script file. */
1220 version:
1222 ldlex_version_script ();
1224 VERSIONK '{' vers_nodes '}'
1226 ldlex_popstate ();
1230 vers_nodes:
1231 vers_node
1232 | vers_nodes vers_node
1235 vers_node:
1236 '{' vers_tag '}' ';'
1238 lang_register_vers_node (NULL, $2, NULL);
1240 | VERS_TAG '{' vers_tag '}' ';'
1242 lang_register_vers_node ($1, $3, NULL);
1244 | VERS_TAG '{' vers_tag '}' verdep ';'
1246 lang_register_vers_node ($1, $3, $5);
1250 verdep:
1251 VERS_TAG
1253 $$ = lang_add_vers_depend (NULL, $1);
1255 | verdep VERS_TAG
1257 $$ = lang_add_vers_depend ($1, $2);
1261 vers_tag:
1262 /* empty */
1264 $$ = lang_new_vers_node (NULL, NULL);
1266 | vers_defns ';'
1268 $$ = lang_new_vers_node ($1, NULL);
1270 | GLOBAL ':' vers_defns ';'
1272 $$ = lang_new_vers_node ($3, NULL);
1274 | LOCAL ':' vers_defns ';'
1276 $$ = lang_new_vers_node (NULL, $3);
1278 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1280 $$ = lang_new_vers_node ($3, $7);
1284 vers_defns:
1285 VERS_IDENTIFIER
1287 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, FALSE);
1289 | NAME
1291 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, TRUE);
1293 | vers_defns ';' VERS_IDENTIFIER
1295 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, FALSE);
1297 | vers_defns ';' NAME
1299 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, TRUE);
1301 | vers_defns ';' EXTERN NAME '{'
1303 $<name>$ = ldgram_vers_current_lang;
1304 ldgram_vers_current_lang = $4;
1306 vers_defns opt_semicolon '}'
1308 struct bfd_elf_version_expr *pat;
1309 for (pat = $7; pat->next != NULL; pat = pat->next);
1310 pat->next = $1;
1311 $$ = $7;
1312 ldgram_vers_current_lang = $<name>6;
1314 | EXTERN NAME '{'
1316 $<name>$ = ldgram_vers_current_lang;
1317 ldgram_vers_current_lang = $2;
1319 vers_defns opt_semicolon '}'
1321 $$ = $5;
1322 ldgram_vers_current_lang = $<name>4;
1324 | GLOBAL
1326 $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, FALSE);
1328 | vers_defns ';' GLOBAL
1330 $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, FALSE);
1332 | LOCAL
1334 $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, FALSE);
1336 | vers_defns ';' LOCAL
1338 $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, FALSE);
1340 | EXTERN
1342 $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, FALSE);
1344 | vers_defns ';' EXTERN
1346 $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, FALSE);
1350 opt_semicolon:
1351 /* empty */
1352 | ';'
1356 void
1357 yyerror(arg)
1358 const char *arg;
1360 if (ldfile_assumed_script)
1361 einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
1362 ldfile_input_filename);
1363 if (error_index > 0 && error_index < ERROR_NAME_MAX)
1364 einfo ("%P%F:%S: %s in %s\n", arg, error_names[error_index-1]);
1365 else
1366 einfo ("%P%F:%S: %s\n", arg);