* more static'ing.
[binutils.git] / ld / ldgram.y
blobfefd7bc13486009f615c143f24a502bcb2ac6b3c
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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #define DONTDECLARE_MALLOC
29 #include "bfd.h"
30 #include "sysdep.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 static bfd_boolean ldgram_want_filename = TRUE;
52 FILE *saved_script_handle = NULL;
53 bfd_boolean force_make_executable = FALSE;
55 bfd_boolean ldgram_in_script = FALSE;
56 bfd_boolean ldgram_had_equals = FALSE;
57 bfd_boolean ldgram_had_keep = FALSE;
58 char *ldgram_vers_current_lang = NULL;
60 #define ERROR_NAME_MAX 20
61 static char *error_names[ERROR_NAME_MAX];
62 static int error_index;
63 #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
64 #define POP_ERROR() error_index--;
66 %union {
67 bfd_vma integer;
68 struct big_int
70 bfd_vma integer;
71 char *str;
72 } bigint;
73 fill_type *fill;
74 char *name;
75 const char *cname;
76 struct wildcard_spec wildcard;
77 struct wildcard_list *wildcard_list;
78 struct name_list *name_list;
79 int token;
80 union etree_union *etree;
81 struct phdr_info
83 bfd_boolean filehdr;
84 bfd_boolean phdrs;
85 union etree_union *at;
86 union etree_union *flags;
87 } phdr;
88 struct lang_nocrossref *nocrossref;
89 struct lang_output_section_phdr_list *section_phdr;
90 struct bfd_elf_version_deps *deflist;
91 struct bfd_elf_version_expr *versyms;
92 struct bfd_elf_version_tree *versnode;
95 %type <etree> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val
96 %type <etree> opt_exp_without_type opt_subalign
97 %type <fill> fill_opt fill_exp
98 %type <name_list> exclude_name_list
99 %type <wildcard_list> file_NAME_list
100 %type <name> memspec_opt casesymlist
101 %type <name> memspec_at_opt
102 %type <cname> wildcard_name
103 %type <wildcard> wildcard_spec
104 %token <bigint> INT
105 %token <name> NAME LNAME
106 %type <integer> length
107 %type <phdr> phdr_qualifiers
108 %type <nocrossref> nocrossref_list
109 %type <section_phdr> phdr_opt
110 %type <integer> opt_nocrossrefs
112 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
113 %right <token> '?' ':'
114 %left <token> OROR
115 %left <token> ANDAND
116 %left <token> '|'
117 %left <token> '^'
118 %left <token> '&'
119 %left <token> EQ NE
120 %left <token> '<' '>' LE GE
121 %left <token> LSHIFT RSHIFT
123 %left <token> '+' '-'
124 %left <token> '*' '/' '%'
126 %right UNARY
127 %token END
128 %left <token> '('
129 %token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
130 %token SECTIONS PHDRS DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
131 %token SORT_BY_NAME SORT_BY_ALIGNMENT
132 %token '{' '}'
133 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
134 %token INHIBIT_COMMON_ALLOCATION
135 %token SIZEOF_HEADERS
136 %token SEGMENT_START
137 %token INCLUDE
138 %token MEMORY DEFSYMEND
139 %token NOLOAD DSECT COPY INFO OVERLAY
140 %token NAME LNAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
141 %token <integer> NEXT
142 %token SIZEOF ADDR LOADADDR MAX_K MIN_K
143 %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS
144 %token ORIGIN FILL
145 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
146 %token ALIGNMOD AT SUBALIGN PROVIDE AS_NEEDED
147 %type <token> assign_op atype attributes_opt sect_constraint
148 %type <name> filename
149 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
150 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
151 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
152 %token <name> VERS_TAG VERS_IDENTIFIER
153 %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
154 %token KEEP ONLY_IF_RO ONLY_IF_RW
155 %token EXCLUDE_FILE
156 %type <versyms> vers_defns
157 %type <versnode> vers_tag
158 %type <deflist> verdep
162 file:
163 INPUT_SCRIPT script_file
164 | INPUT_MRI_SCRIPT mri_script_file
165 | INPUT_VERSION_SCRIPT version_script_file
166 | INPUT_DEFSYM defsym_expr
170 filename: NAME;
173 defsym_expr:
174 { ldlex_defsym(); }
175 NAME '=' exp
177 ldlex_popstate();
178 lang_add_assignment(exp_assop($3,$2,$4));
182 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
183 mri_script_file:
185 ldlex_mri_script ();
186 PUSH_ERROR (_("MRI style script"));
188 mri_script_lines
190 ldlex_popstate ();
191 mri_draw_tree ();
192 POP_ERROR ();
196 mri_script_lines:
197 mri_script_lines mri_script_command NEWLINE
201 mri_script_command:
202 CHIP exp
203 | CHIP exp ',' exp
204 | NAME {
205 einfo(_("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1);
207 | LIST {
208 config.map_filename = "-";
210 | ORDER ordernamelist
211 | ENDWORD
212 | PUBLIC NAME '=' exp
213 { mri_public($2, $4); }
214 | PUBLIC NAME ',' exp
215 { mri_public($2, $4); }
216 | PUBLIC NAME exp
217 { mri_public($2, $3); }
218 | FORMAT NAME
219 { mri_format($2); }
220 | SECT NAME ',' exp
221 { mri_output_section($2, $4);}
222 | SECT NAME exp
223 { mri_output_section($2, $3);}
224 | SECT NAME '=' exp
225 { mri_output_section($2, $4);}
226 | ALIGN_K NAME '=' exp
227 { mri_align($2,$4); }
228 | ALIGN_K NAME ',' exp
229 { mri_align($2,$4); }
230 | ALIGNMOD NAME '=' exp
231 { mri_alignmod($2,$4); }
232 | ALIGNMOD NAME ',' exp
233 { mri_alignmod($2,$4); }
234 | ABSOLUTE mri_abs_name_list
235 | LOAD mri_load_name_list
236 | NAMEWORD NAME
237 { mri_name($2); }
238 | ALIAS NAME ',' NAME
239 { mri_alias($2,$4,0);}
240 | ALIAS NAME ',' INT
241 { mri_alias ($2, 0, (int) $4.integer); }
242 | BASE exp
243 { mri_base($2); }
244 | TRUNCATE INT
245 { mri_truncate ((unsigned int) $2.integer); }
246 | CASE casesymlist
247 | EXTERN extern_name_list
248 | INCLUDE filename
249 { ldlex_script (); ldfile_open_command_file($2); }
250 mri_script_lines END
251 { ldlex_popstate (); }
252 | START NAME
253 { lang_add_entry ($2, FALSE); }
257 ordernamelist:
258 ordernamelist ',' NAME { mri_order($3); }
259 | ordernamelist NAME { mri_order($2); }
263 mri_load_name_list:
264 NAME
265 { mri_load($1); }
266 | mri_load_name_list ',' NAME { mri_load($3); }
269 mri_abs_name_list:
270 NAME
271 { mri_only_load($1); }
272 | mri_abs_name_list ',' NAME
273 { mri_only_load($3); }
276 casesymlist:
277 /* empty */ { $$ = NULL; }
278 | NAME
279 | casesymlist ',' NAME
282 extern_name_list:
283 NAME
284 { ldlang_add_undef ($1); }
285 | extern_name_list NAME
286 { ldlang_add_undef ($2); }
287 | extern_name_list ',' NAME
288 { ldlang_add_undef ($3); }
291 script_file:
293 ldlex_both();
295 ifile_list
297 ldlex_popstate();
302 ifile_list:
303 ifile_list ifile_p1
309 ifile_p1:
310 memory
311 | sections
312 | phdrs
313 | startup
314 | high_level_library
315 | low_level_library
316 | floating_point_support
317 | statement_anywhere
318 | version
319 | ';'
320 | TARGET_K '(' NAME ')'
321 { lang_add_target($3); }
322 | SEARCH_DIR '(' filename ')'
323 { ldfile_add_library_path ($3, FALSE); }
324 | OUTPUT '(' filename ')'
325 { lang_add_output($3, 1); }
326 | OUTPUT_FORMAT '(' NAME ')'
327 { lang_add_output_format ($3, (char *) NULL,
328 (char *) NULL, 1); }
329 | OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')'
330 { lang_add_output_format ($3, $5, $7, 1); }
331 | OUTPUT_ARCH '(' NAME ')'
332 { ldfile_set_output_arch ($3, bfd_arch_unknown); }
333 | FORCE_COMMON_ALLOCATION
334 { command_line.force_common_definition = TRUE ; }
335 | INHIBIT_COMMON_ALLOCATION
336 { command_line.inhibit_common_definition = TRUE ; }
337 | INPUT '(' input_list ')'
338 | GROUP
339 { lang_enter_group (); }
340 '(' input_list ')'
341 { lang_leave_group (); }
342 | MAP '(' filename ')'
343 { lang_add_map($3); }
344 | INCLUDE filename
345 { ldlex_script (); ldfile_open_command_file($2); }
346 ifile_list END
347 { ldlex_popstate (); }
348 | NOCROSSREFS '(' nocrossref_list ')'
350 lang_add_nocrossref ($3);
352 | EXTERN '(' extern_name_list ')'
355 input_list:
356 NAME
357 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
358 (char *)NULL); }
359 | input_list ',' NAME
360 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
361 (char *)NULL); }
362 | input_list NAME
363 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
364 (char *)NULL); }
365 | LNAME
366 { lang_add_input_file($1,lang_input_file_is_l_enum,
367 (char *)NULL); }
368 | input_list ',' LNAME
369 { lang_add_input_file($3,lang_input_file_is_l_enum,
370 (char *)NULL); }
371 | input_list LNAME
372 { lang_add_input_file($2,lang_input_file_is_l_enum,
373 (char *)NULL); }
374 | AS_NEEDED '('
375 { $<integer>$ = as_needed; as_needed = TRUE; }
376 input_list ')'
377 { as_needed = $<integer>3; }
378 | input_list ',' AS_NEEDED '('
379 { $<integer>$ = as_needed; as_needed = TRUE; }
380 input_list ')'
381 { as_needed = $<integer>5; }
382 | input_list AS_NEEDED '('
383 { $<integer>$ = as_needed; as_needed = TRUE; }
384 input_list ')'
385 { as_needed = $<integer>4; }
388 sections:
389 SECTIONS '{' sec_or_group_p1 '}'
392 sec_or_group_p1:
393 sec_or_group_p1 section
394 | sec_or_group_p1 statement_anywhere
398 statement_anywhere:
399 ENTRY '(' NAME ')'
400 { lang_add_entry ($3, FALSE); }
401 | assignment end
402 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')'
403 { ldlex_popstate ();
404 lang_add_assignment (exp_assert ($4, $6)); }
407 /* The '*' and '?' cases are there because the lexer returns them as
408 separate tokens rather than as NAME. */
409 wildcard_name:
410 NAME
412 $$ = $1;
414 | '*'
416 $$ = "*";
418 | '?'
420 $$ = "?";
424 wildcard_spec:
425 wildcard_name
427 $$.name = $1;
428 $$.sorted = none;
429 $$.exclude_name_list = NULL;
431 | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
433 $$.name = $5;
434 $$.sorted = none;
435 $$.exclude_name_list = $3;
437 | SORT_BY_NAME '(' wildcard_name ')'
439 $$.name = $3;
440 $$.sorted = by_name;
441 $$.exclude_name_list = NULL;
443 | SORT_BY_ALIGNMENT '(' wildcard_name ')'
445 $$.name = $3;
446 $$.sorted = by_alignment;
447 $$.exclude_name_list = NULL;
449 | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
451 $$.name = $5;
452 $$.sorted = by_name_alignment;
453 $$.exclude_name_list = NULL;
455 | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_name ')' ')'
457 $$.name = $5;
458 $$.sorted = by_name;
459 $$.exclude_name_list = NULL;
461 | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_name ')' ')'
463 $$.name = $5;
464 $$.sorted = by_alignment_name;
465 $$.exclude_name_list = NULL;
467 | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
469 $$.name = $5;
470 $$.sorted = by_alignment;
471 $$.exclude_name_list = NULL;
473 | SORT_BY_NAME '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')'
475 $$.name = $7;
476 $$.sorted = by_name;
477 $$.exclude_name_list = $5;
481 exclude_name_list:
482 exclude_name_list wildcard_name
484 struct name_list *tmp;
485 tmp = (struct name_list *) xmalloc (sizeof *tmp);
486 tmp->name = $2;
487 tmp->next = $1;
488 $$ = tmp;
491 wildcard_name
493 struct name_list *tmp;
494 tmp = (struct name_list *) xmalloc (sizeof *tmp);
495 tmp->name = $1;
496 tmp->next = NULL;
497 $$ = tmp;
501 file_NAME_list:
502 file_NAME_list opt_comma wildcard_spec
504 struct wildcard_list *tmp;
505 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
506 tmp->next = $1;
507 tmp->spec = $3;
508 $$ = tmp;
511 wildcard_spec
513 struct wildcard_list *tmp;
514 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
515 tmp->next = NULL;
516 tmp->spec = $1;
517 $$ = tmp;
521 input_section_spec_no_keep:
522 NAME
524 struct wildcard_spec tmp;
525 tmp.name = $1;
526 tmp.exclude_name_list = NULL;
527 tmp.sorted = none;
528 lang_add_wild (&tmp, NULL, ldgram_had_keep);
530 | '[' file_NAME_list ']'
532 lang_add_wild (NULL, $2, ldgram_had_keep);
534 | wildcard_spec '(' file_NAME_list ')'
536 lang_add_wild (&$1, $3, ldgram_had_keep);
540 input_section_spec:
541 input_section_spec_no_keep
542 | KEEP '('
543 { ldgram_had_keep = TRUE; }
544 input_section_spec_no_keep ')'
545 { ldgram_had_keep = FALSE; }
548 statement:
549 assignment end
550 | CREATE_OBJECT_SYMBOLS
552 lang_add_attribute(lang_object_symbols_statement_enum);
554 | ';'
555 | CONSTRUCTORS
558 lang_add_attribute(lang_constructors_statement_enum);
560 | SORT_BY_NAME '(' CONSTRUCTORS ')'
562 constructors_sorted = TRUE;
563 lang_add_attribute (lang_constructors_statement_enum);
565 | input_section_spec
566 | length '(' mustbe_exp ')'
568 lang_add_data ((int) $1, $3);
571 | FILL '(' fill_exp ')'
573 lang_add_fill ($3);
577 statement_list:
578 statement_list statement
579 | statement
582 statement_list_opt:
583 /* empty */
584 | statement_list
587 length:
588 QUAD
589 { $$ = $1; }
590 | SQUAD
591 { $$ = $1; }
592 | LONG
593 { $$ = $1; }
594 | SHORT
595 { $$ = $1; }
596 | BYTE
597 { $$ = $1; }
600 fill_exp:
601 mustbe_exp
603 $$ = exp_get_fill ($1,
605 "fill value",
606 lang_first_phase_enum);
610 fill_opt:
611 '=' fill_exp
612 { $$ = $2; }
613 | { $$ = (fill_type *) 0; }
616 assign_op:
617 PLUSEQ
618 { $$ = '+'; }
619 | MINUSEQ
620 { $$ = '-'; }
621 | MULTEQ
622 { $$ = '*'; }
623 | DIVEQ
624 { $$ = '/'; }
625 | LSHIFTEQ
626 { $$ = LSHIFT; }
627 | RSHIFTEQ
628 { $$ = RSHIFT; }
629 | ANDEQ
630 { $$ = '&'; }
631 | OREQ
632 { $$ = '|'; }
636 end: ';' | ','
640 assignment:
641 NAME '=' mustbe_exp
643 lang_add_assignment (exp_assop ($2, $1, $3));
645 | NAME assign_op mustbe_exp
647 lang_add_assignment (exp_assop ('=', $1,
648 exp_binop ($2,
649 exp_nameop (NAME,
650 $1),
651 $3)));
653 | PROVIDE '(' NAME '=' mustbe_exp ')'
655 lang_add_assignment (exp_provide ($3, $5));
660 opt_comma:
661 ',' | ;
664 memory:
665 MEMORY '{' memory_spec memory_spec_list '}'
668 memory_spec_list:
669 memory_spec_list memory_spec
670 | memory_spec_list ',' memory_spec
675 memory_spec: NAME
676 { region = lang_memory_region_lookup ($1, TRUE); }
677 attributes_opt ':'
678 origin_spec opt_comma length_spec
682 origin_spec:
683 ORIGIN '=' mustbe_exp
684 { region->current =
685 region->origin =
686 exp_get_vma($3, 0L,"origin", lang_first_phase_enum);
690 length_spec:
691 LENGTH '=' mustbe_exp
692 { region->length = exp_get_vma($3,
693 ~((bfd_vma)0),
694 "length",
695 lang_first_phase_enum);
699 attributes_opt:
700 /* empty */
701 { /* dummy action to avoid bison 1.25 error message */ }
702 | '(' attributes_list ')'
705 attributes_list:
706 attributes_string
707 | attributes_list attributes_string
710 attributes_string:
711 NAME
712 { lang_set_flags (region, $1, 0); }
713 | '!' NAME
714 { lang_set_flags (region, $2, 1); }
717 startup:
718 STARTUP '(' filename ')'
719 { lang_startup($3); }
722 high_level_library:
723 HLL '(' high_level_library_NAME_list ')'
724 | HLL '(' ')'
725 { ldemul_hll((char *)NULL); }
728 high_level_library_NAME_list:
729 high_level_library_NAME_list opt_comma filename
730 { ldemul_hll($3); }
731 | filename
732 { ldemul_hll($1); }
736 low_level_library:
737 SYSLIB '(' low_level_library_NAME_list ')'
738 ; low_level_library_NAME_list:
739 low_level_library_NAME_list opt_comma filename
740 { ldemul_syslib($3); }
744 floating_point_support:
745 FLOAT
746 { lang_float(TRUE); }
747 | NOFLOAT
748 { lang_float(FALSE); }
751 nocrossref_list:
752 /* empty */
754 $$ = NULL;
756 | NAME nocrossref_list
758 struct lang_nocrossref *n;
760 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
761 n->name = $1;
762 n->next = $2;
763 $$ = n;
765 | NAME ',' nocrossref_list
767 struct lang_nocrossref *n;
769 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
770 n->name = $1;
771 n->next = $3;
772 $$ = n;
776 mustbe_exp: { ldlex_expression (); }
778 { ldlex_popstate (); $$=$2;}
781 exp :
782 '-' exp %prec UNARY
783 { $$ = exp_unop ('-', $2); }
784 | '(' exp ')'
785 { $$ = $2; }
786 | NEXT '(' exp ')' %prec UNARY
787 { $$ = exp_unop ((int) $1,$3); }
788 | '!' exp %prec UNARY
789 { $$ = exp_unop ('!', $2); }
790 | '+' exp %prec UNARY
791 { $$ = $2; }
792 | '~' exp %prec UNARY
793 { $$ = exp_unop ('~', $2);}
795 | exp '*' exp
796 { $$ = exp_binop ('*', $1, $3); }
797 | exp '/' exp
798 { $$ = exp_binop ('/', $1, $3); }
799 | exp '%' exp
800 { $$ = exp_binop ('%', $1, $3); }
801 | exp '+' exp
802 { $$ = exp_binop ('+', $1, $3); }
803 | exp '-' exp
804 { $$ = exp_binop ('-' , $1, $3); }
805 | exp LSHIFT exp
806 { $$ = exp_binop (LSHIFT , $1, $3); }
807 | exp RSHIFT exp
808 { $$ = exp_binop (RSHIFT , $1, $3); }
809 | exp EQ exp
810 { $$ = exp_binop (EQ , $1, $3); }
811 | exp NE exp
812 { $$ = exp_binop (NE , $1, $3); }
813 | exp LE exp
814 { $$ = exp_binop (LE , $1, $3); }
815 | exp GE exp
816 { $$ = exp_binop (GE , $1, $3); }
817 | exp '<' exp
818 { $$ = exp_binop ('<' , $1, $3); }
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 ':' exp
828 { $$ = exp_trinop ('?' , $1, $3, $5); }
829 | exp ANDAND exp
830 { $$ = exp_binop (ANDAND , $1, $3); }
831 | exp OROR exp
832 { $$ = exp_binop (OROR , $1, $3); }
833 | DEFINED '(' NAME ')'
834 { $$ = exp_nameop (DEFINED, $3); }
835 | INT
836 { $$ = exp_bigintop ($1.integer, $1.str); }
837 | SIZEOF_HEADERS
838 { $$ = exp_nameop (SIZEOF_HEADERS,0); }
840 | SIZEOF '(' NAME ')'
841 { $$ = exp_nameop (SIZEOF,$3); }
842 | ADDR '(' NAME ')'
843 { $$ = exp_nameop (ADDR,$3); }
844 | LOADADDR '(' NAME ')'
845 { $$ = exp_nameop (LOADADDR,$3); }
846 | ABSOLUTE '(' exp ')'
847 { $$ = exp_unop (ABSOLUTE, $3); }
848 | ALIGN_K '(' exp ')'
849 { $$ = exp_unop (ALIGN_K,$3); }
850 | ALIGN_K '(' exp ',' exp ')'
851 { $$ = exp_binop (ALIGN_K,$3,$5); }
852 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
853 { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
854 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
855 { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
856 | DATA_SEGMENT_END '(' exp ')'
857 { $$ = exp_unop (DATA_SEGMENT_END, $3); }
858 | SEGMENT_START '(' NAME ',' exp ')'
859 { /* The operands to the expression node are
860 placed in the opposite order from the way
861 in which they appear in the script as
862 that allows us to reuse more code in
863 fold_binary. */
864 $$ = exp_binop (SEGMENT_START,
866 exp_nameop (NAME, $3)); }
867 | BLOCK '(' exp ')'
868 { $$ = exp_unop (ALIGN_K,$3); }
869 | NAME
870 { $$ = exp_nameop (NAME,$1); }
871 | MAX_K '(' exp ',' exp ')'
872 { $$ = exp_binop (MAX_K, $3, $5 ); }
873 | MIN_K '(' exp ',' exp ')'
874 { $$ = exp_binop (MIN_K, $3, $5 ); }
875 | ASSERT_K '(' exp ',' NAME ')'
876 { $$ = exp_assert ($3, $5); }
877 | ORIGIN '(' NAME ')'
878 { $$ = exp_nameop (ORIGIN, $3); }
879 | LENGTH '(' NAME ')'
880 { $$ = exp_nameop (LENGTH, $3); }
884 memspec_at_opt:
885 AT '>' NAME { $$ = $3; }
886 | { $$ = 0; }
889 opt_at:
890 AT '(' exp ')' { $$ = $3; }
891 | { $$ = 0; }
894 opt_subalign:
895 SUBALIGN '(' exp ')' { $$ = $3; }
896 | { $$ = 0; }
899 sect_constraint:
900 ONLY_IF_RO { $$ = ONLY_IF_RO; }
901 | ONLY_IF_RW { $$ = ONLY_IF_RW; }
902 | { $$ = 0; }
905 section: NAME { ldlex_expression(); }
906 opt_exp_with_type
907 opt_at
908 opt_subalign { ldlex_popstate (); ldlex_script (); }
909 sect_constraint
912 lang_enter_output_section_statement($1, $3,
913 sectype,
914 0, $5, $4, $7);
916 statement_list_opt
917 '}' { ldlex_popstate (); ldlex_expression (); }
918 memspec_opt memspec_at_opt phdr_opt fill_opt
920 ldlex_popstate ();
921 lang_leave_output_section_statement ($16, $13, $15, $14);
923 opt_comma
925 | OVERLAY
926 { ldlex_expression (); }
927 opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
928 { ldlex_popstate (); ldlex_script (); }
931 lang_enter_overlay ($3, $6);
933 overlay_section
935 { ldlex_popstate (); ldlex_expression (); }
936 memspec_opt memspec_at_opt phdr_opt fill_opt
938 ldlex_popstate ();
939 lang_leave_overlay ($5, (int) $4,
940 $16, $13, $15, $14);
942 opt_comma
943 | /* The GROUP case is just enough to support the gcc
944 svr3.ifile script. It is not intended to be full
945 support. I'm not even sure what GROUP is supposed
946 to mean. */
947 GROUP { ldlex_expression (); }
948 opt_exp_with_type
950 ldlex_popstate ();
951 lang_add_assignment (exp_assop ('=', ".", $3));
953 '{' sec_or_group_p1 '}'
956 type:
957 NOLOAD { sectype = noload_section; }
958 | DSECT { sectype = dsect_section; }
959 | COPY { sectype = copy_section; }
960 | INFO { sectype = info_section; }
961 | OVERLAY { sectype = overlay_section; }
964 atype:
965 '(' type ')'
966 | /* EMPTY */ { sectype = normal_section; }
967 | '(' ')' { sectype = normal_section; }
970 opt_exp_with_type:
971 exp atype ':' { $$ = $1; }
972 | atype ':' { $$ = (etree_type *)NULL; }
973 | /* The BIND cases are to support the gcc svr3.ifile
974 script. They aren't intended to implement full
975 support for the BIND keyword. I'm not even sure
976 what BIND is supposed to mean. */
977 BIND '(' exp ')' atype ':' { $$ = $3; }
978 | BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
979 { $$ = $3; }
982 opt_exp_without_type:
983 exp ':' { $$ = $1; }
984 | ':' { $$ = (etree_type *) NULL; }
987 opt_nocrossrefs:
988 /* empty */
989 { $$ = 0; }
990 | NOCROSSREFS
991 { $$ = 1; }
994 memspec_opt:
995 '>' NAME
996 { $$ = $2; }
997 | { $$ = DEFAULT_MEMORY_REGION; }
1000 phdr_opt:
1001 /* empty */
1003 $$ = NULL;
1005 | phdr_opt ':' NAME
1007 struct lang_output_section_phdr_list *n;
1009 n = ((struct lang_output_section_phdr_list *)
1010 xmalloc (sizeof *n));
1011 n->name = $3;
1012 n->used = FALSE;
1013 n->next = $1;
1014 $$ = n;
1018 overlay_section:
1019 /* empty */
1020 | overlay_section
1021 NAME
1023 ldlex_script ();
1024 lang_enter_overlay_section ($2);
1026 '{' statement_list_opt '}'
1027 { ldlex_popstate (); ldlex_expression (); }
1028 phdr_opt fill_opt
1030 ldlex_popstate ();
1031 lang_leave_overlay_section ($9, $8);
1033 opt_comma
1036 phdrs:
1037 PHDRS '{' phdr_list '}'
1040 phdr_list:
1041 /* empty */
1042 | phdr_list phdr
1045 phdr:
1046 NAME { ldlex_expression (); }
1047 phdr_type phdr_qualifiers { ldlex_popstate (); }
1050 lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1051 $4.flags);
1055 phdr_type:
1058 $$ = $1;
1060 if ($1->type.node_class == etree_name
1061 && $1->type.node_code == NAME)
1063 const char *s;
1064 unsigned int i;
1065 static const char * const phdr_types[] =
1067 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1068 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
1069 "PT_PHDR", "PT_TLS"
1072 s = $1->name.name;
1073 for (i = 0;
1074 i < sizeof phdr_types / sizeof phdr_types[0];
1075 i++)
1076 if (strcmp (s, phdr_types[i]) == 0)
1078 $$ = exp_intop (i);
1079 break;
1081 if (i == sizeof phdr_types / sizeof phdr_types[0])
1083 if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1084 $$ = exp_intop (0x6474e550);
1085 else if (strcmp (s, "PT_GNU_STACK") == 0)
1086 $$ = exp_intop (0x6474e551);
1087 else
1089 einfo (_("\
1090 %X%P:%S: unknown phdr type `%s' (try integer literal)\n"),
1092 $$ = exp_intop (0);
1099 phdr_qualifiers:
1100 /* empty */
1102 memset (&$$, 0, sizeof (struct phdr_info));
1104 | NAME phdr_val phdr_qualifiers
1106 $$ = $3;
1107 if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
1108 $$.filehdr = TRUE;
1109 else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
1110 $$.phdrs = TRUE;
1111 else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1112 $$.flags = $2;
1113 else
1114 einfo (_("%X%P:%S: PHDRS syntax error at `%s'\n"), $1);
1116 | AT '(' exp ')' phdr_qualifiers
1118 $$ = $5;
1119 $$.at = $3;
1123 phdr_val:
1124 /* empty */
1126 $$ = NULL;
1128 | '(' exp ')'
1130 $$ = $2;
1134 /* This syntax is used within an external version script file. */
1136 version_script_file:
1138 ldlex_version_file ();
1139 PUSH_ERROR (_("VERSION script"));
1141 vers_nodes
1143 ldlex_popstate ();
1144 POP_ERROR ();
1148 /* This is used within a normal linker script file. */
1150 version:
1152 ldlex_version_script ();
1154 VERSIONK '{' vers_nodes '}'
1156 ldlex_popstate ();
1160 vers_nodes:
1161 vers_node
1162 | vers_nodes vers_node
1165 vers_node:
1166 '{' vers_tag '}' ';'
1168 lang_register_vers_node (NULL, $2, NULL);
1170 | VERS_TAG '{' vers_tag '}' ';'
1172 lang_register_vers_node ($1, $3, NULL);
1174 | VERS_TAG '{' vers_tag '}' verdep ';'
1176 lang_register_vers_node ($1, $3, $5);
1180 verdep:
1181 VERS_TAG
1183 $$ = lang_add_vers_depend (NULL, $1);
1185 | verdep VERS_TAG
1187 $$ = lang_add_vers_depend ($1, $2);
1191 vers_tag:
1192 /* empty */
1194 $$ = lang_new_vers_node (NULL, NULL);
1196 | vers_defns ';'
1198 $$ = lang_new_vers_node ($1, NULL);
1200 | GLOBAL ':' vers_defns ';'
1202 $$ = lang_new_vers_node ($3, NULL);
1204 | LOCAL ':' vers_defns ';'
1206 $$ = lang_new_vers_node (NULL, $3);
1208 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1210 $$ = lang_new_vers_node ($3, $7);
1214 vers_defns:
1215 VERS_IDENTIFIER
1217 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang);
1219 | vers_defns ';' VERS_IDENTIFIER
1221 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang);
1223 | vers_defns ';' EXTERN NAME '{'
1225 $<name>$ = ldgram_vers_current_lang;
1226 ldgram_vers_current_lang = $4;
1228 vers_defns opt_semicolon '}'
1230 $$ = $7;
1231 ldgram_vers_current_lang = $<name>6;
1233 | EXTERN NAME '{'
1235 $<name>$ = ldgram_vers_current_lang;
1236 ldgram_vers_current_lang = $2;
1238 vers_defns opt_semicolon '}'
1240 $$ = $5;
1241 ldgram_vers_current_lang = $<name>4;
1245 opt_semicolon:
1246 /* empty */
1247 | ';'
1251 void
1252 yyerror(arg)
1253 const char *arg;
1255 if (ldfile_assumed_script)
1256 einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
1257 ldfile_input_filename);
1258 if (error_index > 0 && error_index < ERROR_NAME_MAX)
1259 einfo ("%P%F:%S: %s in %s\n", arg, error_names[error_index-1]);
1260 else
1261 einfo ("%P%F:%S: %s\n", arg);