* mep.h (EF_MEP_COP_*): New.
[binutils.git] / ld / ldgram.y
blob4d06725e46786966f6c8b541c0d7a4b5780e9513
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, 2009 Free Software Foundation, Inc.
4 Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
6 This file is part of the GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
28 #define DONTDECLARE_MALLOC
30 #include "sysdep.h"
31 #include "bfd.h"
32 #include "bfdlink.h"
33 #include "ld.h"
34 #include "ldexp.h"
35 #include "ldver.h"
36 #include "ldlang.h"
37 #include "ldfile.h"
38 #include "ldemul.h"
39 #include "ldmisc.h"
40 #include "ldmain.h"
41 #include "mri.h"
42 #include "ldctor.h"
43 #include "ldlex.h"
45 #ifndef YYDEBUG
46 #define YYDEBUG 1
47 #endif
49 static enum section_type sectype;
50 static lang_memory_region_type *region;
52 bfd_boolean ldgram_had_keep = FALSE;
53 char *ldgram_vers_current_lang = NULL;
55 #define ERROR_NAME_MAX 20
56 static char *error_names[ERROR_NAME_MAX];
57 static int error_index;
58 #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
59 #define POP_ERROR() error_index--;
61 %union {
62 bfd_vma integer;
63 struct big_int
65 bfd_vma integer;
66 char *str;
67 } bigint;
68 fill_type *fill;
69 char *name;
70 const char *cname;
71 struct wildcard_spec wildcard;
72 struct wildcard_list *wildcard_list;
73 struct name_list *name_list;
74 int token;
75 union etree_union *etree;
76 struct phdr_info
78 bfd_boolean filehdr;
79 bfd_boolean phdrs;
80 union etree_union *at;
81 union etree_union *flags;
82 } phdr;
83 struct lang_nocrossref *nocrossref;
84 struct lang_output_section_phdr_list *section_phdr;
85 struct bfd_elf_version_deps *deflist;
86 struct bfd_elf_version_expr *versyms;
87 struct bfd_elf_version_tree *versnode;
90 %type <etree> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val
91 %type <etree> opt_exp_without_type opt_subalign opt_align
92 %type <fill> fill_opt fill_exp
93 %type <name_list> exclude_name_list
94 %type <wildcard_list> file_NAME_list
95 %type <name> memspec_opt casesymlist
96 %type <name> memspec_at_opt
97 %type <cname> wildcard_name
98 %type <wildcard> wildcard_spec
99 %token <bigint> INT
100 %token <name> NAME LNAME
101 %type <integer> length
102 %type <phdr> phdr_qualifiers
103 %type <nocrossref> nocrossref_list
104 %type <section_phdr> phdr_opt
105 %type <integer> opt_nocrossrefs
107 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
108 %right <token> '?' ':'
109 %left <token> OROR
110 %left <token> ANDAND
111 %left <token> '|'
112 %left <token> '^'
113 %left <token> '&'
114 %left <token> EQ NE
115 %left <token> '<' '>' LE GE
116 %left <token> LSHIFT RSHIFT
118 %left <token> '+' '-'
119 %left <token> '*' '/' '%'
121 %right UNARY
122 %token END
123 %left <token> '('
124 %token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
125 %token SECTIONS PHDRS INSERT_K AFTER BEFORE
126 %token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
127 %token SORT_BY_NAME SORT_BY_ALIGNMENT
128 %token '{' '}'
129 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
130 %token INHIBIT_COMMON_ALLOCATION
131 %token SEGMENT_START
132 %token INCLUDE
133 %token MEMORY
134 %token REGION_ALIAS
135 %token NOLOAD DSECT COPY INFO OVERLAY
136 %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY
137 %token <integer> NEXT
138 %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K
139 %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS
140 %token ORIGIN FILL
141 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
142 %token ALIGNMOD AT SUBALIGN PROVIDE PROVIDE_HIDDEN AS_NEEDED
143 %type <token> assign_op atype attributes_opt sect_constraint
144 %type <name> filename
145 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
146 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
147 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
148 %token <name> VERS_TAG VERS_IDENTIFIER
149 %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
150 %token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL
151 %token EXCLUDE_FILE
152 %token CONSTANT
153 %type <versyms> vers_defns
154 %type <versnode> vers_tag
155 %type <deflist> verdep
156 %token INPUT_DYNAMIC_LIST
160 file:
161 INPUT_SCRIPT script_file
162 | INPUT_MRI_SCRIPT mri_script_file
163 | INPUT_VERSION_SCRIPT version_script_file
164 | INPUT_DYNAMIC_LIST dynamic_list_file
165 | INPUT_DEFSYM defsym_expr
169 filename: NAME;
172 defsym_expr:
173 { ldlex_defsym(); }
174 NAME '=' exp
176 ldlex_popstate();
177 lang_add_assignment(exp_assop($3,$2,$4));
181 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
182 mri_script_file:
184 ldlex_mri_script ();
185 PUSH_ERROR (_("MRI style script"));
187 mri_script_lines
189 ldlex_popstate ();
190 mri_draw_tree ();
191 POP_ERROR ();
195 mri_script_lines:
196 mri_script_lines mri_script_command NEWLINE
200 mri_script_command:
201 CHIP exp
202 | CHIP exp ',' exp
203 | NAME {
204 einfo(_("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1);
206 | LIST {
207 config.map_filename = "-";
209 | ORDER ordernamelist
210 | ENDWORD
211 | PUBLIC NAME '=' exp
212 { mri_public($2, $4); }
213 | PUBLIC NAME ',' exp
214 { mri_public($2, $4); }
215 | PUBLIC NAME exp
216 { mri_public($2, $3); }
217 | FORMAT NAME
218 { mri_format($2); }
219 | SECT NAME ',' exp
220 { mri_output_section($2, $4);}
221 | SECT NAME exp
222 { mri_output_section($2, $3);}
223 | SECT NAME '=' exp
224 { mri_output_section($2, $4);}
225 | ALIGN_K NAME '=' exp
226 { mri_align($2,$4); }
227 | ALIGN_K NAME ',' exp
228 { mri_align($2,$4); }
229 | ALIGNMOD NAME '=' exp
230 { mri_alignmod($2,$4); }
231 | ALIGNMOD NAME ',' exp
232 { mri_alignmod($2,$4); }
233 | ABSOLUTE mri_abs_name_list
234 | LOAD mri_load_name_list
235 | NAMEWORD NAME
236 { mri_name($2); }
237 | ALIAS NAME ',' NAME
238 { mri_alias($2,$4,0);}
239 | ALIAS NAME ',' INT
240 { mri_alias ($2, 0, (int) $4.integer); }
241 | BASE exp
242 { mri_base($2); }
243 | TRUNCATE INT
244 { mri_truncate ((unsigned int) $2.integer); }
245 | CASE casesymlist
246 | EXTERN extern_name_list
247 | INCLUDE filename
248 { ldlex_script (); ldfile_open_command_file($2); }
249 mri_script_lines END
250 { ldlex_popstate (); }
251 | START NAME
252 { lang_add_entry ($2, FALSE); }
256 ordernamelist:
257 ordernamelist ',' NAME { mri_order($3); }
258 | ordernamelist NAME { mri_order($2); }
262 mri_load_name_list:
263 NAME
264 { mri_load($1); }
265 | mri_load_name_list ',' NAME { mri_load($3); }
268 mri_abs_name_list:
269 NAME
270 { mri_only_load($1); }
271 | mri_abs_name_list ',' NAME
272 { mri_only_load($3); }
275 casesymlist:
276 /* empty */ { $$ = NULL; }
277 | NAME
278 | casesymlist ',' NAME
281 /* Parsed as expressions so that commas separate entries */
282 extern_name_list:
283 { ldlex_expression (); }
284 extern_name_list_body
285 { ldlex_popstate (); }
287 extern_name_list_body:
288 NAME
289 { ldlang_add_undef ($1); }
290 | extern_name_list_body NAME
291 { ldlang_add_undef ($2); }
292 | extern_name_list_body ',' NAME
293 { ldlang_add_undef ($3); }
296 script_file:
297 { ldlex_both(); }
298 ifile_list
299 { ldlex_popstate(); }
302 ifile_list:
303 ifile_list ifile_p1
308 ifile_p1:
309 memory
310 | sections
311 | phdrs
312 | startup
313 | high_level_library
314 | low_level_library
315 | floating_point_support
316 | statement_anywhere
317 | version
318 | ';'
319 | TARGET_K '(' NAME ')'
320 { lang_add_target($3); }
321 | SEARCH_DIR '(' filename ')'
322 { ldfile_add_library_path ($3, FALSE); }
323 | OUTPUT '(' filename ')'
324 { lang_add_output($3, 1); }
325 | OUTPUT_FORMAT '(' NAME ')'
326 { lang_add_output_format ($3, (char *) NULL,
327 (char *) NULL, 1); }
328 | OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')'
329 { lang_add_output_format ($3, $5, $7, 1); }
330 | OUTPUT_ARCH '(' NAME ')'
331 { ldfile_set_output_arch ($3, bfd_arch_unknown); }
332 | FORCE_COMMON_ALLOCATION
333 { command_line.force_common_definition = TRUE ; }
334 | INHIBIT_COMMON_ALLOCATION
335 { command_line.inhibit_common_definition = TRUE ; }
336 | INPUT '(' input_list ')'
337 | GROUP
338 { lang_enter_group (); }
339 '(' input_list ')'
340 { lang_leave_group (); }
341 | MAP '(' filename ')'
342 { lang_add_map($3); }
343 | INCLUDE filename
344 { ldlex_script (); ldfile_open_command_file($2); }
345 ifile_list END
346 { ldlex_popstate (); }
347 | NOCROSSREFS '(' nocrossref_list ')'
349 lang_add_nocrossref ($3);
351 | EXTERN '(' extern_name_list ')'
352 | INSERT_K AFTER NAME
353 { lang_add_insert ($3, 0); }
354 | INSERT_K BEFORE NAME
355 { lang_add_insert ($3, 1); }
356 | REGION_ALIAS '(' NAME ',' NAME ')'
357 { lang_memory_region_alias ($3, $5); }
360 input_list:
361 NAME
362 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
363 (char *)NULL); }
364 | input_list ',' NAME
365 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
366 (char *)NULL); }
367 | input_list NAME
368 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
369 (char *)NULL); }
370 | LNAME
371 { lang_add_input_file($1,lang_input_file_is_l_enum,
372 (char *)NULL); }
373 | input_list ',' LNAME
374 { lang_add_input_file($3,lang_input_file_is_l_enum,
375 (char *)NULL); }
376 | input_list LNAME
377 { lang_add_input_file($2,lang_input_file_is_l_enum,
378 (char *)NULL); }
379 | AS_NEEDED '('
380 { $<integer>$ = as_needed; as_needed = TRUE; }
381 input_list ')'
382 { as_needed = $<integer>3; }
383 | input_list ',' AS_NEEDED '('
384 { $<integer>$ = as_needed; as_needed = TRUE; }
385 input_list ')'
386 { as_needed = $<integer>5; }
387 | input_list AS_NEEDED '('
388 { $<integer>$ = as_needed; as_needed = TRUE; }
389 input_list ')'
390 { as_needed = $<integer>4; }
393 sections:
394 SECTIONS '{' sec_or_group_p1 '}'
397 sec_or_group_p1:
398 sec_or_group_p1 section
399 | sec_or_group_p1 statement_anywhere
403 statement_anywhere:
404 ENTRY '(' NAME ')'
405 { lang_add_entry ($3, FALSE); }
406 | assignment end
407 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')'
408 { ldlex_popstate ();
409 lang_add_assignment (exp_assert ($4, $6)); }
412 /* The '*' and '?' cases are there because the lexer returns them as
413 separate tokens rather than as NAME. */
414 wildcard_name:
415 NAME
417 $$ = $1;
419 | '*'
421 $$ = "*";
423 | '?'
425 $$ = "?";
429 wildcard_spec:
430 wildcard_name
432 $$.name = $1;
433 $$.sorted = none;
434 $$.exclude_name_list = NULL;
436 | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
438 $$.name = $5;
439 $$.sorted = none;
440 $$.exclude_name_list = $3;
442 | SORT_BY_NAME '(' wildcard_name ')'
444 $$.name = $3;
445 $$.sorted = by_name;
446 $$.exclude_name_list = NULL;
448 | SORT_BY_ALIGNMENT '(' wildcard_name ')'
450 $$.name = $3;
451 $$.sorted = by_alignment;
452 $$.exclude_name_list = NULL;
454 | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
456 $$.name = $5;
457 $$.sorted = by_name_alignment;
458 $$.exclude_name_list = NULL;
460 | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_name ')' ')'
462 $$.name = $5;
463 $$.sorted = by_name;
464 $$.exclude_name_list = NULL;
466 | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_name ')' ')'
468 $$.name = $5;
469 $$.sorted = by_alignment_name;
470 $$.exclude_name_list = NULL;
472 | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
474 $$.name = $5;
475 $$.sorted = by_alignment;
476 $$.exclude_name_list = NULL;
478 | SORT_BY_NAME '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')'
480 $$.name = $7;
481 $$.sorted = by_name;
482 $$.exclude_name_list = $5;
486 exclude_name_list:
487 exclude_name_list wildcard_name
489 struct name_list *tmp;
490 tmp = (struct name_list *) xmalloc (sizeof *tmp);
491 tmp->name = $2;
492 tmp->next = $1;
493 $$ = tmp;
496 wildcard_name
498 struct name_list *tmp;
499 tmp = (struct name_list *) xmalloc (sizeof *tmp);
500 tmp->name = $1;
501 tmp->next = NULL;
502 $$ = tmp;
506 file_NAME_list:
507 file_NAME_list opt_comma wildcard_spec
509 struct wildcard_list *tmp;
510 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
511 tmp->next = $1;
512 tmp->spec = $3;
513 $$ = tmp;
516 wildcard_spec
518 struct wildcard_list *tmp;
519 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
520 tmp->next = NULL;
521 tmp->spec = $1;
522 $$ = tmp;
526 input_section_spec_no_keep:
527 NAME
529 struct wildcard_spec tmp;
530 tmp.name = $1;
531 tmp.exclude_name_list = NULL;
532 tmp.sorted = none;
533 lang_add_wild (&tmp, NULL, ldgram_had_keep);
535 | '[' file_NAME_list ']'
537 lang_add_wild (NULL, $2, ldgram_had_keep);
539 | wildcard_spec '(' file_NAME_list ')'
541 lang_add_wild (&$1, $3, ldgram_had_keep);
545 input_section_spec:
546 input_section_spec_no_keep
547 | KEEP '('
548 { ldgram_had_keep = TRUE; }
549 input_section_spec_no_keep ')'
550 { ldgram_had_keep = FALSE; }
553 statement:
554 assignment end
555 | CREATE_OBJECT_SYMBOLS
557 lang_add_attribute(lang_object_symbols_statement_enum);
559 | ';'
560 | CONSTRUCTORS
563 lang_add_attribute(lang_constructors_statement_enum);
565 | SORT_BY_NAME '(' CONSTRUCTORS ')'
567 constructors_sorted = TRUE;
568 lang_add_attribute (lang_constructors_statement_enum);
570 | input_section_spec
571 | length '(' mustbe_exp ')'
573 lang_add_data ((int) $1, $3);
576 | FILL '(' fill_exp ')'
578 lang_add_fill ($3);
580 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')' end
581 { ldlex_popstate ();
582 lang_add_assignment (exp_assert ($4, $6)); }
583 | INCLUDE filename
584 { ldlex_script (); ldfile_open_command_file($2); }
585 statement_list_opt END
586 { ldlex_popstate (); }
589 statement_list:
590 statement_list statement
591 | statement
594 statement_list_opt:
595 /* empty */
596 | statement_list
599 length:
600 QUAD
601 { $$ = $1; }
602 | SQUAD
603 { $$ = $1; }
604 | LONG
605 { $$ = $1; }
606 | SHORT
607 { $$ = $1; }
608 | BYTE
609 { $$ = $1; }
612 fill_exp:
613 mustbe_exp
615 $$ = exp_get_fill ($1, 0, "fill value");
619 fill_opt:
620 '=' fill_exp
621 { $$ = $2; }
622 | { $$ = (fill_type *) 0; }
625 assign_op:
626 PLUSEQ
627 { $$ = '+'; }
628 | MINUSEQ
629 { $$ = '-'; }
630 | MULTEQ
631 { $$ = '*'; }
632 | DIVEQ
633 { $$ = '/'; }
634 | LSHIFTEQ
635 { $$ = LSHIFT; }
636 | RSHIFTEQ
637 { $$ = RSHIFT; }
638 | ANDEQ
639 { $$ = '&'; }
640 | OREQ
641 { $$ = '|'; }
645 end: ';' | ','
649 assignment:
650 NAME '=' mustbe_exp
652 lang_add_assignment (exp_assop ($2, $1, $3));
654 | NAME assign_op mustbe_exp
656 lang_add_assignment (exp_assop ('=', $1,
657 exp_binop ($2,
658 exp_nameop (NAME,
659 $1),
660 $3)));
662 | PROVIDE '(' NAME '=' mustbe_exp ')'
664 lang_add_assignment (exp_provide ($3, $5, FALSE));
666 | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
668 lang_add_assignment (exp_provide ($3, $5, TRUE));
673 opt_comma:
674 ',' | ;
677 memory:
678 MEMORY '{' memory_spec_list_opt '}'
681 memory_spec_list_opt: memory_spec_list | ;
683 memory_spec_list:
684 memory_spec_list opt_comma memory_spec
685 | memory_spec
689 memory_spec: NAME
690 { region = lang_memory_region_lookup ($1, TRUE); }
691 attributes_opt ':'
692 origin_spec opt_comma length_spec
694 | INCLUDE filename
695 { ldlex_script (); ldfile_open_command_file($2); }
696 memory_spec_list_opt END
697 { ldlex_popstate (); }
700 origin_spec:
701 ORIGIN '=' mustbe_exp
703 region->origin = exp_get_vma ($3, 0, "origin");
704 region->current = region->origin;
708 length_spec:
709 LENGTH '=' mustbe_exp
711 region->length = exp_get_vma ($3, -1, "length");
715 attributes_opt:
716 /* empty */
717 { /* dummy action to avoid bison 1.25 error message */ }
718 | '(' attributes_list ')'
721 attributes_list:
722 attributes_string
723 | attributes_list attributes_string
726 attributes_string:
727 NAME
728 { lang_set_flags (region, $1, 0); }
729 | '!' NAME
730 { lang_set_flags (region, $2, 1); }
733 startup:
734 STARTUP '(' filename ')'
735 { lang_startup($3); }
738 high_level_library:
739 HLL '(' high_level_library_NAME_list ')'
740 | HLL '(' ')'
741 { ldemul_hll((char *)NULL); }
744 high_level_library_NAME_list:
745 high_level_library_NAME_list opt_comma filename
746 { ldemul_hll($3); }
747 | filename
748 { ldemul_hll($1); }
752 low_level_library:
753 SYSLIB '(' low_level_library_NAME_list ')'
754 ; low_level_library_NAME_list:
755 low_level_library_NAME_list opt_comma filename
756 { ldemul_syslib($3); }
760 floating_point_support:
761 FLOAT
762 { lang_float(TRUE); }
763 | NOFLOAT
764 { lang_float(FALSE); }
767 nocrossref_list:
768 /* empty */
770 $$ = NULL;
772 | NAME nocrossref_list
774 struct lang_nocrossref *n;
776 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
777 n->name = $1;
778 n->next = $2;
779 $$ = n;
781 | NAME ',' nocrossref_list
783 struct lang_nocrossref *n;
785 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
786 n->name = $1;
787 n->next = $3;
788 $$ = n;
792 mustbe_exp: { ldlex_expression (); }
794 { ldlex_popstate (); $$=$2;}
797 exp :
798 '-' exp %prec UNARY
799 { $$ = exp_unop ('-', $2); }
800 | '(' exp ')'
801 { $$ = $2; }
802 | NEXT '(' exp ')' %prec UNARY
803 { $$ = exp_unop ((int) $1,$3); }
804 | '!' exp %prec UNARY
805 { $$ = exp_unop ('!', $2); }
806 | '+' exp %prec UNARY
807 { $$ = $2; }
808 | '~' exp %prec UNARY
809 { $$ = exp_unop ('~', $2);}
811 | exp '*' exp
812 { $$ = exp_binop ('*', $1, $3); }
813 | exp '/' exp
814 { $$ = exp_binop ('/', $1, $3); }
815 | exp '%' exp
816 { $$ = exp_binop ('%', $1, $3); }
817 | exp '+' exp
818 { $$ = exp_binop ('+', $1, $3); }
819 | exp '-' exp
820 { $$ = exp_binop ('-' , $1, $3); }
821 | exp LSHIFT exp
822 { $$ = exp_binop (LSHIFT , $1, $3); }
823 | exp RSHIFT exp
824 { $$ = exp_binop (RSHIFT , $1, $3); }
825 | exp EQ exp
826 { $$ = exp_binop (EQ , $1, $3); }
827 | exp NE exp
828 { $$ = exp_binop (NE , $1, $3); }
829 | exp LE exp
830 { $$ = exp_binop (LE , $1, $3); }
831 | exp GE exp
832 { $$ = exp_binop (GE , $1, $3); }
833 | exp '<' exp
834 { $$ = exp_binop ('<' , $1, $3); }
835 | exp '>' exp
836 { $$ = exp_binop ('>' , $1, $3); }
837 | exp '&' exp
838 { $$ = exp_binop ('&' , $1, $3); }
839 | exp '^' exp
840 { $$ = exp_binop ('^' , $1, $3); }
841 | exp '|' exp
842 { $$ = exp_binop ('|' , $1, $3); }
843 | exp '?' exp ':' exp
844 { $$ = exp_trinop ('?' , $1, $3, $5); }
845 | exp ANDAND exp
846 { $$ = exp_binop (ANDAND , $1, $3); }
847 | exp OROR exp
848 { $$ = exp_binop (OROR , $1, $3); }
849 | DEFINED '(' NAME ')'
850 { $$ = exp_nameop (DEFINED, $3); }
851 | INT
852 { $$ = exp_bigintop ($1.integer, $1.str); }
853 | SIZEOF_HEADERS
854 { $$ = exp_nameop (SIZEOF_HEADERS,0); }
856 | ALIGNOF '(' NAME ')'
857 { $$ = exp_nameop (ALIGNOF,$3); }
858 | SIZEOF '(' NAME ')'
859 { $$ = exp_nameop (SIZEOF,$3); }
860 | ADDR '(' NAME ')'
861 { $$ = exp_nameop (ADDR,$3); }
862 | LOADADDR '(' NAME ')'
863 { $$ = exp_nameop (LOADADDR,$3); }
864 | CONSTANT '(' NAME ')'
865 { $$ = exp_nameop (CONSTANT,$3); }
866 | ABSOLUTE '(' exp ')'
867 { $$ = exp_unop (ABSOLUTE, $3); }
868 | ALIGN_K '(' exp ')'
869 { $$ = exp_unop (ALIGN_K,$3); }
870 | ALIGN_K '(' exp ',' exp ')'
871 { $$ = exp_binop (ALIGN_K,$3,$5); }
872 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
873 { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
874 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
875 { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
876 | DATA_SEGMENT_END '(' exp ')'
877 { $$ = exp_unop (DATA_SEGMENT_END, $3); }
878 | SEGMENT_START '(' NAME ',' exp ')'
879 { /* The operands to the expression node are
880 placed in the opposite order from the way
881 in which they appear in the script as
882 that allows us to reuse more code in
883 fold_binary. */
884 $$ = exp_binop (SEGMENT_START,
886 exp_nameop (NAME, $3)); }
887 | BLOCK '(' exp ')'
888 { $$ = exp_unop (ALIGN_K,$3); }
889 | NAME
890 { $$ = exp_nameop (NAME,$1); }
891 | MAX_K '(' exp ',' exp ')'
892 { $$ = exp_binop (MAX_K, $3, $5 ); }
893 | MIN_K '(' exp ',' exp ')'
894 { $$ = exp_binop (MIN_K, $3, $5 ); }
895 | ASSERT_K '(' exp ',' NAME ')'
896 { $$ = exp_assert ($3, $5); }
897 | ORIGIN '(' NAME ')'
898 { $$ = exp_nameop (ORIGIN, $3); }
899 | LENGTH '(' NAME ')'
900 { $$ = exp_nameop (LENGTH, $3); }
904 memspec_at_opt:
905 AT '>' NAME { $$ = $3; }
906 | { $$ = 0; }
909 opt_at:
910 AT '(' exp ')' { $$ = $3; }
911 | { $$ = 0; }
914 opt_align:
915 ALIGN_K '(' exp ')' { $$ = $3; }
916 | { $$ = 0; }
919 opt_subalign:
920 SUBALIGN '(' exp ')' { $$ = $3; }
921 | { $$ = 0; }
924 sect_constraint:
925 ONLY_IF_RO { $$ = ONLY_IF_RO; }
926 | ONLY_IF_RW { $$ = ONLY_IF_RW; }
927 | SPECIAL { $$ = SPECIAL; }
928 | { $$ = 0; }
931 section: NAME { ldlex_expression(); }
932 opt_exp_with_type
933 opt_at
934 opt_align
935 opt_subalign { ldlex_popstate (); ldlex_script (); }
936 sect_constraint
939 lang_enter_output_section_statement($1, $3,
940 sectype,
941 $5, $6, $4, $8);
943 statement_list_opt
944 '}' { ldlex_popstate (); ldlex_expression (); }
945 memspec_opt memspec_at_opt phdr_opt fill_opt
947 ldlex_popstate ();
948 lang_leave_output_section_statement ($17, $14, $16, $15);
950 opt_comma
952 | OVERLAY
953 { ldlex_expression (); }
954 opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
955 { ldlex_popstate (); ldlex_script (); }
958 lang_enter_overlay ($3, $6);
960 overlay_section
962 { ldlex_popstate (); ldlex_expression (); }
963 memspec_opt memspec_at_opt phdr_opt fill_opt
965 ldlex_popstate ();
966 lang_leave_overlay ($5, (int) $4,
967 $16, $13, $15, $14);
969 opt_comma
970 | /* The GROUP case is just enough to support the gcc
971 svr3.ifile script. It is not intended to be full
972 support. I'm not even sure what GROUP is supposed
973 to mean. */
974 GROUP { ldlex_expression (); }
975 opt_exp_with_type
977 ldlex_popstate ();
978 lang_add_assignment (exp_assop ('=', ".", $3));
980 '{' sec_or_group_p1 '}'
981 | INCLUDE filename
982 { ldlex_script (); ldfile_open_command_file($2); }
983 sec_or_group_p1 END
984 { ldlex_popstate (); }
987 type:
988 NOLOAD { sectype = noload_section; }
989 | DSECT { sectype = noalloc_section; }
990 | COPY { sectype = noalloc_section; }
991 | INFO { sectype = noalloc_section; }
992 | OVERLAY { sectype = noalloc_section; }
995 atype:
996 '(' type ')'
997 | /* EMPTY */ { sectype = normal_section; }
998 | '(' ')' { sectype = normal_section; }
1001 opt_exp_with_type:
1002 exp atype ':' { $$ = $1; }
1003 | atype ':' { $$ = (etree_type *)NULL; }
1004 | /* The BIND cases are to support the gcc svr3.ifile
1005 script. They aren't intended to implement full
1006 support for the BIND keyword. I'm not even sure
1007 what BIND is supposed to mean. */
1008 BIND '(' exp ')' atype ':' { $$ = $3; }
1009 | BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
1010 { $$ = $3; }
1013 opt_exp_without_type:
1014 exp ':' { $$ = $1; }
1015 | ':' { $$ = (etree_type *) NULL; }
1018 opt_nocrossrefs:
1019 /* empty */
1020 { $$ = 0; }
1021 | NOCROSSREFS
1022 { $$ = 1; }
1025 memspec_opt:
1026 '>' NAME
1027 { $$ = $2; }
1028 | { $$ = DEFAULT_MEMORY_REGION; }
1031 phdr_opt:
1032 /* empty */
1034 $$ = NULL;
1036 | phdr_opt ':' NAME
1038 struct lang_output_section_phdr_list *n;
1040 n = ((struct lang_output_section_phdr_list *)
1041 xmalloc (sizeof *n));
1042 n->name = $3;
1043 n->used = FALSE;
1044 n->next = $1;
1045 $$ = n;
1049 overlay_section:
1050 /* empty */
1051 | overlay_section
1052 NAME
1054 ldlex_script ();
1055 lang_enter_overlay_section ($2);
1057 '{' statement_list_opt '}'
1058 { ldlex_popstate (); ldlex_expression (); }
1059 phdr_opt fill_opt
1061 ldlex_popstate ();
1062 lang_leave_overlay_section ($9, $8);
1064 opt_comma
1067 phdrs:
1068 PHDRS '{' phdr_list '}'
1071 phdr_list:
1072 /* empty */
1073 | phdr_list phdr
1076 phdr:
1077 NAME { ldlex_expression (); }
1078 phdr_type phdr_qualifiers { ldlex_popstate (); }
1081 lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1082 $4.flags);
1086 phdr_type:
1089 $$ = $1;
1091 if ($1->type.node_class == etree_name
1092 && $1->type.node_code == NAME)
1094 const char *s;
1095 unsigned int i;
1096 static const char * const phdr_types[] =
1098 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1099 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
1100 "PT_PHDR", "PT_TLS"
1103 s = $1->name.name;
1104 for (i = 0;
1105 i < sizeof phdr_types / sizeof phdr_types[0];
1106 i++)
1107 if (strcmp (s, phdr_types[i]) == 0)
1109 $$ = exp_intop (i);
1110 break;
1112 if (i == sizeof phdr_types / sizeof phdr_types[0])
1114 if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1115 $$ = exp_intop (0x6474e550);
1116 else if (strcmp (s, "PT_GNU_STACK") == 0)
1117 $$ = exp_intop (0x6474e551);
1118 else
1120 einfo (_("\
1121 %X%P:%S: unknown phdr type `%s' (try integer literal)\n"),
1123 $$ = exp_intop (0);
1130 phdr_qualifiers:
1131 /* empty */
1133 memset (&$$, 0, sizeof (struct phdr_info));
1135 | NAME phdr_val phdr_qualifiers
1137 $$ = $3;
1138 if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
1139 $$.filehdr = TRUE;
1140 else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
1141 $$.phdrs = TRUE;
1142 else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1143 $$.flags = $2;
1144 else
1145 einfo (_("%X%P:%S: PHDRS syntax error at `%s'\n"), $1);
1147 | AT '(' exp ')' phdr_qualifiers
1149 $$ = $5;
1150 $$.at = $3;
1154 phdr_val:
1155 /* empty */
1157 $$ = NULL;
1159 | '(' exp ')'
1161 $$ = $2;
1165 dynamic_list_file:
1167 ldlex_version_file ();
1168 PUSH_ERROR (_("dynamic list"));
1170 dynamic_list_nodes
1172 ldlex_popstate ();
1173 POP_ERROR ();
1177 dynamic_list_nodes:
1178 dynamic_list_node
1179 | dynamic_list_nodes dynamic_list_node
1182 dynamic_list_node:
1183 '{' dynamic_list_tag '}' ';'
1186 dynamic_list_tag:
1187 vers_defns ';'
1189 lang_append_dynamic_list ($1);
1193 /* This syntax is used within an external version script file. */
1195 version_script_file:
1197 ldlex_version_file ();
1198 PUSH_ERROR (_("VERSION script"));
1200 vers_nodes
1202 ldlex_popstate ();
1203 POP_ERROR ();
1207 /* This is used within a normal linker script file. */
1209 version:
1211 ldlex_version_script ();
1213 VERSIONK '{' vers_nodes '}'
1215 ldlex_popstate ();
1219 vers_nodes:
1220 vers_node
1221 | vers_nodes vers_node
1224 vers_node:
1225 '{' vers_tag '}' ';'
1227 lang_register_vers_node (NULL, $2, NULL);
1229 | VERS_TAG '{' vers_tag '}' ';'
1231 lang_register_vers_node ($1, $3, NULL);
1233 | VERS_TAG '{' vers_tag '}' verdep ';'
1235 lang_register_vers_node ($1, $3, $5);
1239 verdep:
1240 VERS_TAG
1242 $$ = lang_add_vers_depend (NULL, $1);
1244 | verdep VERS_TAG
1246 $$ = lang_add_vers_depend ($1, $2);
1250 vers_tag:
1251 /* empty */
1253 $$ = lang_new_vers_node (NULL, NULL);
1255 | vers_defns ';'
1257 $$ = lang_new_vers_node ($1, NULL);
1259 | GLOBAL ':' vers_defns ';'
1261 $$ = lang_new_vers_node ($3, NULL);
1263 | LOCAL ':' vers_defns ';'
1265 $$ = lang_new_vers_node (NULL, $3);
1267 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1269 $$ = lang_new_vers_node ($3, $7);
1273 vers_defns:
1274 VERS_IDENTIFIER
1276 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, FALSE);
1278 | NAME
1280 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, TRUE);
1282 | vers_defns ';' VERS_IDENTIFIER
1284 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, FALSE);
1286 | vers_defns ';' NAME
1288 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, TRUE);
1290 | vers_defns ';' EXTERN NAME '{'
1292 $<name>$ = ldgram_vers_current_lang;
1293 ldgram_vers_current_lang = $4;
1295 vers_defns opt_semicolon '}'
1297 struct bfd_elf_version_expr *pat;
1298 for (pat = $7; pat->next != NULL; pat = pat->next);
1299 pat->next = $1;
1300 $$ = $7;
1301 ldgram_vers_current_lang = $<name>6;
1303 | EXTERN NAME '{'
1305 $<name>$ = ldgram_vers_current_lang;
1306 ldgram_vers_current_lang = $2;
1308 vers_defns opt_semicolon '}'
1310 $$ = $5;
1311 ldgram_vers_current_lang = $<name>4;
1313 | GLOBAL
1315 $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, FALSE);
1317 | vers_defns ';' GLOBAL
1319 $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, FALSE);
1321 | LOCAL
1323 $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, FALSE);
1325 | vers_defns ';' LOCAL
1327 $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, FALSE);
1329 | EXTERN
1331 $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, FALSE);
1333 | vers_defns ';' EXTERN
1335 $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, FALSE);
1339 opt_semicolon:
1340 /* empty */
1341 | ';'
1345 void
1346 yyerror(arg)
1347 const char *arg;
1349 if (ldfile_assumed_script)
1350 einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
1351 ldfile_input_filename);
1352 if (error_index > 0 && error_index < ERROR_NAME_MAX)
1353 einfo ("%P%F:%S: %s in %s\n", arg, error_names[error_index-1]);
1354 else
1355 einfo ("%P%F:%S: %s\n", arg);