daily update
[binutils.git] / ld / ldgram.y
blobed0aaa76259933ba42e4eef343779ed173d1d354
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 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 NOLOAD DSECT COPY INFO OVERLAY
138 %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY
139 %token <integer> NEXT
140 %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K
141 %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS
142 %token ORIGIN FILL
143 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
144 %token ALIGNMOD AT SUBALIGN PROVIDE PROVIDE_HIDDEN AS_NEEDED
145 %type <token> assign_op atype attributes_opt sect_constraint
146 %type <name> filename
147 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
148 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
149 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
150 %token <name> VERS_TAG VERS_IDENTIFIER
151 %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
152 %token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL
153 %token EXCLUDE_FILE
154 %token CONSTANT
155 %type <versyms> vers_defns
156 %type <versnode> vers_tag
157 %type <deflist> verdep
158 %token INPUT_DYNAMIC_LIST
162 file:
163 INPUT_SCRIPT script_file
164 | INPUT_MRI_SCRIPT mri_script_file
165 | INPUT_VERSION_SCRIPT version_script_file
166 | INPUT_DYNAMIC_LIST dynamic_list_file
167 | INPUT_DEFSYM defsym_expr
171 filename: NAME;
174 defsym_expr:
175 { ldlex_defsym(); }
176 NAME '=' exp
178 ldlex_popstate();
179 lang_add_assignment(exp_assop($3,$2,$4));
183 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
184 mri_script_file:
186 ldlex_mri_script ();
187 PUSH_ERROR (_("MRI style script"));
189 mri_script_lines
191 ldlex_popstate ();
192 mri_draw_tree ();
193 POP_ERROR ();
197 mri_script_lines:
198 mri_script_lines mri_script_command NEWLINE
202 mri_script_command:
203 CHIP exp
204 | CHIP exp ',' exp
205 | NAME {
206 einfo(_("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1);
208 | LIST {
209 config.map_filename = "-";
211 | ORDER ordernamelist
212 | ENDWORD
213 | PUBLIC NAME '=' exp
214 { mri_public($2, $4); }
215 | PUBLIC NAME ',' exp
216 { mri_public($2, $4); }
217 | PUBLIC NAME exp
218 { mri_public($2, $3); }
219 | FORMAT NAME
220 { mri_format($2); }
221 | SECT NAME ',' exp
222 { mri_output_section($2, $4);}
223 | SECT NAME exp
224 { mri_output_section($2, $3);}
225 | SECT NAME '=' exp
226 { mri_output_section($2, $4);}
227 | ALIGN_K NAME '=' exp
228 { mri_align($2,$4); }
229 | ALIGN_K NAME ',' exp
230 { mri_align($2,$4); }
231 | ALIGNMOD NAME '=' exp
232 { mri_alignmod($2,$4); }
233 | ALIGNMOD NAME ',' exp
234 { mri_alignmod($2,$4); }
235 | ABSOLUTE mri_abs_name_list
236 | LOAD mri_load_name_list
237 | NAMEWORD NAME
238 { mri_name($2); }
239 | ALIAS NAME ',' NAME
240 { mri_alias($2,$4,0);}
241 | ALIAS NAME ',' INT
242 { mri_alias ($2, 0, (int) $4.integer); }
243 | BASE exp
244 { mri_base($2); }
245 | TRUNCATE INT
246 { mri_truncate ((unsigned int) $2.integer); }
247 | CASE casesymlist
248 | EXTERN extern_name_list
249 | INCLUDE filename
250 { ldlex_script (); ldfile_open_command_file($2); }
251 mri_script_lines END
252 { ldlex_popstate (); }
253 | START NAME
254 { lang_add_entry ($2, FALSE); }
258 ordernamelist:
259 ordernamelist ',' NAME { mri_order($3); }
260 | ordernamelist NAME { mri_order($2); }
264 mri_load_name_list:
265 NAME
266 { mri_load($1); }
267 | mri_load_name_list ',' NAME { mri_load($3); }
270 mri_abs_name_list:
271 NAME
272 { mri_only_load($1); }
273 | mri_abs_name_list ',' NAME
274 { mri_only_load($3); }
277 casesymlist:
278 /* empty */ { $$ = NULL; }
279 | NAME
280 | casesymlist ',' NAME
283 /* Parsed as expressions so that commas separate entries */
284 extern_name_list:
285 { ldlex_expression (); }
286 extern_name_list_body
287 { ldlex_popstate (); }
289 extern_name_list_body:
290 NAME
291 { ldlang_add_undef ($1, FALSE); }
292 | extern_name_list_body NAME
293 { ldlang_add_undef ($2, FALSE); }
294 | extern_name_list_body ',' NAME
295 { ldlang_add_undef ($3, FALSE); }
298 script_file:
299 { ldlex_both(); }
300 ifile_list
301 { ldlex_popstate(); }
304 ifile_list:
305 ifile_list ifile_p1
310 ifile_p1:
311 memory
312 | sections
313 | phdrs
314 | startup
315 | high_level_library
316 | low_level_library
317 | floating_point_support
318 | statement_anywhere
319 | version
320 | ';'
321 | TARGET_K '(' NAME ')'
322 { lang_add_target($3); }
323 | SEARCH_DIR '(' filename ')'
324 { ldfile_add_library_path ($3, FALSE); }
325 | OUTPUT '(' filename ')'
326 { lang_add_output($3, 1); }
327 | OUTPUT_FORMAT '(' NAME ')'
328 { lang_add_output_format ($3, (char *) NULL,
329 (char *) NULL, 1); }
330 | OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')'
331 { lang_add_output_format ($3, $5, $7, 1); }
332 | OUTPUT_ARCH '(' NAME ')'
333 { ldfile_set_output_arch ($3, bfd_arch_unknown); }
334 | FORCE_COMMON_ALLOCATION
335 { command_line.force_common_definition = TRUE ; }
336 | INHIBIT_COMMON_ALLOCATION
337 { command_line.inhibit_common_definition = TRUE ; }
338 | INPUT '(' input_list ')'
339 | GROUP
340 { lang_enter_group (); }
341 '(' input_list ')'
342 { lang_leave_group (); }
343 | MAP '(' filename ')'
344 { lang_add_map($3); }
345 | INCLUDE filename
346 { ldlex_script (); ldfile_open_command_file($2); }
347 ifile_list END
348 { ldlex_popstate (); }
349 | NOCROSSREFS '(' nocrossref_list ')'
351 lang_add_nocrossref ($3);
353 | EXTERN '(' extern_name_list ')'
354 | INSERT_K AFTER NAME
355 { lang_add_insert ($3, 0); }
356 | INSERT_K BEFORE NAME
357 { lang_add_insert ($3, 1); }
358 | REGION_ALIAS '(' NAME ',' NAME ')'
359 { lang_memory_region_alias ($3, $5); }
362 input_list:
363 NAME
364 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
365 (char *)NULL); }
366 | input_list ',' NAME
367 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
368 (char *)NULL); }
369 | input_list NAME
370 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
371 (char *)NULL); }
372 | LNAME
373 { lang_add_input_file($1,lang_input_file_is_l_enum,
374 (char *)NULL); }
375 | input_list ',' LNAME
376 { lang_add_input_file($3,lang_input_file_is_l_enum,
377 (char *)NULL); }
378 | input_list LNAME
379 { lang_add_input_file($2,lang_input_file_is_l_enum,
380 (char *)NULL); }
381 | AS_NEEDED '('
382 { $<integer>$ = add_DT_NEEDED_for_regular; add_DT_NEEDED_for_regular = TRUE; }
383 input_list ')'
384 { add_DT_NEEDED_for_regular = $<integer>3; }
385 | input_list ',' AS_NEEDED '('
386 { $<integer>$ = add_DT_NEEDED_for_regular; add_DT_NEEDED_for_regular = TRUE; }
387 input_list ')'
388 { add_DT_NEEDED_for_regular = $<integer>5; }
389 | input_list AS_NEEDED '('
390 { $<integer>$ = add_DT_NEEDED_for_regular; add_DT_NEEDED_for_regular = TRUE; }
391 input_list ')'
392 { add_DT_NEEDED_for_regular = $<integer>4; }
395 sections:
396 SECTIONS '{' sec_or_group_p1 '}'
399 sec_or_group_p1:
400 sec_or_group_p1 section
401 | sec_or_group_p1 statement_anywhere
405 statement_anywhere:
406 ENTRY '(' NAME ')'
407 { lang_add_entry ($3, FALSE); }
408 | assignment end
409 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')'
410 { ldlex_popstate ();
411 lang_add_assignment (exp_assert ($4, $6)); }
414 /* The '*' and '?' cases are there because the lexer returns them as
415 separate tokens rather than as NAME. */
416 wildcard_name:
417 NAME
419 $$ = $1;
421 | '*'
423 $$ = "*";
425 | '?'
427 $$ = "?";
431 wildcard_spec:
432 wildcard_name
434 $$.name = $1;
435 $$.sorted = none;
436 $$.exclude_name_list = NULL;
438 | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
440 $$.name = $5;
441 $$.sorted = none;
442 $$.exclude_name_list = $3;
444 | SORT_BY_NAME '(' wildcard_name ')'
446 $$.name = $3;
447 $$.sorted = by_name;
448 $$.exclude_name_list = NULL;
450 | SORT_BY_ALIGNMENT '(' wildcard_name ')'
452 $$.name = $3;
453 $$.sorted = by_alignment;
454 $$.exclude_name_list = NULL;
456 | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
458 $$.name = $5;
459 $$.sorted = by_name_alignment;
460 $$.exclude_name_list = NULL;
462 | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_name ')' ')'
464 $$.name = $5;
465 $$.sorted = by_name;
466 $$.exclude_name_list = NULL;
468 | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_name ')' ')'
470 $$.name = $5;
471 $$.sorted = by_alignment_name;
472 $$.exclude_name_list = NULL;
474 | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
476 $$.name = $5;
477 $$.sorted = by_alignment;
478 $$.exclude_name_list = NULL;
480 | SORT_BY_NAME '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')'
482 $$.name = $7;
483 $$.sorted = by_name;
484 $$.exclude_name_list = $5;
486 | SORT_BY_INIT_PRIORITY '(' wildcard_name ')'
488 $$.name = $3;
489 $$.sorted = by_init_priority;
490 $$.exclude_name_list = NULL;
494 exclude_name_list:
495 exclude_name_list wildcard_name
497 struct name_list *tmp;
498 tmp = (struct name_list *) xmalloc (sizeof *tmp);
499 tmp->name = $2;
500 tmp->next = $1;
501 $$ = tmp;
504 wildcard_name
506 struct name_list *tmp;
507 tmp = (struct name_list *) xmalloc (sizeof *tmp);
508 tmp->name = $1;
509 tmp->next = NULL;
510 $$ = tmp;
514 file_NAME_list:
515 file_NAME_list opt_comma wildcard_spec
517 struct wildcard_list *tmp;
518 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
519 tmp->next = $1;
520 tmp->spec = $3;
521 $$ = tmp;
524 wildcard_spec
526 struct wildcard_list *tmp;
527 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
528 tmp->next = NULL;
529 tmp->spec = $1;
530 $$ = tmp;
534 input_section_spec_no_keep:
535 NAME
537 struct wildcard_spec tmp;
538 tmp.name = $1;
539 tmp.exclude_name_list = NULL;
540 tmp.sorted = none;
541 lang_add_wild (&tmp, NULL, ldgram_had_keep);
543 | '[' file_NAME_list ']'
545 lang_add_wild (NULL, $2, ldgram_had_keep);
547 | wildcard_spec '(' file_NAME_list ')'
549 lang_add_wild (&$1, $3, ldgram_had_keep);
553 input_section_spec:
554 input_section_spec_no_keep
555 | KEEP '('
556 { ldgram_had_keep = TRUE; }
557 input_section_spec_no_keep ')'
558 { ldgram_had_keep = FALSE; }
561 statement:
562 assignment end
563 | CREATE_OBJECT_SYMBOLS
565 lang_add_attribute(lang_object_symbols_statement_enum);
567 | ';'
568 | CONSTRUCTORS
571 lang_add_attribute(lang_constructors_statement_enum);
573 | SORT_BY_NAME '(' CONSTRUCTORS ')'
575 constructors_sorted = TRUE;
576 lang_add_attribute (lang_constructors_statement_enum);
578 | input_section_spec
579 | length '(' mustbe_exp ')'
581 lang_add_data ((int) $1, $3);
584 | FILL '(' fill_exp ')'
586 lang_add_fill ($3);
588 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')' end
589 { ldlex_popstate ();
590 lang_add_assignment (exp_assert ($4, $6)); }
591 | INCLUDE filename
592 { ldlex_script (); ldfile_open_command_file($2); }
593 statement_list_opt END
594 { ldlex_popstate (); }
597 statement_list:
598 statement_list statement
599 | statement
602 statement_list_opt:
603 /* empty */
604 | statement_list
607 length:
608 QUAD
609 { $$ = $1; }
610 | SQUAD
611 { $$ = $1; }
612 | LONG
613 { $$ = $1; }
614 | SHORT
615 { $$ = $1; }
616 | BYTE
617 { $$ = $1; }
620 fill_exp:
621 mustbe_exp
623 $$ = exp_get_fill ($1, 0, "fill value");
627 fill_opt:
628 '=' fill_exp
629 { $$ = $2; }
630 | { $$ = (fill_type *) 0; }
633 assign_op:
634 PLUSEQ
635 { $$ = '+'; }
636 | MINUSEQ
637 { $$ = '-'; }
638 | MULTEQ
639 { $$ = '*'; }
640 | DIVEQ
641 { $$ = '/'; }
642 | LSHIFTEQ
643 { $$ = LSHIFT; }
644 | RSHIFTEQ
645 { $$ = RSHIFT; }
646 | ANDEQ
647 { $$ = '&'; }
648 | OREQ
649 { $$ = '|'; }
653 end: ';' | ','
657 assignment:
658 NAME '=' mustbe_exp
660 lang_add_assignment (exp_assop ($2, $1, $3));
662 | NAME assign_op mustbe_exp
664 lang_add_assignment (exp_assop ('=', $1,
665 exp_binop ($2,
666 exp_nameop (NAME,
667 $1),
668 $3)));
670 | PROVIDE '(' NAME '=' mustbe_exp ')'
672 lang_add_assignment (exp_provide ($3, $5, FALSE));
674 | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
676 lang_add_assignment (exp_provide ($3, $5, TRUE));
681 opt_comma:
682 ',' | ;
685 memory:
686 MEMORY '{' memory_spec_list_opt '}'
689 memory_spec_list_opt: memory_spec_list | ;
691 memory_spec_list:
692 memory_spec_list opt_comma memory_spec
693 | memory_spec
697 memory_spec: NAME
698 { region = lang_memory_region_lookup ($1, TRUE); }
699 attributes_opt ':'
700 origin_spec opt_comma length_spec
702 | INCLUDE filename
703 { ldlex_script (); ldfile_open_command_file($2); }
704 memory_spec_list_opt END
705 { ldlex_popstate (); }
708 origin_spec:
709 ORIGIN '=' mustbe_exp
711 region->origin = exp_get_vma ($3, 0, "origin");
712 region->current = region->origin;
716 length_spec:
717 LENGTH '=' mustbe_exp
719 region->length = exp_get_vma ($3, -1, "length");
723 attributes_opt:
724 /* empty */
725 { /* dummy action to avoid bison 1.25 error message */ }
726 | '(' attributes_list ')'
729 attributes_list:
730 attributes_string
731 | attributes_list attributes_string
734 attributes_string:
735 NAME
736 { lang_set_flags (region, $1, 0); }
737 | '!' NAME
738 { lang_set_flags (region, $2, 1); }
741 startup:
742 STARTUP '(' filename ')'
743 { lang_startup($3); }
746 high_level_library:
747 HLL '(' high_level_library_NAME_list ')'
748 | HLL '(' ')'
749 { ldemul_hll((char *)NULL); }
752 high_level_library_NAME_list:
753 high_level_library_NAME_list opt_comma filename
754 { ldemul_hll($3); }
755 | filename
756 { ldemul_hll($1); }
760 low_level_library:
761 SYSLIB '(' low_level_library_NAME_list ')'
762 ; low_level_library_NAME_list:
763 low_level_library_NAME_list opt_comma filename
764 { ldemul_syslib($3); }
768 floating_point_support:
769 FLOAT
770 { lang_float(TRUE); }
771 | NOFLOAT
772 { lang_float(FALSE); }
775 nocrossref_list:
776 /* empty */
778 $$ = NULL;
780 | NAME nocrossref_list
782 struct lang_nocrossref *n;
784 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
785 n->name = $1;
786 n->next = $2;
787 $$ = n;
789 | NAME ',' nocrossref_list
791 struct lang_nocrossref *n;
793 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
794 n->name = $1;
795 n->next = $3;
796 $$ = n;
800 mustbe_exp: { ldlex_expression (); }
802 { ldlex_popstate (); $$=$2;}
805 exp :
806 '-' exp %prec UNARY
807 { $$ = exp_unop ('-', $2); }
808 | '(' exp ')'
809 { $$ = $2; }
810 | NEXT '(' exp ')' %prec UNARY
811 { $$ = exp_unop ((int) $1,$3); }
812 | '!' exp %prec UNARY
813 { $$ = exp_unop ('!', $2); }
814 | '+' exp %prec UNARY
815 { $$ = $2; }
816 | '~' exp %prec UNARY
817 { $$ = exp_unop ('~', $2);}
819 | exp '*' exp
820 { $$ = exp_binop ('*', $1, $3); }
821 | exp '/' exp
822 { $$ = exp_binop ('/', $1, $3); }
823 | exp '%' exp
824 { $$ = exp_binop ('%', $1, $3); }
825 | exp '+' exp
826 { $$ = exp_binop ('+', $1, $3); }
827 | exp '-' exp
828 { $$ = exp_binop ('-' , $1, $3); }
829 | exp LSHIFT exp
830 { $$ = exp_binop (LSHIFT , $1, $3); }
831 | exp RSHIFT exp
832 { $$ = exp_binop (RSHIFT , $1, $3); }
833 | exp EQ exp
834 { $$ = exp_binop (EQ , $1, $3); }
835 | exp NE exp
836 { $$ = exp_binop (NE , $1, $3); }
837 | exp LE exp
838 { $$ = exp_binop (LE , $1, $3); }
839 | exp GE exp
840 { $$ = exp_binop (GE , $1, $3); }
841 | exp '<' exp
842 { $$ = exp_binop ('<' , $1, $3); }
843 | exp '>' exp
844 { $$ = exp_binop ('>' , $1, $3); }
845 | exp '&' exp
846 { $$ = exp_binop ('&' , $1, $3); }
847 | exp '^' exp
848 { $$ = exp_binop ('^' , $1, $3); }
849 | exp '|' exp
850 { $$ = exp_binop ('|' , $1, $3); }
851 | exp '?' exp ':' exp
852 { $$ = exp_trinop ('?' , $1, $3, $5); }
853 | exp ANDAND exp
854 { $$ = exp_binop (ANDAND , $1, $3); }
855 | exp OROR exp
856 { $$ = exp_binop (OROR , $1, $3); }
857 | DEFINED '(' NAME ')'
858 { $$ = exp_nameop (DEFINED, $3); }
859 | INT
860 { $$ = exp_bigintop ($1.integer, $1.str); }
861 | SIZEOF_HEADERS
862 { $$ = exp_nameop (SIZEOF_HEADERS,0); }
864 | ALIGNOF '(' NAME ')'
865 { $$ = exp_nameop (ALIGNOF,$3); }
866 | SIZEOF '(' NAME ')'
867 { $$ = exp_nameop (SIZEOF,$3); }
868 | ADDR '(' NAME ')'
869 { $$ = exp_nameop (ADDR,$3); }
870 | LOADADDR '(' NAME ')'
871 { $$ = exp_nameop (LOADADDR,$3); }
872 | CONSTANT '(' NAME ')'
873 { $$ = exp_nameop (CONSTANT,$3); }
874 | ABSOLUTE '(' exp ')'
875 { $$ = exp_unop (ABSOLUTE, $3); }
876 | ALIGN_K '(' exp ')'
877 { $$ = exp_unop (ALIGN_K,$3); }
878 | ALIGN_K '(' exp ',' exp ')'
879 { $$ = exp_binop (ALIGN_K,$3,$5); }
880 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
881 { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
882 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
883 { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
884 | DATA_SEGMENT_END '(' exp ')'
885 { $$ = exp_unop (DATA_SEGMENT_END, $3); }
886 | SEGMENT_START '(' NAME ',' exp ')'
887 { /* The operands to the expression node are
888 placed in the opposite order from the way
889 in which they appear in the script as
890 that allows us to reuse more code in
891 fold_binary. */
892 $$ = exp_binop (SEGMENT_START,
894 exp_nameop (NAME, $3)); }
895 | BLOCK '(' exp ')'
896 { $$ = exp_unop (ALIGN_K,$3); }
897 | NAME
898 { $$ = exp_nameop (NAME,$1); }
899 | MAX_K '(' exp ',' exp ')'
900 { $$ = exp_binop (MAX_K, $3, $5 ); }
901 | MIN_K '(' exp ',' exp ')'
902 { $$ = exp_binop (MIN_K, $3, $5 ); }
903 | ASSERT_K '(' exp ',' NAME ')'
904 { $$ = exp_assert ($3, $5); }
905 | ORIGIN '(' NAME ')'
906 { $$ = exp_nameop (ORIGIN, $3); }
907 | LENGTH '(' NAME ')'
908 { $$ = exp_nameop (LENGTH, $3); }
912 memspec_at_opt:
913 AT '>' NAME { $$ = $3; }
914 | { $$ = 0; }
917 opt_at:
918 AT '(' exp ')' { $$ = $3; }
919 | { $$ = 0; }
922 opt_align:
923 ALIGN_K '(' exp ')' { $$ = $3; }
924 | { $$ = 0; }
927 opt_subalign:
928 SUBALIGN '(' exp ')' { $$ = $3; }
929 | { $$ = 0; }
932 sect_constraint:
933 ONLY_IF_RO { $$ = ONLY_IF_RO; }
934 | ONLY_IF_RW { $$ = ONLY_IF_RW; }
935 | SPECIAL { $$ = SPECIAL; }
936 | { $$ = 0; }
939 section: NAME { ldlex_expression(); }
940 opt_exp_with_type
941 opt_at
942 opt_align
943 opt_subalign { ldlex_popstate (); ldlex_script (); }
944 sect_constraint
947 lang_enter_output_section_statement($1, $3,
948 sectype,
949 $5, $6, $4, $8);
951 statement_list_opt
952 '}' { ldlex_popstate (); ldlex_expression (); }
953 memspec_opt memspec_at_opt phdr_opt fill_opt
955 ldlex_popstate ();
956 lang_leave_output_section_statement ($17, $14, $16, $15);
958 opt_comma
960 | OVERLAY
961 { ldlex_expression (); }
962 opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
963 { ldlex_popstate (); ldlex_script (); }
966 lang_enter_overlay ($3, $6);
968 overlay_section
970 { ldlex_popstate (); ldlex_expression (); }
971 memspec_opt memspec_at_opt phdr_opt fill_opt
973 ldlex_popstate ();
974 lang_leave_overlay ($5, (int) $4,
975 $16, $13, $15, $14);
977 opt_comma
978 | /* The GROUP case is just enough to support the gcc
979 svr3.ifile script. It is not intended to be full
980 support. I'm not even sure what GROUP is supposed
981 to mean. */
982 GROUP { ldlex_expression (); }
983 opt_exp_with_type
985 ldlex_popstate ();
986 lang_add_assignment (exp_assop ('=', ".", $3));
988 '{' sec_or_group_p1 '}'
989 | INCLUDE filename
990 { ldlex_script (); ldfile_open_command_file($2); }
991 sec_or_group_p1 END
992 { ldlex_popstate (); }
995 type:
996 NOLOAD { sectype = noload_section; }
997 | DSECT { sectype = noalloc_section; }
998 | COPY { sectype = noalloc_section; }
999 | INFO { sectype = noalloc_section; }
1000 | OVERLAY { sectype = noalloc_section; }
1003 atype:
1004 '(' type ')'
1005 | /* EMPTY */ { sectype = normal_section; }
1006 | '(' ')' { sectype = normal_section; }
1009 opt_exp_with_type:
1010 exp atype ':' { $$ = $1; }
1011 | atype ':' { $$ = (etree_type *)NULL; }
1012 | /* The BIND cases are to support the gcc svr3.ifile
1013 script. They aren't intended to implement full
1014 support for the BIND keyword. I'm not even sure
1015 what BIND is supposed to mean. */
1016 BIND '(' exp ')' atype ':' { $$ = $3; }
1017 | BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
1018 { $$ = $3; }
1021 opt_exp_without_type:
1022 exp ':' { $$ = $1; }
1023 | ':' { $$ = (etree_type *) NULL; }
1026 opt_nocrossrefs:
1027 /* empty */
1028 { $$ = 0; }
1029 | NOCROSSREFS
1030 { $$ = 1; }
1033 memspec_opt:
1034 '>' NAME
1035 { $$ = $2; }
1036 | { $$ = DEFAULT_MEMORY_REGION; }
1039 phdr_opt:
1040 /* empty */
1042 $$ = NULL;
1044 | phdr_opt ':' NAME
1046 struct lang_output_section_phdr_list *n;
1048 n = ((struct lang_output_section_phdr_list *)
1049 xmalloc (sizeof *n));
1050 n->name = $3;
1051 n->used = FALSE;
1052 n->next = $1;
1053 $$ = n;
1057 overlay_section:
1058 /* empty */
1059 | overlay_section
1060 NAME
1062 ldlex_script ();
1063 lang_enter_overlay_section ($2);
1065 '{' statement_list_opt '}'
1066 { ldlex_popstate (); ldlex_expression (); }
1067 phdr_opt fill_opt
1069 ldlex_popstate ();
1070 lang_leave_overlay_section ($9, $8);
1072 opt_comma
1075 phdrs:
1076 PHDRS '{' phdr_list '}'
1079 phdr_list:
1080 /* empty */
1081 | phdr_list phdr
1084 phdr:
1085 NAME { ldlex_expression (); }
1086 phdr_type phdr_qualifiers { ldlex_popstate (); }
1089 lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1090 $4.flags);
1094 phdr_type:
1097 $$ = $1;
1099 if ($1->type.node_class == etree_name
1100 && $1->type.node_code == NAME)
1102 const char *s;
1103 unsigned int i;
1104 static const char * const phdr_types[] =
1106 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1107 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
1108 "PT_PHDR", "PT_TLS"
1111 s = $1->name.name;
1112 for (i = 0;
1113 i < sizeof phdr_types / sizeof phdr_types[0];
1114 i++)
1115 if (strcmp (s, phdr_types[i]) == 0)
1117 $$ = exp_intop (i);
1118 break;
1120 if (i == sizeof phdr_types / sizeof phdr_types[0])
1122 if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1123 $$ = exp_intop (0x6474e550);
1124 else if (strcmp (s, "PT_GNU_STACK") == 0)
1125 $$ = exp_intop (0x6474e551);
1126 else
1128 einfo (_("\
1129 %X%P:%S: unknown phdr type `%s' (try integer literal)\n"),
1131 $$ = exp_intop (0);
1138 phdr_qualifiers:
1139 /* empty */
1141 memset (&$$, 0, sizeof (struct phdr_info));
1143 | NAME phdr_val phdr_qualifiers
1145 $$ = $3;
1146 if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
1147 $$.filehdr = TRUE;
1148 else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
1149 $$.phdrs = TRUE;
1150 else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1151 $$.flags = $2;
1152 else
1153 einfo (_("%X%P:%S: PHDRS syntax error at `%s'\n"), $1);
1155 | AT '(' exp ')' phdr_qualifiers
1157 $$ = $5;
1158 $$.at = $3;
1162 phdr_val:
1163 /* empty */
1165 $$ = NULL;
1167 | '(' exp ')'
1169 $$ = $2;
1173 dynamic_list_file:
1175 ldlex_version_file ();
1176 PUSH_ERROR (_("dynamic list"));
1178 dynamic_list_nodes
1180 ldlex_popstate ();
1181 POP_ERROR ();
1185 dynamic_list_nodes:
1186 dynamic_list_node
1187 | dynamic_list_nodes dynamic_list_node
1190 dynamic_list_node:
1191 '{' dynamic_list_tag '}' ';'
1194 dynamic_list_tag:
1195 vers_defns ';'
1197 lang_append_dynamic_list ($1);
1201 /* This syntax is used within an external version script file. */
1203 version_script_file:
1205 ldlex_version_file ();
1206 PUSH_ERROR (_("VERSION script"));
1208 vers_nodes
1210 ldlex_popstate ();
1211 POP_ERROR ();
1215 /* This is used within a normal linker script file. */
1217 version:
1219 ldlex_version_script ();
1221 VERSIONK '{' vers_nodes '}'
1223 ldlex_popstate ();
1227 vers_nodes:
1228 vers_node
1229 | vers_nodes vers_node
1232 vers_node:
1233 '{' vers_tag '}' ';'
1235 lang_register_vers_node (NULL, $2, NULL);
1237 | VERS_TAG '{' vers_tag '}' ';'
1239 lang_register_vers_node ($1, $3, NULL);
1241 | VERS_TAG '{' vers_tag '}' verdep ';'
1243 lang_register_vers_node ($1, $3, $5);
1247 verdep:
1248 VERS_TAG
1250 $$ = lang_add_vers_depend (NULL, $1);
1252 | verdep VERS_TAG
1254 $$ = lang_add_vers_depend ($1, $2);
1258 vers_tag:
1259 /* empty */
1261 $$ = lang_new_vers_node (NULL, NULL);
1263 | vers_defns ';'
1265 $$ = lang_new_vers_node ($1, NULL);
1267 | GLOBAL ':' vers_defns ';'
1269 $$ = lang_new_vers_node ($3, NULL);
1271 | LOCAL ':' vers_defns ';'
1273 $$ = lang_new_vers_node (NULL, $3);
1275 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1277 $$ = lang_new_vers_node ($3, $7);
1281 vers_defns:
1282 VERS_IDENTIFIER
1284 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, FALSE);
1286 | NAME
1288 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, TRUE);
1290 | vers_defns ';' VERS_IDENTIFIER
1292 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, FALSE);
1294 | vers_defns ';' NAME
1296 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, TRUE);
1298 | vers_defns ';' EXTERN NAME '{'
1300 $<name>$ = ldgram_vers_current_lang;
1301 ldgram_vers_current_lang = $4;
1303 vers_defns opt_semicolon '}'
1305 struct bfd_elf_version_expr *pat;
1306 for (pat = $7; pat->next != NULL; pat = pat->next);
1307 pat->next = $1;
1308 $$ = $7;
1309 ldgram_vers_current_lang = $<name>6;
1311 | EXTERN NAME '{'
1313 $<name>$ = ldgram_vers_current_lang;
1314 ldgram_vers_current_lang = $2;
1316 vers_defns opt_semicolon '}'
1318 $$ = $5;
1319 ldgram_vers_current_lang = $<name>4;
1321 | GLOBAL
1323 $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, FALSE);
1325 | vers_defns ';' GLOBAL
1327 $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, FALSE);
1329 | LOCAL
1331 $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, FALSE);
1333 | vers_defns ';' LOCAL
1335 $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, FALSE);
1337 | EXTERN
1339 $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, FALSE);
1341 | vers_defns ';' EXTERN
1343 $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, FALSE);
1347 opt_semicolon:
1348 /* empty */
1349 | ';'
1353 void
1354 yyerror(arg)
1355 const char *arg;
1357 if (ldfile_assumed_script)
1358 einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
1359 ldfile_input_filename);
1360 if (error_index > 0 && error_index < ERROR_NAME_MAX)
1361 einfo ("%P%F:%S: %s in %s\n", arg, error_names[error_index-1]);
1362 else
1363 einfo ("%P%F:%S: %s\n", arg);