* elf32-spu.c (spu_elf_check_vma): Do not reset auto_overlay
[binutils.git] / gold / yyscript.y
blobb01800579d62a27a01338e7eeb3c6c53db115466
1 /* yyscript.y -- linker script grammar for gold. */
3 /* Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <iant@google.com>.
6 This file is part of gold.
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. */
23 /* This is a bison grammar to parse a subset of the original GNU ld
24 linker script language. */
28 #include "config.h"
30 #include <stddef.h>
31 #include <stdint.h>
32 #include <stdlib.h>
33 #include <string.h>
35 #include "script-c.h"
39 /* We need to use a pure parser because we might be multi-threaded.
40 We pass some arguments through the parser to the lexer. */
42 %pure-parser
44 %parse-param {void* closure}
45 %lex-param {void* closure}
47 /* Since we require bison anyhow, we take advantage of it. */
49 %error-verbose
51 /* The values associated with tokens. */
53 %union {
54 /* A string. */
55 struct Parser_string string;
56 /* A number. */
57 uint64_t integer;
58 /* An expression. */
59 Expression_ptr expr;
60 /* An output section header. */
61 struct Parser_output_section_header output_section_header;
62 /* An output section trailer. */
63 struct Parser_output_section_trailer output_section_trailer;
64 /* A section constraint. */
65 enum Section_constraint constraint;
66 /* A complete input section specification. */
67 struct Input_section_spec input_section_spec;
68 /* A list of wildcard specifications, with exclusions. */
69 struct Wildcard_sections wildcard_sections;
70 /* A single wildcard specification. */
71 struct Wildcard_section wildcard_section;
72 /* A list of strings. */
73 String_list_ptr string_list;
74 /* Information for a program header. */
75 struct Phdr_info phdr_info;
76 /* Used for version scripts and within VERSION {}. */
77 struct Version_dependency_list* deplist;
78 struct Version_expression_list* versyms;
79 struct Version_tree* versnode;
82 /* Operators, including a precedence table for expressions. */
84 %right PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
85 %right '?' ':'
86 %left OROR
87 %left ANDAND
88 %left '|'
89 %left '^'
90 %left '&'
91 %left EQ NE
92 %left '<' '>' LE GE
93 %left LSHIFT RSHIFT
94 %left '+' '-'
95 %left '*' '/' '%'
97 /* A fake operator used to indicate unary operator precedence. */
98 %right UNARY
100 /* Constants. */
102 %token <string> STRING
103 %token <string> QUOTED_STRING
104 %token <integer> INTEGER
106 /* Keywords. This list is taken from ldgram.y and ldlex.l in the old
107 GNU linker, with the keywords which only appear in MRI mode
108 removed. Not all these keywords are actually used in this grammar.
109 In most cases the keyword is recognized as the token name in upper
110 case. The comments indicate where this is not the case. */
112 %token ABSOLUTE
113 %token ADDR
114 %token ALIGN_K /* ALIGN */
115 %token ALIGNOF
116 %token ASSERT_K /* ASSERT */
117 %token AS_NEEDED
118 %token AT
119 %token BIND
120 %token BLOCK
121 %token BYTE
122 %token CONSTANT
123 %token CONSTRUCTORS
124 %token CREATE_OBJECT_SYMBOLS
125 %token DATA_SEGMENT_ALIGN
126 %token DATA_SEGMENT_END
127 %token DATA_SEGMENT_RELRO_END
128 %token DEFINED
129 %token ENTRY
130 %token EXCLUDE_FILE
131 %token EXTERN
132 %token FILL
133 %token FLOAT
134 %token FORCE_COMMON_ALLOCATION
135 %token GLOBAL /* global */
136 %token GROUP
137 %token HLL
138 %token INCLUDE
139 %token INHIBIT_COMMON_ALLOCATION
140 %token INPUT
141 %token KEEP
142 %token LENGTH /* LENGTH, l, len */
143 %token LOADADDR
144 %token LOCAL /* local */
145 %token LONG
146 %token MAP
147 %token MAX_K /* MAX */
148 %token MEMORY
149 %token MIN_K /* MIN */
150 %token NEXT
151 %token NOCROSSREFS
152 %token NOFLOAT
153 %token ONLY_IF_RO
154 %token ONLY_IF_RW
155 %token ORIGIN /* ORIGIN, o, org */
156 %token OUTPUT
157 %token OUTPUT_ARCH
158 %token OUTPUT_FORMAT
159 %token OVERLAY
160 %token PHDRS
161 %token PROVIDE
162 %token PROVIDE_HIDDEN
163 %token QUAD
164 %token SEARCH_DIR
165 %token SECTIONS
166 %token SEGMENT_START
167 %token SHORT
168 %token SIZEOF
169 %token SIZEOF_HEADERS /* SIZEOF_HEADERS, sizeof_headers */
170 %token SORT_BY_ALIGNMENT
171 %token SORT_BY_NAME
172 %token SPECIAL
173 %token SQUAD
174 %token STARTUP
175 %token SUBALIGN
176 %token SYSLIB
177 %token TARGET_K /* TARGET */
178 %token TRUNCATE
179 %token VERSIONK /* VERSION */
181 /* Keywords, part 2. These are keywords that are unique to gold,
182 and not present in the old GNU linker. As before, unless the
183 comments say otherwise, the keyword is recognized as the token
184 name in upper case. */
186 %token OPTION
188 /* Special tokens used to tell the grammar what type of tokens we are
189 parsing. The token stream always begins with one of these tokens.
190 We do this because version scripts can appear embedded within
191 linker scripts, and because --defsym uses the expression
192 parser. */
193 %token PARSING_LINKER_SCRIPT
194 %token PARSING_VERSION_SCRIPT
195 %token PARSING_DEFSYM
196 %token PARSING_DYNAMIC_LIST
198 /* Non-terminal types, where needed. */
200 %type <expr> parse_exp exp opt_address_and_section_type
201 %type <expr> opt_at opt_align opt_subalign opt_fill
202 %type <output_section_header> section_header
203 %type <output_section_trailer> section_trailer
204 %type <constraint> opt_constraint
205 %type <string_list> opt_phdr
206 %type <integer> data_length
207 %type <input_section_spec> input_section_no_keep
208 %type <wildcard_sections> wildcard_sections
209 %type <wildcard_section> wildcard_file wildcard_section
210 %type <string_list> exclude_names
211 %type <string> wildcard_name
212 %type <integer> phdr_type
213 %type <phdr_info> phdr_info
214 %type <versyms> vers_defns
215 %type <versnode> vers_tag
216 %type <deplist> verdep
217 %type <string> string
221 /* Read the special token to see what to read next. */
222 top:
223 PARSING_LINKER_SCRIPT linker_script
224 | PARSING_VERSION_SCRIPT version_script
225 | PARSING_DEFSYM defsym_expr
226 | PARSING_DYNAMIC_LIST dynamic_list_expr
229 /* A file contains a list of commands. */
230 linker_script:
231 linker_script file_cmd
232 | /* empty */
235 /* A command which may appear at top level of a linker script. */
236 file_cmd:
237 FORCE_COMMON_ALLOCATION
238 { script_set_common_allocation(closure, 1); }
239 | GROUP
240 { script_start_group(closure); }
241 '(' input_list ')'
242 { script_end_group(closure); }
243 | INHIBIT_COMMON_ALLOCATION
244 { script_set_common_allocation(closure, 0); }
245 | INPUT '(' input_list ')'
246 | OPTION '(' string ')'
247 { script_parse_option(closure, $3.value, $3.length); }
248 | OUTPUT_FORMAT '(' string ')'
250 if (!script_check_output_format(closure, $3.value, $3.length,
251 NULL, 0, NULL, 0))
252 YYABORT;
254 | OUTPUT_FORMAT '(' string ',' string ',' string ')'
256 if (!script_check_output_format(closure, $3.value, $3.length,
257 $5.value, $5.length,
258 $7.value, $7.length))
259 YYABORT;
261 | PHDRS '{' phdrs_defs '}'
262 | SEARCH_DIR '(' string ')'
263 { script_add_search_dir(closure, $3.value, $3.length); }
264 | SECTIONS '{'
265 { script_start_sections(closure); }
266 sections_block '}'
267 { script_finish_sections(closure); }
268 | VERSIONK '{'
269 { script_push_lex_into_version_mode(closure); }
270 version_script '}'
271 { script_pop_lex_mode(closure); }
272 | file_or_sections_cmd
273 | ignore_cmd
274 | ';'
277 /* Top level commands which we ignore. The GNU linker uses these to
278 select the output format, but we don't offer a choice. Ignoring
279 these is more-or-less OK since most scripts simply explicitly
280 choose the default. */
281 ignore_cmd:
282 OUTPUT_ARCH '(' string ')'
285 /* A list of input file names. */
286 input_list:
287 input_list_element
288 | input_list opt_comma input_list_element
291 /* An input file name. */
292 input_list_element:
293 string
294 { script_add_file(closure, $1.value, $1.length); }
295 | AS_NEEDED
296 { script_start_as_needed(closure); }
297 '(' input_list ')'
298 { script_end_as_needed(closure); }
301 /* Commands in a SECTIONS block. */
302 sections_block:
303 sections_block section_block_cmd
304 | /* empty */
307 /* A command which may appear within a SECTIONS block. */
308 section_block_cmd:
309 file_or_sections_cmd
310 | string section_header
311 { script_start_output_section(closure, $1.value, $1.length, &$2); }
312 '{' section_cmds '}' section_trailer
313 { script_finish_output_section(closure, &$7); }
316 /* The header of an output section in a SECTIONS block--everything
317 after the name. */
318 section_header:
319 { script_push_lex_into_expression_mode(closure); }
320 opt_address_and_section_type opt_at opt_align opt_subalign
321 { script_pop_lex_mode(closure); }
322 opt_constraint
324 $$.address = $2;
325 $$.load_address = $3;
326 $$.align = $4;
327 $$.subalign = $5;
328 $$.constraint = $7;
332 /* The optional address followed by the optional section type. This
333 is a separate nonterminal to avoid a shift/reduce conflict on
334 '(' in section_header. */
336 opt_address_and_section_type:
338 { $$ = NULL; }
339 | '(' ')' ':'
340 { $$ = NULL; }
341 | exp ':'
342 { $$ = $1; }
343 | exp '(' ')' ':'
344 { $$ = $1; }
345 | exp '(' string ')' ':'
347 yyerror(closure, "section types are not supported");
348 $$ = $1;
352 /* The address at which an output section should be loaded. */
353 opt_at:
354 /* empty */
355 { $$ = NULL; }
356 | AT '(' exp ')'
357 { $$ = $3; }
360 /* The alignment of an output section. */
361 opt_align:
362 /* empty */
363 { $$ = NULL; }
364 | ALIGN_K '(' exp ')'
365 { $$ = $3; }
368 /* The input section alignment within an output section. */
369 opt_subalign:
370 /* empty */
371 { $$ = NULL; }
372 | SUBALIGN '(' exp ')'
373 { $$ = $3; }
376 /* A section constraint. */
377 opt_constraint:
378 /* empty */
379 { $$ = CONSTRAINT_NONE; }
380 | ONLY_IF_RO
381 { $$ = CONSTRAINT_ONLY_IF_RO; }
382 | ONLY_IF_RW
383 { $$ = CONSTRAINT_ONLY_IF_RW; }
384 | SPECIAL
385 { $$ = CONSTRAINT_SPECIAL; }
388 /* The trailer of an output section in a SECTIONS block. */
389 section_trailer:
390 opt_memspec opt_at_memspec opt_phdr opt_fill opt_comma
392 $$.fill = $4;
393 $$.phdrs = $3;
397 /* A memory specification for an output section. */
398 opt_memspec:
399 '>' string
400 { yyerror(closure, "memory regions are not supported"); }
401 | /* empty */
404 /* A memory specification for where to load an output section. */
405 opt_at_memspec:
406 AT '>' string
407 { yyerror(closure, "memory regions are not supported"); }
408 | /* empty */
411 /* The program segment an output section should go into. */
412 opt_phdr:
413 opt_phdr ':' string
414 { $$ = script_string_list_push_back($1, $3.value, $3.length); }
415 | /* empty */
416 { $$ = NULL; }
419 /* The value to use to fill an output section. FIXME: This does not
420 handle a string of arbitrary length. */
421 opt_fill:
422 '=' parse_exp
423 { $$ = $2; }
424 | /* empty */
425 { $$ = NULL; }
428 /* Commands which may appear within the description of an output
429 section in a SECTIONS block. */
430 section_cmds:
431 /* empty */
432 | section_cmds section_cmd
435 /* A command which may appear within the description of an output
436 section in a SECTIONS block. */
437 section_cmd:
438 assignment end
439 | input_section_spec
440 | data_length '(' parse_exp ')'
441 { script_add_data(closure, $1, $3); }
442 | ASSERT_K '(' parse_exp ',' string ')'
443 { script_add_assertion(closure, $3, $5.value, $5.length); }
444 | FILL '(' parse_exp ')'
445 { script_add_fill(closure, $3); }
446 | CONSTRUCTORS
448 /* The GNU linker uses CONSTRUCTORS for the a.out object
449 file format. It does nothing when using ELF. Since
450 some ELF linker scripts use it although it does
451 nothing, we accept it and ignore it. */
453 | SORT_BY_NAME '(' CONSTRUCTORS ')'
454 | ';'
457 /* The length of data which may appear within the description of an
458 output section in a SECTIONS block. */
459 data_length:
460 QUAD
461 { $$ = QUAD; }
462 | SQUAD
463 { $$ = SQUAD; }
464 | LONG
465 { $$ = LONG; }
466 | SHORT
467 { $$ = SHORT; }
468 | BYTE
469 { $$ = BYTE; }
472 /* An input section specification. This may appear within the
473 description of an output section in a SECTIONS block. */
474 input_section_spec:
475 input_section_no_keep
476 { script_add_input_section(closure, &$1, 0); }
477 | KEEP '(' input_section_no_keep ')'
478 { script_add_input_section(closure, &$3, 1); }
481 /* An input section specification within a KEEP clause. */
482 input_section_no_keep:
483 string
485 $$.file.name = $1;
486 $$.file.sort = SORT_WILDCARD_NONE;
487 $$.input_sections.sections = NULL;
488 $$.input_sections.exclude = NULL;
490 | wildcard_file '(' wildcard_sections ')'
492 $$.file = $1;
493 $$.input_sections = $3;
497 /* A wildcard file specification. */
498 wildcard_file:
499 wildcard_name
501 $$.name = $1;
502 $$.sort = SORT_WILDCARD_NONE;
504 | SORT_BY_NAME '(' wildcard_name ')'
506 $$.name = $3;
507 $$.sort = SORT_WILDCARD_BY_NAME;
511 /* A list of wild card section specifications. */
512 wildcard_sections:
513 wildcard_sections opt_comma wildcard_section
515 $$.sections = script_string_sort_list_add($1.sections, &$3);
516 $$.exclude = $1.exclude;
518 | wildcard_section
520 $$.sections = script_new_string_sort_list(&$1);
521 $$.exclude = NULL;
523 | wildcard_sections opt_comma EXCLUDE_FILE '(' exclude_names ')'
525 $$.sections = $1.sections;
526 $$.exclude = script_string_list_append($1.exclude, $5);
528 | EXCLUDE_FILE '(' exclude_names ')'
530 $$.sections = NULL;
531 $$.exclude = $3;
535 /* A single wild card specification. */
536 wildcard_section:
537 wildcard_name
539 $$.name = $1;
540 $$.sort = SORT_WILDCARD_NONE;
542 | SORT_BY_NAME '(' wildcard_section ')'
544 $$.name = $3.name;
545 switch ($3.sort)
547 case SORT_WILDCARD_NONE:
548 $$.sort = SORT_WILDCARD_BY_NAME;
549 break;
550 case SORT_WILDCARD_BY_NAME:
551 case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
552 break;
553 case SORT_WILDCARD_BY_ALIGNMENT:
554 case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
555 $$.sort = SORT_WILDCARD_BY_NAME_BY_ALIGNMENT;
556 break;
557 default:
558 abort();
561 | SORT_BY_ALIGNMENT '(' wildcard_section ')'
563 $$.name = $3.name;
564 switch ($3.sort)
566 case SORT_WILDCARD_NONE:
567 $$.sort = SORT_WILDCARD_BY_ALIGNMENT;
568 break;
569 case SORT_WILDCARD_BY_ALIGNMENT:
570 case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
571 break;
572 case SORT_WILDCARD_BY_NAME:
573 case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
574 $$.sort = SORT_WILDCARD_BY_ALIGNMENT_BY_NAME;
575 break;
576 default:
577 abort();
582 /* A list of file names to exclude. */
583 exclude_names:
584 exclude_names opt_comma wildcard_name
585 { $$ = script_string_list_push_back($1, $3.value, $3.length); }
586 | wildcard_name
587 { $$ = script_new_string_list($1.value, $1.length); }
590 /* A single wildcard name. We recognize '*' and '?' specially since
591 they are expression tokens. */
592 wildcard_name:
593 string
594 { $$ = $1; }
595 | '*'
597 $$.value = "*";
598 $$.length = 1;
600 | '?'
602 $$.value = "?";
603 $$.length = 1;
607 /* A command which may appear at the top level of a linker script, or
608 within a SECTIONS block. */
609 file_or_sections_cmd:
610 ENTRY '(' string ')'
611 { script_set_entry(closure, $3.value, $3.length); }
612 | assignment end
613 | ASSERT_K '(' parse_exp ',' string ')'
614 { script_add_assertion(closure, $3, $5.value, $5.length); }
617 /* A list of program header definitions. */
618 phdrs_defs:
619 phdrs_defs phdr_def
620 | /* empty */
623 /* A program header definition. */
624 phdr_def:
625 string phdr_type phdr_info ';'
626 { script_add_phdr(closure, $1.value, $1.length, $2, &$3); }
629 /* A program header type. The GNU linker accepts a general expression
630 here, but that would be a pain because we would have to dig into
631 the expression structure. It's unlikely that anybody uses anything
632 other than a string or a number here, so that is all we expect. */
633 phdr_type:
634 string
635 { $$ = script_phdr_string_to_type(closure, $1.value, $1.length); }
636 | INTEGER
637 { $$ = $1; }
640 /* Additional information for a program header. */
641 phdr_info:
642 /* empty */
643 { memset(&$$, 0, sizeof(struct Phdr_info)); }
644 | string phdr_info
646 $$ = $2;
647 if ($1.length == 7 && strncmp($1.value, "FILEHDR", 7) == 0)
648 $$.includes_filehdr = 1;
649 else
650 yyerror(closure, "PHDRS syntax error");
652 | PHDRS phdr_info
654 $$ = $2;
655 $$.includes_phdrs = 1;
657 | string '(' INTEGER ')' phdr_info
659 $$ = $5;
660 if ($1.length == 5 && strncmp($1.value, "FLAGS", 5) == 0)
662 $$.is_flags_valid = 1;
663 $$.flags = $3;
665 else
666 yyerror(closure, "PHDRS syntax error");
668 | AT '(' parse_exp ')' phdr_info
670 $$ = $5;
671 $$.load_address = $3;
675 /* Set a symbol to a value. */
676 assignment:
677 string '=' parse_exp
678 { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
679 | string PLUSEQ parse_exp
681 Expression_ptr s = script_exp_string($1.value, $1.length);
682 Expression_ptr e = script_exp_binary_add(s, $3);
683 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
685 | string MINUSEQ parse_exp
687 Expression_ptr s = script_exp_string($1.value, $1.length);
688 Expression_ptr e = script_exp_binary_sub(s, $3);
689 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
691 | string MULTEQ parse_exp
693 Expression_ptr s = script_exp_string($1.value, $1.length);
694 Expression_ptr e = script_exp_binary_mult(s, $3);
695 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
697 | string DIVEQ parse_exp
699 Expression_ptr s = script_exp_string($1.value, $1.length);
700 Expression_ptr e = script_exp_binary_div(s, $3);
701 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
703 | string LSHIFTEQ parse_exp
705 Expression_ptr s = script_exp_string($1.value, $1.length);
706 Expression_ptr e = script_exp_binary_lshift(s, $3);
707 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
709 | string RSHIFTEQ parse_exp
711 Expression_ptr s = script_exp_string($1.value, $1.length);
712 Expression_ptr e = script_exp_binary_rshift(s, $3);
713 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
715 | string ANDEQ parse_exp
717 Expression_ptr s = script_exp_string($1.value, $1.length);
718 Expression_ptr e = script_exp_binary_bitwise_and(s, $3);
719 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
721 | string OREQ parse_exp
723 Expression_ptr s = script_exp_string($1.value, $1.length);
724 Expression_ptr e = script_exp_binary_bitwise_or(s, $3);
725 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
727 | PROVIDE '(' string '=' parse_exp ')'
728 { script_set_symbol(closure, $3.value, $3.length, $5, 1, 0); }
729 | PROVIDE_HIDDEN '(' string '=' parse_exp ')'
730 { script_set_symbol(closure, $3.value, $3.length, $5, 1, 1); }
733 /* Parse an expression, putting the lexer into the right mode. */
734 parse_exp:
735 { script_push_lex_into_expression_mode(closure); }
738 script_pop_lex_mode(closure);
739 $$ = $2;
743 /* An expression. */
744 exp:
745 '(' exp ')'
746 { $$ = $2; }
747 | '-' exp %prec UNARY
748 { $$ = script_exp_unary_minus($2); }
749 | '!' exp %prec UNARY
750 { $$ = script_exp_unary_logical_not($2); }
751 | '~' exp %prec UNARY
752 { $$ = script_exp_unary_bitwise_not($2); }
753 | '+' exp %prec UNARY
754 { $$ = $2; }
755 | exp '*' exp
756 { $$ = script_exp_binary_mult($1, $3); }
757 | exp '/' exp
758 { $$ = script_exp_binary_div($1, $3); }
759 | exp '%' exp
760 { $$ = script_exp_binary_mod($1, $3); }
761 | exp '+' exp
762 { $$ = script_exp_binary_add($1, $3); }
763 | exp '-' exp
764 { $$ = script_exp_binary_sub($1, $3); }
765 | exp LSHIFT exp
766 { $$ = script_exp_binary_lshift($1, $3); }
767 | exp RSHIFT exp
768 { $$ = script_exp_binary_rshift($1, $3); }
769 | exp EQ exp
770 { $$ = script_exp_binary_eq($1, $3); }
771 | exp NE exp
772 { $$ = script_exp_binary_ne($1, $3); }
773 | exp LE exp
774 { $$ = script_exp_binary_le($1, $3); }
775 | exp GE exp
776 { $$ = script_exp_binary_ge($1, $3); }
777 | exp '<' exp
778 { $$ = script_exp_binary_lt($1, $3); }
779 | exp '>' exp
780 { $$ = script_exp_binary_gt($1, $3); }
781 | exp '&' exp
782 { $$ = script_exp_binary_bitwise_and($1, $3); }
783 | exp '^' exp
784 { $$ = script_exp_binary_bitwise_xor($1, $3); }
785 | exp '|' exp
786 { $$ = script_exp_binary_bitwise_or($1, $3); }
787 | exp ANDAND exp
788 { $$ = script_exp_binary_logical_and($1, $3); }
789 | exp OROR exp
790 { $$ = script_exp_binary_logical_or($1, $3); }
791 | exp '?' exp ':' exp
792 { $$ = script_exp_trinary_cond($1, $3, $5); }
793 | INTEGER
794 { $$ = script_exp_integer($1); }
795 | string
796 { $$ = script_exp_string($1.value, $1.length); }
797 | MAX_K '(' exp ',' exp ')'
798 { $$ = script_exp_function_max($3, $5); }
799 | MIN_K '(' exp ',' exp ')'
800 { $$ = script_exp_function_min($3, $5); }
801 | DEFINED '(' string ')'
802 { $$ = script_exp_function_defined($3.value, $3.length); }
803 | SIZEOF_HEADERS
804 { $$ = script_exp_function_sizeof_headers(); }
805 | ALIGNOF '(' string ')'
806 { $$ = script_exp_function_alignof($3.value, $3.length); }
807 | SIZEOF '(' string ')'
808 { $$ = script_exp_function_sizeof($3.value, $3.length); }
809 | ADDR '(' string ')'
810 { $$ = script_exp_function_addr($3.value, $3.length); }
811 | LOADADDR '(' string ')'
812 { $$ = script_exp_function_loadaddr($3.value, $3.length); }
813 | ORIGIN '(' string ')'
814 { $$ = script_exp_function_origin($3.value, $3.length); }
815 | LENGTH '(' string ')'
816 { $$ = script_exp_function_length($3.value, $3.length); }
817 | CONSTANT '(' string ')'
818 { $$ = script_exp_function_constant($3.value, $3.length); }
819 | ABSOLUTE '(' exp ')'
820 { $$ = script_exp_function_absolute($3); }
821 | ALIGN_K '(' exp ')'
822 { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
823 | ALIGN_K '(' exp ',' exp ')'
824 { $$ = script_exp_function_align($3, $5); }
825 | BLOCK '(' exp ')'
826 { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
827 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
829 script_data_segment_align(closure);
830 $$ = script_exp_function_data_segment_align($3, $5);
832 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
834 script_data_segment_relro_end(closure);
835 $$ = script_exp_function_data_segment_relro_end($3, $5);
837 | DATA_SEGMENT_END '(' exp ')'
838 { $$ = script_exp_function_data_segment_end($3); }
839 | SEGMENT_START '(' string ',' exp ')'
841 $$ = script_exp_function_segment_start($3.value, $3.length, $5);
843 | ASSERT_K '(' exp ',' string ')'
844 { $$ = script_exp_function_assert($3, $5.value, $5.length); }
847 /* Handle the --defsym option. */
848 defsym_expr:
849 string '=' parse_exp
850 { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
853 /* Handle the --dynamic-list option. A dynamic list has the format
854 { sym1; sym2; extern "C++" { namespace::sym3 }; };
855 We store the symbol we see in the "local" list; that is where
856 Command_line::in_dynamic_list() will look to do its check.
857 TODO(csilvers): More than one of these brace-lists can appear, and
858 should just be merged and treated as a single list. */
859 dynamic_list_expr: dynamic_list_nodes ;
861 dynamic_list_nodes:
862 dynamic_list_node
863 | dynamic_list_nodes dynamic_list_node
866 dynamic_list_node:
867 '{' vers_defns ';' '}' ';'
868 { script_new_vers_node (closure, NULL, $2); }
871 /* A version script. */
872 version_script:
873 vers_nodes
876 vers_nodes:
877 vers_node
878 | vers_nodes vers_node
881 vers_node:
882 '{' vers_tag '}' ';'
884 script_register_vers_node (closure, NULL, 0, $2, NULL);
886 | string '{' vers_tag '}' ';'
888 script_register_vers_node (closure, $1.value, $1.length, $3,
889 NULL);
891 | string '{' vers_tag '}' verdep ';'
893 script_register_vers_node (closure, $1.value, $1.length, $3, $5);
897 verdep:
898 string
900 $$ = script_add_vers_depend (closure, NULL, $1.value, $1.length);
902 | verdep string
904 $$ = script_add_vers_depend (closure, $1, $2.value, $2.length);
908 vers_tag:
909 /* empty */
910 { $$ = script_new_vers_node (closure, NULL, NULL); }
911 | vers_defns ';'
912 { $$ = script_new_vers_node (closure, $1, NULL); }
913 | GLOBAL ':' vers_defns ';'
914 { $$ = script_new_vers_node (closure, $3, NULL); }
915 | LOCAL ':' vers_defns ';'
916 { $$ = script_new_vers_node (closure, NULL, $3); }
917 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
918 { $$ = script_new_vers_node (closure, $3, $7); }
921 /* Here is one of the rare places we care about the distinction
922 between STRING and QUOTED_STRING. For QUOTED_STRING, we do exact
923 matching on the pattern, so we pass in true for the exact_match
924 parameter. For STRING, we do glob matching and pass in false. */
925 vers_defns:
926 STRING
928 $$ = script_new_vers_pattern (closure, NULL, $1.value,
929 $1.length, 0);
931 | QUOTED_STRING
933 $$ = script_new_vers_pattern (closure, NULL, $1.value,
934 $1.length, 1);
936 | vers_defns ';' STRING
938 $$ = script_new_vers_pattern (closure, $1, $3.value,
939 $3.length, 0);
941 | vers_defns ';' QUOTED_STRING
943 $$ = script_new_vers_pattern (closure, $1, $3.value,
944 $3.length, 1);
946 | /* Push string on the language stack. */
947 EXTERN string '{'
948 { version_script_push_lang (closure, $2.value, $2.length); }
949 vers_defns opt_semicolon '}'
951 $$ = $5;
952 version_script_pop_lang(closure);
954 | /* Push string on the language stack. This is more complicated
955 than the other cases because we need to merge the linked-list
956 state from the pre-EXTERN defns and the post-EXTERN defns. */
957 vers_defns ';' EXTERN string '{'
958 { version_script_push_lang (closure, $4.value, $4.length); }
959 vers_defns opt_semicolon '}'
961 $$ = script_merge_expressions ($1, $7);
962 version_script_pop_lang(closure);
964 | EXTERN // "extern" as a symbol name
966 $$ = script_new_vers_pattern (closure, NULL, "extern",
967 sizeof("extern") - 1, 1);
969 | vers_defns ';' EXTERN
971 $$ = script_new_vers_pattern (closure, $1, "extern",
972 sizeof("extern") - 1, 1);
976 /* A string can be either a STRING or a QUOTED_STRING. Almost all the
977 time we don't care, and we use this rule. */
978 string:
979 STRING
980 { $$ = $1; }
981 | QUOTED_STRING
982 { $$ = $1; }
985 /* Some statements require a terminator, which may be a semicolon or a
986 comma. */
987 end:
989 | ','
992 /* An optional semicolon. */
993 opt_semicolon:
995 | /* empty */
998 /* An optional comma. */
999 opt_comma:
1001 | /* empty */