* ldlang.c (lang_record_phdrs): Don't add orphans to PT_INTERP header.
[binutils.git] / ld / ldgram.y
blob1149e6b29c40cbe9db08c542a9fab873e016224f
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 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 NOLOAD DSECT COPY INFO OVERLAY
135 %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY
136 %token <integer> NEXT
137 %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K
138 %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS
139 %token ORIGIN FILL
140 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
141 %token ALIGNMOD AT SUBALIGN PROVIDE PROVIDE_HIDDEN AS_NEEDED
142 %type <token> assign_op atype attributes_opt sect_constraint
143 %type <name> filename
144 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
145 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
146 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
147 %token <name> VERS_TAG VERS_IDENTIFIER
148 %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
149 %token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL
150 %token EXCLUDE_FILE
151 %token CONSTANT
152 %type <versyms> vers_defns
153 %type <versnode> vers_tag
154 %type <deflist> verdep
155 %token INPUT_DYNAMIC_LIST
159 file:
160 INPUT_SCRIPT script_file
161 | INPUT_MRI_SCRIPT mri_script_file
162 | INPUT_VERSION_SCRIPT version_script_file
163 | INPUT_DYNAMIC_LIST dynamic_list_file
164 | INPUT_DEFSYM defsym_expr
168 filename: NAME;
171 defsym_expr:
172 { ldlex_defsym(); }
173 NAME '=' exp
175 ldlex_popstate();
176 lang_add_assignment(exp_assop($3,$2,$4));
180 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
181 mri_script_file:
183 ldlex_mri_script ();
184 PUSH_ERROR (_("MRI style script"));
186 mri_script_lines
188 ldlex_popstate ();
189 mri_draw_tree ();
190 POP_ERROR ();
194 mri_script_lines:
195 mri_script_lines mri_script_command NEWLINE
199 mri_script_command:
200 CHIP exp
201 | CHIP exp ',' exp
202 | NAME {
203 einfo(_("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1);
205 | LIST {
206 config.map_filename = "-";
208 | ORDER ordernamelist
209 | ENDWORD
210 | PUBLIC NAME '=' exp
211 { mri_public($2, $4); }
212 | PUBLIC NAME ',' exp
213 { mri_public($2, $4); }
214 | PUBLIC NAME exp
215 { mri_public($2, $3); }
216 | FORMAT NAME
217 { mri_format($2); }
218 | SECT NAME ',' exp
219 { mri_output_section($2, $4);}
220 | SECT NAME exp
221 { mri_output_section($2, $3);}
222 | SECT NAME '=' exp
223 { mri_output_section($2, $4);}
224 | ALIGN_K NAME '=' exp
225 { mri_align($2,$4); }
226 | ALIGN_K NAME ',' exp
227 { mri_align($2,$4); }
228 | ALIGNMOD NAME '=' exp
229 { mri_alignmod($2,$4); }
230 | ALIGNMOD NAME ',' exp
231 { mri_alignmod($2,$4); }
232 | ABSOLUTE mri_abs_name_list
233 | LOAD mri_load_name_list
234 | NAMEWORD NAME
235 { mri_name($2); }
236 | ALIAS NAME ',' NAME
237 { mri_alias($2,$4,0);}
238 | ALIAS NAME ',' INT
239 { mri_alias ($2, 0, (int) $4.integer); }
240 | BASE exp
241 { mri_base($2); }
242 | TRUNCATE INT
243 { mri_truncate ((unsigned int) $2.integer); }
244 | CASE casesymlist
245 | EXTERN extern_name_list
246 | INCLUDE filename
247 { ldlex_script (); ldfile_open_command_file($2); }
248 mri_script_lines END
249 { ldlex_popstate (); }
250 | START NAME
251 { lang_add_entry ($2, FALSE); }
255 ordernamelist:
256 ordernamelist ',' NAME { mri_order($3); }
257 | ordernamelist NAME { mri_order($2); }
261 mri_load_name_list:
262 NAME
263 { mri_load($1); }
264 | mri_load_name_list ',' NAME { mri_load($3); }
267 mri_abs_name_list:
268 NAME
269 { mri_only_load($1); }
270 | mri_abs_name_list ',' NAME
271 { mri_only_load($3); }
274 casesymlist:
275 /* empty */ { $$ = NULL; }
276 | NAME
277 | casesymlist ',' NAME
280 /* Parsed as expressions so that commas separate entries */
281 extern_name_list:
282 { ldlex_expression (); }
283 extern_name_list_body
284 { ldlex_popstate (); }
286 extern_name_list_body:
287 NAME
288 { ldlang_add_undef ($1); }
289 | extern_name_list_body NAME
290 { ldlang_add_undef ($2); }
291 | extern_name_list_body ',' NAME
292 { ldlang_add_undef ($3); }
295 script_file:
296 { ldlex_both(); }
297 ifile_list
298 { ldlex_popstate(); }
301 ifile_list:
302 ifile_list ifile_p1
307 ifile_p1:
308 memory
309 | sections
310 | phdrs
311 | startup
312 | high_level_library
313 | low_level_library
314 | floating_point_support
315 | statement_anywhere
316 | version
317 | ';'
318 | TARGET_K '(' NAME ')'
319 { lang_add_target($3); }
320 | SEARCH_DIR '(' filename ')'
321 { ldfile_add_library_path ($3, FALSE); }
322 | OUTPUT '(' filename ')'
323 { lang_add_output($3, 1); }
324 | OUTPUT_FORMAT '(' NAME ')'
325 { lang_add_output_format ($3, (char *) NULL,
326 (char *) NULL, 1); }
327 | OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')'
328 { lang_add_output_format ($3, $5, $7, 1); }
329 | OUTPUT_ARCH '(' NAME ')'
330 { ldfile_set_output_arch ($3, bfd_arch_unknown); }
331 | FORCE_COMMON_ALLOCATION
332 { command_line.force_common_definition = TRUE ; }
333 | INHIBIT_COMMON_ALLOCATION
334 { command_line.inhibit_common_definition = TRUE ; }
335 | INPUT '(' input_list ')'
336 | GROUP
337 { lang_enter_group (); }
338 '(' input_list ')'
339 { lang_leave_group (); }
340 | MAP '(' filename ')'
341 { lang_add_map($3); }
342 | INCLUDE filename
343 { ldlex_script (); ldfile_open_command_file($2); }
344 ifile_list END
345 { ldlex_popstate (); }
346 | NOCROSSREFS '(' nocrossref_list ')'
348 lang_add_nocrossref ($3);
350 | EXTERN '(' extern_name_list ')'
351 | INSERT_K AFTER NAME
352 { lang_add_insert ($3, 0); }
353 | INSERT_K BEFORE NAME
354 { lang_add_insert ($3, 1); }
357 input_list:
358 NAME
359 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
360 (char *)NULL); }
361 | input_list ',' NAME
362 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
363 (char *)NULL); }
364 | input_list NAME
365 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
366 (char *)NULL); }
367 | LNAME
368 { lang_add_input_file($1,lang_input_file_is_l_enum,
369 (char *)NULL); }
370 | input_list ',' LNAME
371 { lang_add_input_file($3,lang_input_file_is_l_enum,
372 (char *)NULL); }
373 | input_list LNAME
374 { lang_add_input_file($2,lang_input_file_is_l_enum,
375 (char *)NULL); }
376 | AS_NEEDED '('
377 { $<integer>$ = as_needed; as_needed = TRUE; }
378 input_list ')'
379 { as_needed = $<integer>3; }
380 | input_list ',' AS_NEEDED '('
381 { $<integer>$ = as_needed; as_needed = TRUE; }
382 input_list ')'
383 { as_needed = $<integer>5; }
384 | input_list AS_NEEDED '('
385 { $<integer>$ = as_needed; as_needed = TRUE; }
386 input_list ')'
387 { as_needed = $<integer>4; }
390 sections:
391 SECTIONS '{' sec_or_group_p1 '}'
394 sec_or_group_p1:
395 sec_or_group_p1 section
396 | sec_or_group_p1 statement_anywhere
400 statement_anywhere:
401 ENTRY '(' NAME ')'
402 { lang_add_entry ($3, FALSE); }
403 | assignment end
404 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')'
405 { ldlex_popstate ();
406 lang_add_assignment (exp_assert ($4, $6)); }
409 /* The '*' and '?' cases are there because the lexer returns them as
410 separate tokens rather than as NAME. */
411 wildcard_name:
412 NAME
414 $$ = $1;
416 | '*'
418 $$ = "*";
420 | '?'
422 $$ = "?";
426 wildcard_spec:
427 wildcard_name
429 $$.name = $1;
430 $$.sorted = none;
431 $$.exclude_name_list = NULL;
433 | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
435 $$.name = $5;
436 $$.sorted = none;
437 $$.exclude_name_list = $3;
439 | SORT_BY_NAME '(' wildcard_name ')'
441 $$.name = $3;
442 $$.sorted = by_name;
443 $$.exclude_name_list = NULL;
445 | SORT_BY_ALIGNMENT '(' wildcard_name ')'
447 $$.name = $3;
448 $$.sorted = by_alignment;
449 $$.exclude_name_list = NULL;
451 | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
453 $$.name = $5;
454 $$.sorted = by_name_alignment;
455 $$.exclude_name_list = NULL;
457 | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_name ')' ')'
459 $$.name = $5;
460 $$.sorted = by_name;
461 $$.exclude_name_list = NULL;
463 | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_name ')' ')'
465 $$.name = $5;
466 $$.sorted = by_alignment_name;
467 $$.exclude_name_list = NULL;
469 | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
471 $$.name = $5;
472 $$.sorted = by_alignment;
473 $$.exclude_name_list = NULL;
475 | SORT_BY_NAME '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')'
477 $$.name = $7;
478 $$.sorted = by_name;
479 $$.exclude_name_list = $5;
483 exclude_name_list:
484 exclude_name_list wildcard_name
486 struct name_list *tmp;
487 tmp = (struct name_list *) xmalloc (sizeof *tmp);
488 tmp->name = $2;
489 tmp->next = $1;
490 $$ = tmp;
493 wildcard_name
495 struct name_list *tmp;
496 tmp = (struct name_list *) xmalloc (sizeof *tmp);
497 tmp->name = $1;
498 tmp->next = NULL;
499 $$ = tmp;
503 file_NAME_list:
504 file_NAME_list opt_comma wildcard_spec
506 struct wildcard_list *tmp;
507 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
508 tmp->next = $1;
509 tmp->spec = $3;
510 $$ = tmp;
513 wildcard_spec
515 struct wildcard_list *tmp;
516 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
517 tmp->next = NULL;
518 tmp->spec = $1;
519 $$ = tmp;
523 input_section_spec_no_keep:
524 NAME
526 struct wildcard_spec tmp;
527 tmp.name = $1;
528 tmp.exclude_name_list = NULL;
529 tmp.sorted = none;
530 lang_add_wild (&tmp, NULL, ldgram_had_keep);
532 | '[' file_NAME_list ']'
534 lang_add_wild (NULL, $2, ldgram_had_keep);
536 | wildcard_spec '(' file_NAME_list ')'
538 lang_add_wild (&$1, $3, ldgram_had_keep);
542 input_section_spec:
543 input_section_spec_no_keep
544 | KEEP '('
545 { ldgram_had_keep = TRUE; }
546 input_section_spec_no_keep ')'
547 { ldgram_had_keep = FALSE; }
550 statement:
551 assignment end
552 | CREATE_OBJECT_SYMBOLS
554 lang_add_attribute(lang_object_symbols_statement_enum);
556 | ';'
557 | CONSTRUCTORS
560 lang_add_attribute(lang_constructors_statement_enum);
562 | SORT_BY_NAME '(' CONSTRUCTORS ')'
564 constructors_sorted = TRUE;
565 lang_add_attribute (lang_constructors_statement_enum);
567 | input_section_spec
568 | length '(' mustbe_exp ')'
570 lang_add_data ((int) $1, $3);
573 | FILL '(' fill_exp ')'
575 lang_add_fill ($3);
577 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')' end
578 { ldlex_popstate ();
579 lang_add_assignment (exp_assert ($4, $6)); }
580 | INCLUDE filename
581 { ldlex_script (); ldfile_open_command_file($2); }
582 statement_list_opt END
583 { ldlex_popstate (); }
586 statement_list:
587 statement_list statement
588 | statement
591 statement_list_opt:
592 /* empty */
593 | statement_list
596 length:
597 QUAD
598 { $$ = $1; }
599 | SQUAD
600 { $$ = $1; }
601 | LONG
602 { $$ = $1; }
603 | SHORT
604 { $$ = $1; }
605 | BYTE
606 { $$ = $1; }
609 fill_exp:
610 mustbe_exp
612 $$ = exp_get_fill ($1, 0, "fill value");
616 fill_opt:
617 '=' fill_exp
618 { $$ = $2; }
619 | { $$ = (fill_type *) 0; }
622 assign_op:
623 PLUSEQ
624 { $$ = '+'; }
625 | MINUSEQ
626 { $$ = '-'; }
627 | MULTEQ
628 { $$ = '*'; }
629 | DIVEQ
630 { $$ = '/'; }
631 | LSHIFTEQ
632 { $$ = LSHIFT; }
633 | RSHIFTEQ
634 { $$ = RSHIFT; }
635 | ANDEQ
636 { $$ = '&'; }
637 | OREQ
638 { $$ = '|'; }
642 end: ';' | ','
646 assignment:
647 NAME '=' mustbe_exp
649 lang_add_assignment (exp_assop ($2, $1, $3));
651 | NAME assign_op mustbe_exp
653 lang_add_assignment (exp_assop ('=', $1,
654 exp_binop ($2,
655 exp_nameop (NAME,
656 $1),
657 $3)));
659 | PROVIDE '(' NAME '=' mustbe_exp ')'
661 lang_add_assignment (exp_provide ($3, $5, FALSE));
663 | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
665 lang_add_assignment (exp_provide ($3, $5, TRUE));
670 opt_comma:
671 ',' | ;
674 memory:
675 MEMORY '{' memory_spec_list_opt '}'
678 memory_spec_list_opt: memory_spec_list | ;
680 memory_spec_list:
681 memory_spec_list opt_comma memory_spec
682 | memory_spec
686 memory_spec: NAME
687 { region = lang_memory_region_lookup ($1, TRUE); }
688 attributes_opt ':'
689 origin_spec opt_comma length_spec
691 | INCLUDE filename
692 { ldlex_script (); ldfile_open_command_file($2); }
693 memory_spec_list_opt END
694 { ldlex_popstate (); }
697 origin_spec:
698 ORIGIN '=' mustbe_exp
700 region->origin = exp_get_vma ($3, 0, "origin");
701 region->current = region->origin;
705 length_spec:
706 LENGTH '=' mustbe_exp
708 region->length = exp_get_vma ($3, -1, "length");
712 attributes_opt:
713 /* empty */
714 { /* dummy action to avoid bison 1.25 error message */ }
715 | '(' attributes_list ')'
718 attributes_list:
719 attributes_string
720 | attributes_list attributes_string
723 attributes_string:
724 NAME
725 { lang_set_flags (region, $1, 0); }
726 | '!' NAME
727 { lang_set_flags (region, $2, 1); }
730 startup:
731 STARTUP '(' filename ')'
732 { lang_startup($3); }
735 high_level_library:
736 HLL '(' high_level_library_NAME_list ')'
737 | HLL '(' ')'
738 { ldemul_hll((char *)NULL); }
741 high_level_library_NAME_list:
742 high_level_library_NAME_list opt_comma filename
743 { ldemul_hll($3); }
744 | filename
745 { ldemul_hll($1); }
749 low_level_library:
750 SYSLIB '(' low_level_library_NAME_list ')'
751 ; low_level_library_NAME_list:
752 low_level_library_NAME_list opt_comma filename
753 { ldemul_syslib($3); }
757 floating_point_support:
758 FLOAT
759 { lang_float(TRUE); }
760 | NOFLOAT
761 { lang_float(FALSE); }
764 nocrossref_list:
765 /* empty */
767 $$ = NULL;
769 | NAME nocrossref_list
771 struct lang_nocrossref *n;
773 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
774 n->name = $1;
775 n->next = $2;
776 $$ = n;
778 | NAME ',' nocrossref_list
780 struct lang_nocrossref *n;
782 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
783 n->name = $1;
784 n->next = $3;
785 $$ = n;
789 mustbe_exp: { ldlex_expression (); }
791 { ldlex_popstate (); $$=$2;}
794 exp :
795 '-' exp %prec UNARY
796 { $$ = exp_unop ('-', $2); }
797 | '(' exp ')'
798 { $$ = $2; }
799 | NEXT '(' exp ')' %prec UNARY
800 { $$ = exp_unop ((int) $1,$3); }
801 | '!' exp %prec UNARY
802 { $$ = exp_unop ('!', $2); }
803 | '+' exp %prec UNARY
804 { $$ = $2; }
805 | '~' exp %prec UNARY
806 { $$ = exp_unop ('~', $2);}
808 | exp '*' exp
809 { $$ = exp_binop ('*', $1, $3); }
810 | exp '/' exp
811 { $$ = exp_binop ('/', $1, $3); }
812 | exp '%' exp
813 { $$ = exp_binop ('%', $1, $3); }
814 | exp '+' exp
815 { $$ = exp_binop ('+', $1, $3); }
816 | exp '-' exp
817 { $$ = exp_binop ('-' , $1, $3); }
818 | exp LSHIFT exp
819 { $$ = exp_binop (LSHIFT , $1, $3); }
820 | exp RSHIFT exp
821 { $$ = exp_binop (RSHIFT , $1, $3); }
822 | exp EQ exp
823 { $$ = exp_binop (EQ , $1, $3); }
824 | exp NE exp
825 { $$ = exp_binop (NE , $1, $3); }
826 | exp LE exp
827 { $$ = exp_binop (LE , $1, $3); }
828 | exp GE exp
829 { $$ = exp_binop (GE , $1, $3); }
830 | exp '<' exp
831 { $$ = exp_binop ('<' , $1, $3); }
832 | exp '>' exp
833 { $$ = exp_binop ('>' , $1, $3); }
834 | exp '&' exp
835 { $$ = exp_binop ('&' , $1, $3); }
836 | exp '^' exp
837 { $$ = exp_binop ('^' , $1, $3); }
838 | exp '|' exp
839 { $$ = exp_binop ('|' , $1, $3); }
840 | exp '?' exp ':' exp
841 { $$ = exp_trinop ('?' , $1, $3, $5); }
842 | exp ANDAND exp
843 { $$ = exp_binop (ANDAND , $1, $3); }
844 | exp OROR exp
845 { $$ = exp_binop (OROR , $1, $3); }
846 | DEFINED '(' NAME ')'
847 { $$ = exp_nameop (DEFINED, $3); }
848 | INT
849 { $$ = exp_bigintop ($1.integer, $1.str); }
850 | SIZEOF_HEADERS
851 { $$ = exp_nameop (SIZEOF_HEADERS,0); }
853 | ALIGNOF '(' NAME ')'
854 { $$ = exp_nameop (ALIGNOF,$3); }
855 | SIZEOF '(' NAME ')'
856 { $$ = exp_nameop (SIZEOF,$3); }
857 | ADDR '(' NAME ')'
858 { $$ = exp_nameop (ADDR,$3); }
859 | LOADADDR '(' NAME ')'
860 { $$ = exp_nameop (LOADADDR,$3); }
861 | CONSTANT '(' NAME ')'
862 { $$ = exp_nameop (CONSTANT,$3); }
863 | ABSOLUTE '(' exp ')'
864 { $$ = exp_unop (ABSOLUTE, $3); }
865 | ALIGN_K '(' exp ')'
866 { $$ = exp_unop (ALIGN_K,$3); }
867 | ALIGN_K '(' exp ',' exp ')'
868 { $$ = exp_binop (ALIGN_K,$3,$5); }
869 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
870 { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
871 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
872 { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
873 | DATA_SEGMENT_END '(' exp ')'
874 { $$ = exp_unop (DATA_SEGMENT_END, $3); }
875 | SEGMENT_START '(' NAME ',' exp ')'
876 { /* The operands to the expression node are
877 placed in the opposite order from the way
878 in which they appear in the script as
879 that allows us to reuse more code in
880 fold_binary. */
881 $$ = exp_binop (SEGMENT_START,
883 exp_nameop (NAME, $3)); }
884 | BLOCK '(' exp ')'
885 { $$ = exp_unop (ALIGN_K,$3); }
886 | NAME
887 { $$ = exp_nameop (NAME,$1); }
888 | MAX_K '(' exp ',' exp ')'
889 { $$ = exp_binop (MAX_K, $3, $5 ); }
890 | MIN_K '(' exp ',' exp ')'
891 { $$ = exp_binop (MIN_K, $3, $5 ); }
892 | ASSERT_K '(' exp ',' NAME ')'
893 { $$ = exp_assert ($3, $5); }
894 | ORIGIN '(' NAME ')'
895 { $$ = exp_nameop (ORIGIN, $3); }
896 | LENGTH '(' NAME ')'
897 { $$ = exp_nameop (LENGTH, $3); }
901 memspec_at_opt:
902 AT '>' NAME { $$ = $3; }
903 | { $$ = 0; }
906 opt_at:
907 AT '(' exp ')' { $$ = $3; }
908 | { $$ = 0; }
911 opt_align:
912 ALIGN_K '(' exp ')' { $$ = $3; }
913 | { $$ = 0; }
916 opt_subalign:
917 SUBALIGN '(' exp ')' { $$ = $3; }
918 | { $$ = 0; }
921 sect_constraint:
922 ONLY_IF_RO { $$ = ONLY_IF_RO; }
923 | ONLY_IF_RW { $$ = ONLY_IF_RW; }
924 | SPECIAL { $$ = SPECIAL; }
925 | { $$ = 0; }
928 section: NAME { ldlex_expression(); }
929 opt_exp_with_type
930 opt_at
931 opt_align
932 opt_subalign { ldlex_popstate (); ldlex_script (); }
933 sect_constraint
936 lang_enter_output_section_statement($1, $3,
937 sectype,
938 $5, $6, $4, $8);
940 statement_list_opt
941 '}' { ldlex_popstate (); ldlex_expression (); }
942 memspec_opt memspec_at_opt phdr_opt fill_opt
944 ldlex_popstate ();
945 lang_leave_output_section_statement ($17, $14, $16, $15);
947 opt_comma
949 | OVERLAY
950 { ldlex_expression (); }
951 opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
952 { ldlex_popstate (); ldlex_script (); }
955 lang_enter_overlay ($3, $6);
957 overlay_section
959 { ldlex_popstate (); ldlex_expression (); }
960 memspec_opt memspec_at_opt phdr_opt fill_opt
962 ldlex_popstate ();
963 lang_leave_overlay ($5, (int) $4,
964 $16, $13, $15, $14);
966 opt_comma
967 | /* The GROUP case is just enough to support the gcc
968 svr3.ifile script. It is not intended to be full
969 support. I'm not even sure what GROUP is supposed
970 to mean. */
971 GROUP { ldlex_expression (); }
972 opt_exp_with_type
974 ldlex_popstate ();
975 lang_add_assignment (exp_assop ('=', ".", $3));
977 '{' sec_or_group_p1 '}'
978 | INCLUDE filename
979 { ldlex_script (); ldfile_open_command_file($2); }
980 sec_or_group_p1 END
981 { ldlex_popstate (); }
984 type:
985 NOLOAD { sectype = noload_section; }
986 | DSECT { sectype = noalloc_section; }
987 | COPY { sectype = noalloc_section; }
988 | INFO { sectype = noalloc_section; }
989 | OVERLAY { sectype = noalloc_section; }
992 atype:
993 '(' type ')'
994 | /* EMPTY */ { sectype = normal_section; }
995 | '(' ')' { sectype = normal_section; }
998 opt_exp_with_type:
999 exp atype ':' { $$ = $1; }
1000 | atype ':' { $$ = (etree_type *)NULL; }
1001 | /* The BIND cases are to support the gcc svr3.ifile
1002 script. They aren't intended to implement full
1003 support for the BIND keyword. I'm not even sure
1004 what BIND is supposed to mean. */
1005 BIND '(' exp ')' atype ':' { $$ = $3; }
1006 | BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
1007 { $$ = $3; }
1010 opt_exp_without_type:
1011 exp ':' { $$ = $1; }
1012 | ':' { $$ = (etree_type *) NULL; }
1015 opt_nocrossrefs:
1016 /* empty */
1017 { $$ = 0; }
1018 | NOCROSSREFS
1019 { $$ = 1; }
1022 memspec_opt:
1023 '>' NAME
1024 { $$ = $2; }
1025 | { $$ = DEFAULT_MEMORY_REGION; }
1028 phdr_opt:
1029 /* empty */
1031 $$ = NULL;
1033 | phdr_opt ':' NAME
1035 struct lang_output_section_phdr_list *n;
1037 n = ((struct lang_output_section_phdr_list *)
1038 xmalloc (sizeof *n));
1039 n->name = $3;
1040 n->used = FALSE;
1041 n->next = $1;
1042 $$ = n;
1046 overlay_section:
1047 /* empty */
1048 | overlay_section
1049 NAME
1051 ldlex_script ();
1052 lang_enter_overlay_section ($2);
1054 '{' statement_list_opt '}'
1055 { ldlex_popstate (); ldlex_expression (); }
1056 phdr_opt fill_opt
1058 ldlex_popstate ();
1059 lang_leave_overlay_section ($9, $8);
1061 opt_comma
1064 phdrs:
1065 PHDRS '{' phdr_list '}'
1068 phdr_list:
1069 /* empty */
1070 | phdr_list phdr
1073 phdr:
1074 NAME { ldlex_expression (); }
1075 phdr_type phdr_qualifiers { ldlex_popstate (); }
1078 lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1079 $4.flags);
1083 phdr_type:
1086 $$ = $1;
1088 if ($1->type.node_class == etree_name
1089 && $1->type.node_code == NAME)
1091 const char *s;
1092 unsigned int i;
1093 static const char * const phdr_types[] =
1095 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1096 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
1097 "PT_PHDR", "PT_TLS"
1100 s = $1->name.name;
1101 for (i = 0;
1102 i < sizeof phdr_types / sizeof phdr_types[0];
1103 i++)
1104 if (strcmp (s, phdr_types[i]) == 0)
1106 $$ = exp_intop (i);
1107 break;
1109 if (i == sizeof phdr_types / sizeof phdr_types[0])
1111 if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1112 $$ = exp_intop (0x6474e550);
1113 else if (strcmp (s, "PT_GNU_STACK") == 0)
1114 $$ = exp_intop (0x6474e551);
1115 else
1117 einfo (_("\
1118 %X%P:%S: unknown phdr type `%s' (try integer literal)\n"),
1120 $$ = exp_intop (0);
1127 phdr_qualifiers:
1128 /* empty */
1130 memset (&$$, 0, sizeof (struct phdr_info));
1132 | NAME phdr_val phdr_qualifiers
1134 $$ = $3;
1135 if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
1136 $$.filehdr = TRUE;
1137 else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
1138 $$.phdrs = TRUE;
1139 else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1140 $$.flags = $2;
1141 else
1142 einfo (_("%X%P:%S: PHDRS syntax error at `%s'\n"), $1);
1144 | AT '(' exp ')' phdr_qualifiers
1146 $$ = $5;
1147 $$.at = $3;
1151 phdr_val:
1152 /* empty */
1154 $$ = NULL;
1156 | '(' exp ')'
1158 $$ = $2;
1162 dynamic_list_file:
1164 ldlex_version_file ();
1165 PUSH_ERROR (_("dynamic list"));
1167 dynamic_list_nodes
1169 ldlex_popstate ();
1170 POP_ERROR ();
1174 dynamic_list_nodes:
1175 dynamic_list_node
1176 | dynamic_list_nodes dynamic_list_node
1179 dynamic_list_node:
1180 '{' dynamic_list_tag '}' ';'
1183 dynamic_list_tag:
1184 vers_defns ';'
1186 lang_append_dynamic_list ($1);
1190 /* This syntax is used within an external version script file. */
1192 version_script_file:
1194 ldlex_version_file ();
1195 PUSH_ERROR (_("VERSION script"));
1197 vers_nodes
1199 ldlex_popstate ();
1200 POP_ERROR ();
1204 /* This is used within a normal linker script file. */
1206 version:
1208 ldlex_version_script ();
1210 VERSIONK '{' vers_nodes '}'
1212 ldlex_popstate ();
1216 vers_nodes:
1217 vers_node
1218 | vers_nodes vers_node
1221 vers_node:
1222 '{' vers_tag '}' ';'
1224 lang_register_vers_node (NULL, $2, NULL);
1226 | VERS_TAG '{' vers_tag '}' ';'
1228 lang_register_vers_node ($1, $3, NULL);
1230 | VERS_TAG '{' vers_tag '}' verdep ';'
1232 lang_register_vers_node ($1, $3, $5);
1236 verdep:
1237 VERS_TAG
1239 $$ = lang_add_vers_depend (NULL, $1);
1241 | verdep VERS_TAG
1243 $$ = lang_add_vers_depend ($1, $2);
1247 vers_tag:
1248 /* empty */
1250 $$ = lang_new_vers_node (NULL, NULL);
1252 | vers_defns ';'
1254 $$ = lang_new_vers_node ($1, NULL);
1256 | GLOBAL ':' vers_defns ';'
1258 $$ = lang_new_vers_node ($3, NULL);
1260 | LOCAL ':' vers_defns ';'
1262 $$ = lang_new_vers_node (NULL, $3);
1264 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1266 $$ = lang_new_vers_node ($3, $7);
1270 vers_defns:
1271 VERS_IDENTIFIER
1273 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, FALSE);
1275 | NAME
1277 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, TRUE);
1279 | vers_defns ';' VERS_IDENTIFIER
1281 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, FALSE);
1283 | vers_defns ';' NAME
1285 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, TRUE);
1287 | vers_defns ';' EXTERN NAME '{'
1289 $<name>$ = ldgram_vers_current_lang;
1290 ldgram_vers_current_lang = $4;
1292 vers_defns opt_semicolon '}'
1294 struct bfd_elf_version_expr *pat;
1295 for (pat = $7; pat->next != NULL; pat = pat->next);
1296 pat->next = $1;
1297 $$ = $7;
1298 ldgram_vers_current_lang = $<name>6;
1300 | EXTERN NAME '{'
1302 $<name>$ = ldgram_vers_current_lang;
1303 ldgram_vers_current_lang = $2;
1305 vers_defns opt_semicolon '}'
1307 $$ = $5;
1308 ldgram_vers_current_lang = $<name>4;
1310 | GLOBAL
1312 $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, FALSE);
1314 | vers_defns ';' GLOBAL
1316 $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, FALSE);
1318 | LOCAL
1320 $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, FALSE);
1322 | vers_defns ';' LOCAL
1324 $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, FALSE);
1326 | EXTERN
1328 $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, FALSE);
1330 | vers_defns ';' EXTERN
1332 $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, FALSE);
1336 opt_semicolon:
1337 /* empty */
1338 | ';'
1342 void
1343 yyerror(arg)
1344 const char *arg;
1346 if (ldfile_assumed_script)
1347 einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
1348 ldfile_input_filename);
1349 if (error_index > 0 && error_index < ERROR_NAME_MAX)
1350 einfo ("%P%F:%S: %s in %s\n", arg, error_names[error_index-1]);
1351 else
1352 einfo ("%P%F:%S: %s\n", arg);