Fix assembly of GOT references
[nacl-binutils.git] / ld / ldgram.y
blob2eedd1fcca44b8d0cd20881b9c247fb363de1e13
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 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 opt_align
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 SEGMENT_START
136 %token INCLUDE
137 %token MEMORY
138 %token NOLOAD DSECT COPY INFO OVERLAY
139 %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY
140 %token <integer> NEXT
141 %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K CEILP2 NACL_MASK
142 %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS
143 %token ORIGIN FILL
144 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
145 %token ALIGNMOD AT SUBALIGN PROVIDE PROVIDE_HIDDEN AS_NEEDED
146 %type <token> assign_op atype attributes_opt sect_constraint
147 %type <name> filename
148 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
149 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
150 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
151 %token <name> VERS_TAG VERS_IDENTIFIER
152 %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
153 %token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL
154 %token EXCLUDE_FILE
155 %token CONSTANT
156 %type <versyms> vers_defns
157 %type <versnode> vers_tag
158 %type <deflist> verdep
159 %token INPUT_DYNAMIC_LIST
163 file:
164 INPUT_SCRIPT script_file
165 | INPUT_MRI_SCRIPT mri_script_file
166 | INPUT_VERSION_SCRIPT version_script_file
167 | INPUT_DYNAMIC_LIST dynamic_list_file
168 | INPUT_DEFSYM defsym_expr
172 filename: NAME;
175 defsym_expr:
176 { ldlex_defsym(); }
177 NAME '=' exp
179 ldlex_popstate();
180 lang_add_assignment(exp_assop($3,$2,$4));
184 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
185 mri_script_file:
187 ldlex_mri_script ();
188 PUSH_ERROR (_("MRI style script"));
190 mri_script_lines
192 ldlex_popstate ();
193 mri_draw_tree ();
194 POP_ERROR ();
198 mri_script_lines:
199 mri_script_lines mri_script_command NEWLINE
203 mri_script_command:
204 CHIP exp
205 | CHIP exp ',' exp
206 | NAME {
207 einfo(_("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1);
209 | LIST {
210 config.map_filename = "-";
212 | ORDER ordernamelist
213 | ENDWORD
214 | PUBLIC NAME '=' exp
215 { mri_public($2, $4); }
216 | PUBLIC NAME ',' exp
217 { mri_public($2, $4); }
218 | PUBLIC NAME exp
219 { mri_public($2, $3); }
220 | FORMAT NAME
221 { mri_format($2); }
222 | SECT NAME ',' exp
223 { mri_output_section($2, $4);}
224 | SECT NAME exp
225 { mri_output_section($2, $3);}
226 | SECT NAME '=' exp
227 { mri_output_section($2, $4);}
228 | ALIGN_K NAME '=' exp
229 { mri_align($2,$4); }
230 | ALIGN_K NAME ',' exp
231 { mri_align($2,$4); }
232 | ALIGNMOD NAME '=' exp
233 { mri_alignmod($2,$4); }
234 | ALIGNMOD NAME ',' exp
235 { mri_alignmod($2,$4); }
236 | ABSOLUTE mri_abs_name_list
237 | LOAD mri_load_name_list
238 | NAMEWORD NAME
239 { mri_name($2); }
240 | ALIAS NAME ',' NAME
241 { mri_alias($2,$4,0);}
242 | ALIAS NAME ',' INT
243 { mri_alias ($2, 0, (int) $4.integer); }
244 | BASE exp
245 { mri_base($2); }
246 | TRUNCATE INT
247 { mri_truncate ((unsigned int) $2.integer); }
248 | CASE casesymlist
249 | EXTERN extern_name_list
250 | INCLUDE filename
251 { ldlex_script (); ldfile_open_command_file($2); }
252 mri_script_lines END
253 { ldlex_popstate (); }
254 | START NAME
255 { lang_add_entry ($2, FALSE); }
259 ordernamelist:
260 ordernamelist ',' NAME { mri_order($3); }
261 | ordernamelist NAME { mri_order($2); }
265 mri_load_name_list:
266 NAME
267 { mri_load($1); }
268 | mri_load_name_list ',' NAME { mri_load($3); }
271 mri_abs_name_list:
272 NAME
273 { mri_only_load($1); }
274 | mri_abs_name_list ',' NAME
275 { mri_only_load($3); }
278 casesymlist:
279 /* empty */ { $$ = NULL; }
280 | NAME
281 | casesymlist ',' NAME
284 /* Parsed as expressions so that commas separate entries */
285 extern_name_list:
286 { ldlex_expression (); }
287 extern_name_list_body
288 { ldlex_popstate (); }
290 extern_name_list_body:
291 NAME
292 { ldlang_add_undef ($1); }
293 | extern_name_list_body NAME
294 { ldlang_add_undef ($2); }
295 | extern_name_list_body ',' NAME
296 { ldlang_add_undef ($3); }
299 script_file:
300 { ldlex_both(); }
301 ifile_list
302 { ldlex_popstate(); }
305 ifile_list:
306 ifile_list ifile_p1
311 ifile_p1:
312 memory
313 | sections
314 | phdrs
315 | startup
316 | high_level_library
317 | low_level_library
318 | floating_point_support
319 | statement_anywhere
320 | version
321 | ';'
322 | TARGET_K '(' NAME ')'
323 { lang_add_target($3); }
324 | SEARCH_DIR '(' filename ')'
325 { ldfile_add_library_path ($3, FALSE); }
326 | OUTPUT '(' filename ')'
327 { lang_add_output($3, 1); }
328 | OUTPUT_FORMAT '(' NAME ')'
329 { lang_add_output_format ($3, (char *) NULL,
330 (char *) NULL, 1); }
331 | OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')'
332 { lang_add_output_format ($3, $5, $7, 1); }
333 | OUTPUT_ARCH '(' NAME ')'
334 { ldfile_set_output_arch ($3, bfd_arch_unknown); }
335 | FORCE_COMMON_ALLOCATION
336 { command_line.force_common_definition = TRUE ; }
337 | INHIBIT_COMMON_ALLOCATION
338 { command_line.inhibit_common_definition = TRUE ; }
339 | INPUT '(' input_list ')'
340 | GROUP
341 { lang_enter_group (); }
342 '(' input_list ')'
343 { lang_leave_group (); }
344 | MAP '(' filename ')'
345 { lang_add_map($3); }
346 | INCLUDE filename
347 { ldlex_script (); ldfile_open_command_file($2); }
348 ifile_list END
349 { ldlex_popstate (); }
350 | NOCROSSREFS '(' nocrossref_list ')'
352 lang_add_nocrossref ($3);
354 | EXTERN '(' extern_name_list ')'
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)); }
582 statement_list:
583 statement_list statement
584 | statement
587 statement_list_opt:
588 /* empty */
589 | statement_list
592 length:
593 QUAD
594 { $$ = $1; }
595 | SQUAD
596 { $$ = $1; }
597 | LONG
598 { $$ = $1; }
599 | SHORT
600 { $$ = $1; }
601 | BYTE
602 { $$ = $1; }
605 fill_exp:
606 mustbe_exp
608 $$ = exp_get_fill ($1, 0, "fill value");
612 fill_opt:
613 '=' fill_exp
614 { $$ = $2; }
615 | { $$ = (fill_type *) 0; }
618 assign_op:
619 PLUSEQ
620 { $$ = '+'; }
621 | MINUSEQ
622 { $$ = '-'; }
623 | MULTEQ
624 { $$ = '*'; }
625 | DIVEQ
626 { $$ = '/'; }
627 | LSHIFTEQ
628 { $$ = LSHIFT; }
629 | RSHIFTEQ
630 { $$ = RSHIFT; }
631 | ANDEQ
632 { $$ = '&'; }
633 | OREQ
634 { $$ = '|'; }
638 end: ';' | ','
642 assignment:
643 NAME '=' mustbe_exp
645 lang_add_assignment (exp_assop ($2, $1, $3));
647 | NAME assign_op mustbe_exp
649 lang_add_assignment (exp_assop ('=', $1,
650 exp_binop ($2,
651 exp_nameop (NAME,
652 $1),
653 $3)));
655 | PROVIDE '(' NAME '=' mustbe_exp ')'
657 lang_add_assignment (exp_provide ($3, $5, FALSE));
659 | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
661 lang_add_assignment (exp_provide ($3, $5, TRUE));
666 opt_comma:
667 ',' | ;
670 memory:
671 MEMORY '{' memory_spec memory_spec_list '}'
674 memory_spec_list:
675 memory_spec_list memory_spec
676 | memory_spec_list ',' memory_spec
681 memory_spec: NAME
682 { region = lang_memory_region_lookup ($1, TRUE); }
683 attributes_opt ':'
684 origin_spec opt_comma length_spec
688 origin_spec:
689 ORIGIN '=' mustbe_exp
691 region->origin = exp_get_vma ($3, 0, "origin");
692 region->current = region->origin;
696 length_spec:
697 LENGTH '=' mustbe_exp
699 region->length = exp_get_vma ($3, -1, "length");
703 attributes_opt:
704 /* empty */
705 { /* dummy action to avoid bison 1.25 error message */ }
706 | '(' attributes_list ')'
709 attributes_list:
710 attributes_string
711 | attributes_list attributes_string
714 attributes_string:
715 NAME
716 { lang_set_flags (region, $1, 0); }
717 | '!' NAME
718 { lang_set_flags (region, $2, 1); }
721 startup:
722 STARTUP '(' filename ')'
723 { lang_startup($3); }
726 high_level_library:
727 HLL '(' high_level_library_NAME_list ')'
728 | HLL '(' ')'
729 { ldemul_hll((char *)NULL); }
732 high_level_library_NAME_list:
733 high_level_library_NAME_list opt_comma filename
734 { ldemul_hll($3); }
735 | filename
736 { ldemul_hll($1); }
740 low_level_library:
741 SYSLIB '(' low_level_library_NAME_list ')'
742 ; low_level_library_NAME_list:
743 low_level_library_NAME_list opt_comma filename
744 { ldemul_syslib($3); }
748 floating_point_support:
749 FLOAT
750 { lang_float(TRUE); }
751 | NOFLOAT
752 { lang_float(FALSE); }
755 nocrossref_list:
756 /* empty */
758 $$ = NULL;
760 | NAME nocrossref_list
762 struct lang_nocrossref *n;
764 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
765 n->name = $1;
766 n->next = $2;
767 $$ = n;
769 | NAME ',' nocrossref_list
771 struct lang_nocrossref *n;
773 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
774 n->name = $1;
775 n->next = $3;
776 $$ = n;
780 mustbe_exp: { ldlex_expression (); }
782 { ldlex_popstate (); $$=$2;}
785 exp :
786 '-' exp %prec UNARY
787 { $$ = exp_unop ('-', $2); }
788 | '(' exp ')'
789 { $$ = $2; }
790 | NEXT '(' exp ')' %prec UNARY
791 { $$ = exp_unop ((int) $1,$3); }
792 | '!' exp %prec UNARY
793 { $$ = exp_unop ('!', $2); }
794 | '+' exp %prec UNARY
795 { $$ = $2; }
796 | '~' exp %prec UNARY
797 { $$ = exp_unop ('~', $2);}
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 '+' exp
806 { $$ = exp_binop ('+', $1, $3); }
807 | exp '-' exp
808 { $$ = exp_binop ('-' , $1, $3); }
809 | exp LSHIFT exp
810 { $$ = exp_binop (LSHIFT , $1, $3); }
811 | exp RSHIFT exp
812 { $$ = exp_binop (RSHIFT , $1, $3); }
813 | exp EQ exp
814 { $$ = exp_binop (EQ , $1, $3); }
815 | exp NE exp
816 { $$ = exp_binop (NE , $1, $3); }
817 | exp LE exp
818 { $$ = exp_binop (LE , $1, $3); }
819 | exp GE exp
820 { $$ = exp_binop (GE , $1, $3); }
821 | exp '<' exp
822 { $$ = exp_binop ('<' , $1, $3); }
823 | exp '>' exp
824 { $$ = exp_binop ('>' , $1, $3); }
825 | exp '&' exp
826 { $$ = exp_binop ('&' , $1, $3); }
827 | exp '^' exp
828 { $$ = exp_binop ('^' , $1, $3); }
829 | exp '|' exp
830 { $$ = exp_binop ('|' , $1, $3); }
831 | exp '?' exp ':' exp
832 { $$ = exp_trinop ('?' , $1, $3, $5); }
833 | exp ANDAND exp
834 { $$ = exp_binop (ANDAND , $1, $3); }
835 | exp OROR exp
836 { $$ = exp_binop (OROR , $1, $3); }
837 | DEFINED '(' NAME ')'
838 { $$ = exp_nameop (DEFINED, $3); }
839 | INT
840 { $$ = exp_bigintop ($1.integer, $1.str); }
841 | SIZEOF_HEADERS
842 { $$ = exp_nameop (SIZEOF_HEADERS,0); }
844 | ALIGNOF '(' NAME ')'
845 { $$ = exp_nameop (ALIGNOF,$3); }
846 | SIZEOF '(' NAME ')'
847 { $$ = exp_nameop (SIZEOF,$3); }
848 | ADDR '(' NAME ')'
849 { $$ = exp_nameop (ADDR,$3); }
850 | LOADADDR '(' NAME ')'
851 { $$ = exp_nameop (LOADADDR,$3); }
852 | CONSTANT '(' NAME ')'
853 { $$ = exp_nameop (CONSTANT,$3); }
854 | ABSOLUTE '(' exp ')'
855 { $$ = exp_unop (ABSOLUTE, $3); }
856 | ALIGN_K '(' exp ')'
857 { $$ = exp_unop (ALIGN_K,$3); }
858 | ALIGN_K '(' exp ',' exp ')'
859 { $$ = exp_binop (ALIGN_K,$3,$5); }
860 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
861 { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
862 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
863 { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
864 | DATA_SEGMENT_END '(' exp ')'
865 { $$ = exp_unop (DATA_SEGMENT_END, $3); }
866 | SEGMENT_START '(' NAME ',' exp ')'
867 { /* The operands to the expression node are
868 placed in the opposite order from the way
869 in which they appear in the script as
870 that allows us to reuse more code in
871 fold_binary. */
872 $$ = exp_binop (SEGMENT_START,
874 exp_nameop (NAME, $3)); }
875 | BLOCK '(' exp ')'
876 { $$ = exp_unop (ALIGN_K,$3); }
877 | NAME
878 { $$ = exp_nameop (NAME,$1); }
879 | MAX_K '(' exp ',' exp ')'
880 { $$ = exp_binop (MAX_K, $3, $5 ); }
881 | MIN_K '(' exp ',' exp ')'
882 { $$ = exp_binop (MIN_K, $3, $5 ); }
883 | CEILP2 '(' exp ')'
884 { $$ = exp_unop (CEILP2, $3); }
885 | NACL_MASK '(' exp ')'
886 { $$ = exp_unop (NACL_MASK, $3); }
887 | ASSERT_K '(' exp ',' NAME ')'
888 { $$ = exp_assert ($3, $5); }
889 | ORIGIN '(' NAME ')'
890 { $$ = exp_nameop (ORIGIN, $3); }
891 | LENGTH '(' NAME ')'
892 { $$ = exp_nameop (LENGTH, $3); }
896 memspec_at_opt:
897 AT '>' NAME { $$ = $3; }
898 | { $$ = 0; }
901 opt_at:
902 AT '(' exp ')' { $$ = $3; }
903 | { $$ = 0; }
906 opt_align:
907 ALIGN_K '(' exp ')' { $$ = $3; }
908 | { $$ = 0; }
911 opt_subalign:
912 SUBALIGN '(' exp ')' { $$ = $3; }
913 | { $$ = 0; }
916 sect_constraint:
917 ONLY_IF_RO { $$ = ONLY_IF_RO; }
918 | ONLY_IF_RW { $$ = ONLY_IF_RW; }
919 | SPECIAL { $$ = SPECIAL; }
920 | { $$ = 0; }
923 section: NAME { ldlex_expression(); }
924 opt_exp_with_type
925 opt_at
926 opt_align
927 opt_subalign { ldlex_popstate (); ldlex_script (); }
928 sect_constraint
931 lang_enter_output_section_statement($1, $3,
932 sectype,
933 $5, $6, $4, $8);
935 statement_list_opt
936 '}' { ldlex_popstate (); ldlex_expression (); }
937 memspec_opt memspec_at_opt phdr_opt fill_opt
939 ldlex_popstate ();
940 lang_leave_output_section_statement ($17, $14, $16, $15);
942 opt_comma
944 | OVERLAY
945 { ldlex_expression (); }
946 opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
947 { ldlex_popstate (); ldlex_script (); }
950 lang_enter_overlay ($3, $6);
952 overlay_section
954 { ldlex_popstate (); ldlex_expression (); }
955 memspec_opt memspec_at_opt phdr_opt fill_opt
957 ldlex_popstate ();
958 lang_leave_overlay ($5, (int) $4,
959 $16, $13, $15, $14);
961 opt_comma
962 | /* The GROUP case is just enough to support the gcc
963 svr3.ifile script. It is not intended to be full
964 support. I'm not even sure what GROUP is supposed
965 to mean. */
966 GROUP { ldlex_expression (); }
967 opt_exp_with_type
969 ldlex_popstate ();
970 lang_add_assignment (exp_assop ('=', ".", $3));
972 '{' sec_or_group_p1 '}'
975 type:
976 NOLOAD { sectype = noload_section; }
977 | DSECT { sectype = noalloc_section; }
978 | COPY { sectype = noalloc_section; }
979 | INFO { sectype = noalloc_section; }
980 | OVERLAY { sectype = noalloc_section; }
983 atype:
984 '(' type ')'
985 | /* EMPTY */ { sectype = normal_section; }
986 | '(' ')' { sectype = normal_section; }
989 opt_exp_with_type:
990 exp atype ':' { $$ = $1; }
991 | atype ':' { $$ = (etree_type *)NULL; }
992 | /* The BIND cases are to support the gcc svr3.ifile
993 script. They aren't intended to implement full
994 support for the BIND keyword. I'm not even sure
995 what BIND is supposed to mean. */
996 BIND '(' exp ')' atype ':' { $$ = $3; }
997 | BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
998 { $$ = $3; }
1001 opt_exp_without_type:
1002 exp ':' { $$ = $1; }
1003 | ':' { $$ = (etree_type *) NULL; }
1006 opt_nocrossrefs:
1007 /* empty */
1008 { $$ = 0; }
1009 | NOCROSSREFS
1010 { $$ = 1; }
1013 memspec_opt:
1014 '>' NAME
1015 { $$ = $2; }
1016 | { $$ = DEFAULT_MEMORY_REGION; }
1019 phdr_opt:
1020 /* empty */
1022 $$ = NULL;
1024 | phdr_opt ':' NAME
1026 struct lang_output_section_phdr_list *n;
1028 n = ((struct lang_output_section_phdr_list *)
1029 xmalloc (sizeof *n));
1030 n->name = $3;
1031 n->used = FALSE;
1032 n->next = $1;
1033 $$ = n;
1037 overlay_section:
1038 /* empty */
1039 | overlay_section
1040 NAME
1042 ldlex_script ();
1043 lang_enter_overlay_section ($2);
1045 '{' statement_list_opt '}'
1046 { ldlex_popstate (); ldlex_expression (); }
1047 phdr_opt fill_opt
1049 ldlex_popstate ();
1050 lang_leave_overlay_section ($9, $8);
1052 opt_comma
1055 phdrs:
1056 PHDRS '{' phdr_list '}'
1059 phdr_list:
1060 /* empty */
1061 | phdr_list phdr
1064 phdr:
1065 NAME { ldlex_expression (); }
1066 phdr_type phdr_qualifiers { ldlex_popstate (); }
1069 lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1070 $4.flags);
1074 phdr_type:
1077 $$ = $1;
1079 if ($1->type.node_class == etree_name
1080 && $1->type.node_code == NAME)
1082 const char *s;
1083 unsigned int i;
1084 static const char * const phdr_types[] =
1086 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1087 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
1088 "PT_PHDR", "PT_TLS"
1091 s = $1->name.name;
1092 for (i = 0;
1093 i < sizeof phdr_types / sizeof phdr_types[0];
1094 i++)
1095 if (strcmp (s, phdr_types[i]) == 0)
1097 $$ = exp_intop (i);
1098 break;
1100 if (i == sizeof phdr_types / sizeof phdr_types[0])
1102 if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1103 $$ = exp_intop (0x6474e550);
1104 else if (strcmp (s, "PT_GNU_STACK") == 0)
1105 $$ = exp_intop (0x6474e551);
1106 else
1108 einfo (_("\
1109 %X%P:%S: unknown phdr type `%s' (try integer literal)\n"),
1111 $$ = exp_intop (0);
1118 phdr_qualifiers:
1119 /* empty */
1121 memset (&$$, 0, sizeof (struct phdr_info));
1123 | NAME phdr_val phdr_qualifiers
1125 $$ = $3;
1126 if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
1127 $$.filehdr = TRUE;
1128 else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
1129 $$.phdrs = TRUE;
1130 else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1131 $$.flags = $2;
1132 else
1133 einfo (_("%X%P:%S: PHDRS syntax error at `%s'\n"), $1);
1135 | AT '(' exp ')' phdr_qualifiers
1137 $$ = $5;
1138 $$.at = $3;
1142 phdr_val:
1143 /* empty */
1145 $$ = NULL;
1147 | '(' exp ')'
1149 $$ = $2;
1153 dynamic_list_file:
1155 ldlex_version_file ();
1156 PUSH_ERROR (_("dynamic list"));
1158 dynamic_list_nodes
1160 ldlex_popstate ();
1161 POP_ERROR ();
1165 dynamic_list_nodes:
1166 dynamic_list_node
1167 | dynamic_list_nodes dynamic_list_node
1170 dynamic_list_node:
1171 '{' dynamic_list_tag '}' ';'
1174 dynamic_list_tag:
1175 vers_defns ';'
1177 lang_append_dynamic_list ($1);
1181 /* This syntax is used within an external version script file. */
1183 version_script_file:
1185 ldlex_version_file ();
1186 PUSH_ERROR (_("VERSION script"));
1188 vers_nodes
1190 ldlex_popstate ();
1191 POP_ERROR ();
1195 /* This is used within a normal linker script file. */
1197 version:
1199 ldlex_version_script ();
1201 VERSIONK '{' vers_nodes '}'
1203 ldlex_popstate ();
1207 vers_nodes:
1208 vers_node
1209 | vers_nodes vers_node
1212 vers_node:
1213 '{' vers_tag '}' ';'
1215 lang_register_vers_node (NULL, $2, NULL);
1217 | VERS_TAG '{' vers_tag '}' ';'
1219 lang_register_vers_node ($1, $3, NULL);
1221 | VERS_TAG '{' vers_tag '}' verdep ';'
1223 lang_register_vers_node ($1, $3, $5);
1227 verdep:
1228 VERS_TAG
1230 $$ = lang_add_vers_depend (NULL, $1);
1232 | verdep VERS_TAG
1234 $$ = lang_add_vers_depend ($1, $2);
1238 vers_tag:
1239 /* empty */
1241 $$ = lang_new_vers_node (NULL, NULL);
1243 | vers_defns ';'
1245 $$ = lang_new_vers_node ($1, NULL);
1247 | GLOBAL ':' vers_defns ';'
1249 $$ = lang_new_vers_node ($3, NULL);
1251 | LOCAL ':' vers_defns ';'
1253 $$ = lang_new_vers_node (NULL, $3);
1255 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1257 $$ = lang_new_vers_node ($3, $7);
1261 vers_defns:
1262 VERS_IDENTIFIER
1264 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, FALSE);
1266 | NAME
1268 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, TRUE);
1270 | vers_defns ';' VERS_IDENTIFIER
1272 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, FALSE);
1274 | vers_defns ';' NAME
1276 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, TRUE);
1278 | vers_defns ';' EXTERN NAME '{'
1280 $<name>$ = ldgram_vers_current_lang;
1281 ldgram_vers_current_lang = $4;
1283 vers_defns opt_semicolon '}'
1285 struct bfd_elf_version_expr *pat;
1286 for (pat = $7; pat->next != NULL; pat = pat->next);
1287 pat->next = $1;
1288 $$ = $7;
1289 ldgram_vers_current_lang = $<name>6;
1291 | EXTERN NAME '{'
1293 $<name>$ = ldgram_vers_current_lang;
1294 ldgram_vers_current_lang = $2;
1296 vers_defns opt_semicolon '}'
1298 $$ = $5;
1299 ldgram_vers_current_lang = $<name>4;
1301 | GLOBAL
1303 $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, FALSE);
1305 | vers_defns ';' GLOBAL
1307 $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, FALSE);
1309 | LOCAL
1311 $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, FALSE);
1313 | vers_defns ';' LOCAL
1315 $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, FALSE);
1317 | EXTERN
1319 $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, FALSE);
1321 | vers_defns ';' EXTERN
1323 $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, FALSE);
1327 opt_semicolon:
1328 /* empty */
1329 | ';'
1333 void
1334 yyerror(arg)
1335 const char *arg;
1337 if (ldfile_assumed_script)
1338 einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
1339 ldfile_input_filename);
1340 if (error_index > 0 && error_index < ERROR_NAME_MAX)
1341 einfo ("%P%F:%S: %s in %s\n", arg, error_names[error_index-1]);
1342 else
1343 einfo ("%P%F:%S: %s\n", arg);