* src-release (DEVO_SUPPORT): Correct typos.
[binutils.git] / ld / ldgram.y
blobc6f268b1d7cbb63c08657deb0592b623da22033a
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 Free Software Foundation, Inc.
4 Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
6 This file is part of GNU ld.
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 2 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, MA 02110-1301, USA. */
27 #define DONTDECLARE_MALLOC
29 #include "sysdep.h"
30 #include "bfd.h"
31 #include "bfdlink.h"
32 #include "ld.h"
33 #include "ldexp.h"
34 #include "ldver.h"
35 #include "ldlang.h"
36 #include "ldfile.h"
37 #include "ldemul.h"
38 #include "ldmisc.h"
39 #include "ldmain.h"
40 #include "mri.h"
41 #include "ldctor.h"
42 #include "ldlex.h"
44 #ifndef YYDEBUG
45 #define YYDEBUG 1
46 #endif
48 static enum section_type sectype;
49 static lang_memory_region_type *region;
51 FILE *saved_script_handle = NULL;
52 bfd_boolean force_make_executable = FALSE;
54 bfd_boolean ldgram_in_script = FALSE;
55 bfd_boolean ldgram_had_equals = FALSE;
56 bfd_boolean ldgram_had_keep = FALSE;
57 char *ldgram_vers_current_lang = NULL;
59 #define ERROR_NAME_MAX 20
60 static char *error_names[ERROR_NAME_MAX];
61 static int error_index;
62 #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
63 #define POP_ERROR() error_index--;
65 %union {
66 bfd_vma integer;
67 struct big_int
69 bfd_vma integer;
70 char *str;
71 } bigint;
72 fill_type *fill;
73 char *name;
74 const char *cname;
75 struct wildcard_spec wildcard;
76 struct wildcard_list *wildcard_list;
77 struct name_list *name_list;
78 int token;
79 union etree_union *etree;
80 struct phdr_info
82 bfd_boolean filehdr;
83 bfd_boolean phdrs;
84 union etree_union *at;
85 union etree_union *flags;
86 } phdr;
87 struct lang_nocrossref *nocrossref;
88 struct lang_output_section_phdr_list *section_phdr;
89 struct bfd_elf_version_deps *deflist;
90 struct bfd_elf_version_expr *versyms;
91 struct bfd_elf_version_tree *versnode;
94 %type <etree> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val
95 %type <etree> opt_exp_without_type opt_subalign opt_align
96 %type <fill> fill_opt fill_exp
97 %type <name_list> exclude_name_list
98 %type <wildcard_list> file_NAME_list
99 %type <name> memspec_opt casesymlist
100 %type <name> memspec_at_opt
101 %type <cname> wildcard_name
102 %type <wildcard> wildcard_spec
103 %token <bigint> INT
104 %token <name> NAME LNAME
105 %type <integer> length
106 %type <phdr> phdr_qualifiers
107 %type <nocrossref> nocrossref_list
108 %type <section_phdr> phdr_opt
109 %type <integer> opt_nocrossrefs
111 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
112 %right <token> '?' ':'
113 %left <token> OROR
114 %left <token> ANDAND
115 %left <token> '|'
116 %left <token> '^'
117 %left <token> '&'
118 %left <token> EQ NE
119 %left <token> '<' '>' LE GE
120 %left <token> LSHIFT RSHIFT
122 %left <token> '+' '-'
123 %left <token> '*' '/' '%'
125 %right UNARY
126 %token END
127 %left <token> '('
128 %token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
129 %token SECTIONS PHDRS DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
130 %token SORT_BY_NAME SORT_BY_ALIGNMENT
131 %token '{' '}'
132 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
133 %token INHIBIT_COMMON_ALLOCATION
134 %token SEGMENT_START
135 %token INCLUDE
136 %token MEMORY
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); }
292 | extern_name_list_body NAME
293 { ldlang_add_undef ($2); }
294 | extern_name_list_body ',' NAME
295 { ldlang_add_undef ($3); }
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 ')'
356 input_list:
357 NAME
358 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
359 (char *)NULL); }
360 | input_list ',' NAME
361 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
362 (char *)NULL); }
363 | input_list NAME
364 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
365 (char *)NULL); }
366 | LNAME
367 { lang_add_input_file($1,lang_input_file_is_l_enum,
368 (char *)NULL); }
369 | input_list ',' LNAME
370 { lang_add_input_file($3,lang_input_file_is_l_enum,
371 (char *)NULL); }
372 | input_list LNAME
373 { lang_add_input_file($2,lang_input_file_is_l_enum,
374 (char *)NULL); }
375 | AS_NEEDED '('
376 { $<integer>$ = as_needed; as_needed = TRUE; }
377 input_list ')'
378 { as_needed = $<integer>3; }
379 | input_list ',' AS_NEEDED '('
380 { $<integer>$ = as_needed; as_needed = TRUE; }
381 input_list ')'
382 { as_needed = $<integer>5; }
383 | input_list AS_NEEDED '('
384 { $<integer>$ = as_needed; as_needed = TRUE; }
385 input_list ')'
386 { as_needed = $<integer>4; }
389 sections:
390 SECTIONS '{' sec_or_group_p1 '}'
393 sec_or_group_p1:
394 sec_or_group_p1 section
395 | sec_or_group_p1 statement_anywhere
399 statement_anywhere:
400 ENTRY '(' NAME ')'
401 { lang_add_entry ($3, FALSE); }
402 | assignment end
403 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')'
404 { ldlex_popstate ();
405 lang_add_assignment (exp_assert ($4, $6)); }
408 /* The '*' and '?' cases are there because the lexer returns them as
409 separate tokens rather than as NAME. */
410 wildcard_name:
411 NAME
413 $$ = $1;
415 | '*'
417 $$ = "*";
419 | '?'
421 $$ = "?";
425 wildcard_spec:
426 wildcard_name
428 $$.name = $1;
429 $$.sorted = none;
430 $$.exclude_name_list = NULL;
432 | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
434 $$.name = $5;
435 $$.sorted = none;
436 $$.exclude_name_list = $3;
438 | SORT_BY_NAME '(' wildcard_name ')'
440 $$.name = $3;
441 $$.sorted = by_name;
442 $$.exclude_name_list = NULL;
444 | SORT_BY_ALIGNMENT '(' wildcard_name ')'
446 $$.name = $3;
447 $$.sorted = by_alignment;
448 $$.exclude_name_list = NULL;
450 | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
452 $$.name = $5;
453 $$.sorted = by_name_alignment;
454 $$.exclude_name_list = NULL;
456 | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_name ')' ')'
458 $$.name = $5;
459 $$.sorted = by_name;
460 $$.exclude_name_list = NULL;
462 | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_name ')' ')'
464 $$.name = $5;
465 $$.sorted = by_alignment_name;
466 $$.exclude_name_list = NULL;
468 | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
470 $$.name = $5;
471 $$.sorted = by_alignment;
472 $$.exclude_name_list = NULL;
474 | SORT_BY_NAME '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')'
476 $$.name = $7;
477 $$.sorted = by_name;
478 $$.exclude_name_list = $5;
482 exclude_name_list:
483 exclude_name_list wildcard_name
485 struct name_list *tmp;
486 tmp = (struct name_list *) xmalloc (sizeof *tmp);
487 tmp->name = $2;
488 tmp->next = $1;
489 $$ = tmp;
492 wildcard_name
494 struct name_list *tmp;
495 tmp = (struct name_list *) xmalloc (sizeof *tmp);
496 tmp->name = $1;
497 tmp->next = NULL;
498 $$ = tmp;
502 file_NAME_list:
503 file_NAME_list opt_comma wildcard_spec
505 struct wildcard_list *tmp;
506 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
507 tmp->next = $1;
508 tmp->spec = $3;
509 $$ = tmp;
512 wildcard_spec
514 struct wildcard_list *tmp;
515 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
516 tmp->next = NULL;
517 tmp->spec = $1;
518 $$ = tmp;
522 input_section_spec_no_keep:
523 NAME
525 struct wildcard_spec tmp;
526 tmp.name = $1;
527 tmp.exclude_name_list = NULL;
528 tmp.sorted = none;
529 lang_add_wild (&tmp, NULL, ldgram_had_keep);
531 | '[' file_NAME_list ']'
533 lang_add_wild (NULL, $2, ldgram_had_keep);
535 | wildcard_spec '(' file_NAME_list ')'
537 lang_add_wild (&$1, $3, ldgram_had_keep);
541 input_section_spec:
542 input_section_spec_no_keep
543 | KEEP '('
544 { ldgram_had_keep = TRUE; }
545 input_section_spec_no_keep ')'
546 { ldgram_had_keep = FALSE; }
549 statement:
550 assignment end
551 | CREATE_OBJECT_SYMBOLS
553 lang_add_attribute(lang_object_symbols_statement_enum);
555 | ';'
556 | CONSTRUCTORS
559 lang_add_attribute(lang_constructors_statement_enum);
561 | SORT_BY_NAME '(' CONSTRUCTORS ')'
563 constructors_sorted = TRUE;
564 lang_add_attribute (lang_constructors_statement_enum);
566 | input_section_spec
567 | length '(' mustbe_exp ')'
569 lang_add_data ((int) $1, $3);
572 | FILL '(' fill_exp ')'
574 lang_add_fill ($3);
576 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')' end
577 { ldlex_popstate ();
578 lang_add_assignment (exp_assert ($4, $6)); }
581 statement_list:
582 statement_list statement
583 | statement
586 statement_list_opt:
587 /* empty */
588 | statement_list
591 length:
592 QUAD
593 { $$ = $1; }
594 | SQUAD
595 { $$ = $1; }
596 | LONG
597 { $$ = $1; }
598 | SHORT
599 { $$ = $1; }
600 | BYTE
601 { $$ = $1; }
604 fill_exp:
605 mustbe_exp
607 $$ = exp_get_fill ($1, 0, "fill value");
611 fill_opt:
612 '=' fill_exp
613 { $$ = $2; }
614 | { $$ = (fill_type *) 0; }
617 assign_op:
618 PLUSEQ
619 { $$ = '+'; }
620 | MINUSEQ
621 { $$ = '-'; }
622 | MULTEQ
623 { $$ = '*'; }
624 | DIVEQ
625 { $$ = '/'; }
626 | LSHIFTEQ
627 { $$ = LSHIFT; }
628 | RSHIFTEQ
629 { $$ = RSHIFT; }
630 | ANDEQ
631 { $$ = '&'; }
632 | OREQ
633 { $$ = '|'; }
637 end: ';' | ','
641 assignment:
642 NAME '=' mustbe_exp
644 lang_add_assignment (exp_assop ($2, $1, $3));
646 | NAME assign_op mustbe_exp
648 lang_add_assignment (exp_assop ('=', $1,
649 exp_binop ($2,
650 exp_nameop (NAME,
651 $1),
652 $3)));
654 | PROVIDE '(' NAME '=' mustbe_exp ')'
656 lang_add_assignment (exp_provide ($3, $5, FALSE));
658 | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
660 lang_add_assignment (exp_provide ($3, $5, TRUE));
665 opt_comma:
666 ',' | ;
669 memory:
670 MEMORY '{' memory_spec memory_spec_list '}'
673 memory_spec_list:
674 memory_spec_list memory_spec
675 | memory_spec_list ',' memory_spec
680 memory_spec: NAME
681 { region = lang_memory_region_lookup ($1, TRUE); }
682 attributes_opt ':'
683 origin_spec opt_comma length_spec
687 origin_spec:
688 ORIGIN '=' mustbe_exp
690 region->origin = exp_get_vma ($3, 0, "origin");
691 region->current = region->origin;
695 length_spec:
696 LENGTH '=' mustbe_exp
698 region->length = exp_get_vma ($3, -1, "length");
702 attributes_opt:
703 /* empty */
704 { /* dummy action to avoid bison 1.25 error message */ }
705 | '(' attributes_list ')'
708 attributes_list:
709 attributes_string
710 | attributes_list attributes_string
713 attributes_string:
714 NAME
715 { lang_set_flags (region, $1, 0); }
716 | '!' NAME
717 { lang_set_flags (region, $2, 1); }
720 startup:
721 STARTUP '(' filename ')'
722 { lang_startup($3); }
725 high_level_library:
726 HLL '(' high_level_library_NAME_list ')'
727 | HLL '(' ')'
728 { ldemul_hll((char *)NULL); }
731 high_level_library_NAME_list:
732 high_level_library_NAME_list opt_comma filename
733 { ldemul_hll($3); }
734 | filename
735 { ldemul_hll($1); }
739 low_level_library:
740 SYSLIB '(' low_level_library_NAME_list ')'
741 ; low_level_library_NAME_list:
742 low_level_library_NAME_list opt_comma filename
743 { ldemul_syslib($3); }
747 floating_point_support:
748 FLOAT
749 { lang_float(TRUE); }
750 | NOFLOAT
751 { lang_float(FALSE); }
754 nocrossref_list:
755 /* empty */
757 $$ = NULL;
759 | NAME nocrossref_list
761 struct lang_nocrossref *n;
763 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
764 n->name = $1;
765 n->next = $2;
766 $$ = n;
768 | NAME ',' nocrossref_list
770 struct lang_nocrossref *n;
772 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
773 n->name = $1;
774 n->next = $3;
775 $$ = n;
779 mustbe_exp: { ldlex_expression (); }
781 { ldlex_popstate (); $$=$2;}
784 exp :
785 '-' exp %prec UNARY
786 { $$ = exp_unop ('-', $2); }
787 | '(' exp ')'
788 { $$ = $2; }
789 | NEXT '(' exp ')' %prec UNARY
790 { $$ = exp_unop ((int) $1,$3); }
791 | '!' exp %prec UNARY
792 { $$ = exp_unop ('!', $2); }
793 | '+' exp %prec UNARY
794 { $$ = $2; }
795 | '~' exp %prec UNARY
796 { $$ = exp_unop ('~', $2);}
798 | exp '*' exp
799 { $$ = exp_binop ('*', $1, $3); }
800 | exp '/' exp
801 { $$ = exp_binop ('/', $1, $3); }
802 | exp '%' exp
803 { $$ = exp_binop ('%', $1, $3); }
804 | exp '+' exp
805 { $$ = exp_binop ('+', $1, $3); }
806 | exp '-' exp
807 { $$ = exp_binop ('-' , $1, $3); }
808 | exp LSHIFT exp
809 { $$ = exp_binop (LSHIFT , $1, $3); }
810 | exp RSHIFT exp
811 { $$ = exp_binop (RSHIFT , $1, $3); }
812 | exp EQ exp
813 { $$ = exp_binop (EQ , $1, $3); }
814 | exp NE exp
815 { $$ = exp_binop (NE , $1, $3); }
816 | exp LE exp
817 { $$ = exp_binop (LE , $1, $3); }
818 | exp GE exp
819 { $$ = exp_binop (GE , $1, $3); }
820 | exp '<' exp
821 { $$ = exp_binop ('<' , $1, $3); }
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 ':' exp
831 { $$ = exp_trinop ('?' , $1, $3, $5); }
832 | exp ANDAND exp
833 { $$ = exp_binop (ANDAND , $1, $3); }
834 | exp OROR exp
835 { $$ = exp_binop (OROR , $1, $3); }
836 | DEFINED '(' NAME ')'
837 { $$ = exp_nameop (DEFINED, $3); }
838 | INT
839 { $$ = exp_bigintop ($1.integer, $1.str); }
840 | SIZEOF_HEADERS
841 { $$ = exp_nameop (SIZEOF_HEADERS,0); }
843 | ALIGNOF '(' NAME ')'
844 { $$ = exp_nameop (ALIGNOF,$3); }
845 | SIZEOF '(' NAME ')'
846 { $$ = exp_nameop (SIZEOF,$3); }
847 | ADDR '(' NAME ')'
848 { $$ = exp_nameop (ADDR,$3); }
849 | LOADADDR '(' NAME ')'
850 { $$ = exp_nameop (LOADADDR,$3); }
851 | CONSTANT '(' NAME ')'
852 { $$ = exp_nameop (CONSTANT,$3); }
853 | ABSOLUTE '(' exp ')'
854 { $$ = exp_unop (ABSOLUTE, $3); }
855 | ALIGN_K '(' exp ')'
856 { $$ = exp_unop (ALIGN_K,$3); }
857 | ALIGN_K '(' exp ',' exp ')'
858 { $$ = exp_binop (ALIGN_K,$3,$5); }
859 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
860 { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
861 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
862 { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
863 | DATA_SEGMENT_END '(' exp ')'
864 { $$ = exp_unop (DATA_SEGMENT_END, $3); }
865 | SEGMENT_START '(' NAME ',' exp ')'
866 { /* The operands to the expression node are
867 placed in the opposite order from the way
868 in which they appear in the script as
869 that allows us to reuse more code in
870 fold_binary. */
871 $$ = exp_binop (SEGMENT_START,
873 exp_nameop (NAME, $3)); }
874 | BLOCK '(' exp ')'
875 { $$ = exp_unop (ALIGN_K,$3); }
876 | NAME
877 { $$ = exp_nameop (NAME,$1); }
878 | MAX_K '(' exp ',' exp ')'
879 { $$ = exp_binop (MAX_K, $3, $5 ); }
880 | MIN_K '(' exp ',' exp ')'
881 { $$ = exp_binop (MIN_K, $3, $5 ); }
882 | ASSERT_K '(' exp ',' NAME ')'
883 { $$ = exp_assert ($3, $5); }
884 | ORIGIN '(' NAME ')'
885 { $$ = exp_nameop (ORIGIN, $3); }
886 | LENGTH '(' NAME ')'
887 { $$ = exp_nameop (LENGTH, $3); }
891 memspec_at_opt:
892 AT '>' NAME { $$ = $3; }
893 | { $$ = 0; }
896 opt_at:
897 AT '(' exp ')' { $$ = $3; }
898 | { $$ = 0; }
901 opt_align:
902 ALIGN_K '(' exp ')' { $$ = $3; }
903 | { $$ = 0; }
906 opt_subalign:
907 SUBALIGN '(' exp ')' { $$ = $3; }
908 | { $$ = 0; }
911 sect_constraint:
912 ONLY_IF_RO { $$ = ONLY_IF_RO; }
913 | ONLY_IF_RW { $$ = ONLY_IF_RW; }
914 | SPECIAL { $$ = SPECIAL; }
915 | { $$ = 0; }
918 section: NAME { ldlex_expression(); }
919 opt_exp_with_type
920 opt_at
921 opt_align
922 opt_subalign { ldlex_popstate (); ldlex_script (); }
923 sect_constraint
926 lang_enter_output_section_statement($1, $3,
927 sectype,
928 $5, $6, $4, $8);
930 statement_list_opt
931 '}' { ldlex_popstate (); ldlex_expression (); }
932 memspec_opt memspec_at_opt phdr_opt fill_opt
934 ldlex_popstate ();
935 lang_leave_output_section_statement ($17, $14, $16, $15);
937 opt_comma
939 | OVERLAY
940 { ldlex_expression (); }
941 opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
942 { ldlex_popstate (); ldlex_script (); }
945 lang_enter_overlay ($3, $6);
947 overlay_section
949 { ldlex_popstate (); ldlex_expression (); }
950 memspec_opt memspec_at_opt phdr_opt fill_opt
952 ldlex_popstate ();
953 lang_leave_overlay ($5, (int) $4,
954 $16, $13, $15, $14);
956 opt_comma
957 | /* The GROUP case is just enough to support the gcc
958 svr3.ifile script. It is not intended to be full
959 support. I'm not even sure what GROUP is supposed
960 to mean. */
961 GROUP { ldlex_expression (); }
962 opt_exp_with_type
964 ldlex_popstate ();
965 lang_add_assignment (exp_assop ('=', ".", $3));
967 '{' sec_or_group_p1 '}'
970 type:
971 NOLOAD { sectype = noload_section; }
972 | DSECT { sectype = noalloc_section; }
973 | COPY { sectype = noalloc_section; }
974 | INFO { sectype = noalloc_section; }
975 | OVERLAY { sectype = noalloc_section; }
978 atype:
979 '(' type ')'
980 | /* EMPTY */ { sectype = normal_section; }
981 | '(' ')' { sectype = normal_section; }
984 opt_exp_with_type:
985 exp atype ':' { $$ = $1; }
986 | atype ':' { $$ = (etree_type *)NULL; }
987 | /* The BIND cases are to support the gcc svr3.ifile
988 script. They aren't intended to implement full
989 support for the BIND keyword. I'm not even sure
990 what BIND is supposed to mean. */
991 BIND '(' exp ')' atype ':' { $$ = $3; }
992 | BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
993 { $$ = $3; }
996 opt_exp_without_type:
997 exp ':' { $$ = $1; }
998 | ':' { $$ = (etree_type *) NULL; }
1001 opt_nocrossrefs:
1002 /* empty */
1003 { $$ = 0; }
1004 | NOCROSSREFS
1005 { $$ = 1; }
1008 memspec_opt:
1009 '>' NAME
1010 { $$ = $2; }
1011 | { $$ = DEFAULT_MEMORY_REGION; }
1014 phdr_opt:
1015 /* empty */
1017 $$ = NULL;
1019 | phdr_opt ':' NAME
1021 struct lang_output_section_phdr_list *n;
1023 n = ((struct lang_output_section_phdr_list *)
1024 xmalloc (sizeof *n));
1025 n->name = $3;
1026 n->used = FALSE;
1027 n->next = $1;
1028 $$ = n;
1032 overlay_section:
1033 /* empty */
1034 | overlay_section
1035 NAME
1037 ldlex_script ();
1038 lang_enter_overlay_section ($2);
1040 '{' statement_list_opt '}'
1041 { ldlex_popstate (); ldlex_expression (); }
1042 phdr_opt fill_opt
1044 ldlex_popstate ();
1045 lang_leave_overlay_section ($9, $8);
1047 opt_comma
1050 phdrs:
1051 PHDRS '{' phdr_list '}'
1054 phdr_list:
1055 /* empty */
1056 | phdr_list phdr
1059 phdr:
1060 NAME { ldlex_expression (); }
1061 phdr_type phdr_qualifiers { ldlex_popstate (); }
1064 lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1065 $4.flags);
1069 phdr_type:
1072 $$ = $1;
1074 if ($1->type.node_class == etree_name
1075 && $1->type.node_code == NAME)
1077 const char *s;
1078 unsigned int i;
1079 static const char * const phdr_types[] =
1081 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1082 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
1083 "PT_PHDR", "PT_TLS"
1086 s = $1->name.name;
1087 for (i = 0;
1088 i < sizeof phdr_types / sizeof phdr_types[0];
1089 i++)
1090 if (strcmp (s, phdr_types[i]) == 0)
1092 $$ = exp_intop (i);
1093 break;
1095 if (i == sizeof phdr_types / sizeof phdr_types[0])
1097 if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1098 $$ = exp_intop (0x6474e550);
1099 else if (strcmp (s, "PT_GNU_STACK") == 0)
1100 $$ = exp_intop (0x6474e551);
1101 else
1103 einfo (_("\
1104 %X%P:%S: unknown phdr type `%s' (try integer literal)\n"),
1106 $$ = exp_intop (0);
1113 phdr_qualifiers:
1114 /* empty */
1116 memset (&$$, 0, sizeof (struct phdr_info));
1118 | NAME phdr_val phdr_qualifiers
1120 $$ = $3;
1121 if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
1122 $$.filehdr = TRUE;
1123 else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
1124 $$.phdrs = TRUE;
1125 else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1126 $$.flags = $2;
1127 else
1128 einfo (_("%X%P:%S: PHDRS syntax error at `%s'\n"), $1);
1130 | AT '(' exp ')' phdr_qualifiers
1132 $$ = $5;
1133 $$.at = $3;
1137 phdr_val:
1138 /* empty */
1140 $$ = NULL;
1142 | '(' exp ')'
1144 $$ = $2;
1148 dynamic_list_file:
1150 ldlex_version_file ();
1151 PUSH_ERROR (_("dynamic list"));
1153 dynamic_list_nodes
1155 ldlex_popstate ();
1156 POP_ERROR ();
1160 dynamic_list_nodes:
1161 dynamic_list_node
1162 | dynamic_list_nodes dynamic_list_node
1165 dynamic_list_node:
1166 '{' dynamic_list_tag '}' ';'
1169 dynamic_list_tag:
1170 vers_defns ';'
1172 lang_append_dynamic_list ($1);
1176 /* This syntax is used within an external version script file. */
1178 version_script_file:
1180 ldlex_version_file ();
1181 PUSH_ERROR (_("VERSION script"));
1183 vers_nodes
1185 ldlex_popstate ();
1186 POP_ERROR ();
1190 /* This is used within a normal linker script file. */
1192 version:
1194 ldlex_version_script ();
1196 VERSIONK '{' vers_nodes '}'
1198 ldlex_popstate ();
1202 vers_nodes:
1203 vers_node
1204 | vers_nodes vers_node
1207 vers_node:
1208 '{' vers_tag '}' ';'
1210 lang_register_vers_node (NULL, $2, NULL);
1212 | VERS_TAG '{' vers_tag '}' ';'
1214 lang_register_vers_node ($1, $3, NULL);
1216 | VERS_TAG '{' vers_tag '}' verdep ';'
1218 lang_register_vers_node ($1, $3, $5);
1222 verdep:
1223 VERS_TAG
1225 $$ = lang_add_vers_depend (NULL, $1);
1227 | verdep VERS_TAG
1229 $$ = lang_add_vers_depend ($1, $2);
1233 vers_tag:
1234 /* empty */
1236 $$ = lang_new_vers_node (NULL, NULL);
1238 | vers_defns ';'
1240 $$ = lang_new_vers_node ($1, NULL);
1242 | GLOBAL ':' vers_defns ';'
1244 $$ = lang_new_vers_node ($3, NULL);
1246 | LOCAL ':' vers_defns ';'
1248 $$ = lang_new_vers_node (NULL, $3);
1250 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1252 $$ = lang_new_vers_node ($3, $7);
1256 vers_defns:
1257 VERS_IDENTIFIER
1259 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, FALSE);
1261 | NAME
1263 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, TRUE);
1265 | vers_defns ';' VERS_IDENTIFIER
1267 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, FALSE);
1269 | vers_defns ';' NAME
1271 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, TRUE);
1273 | vers_defns ';' EXTERN NAME '{'
1275 $<name>$ = ldgram_vers_current_lang;
1276 ldgram_vers_current_lang = $4;
1278 vers_defns opt_semicolon '}'
1280 struct bfd_elf_version_expr *pat;
1281 for (pat = $7; pat->next != NULL; pat = pat->next);
1282 pat->next = $1;
1283 $$ = $7;
1284 ldgram_vers_current_lang = $<name>6;
1286 | EXTERN NAME '{'
1288 $<name>$ = ldgram_vers_current_lang;
1289 ldgram_vers_current_lang = $2;
1291 vers_defns opt_semicolon '}'
1293 $$ = $5;
1294 ldgram_vers_current_lang = $<name>4;
1296 | GLOBAL
1298 $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, FALSE);
1300 | vers_defns ';' GLOBAL
1302 $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, FALSE);
1304 | LOCAL
1306 $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, FALSE);
1308 | vers_defns ';' LOCAL
1310 $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, FALSE);
1312 | EXTERN
1314 $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, FALSE);
1316 | vers_defns ';' EXTERN
1318 $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, FALSE);
1322 opt_semicolon:
1323 /* empty */
1324 | ';'
1328 void
1329 yyerror(arg)
1330 const char *arg;
1332 if (ldfile_assumed_script)
1333 einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
1334 ldfile_input_filename);
1335 if (error_index > 0 && error_index < ERROR_NAME_MAX)
1336 einfo ("%P%F:%S: %s in %s\n", arg, error_names[error_index-1]);
1337 else
1338 einfo ("%P%F:%S: %s\n", arg);