include/ChangeLog
[deliverable/binutils-gdb.git] / gold / yyscript.y
CommitLineData
bd52eafb 1/* yyscript.y -- linker script grammar for gold. */
dbe717ef 2
e5756efb 3/* Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
6cb15b7f
ILT
4 Written by Ian Lance Taylor <iant@google.com>.
5
6 This file is part of gold.
7
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.
12
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.
17
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. */
22
dbe717ef
ILT
23/* This is a bison grammar to parse a subset of the original GNU ld
24 linker script language. */
25
26%{
27
28#include "config.h"
29
30#include <stddef.h>
31#include <stdint.h>
494e05f4 32#include <stdlib.h>
1c4f3631 33#include <string.h>
dbe717ef
ILT
34
35#include "script-c.h"
36
37%}
38
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. */
41
42%pure-parser
43
44%parse-param {void* closure}
45%lex-param {void* closure}
46
47/* Since we require bison anyhow, we take advantage of it. */
48
49%error-verbose
50
51/* The values associated with tokens. */
52
53%union {
e5756efb
ILT
54 /* A string. */
55 struct Parser_string string;
56 /* A number. */
57 uint64_t integer;
58 /* An expression. */
59 Expression_ptr expr;
494e05f4
ILT
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;
3802b2dd
ILT
64 /* A section constraint. */
65 enum Section_constraint constraint;
494e05f4
ILT
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;
1c4f3631
ILT
74 /* Information for a program header. */
75 struct Phdr_info phdr_info;
494e05f4 76 /* Used for version scripts and within VERSION {}. */
09124467
ILT
77 struct Version_dependency_list* deplist;
78 struct Version_expression_list* versyms;
79 struct Version_tree* versnode;
dbe717ef
ILT
80}
81
82/* Operators, including a precedence table for expressions. */
83
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 '*' '/' '%'
96
e5756efb
ILT
97/* A fake operator used to indicate unary operator precedence. */
98%right UNARY
99
dbe717ef
ILT
100/* Constants. */
101
102%token <string> STRING
10600224 103%token <string> QUOTED_STRING
dbe717ef
ILT
104%token <integer> INTEGER
105
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. */
111
112%token ABSOLUTE
113%token ADDR
114%token ALIGN_K /* ALIGN */
e5756efb 115%token ALIGNOF
dbe717ef
ILT
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
dbe717ef
ILT
124%token CREATE_OBJECT_SYMBOLS
125%token DATA_SEGMENT_ALIGN
126%token DATA_SEGMENT_END
127%token DATA_SEGMENT_RELRO_END
128%token DEFINED
dbe717ef
ILT
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
dbe717ef
ILT
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
dbe717ef
ILT
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 */
180
195e7dc6
ILT
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. */
185
186%token OPTION
187
e5756efb
ILT
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
c82fbeee 196%token PARSING_DYNAMIC_LIST
e5756efb
ILT
197
198/* Non-terminal types, where needed. */
199
494e05f4
ILT
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
3802b2dd 204%type <constraint> opt_constraint
1c4f3631 205%type <string_list> opt_phdr
494e05f4
ILT
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
1c4f3631
ILT
212%type <integer> phdr_type
213%type <phdr_info> phdr_info
09124467
ILT
214%type <versyms> vers_defns
215%type <versnode> vers_tag
216%type <deplist> verdep
10600224 217%type <string> string
e5756efb 218
dbe717ef
ILT
219%%
220
e5756efb
ILT
221/* Read the special token to see what to read next. */
222top:
223 PARSING_LINKER_SCRIPT linker_script
224 | PARSING_VERSION_SCRIPT version_script
225 | PARSING_DEFSYM defsym_expr
c82fbeee 226 | PARSING_DYNAMIC_LIST dynamic_list_expr
e5756efb
ILT
227 ;
228
d391083d 229/* A file contains a list of commands. */
e5756efb
ILT
230linker_script:
231 linker_script file_cmd
dbe717ef
ILT
232 | /* empty */
233 ;
234
d391083d 235/* A command which may appear at top level of a linker script. */
dbe717ef 236file_cmd:
0dfbdef4
ILT
237 FORCE_COMMON_ALLOCATION
238 { script_set_common_allocation(closure, 1); }
239 | GROUP
dbe717ef
ILT
240 { script_start_group(closure); }
241 '(' input_list ')'
242 { script_end_group(closure); }
0dfbdef4
ILT
243 | INHIBIT_COMMON_ALLOCATION
244 { script_set_common_allocation(closure, 0); }
fbc558e1 245 | INPUT '(' input_list ')'
10600224 246 | OPTION '(' string ')'
e5756efb 247 { script_parse_option(closure, $3.value, $3.length); }
1c4f3631 248 | PHDRS '{' phdrs_defs '}'
3802b2dd
ILT
249 | SEARCH_DIR '(' string ')'
250 { script_add_search_dir(closure, $3.value, $3.length); }
494e05f4
ILT
251 | SECTIONS '{'
252 { script_start_sections(closure); }
253 sections_block '}'
254 { script_finish_sections(closure); }
09124467
ILT
255 | VERSIONK '{'
256 { script_push_lex_into_version_mode(closure); }
257 version_script '}'
258 { script_pop_lex_mode(closure); }
d391083d 259 | file_or_sections_cmd
2dd3e587 260 | ignore_cmd
3802b2dd 261 | ';'
2dd3e587
ILT
262 ;
263
264/* Top level commands which we ignore. The GNU linker uses these to
265 select the output format, but we don't offer a choice. Ignoring
266 these is more-or-less OK since most scripts simply explicitly
267 choose the default. */
268ignore_cmd:
10600224
ILT
269 OUTPUT_FORMAT '(' string ')'
270 | OUTPUT_FORMAT '(' string ',' string ',' string ')'
271 | OUTPUT_ARCH '(' string ')'
dbe717ef
ILT
272 ;
273
d391083d 274/* A list of input file names. */
dbe717ef
ILT
275input_list:
276 input_list_element
277 | input_list opt_comma input_list_element
278 ;
279
d391083d 280/* An input file name. */
dbe717ef 281input_list_element:
10600224 282 string
e5756efb 283 { script_add_file(closure, $1.value, $1.length); }
dbe717ef
ILT
284 | AS_NEEDED
285 { script_start_as_needed(closure); }
286 '(' input_list ')'
287 { script_end_as_needed(closure); }
288 ;
289
494e05f4
ILT
290/* Commands in a SECTIONS block. */
291sections_block:
292 sections_block section_block_cmd
293 | /* empty */
294 ;
295
296/* A command which may appear within a SECTIONS block. */
297section_block_cmd:
298 file_or_sections_cmd
e4967d85 299 | string section_header
494e05f4
ILT
300 { script_start_output_section(closure, $1.value, $1.length, &$2); }
301 '{' section_cmds '}' section_trailer
302 { script_finish_output_section(closure, &$7); }
303 ;
304
305/* The header of an output section in a SECTIONS block--everything
306 after the name. */
307section_header:
308 { script_push_lex_into_expression_mode(closure); }
309 opt_address_and_section_type opt_at opt_align opt_subalign
3802b2dd
ILT
310 { script_pop_lex_mode(closure); }
311 opt_constraint
494e05f4
ILT
312 {
313 $$.address = $2;
314 $$.load_address = $3;
315 $$.align = $4;
316 $$.subalign = $5;
3802b2dd 317 $$.constraint = $7;
494e05f4
ILT
318 }
319 ;
320
321/* The optional address followed by the optional section type. This
322 is a separate nonterminal to avoid a shift/reduce conflict on
323 '(' in section_header. */
324
325opt_address_and_section_type:
326 ':'
327 { $$ = NULL; }
328 | '(' ')' ':'
329 { $$ = NULL; }
330 | exp ':'
331 { $$ = $1; }
332 | exp '(' ')' ':'
333 { $$ = $1; }
e4967d85 334 | exp '(' string ')' ':'
494e05f4
ILT
335 {
336 yyerror(closure, "section types are not supported");
337 $$ = $1;
338 }
339 ;
340
341/* The address at which an output section should be loaded. */
342opt_at:
343 /* empty */
344 { $$ = NULL; }
345 | AT '(' exp ')'
346 { $$ = $3; }
347 ;
348
349/* The alignment of an output section. */
350opt_align:
351 /* empty */
352 { $$ = NULL; }
353 | ALIGN_K '(' exp ')'
354 { $$ = $3; }
355 ;
356
357/* The input section alignment within an output section. */
358opt_subalign:
359 /* empty */
360 { $$ = NULL; }
361 | SUBALIGN '(' exp ')'
362 { $$ = $3; }
363 ;
364
3802b2dd
ILT
365/* A section constraint. */
366opt_constraint:
367 /* empty */
368 { $$ = CONSTRAINT_NONE; }
369 | ONLY_IF_RO
370 { $$ = CONSTRAINT_ONLY_IF_RO; }
371 | ONLY_IF_RW
372 { $$ = CONSTRAINT_ONLY_IF_RW; }
373 | SPECIAL
374 { $$ = CONSTRAINT_SPECIAL; }
375 ;
376
494e05f4
ILT
377/* The trailer of an output section in a SECTIONS block. */
378section_trailer:
494e05f4
ILT
379 opt_memspec opt_at_memspec opt_phdr opt_fill opt_comma
380 {
3802b2dd 381 $$.fill = $4;
1c4f3631 382 $$.phdrs = $3;
494e05f4
ILT
383 }
384 ;
385
386/* A memory specification for an output section. */
387opt_memspec:
e4967d85 388 '>' string
494e05f4
ILT
389 { yyerror(closure, "memory regions are not supported"); }
390 | /* empty */
391 ;
392
393/* A memory specification for where to load an output section. */
394opt_at_memspec:
e4967d85 395 AT '>' string
494e05f4
ILT
396 { yyerror(closure, "memory regions are not supported"); }
397 | /* empty */
398 ;
399
400/* The program segment an output section should go into. */
401opt_phdr:
e4967d85 402 opt_phdr ':' string
1c4f3631 403 { $$ = script_string_list_push_back($1, $3.value, $3.length); }
494e05f4 404 | /* empty */
1c4f3631 405 { $$ = NULL; }
494e05f4
ILT
406 ;
407
a445fddf
ILT
408/* The value to use to fill an output section. FIXME: This does not
409 handle a string of arbitrary length. */
494e05f4 410opt_fill:
3802b2dd 411 '=' parse_exp
494e05f4
ILT
412 { $$ = $2; }
413 | /* empty */
414 { $$ = NULL; }
415 ;
416
417/* Commands which may appear within the description of an output
418 section in a SECTIONS block. */
419section_cmds:
420 /* empty */
421 | section_cmds section_cmd
422 ;
423
424/* A command which may appear within the description of an output
425 section in a SECTIONS block. */
426section_cmd:
427 assignment end
428 | input_section_spec
429 | data_length '(' parse_exp ')'
430 { script_add_data(closure, $1, $3); }
e4967d85 431 | ASSERT_K '(' parse_exp ',' string ')'
494e05f4
ILT
432 { script_add_assertion(closure, $3, $5.value, $5.length); }
433 | FILL '(' parse_exp ')'
434 { script_add_fill(closure, $3); }
435 | CONSTRUCTORS
436 {
437 /* The GNU linker uses CONSTRUCTORS for the a.out object
438 file format. It does nothing when using ELF. Since
439 some ELF linker scripts use it although it does
440 nothing, we accept it and ignore it. */
441 }
3802b2dd 442 | SORT_BY_NAME '(' CONSTRUCTORS ')'
494e05f4
ILT
443 | ';'
444 ;
445
446/* The length of data which may appear within the description of an
447 output section in a SECTIONS block. */
448data_length:
449 QUAD
450 { $$ = QUAD; }
451 | SQUAD
452 { $$ = SQUAD; }
453 | LONG
454 { $$ = LONG; }
455 | SHORT
456 { $$ = SHORT; }
457 | BYTE
458 { $$ = BYTE; }
459 ;
460
461/* An input section specification. This may appear within the
462 description of an output section in a SECTIONS block. */
463input_section_spec:
464 input_section_no_keep
465 { script_add_input_section(closure, &$1, 0); }
466 | KEEP '(' input_section_no_keep ')'
467 { script_add_input_section(closure, &$3, 1); }
468 ;
469
470/* An input section specification within a KEEP clause. */
471input_section_no_keep:
e4967d85 472 string
494e05f4
ILT
473 {
474 $$.file.name = $1;
475 $$.file.sort = SORT_WILDCARD_NONE;
476 $$.input_sections.sections = NULL;
477 $$.input_sections.exclude = NULL;
478 }
479 | wildcard_file '(' wildcard_sections ')'
480 {
481 $$.file = $1;
482 $$.input_sections = $3;
483 }
484 ;
485
486/* A wildcard file specification. */
487wildcard_file:
488 wildcard_name
489 {
490 $$.name = $1;
491 $$.sort = SORT_WILDCARD_NONE;
492 }
493 | SORT_BY_NAME '(' wildcard_name ')'
494 {
495 $$.name = $3;
496 $$.sort = SORT_WILDCARD_BY_NAME;
497 }
498 ;
499
500/* A list of wild card section specifications. */
501wildcard_sections:
502 wildcard_sections opt_comma wildcard_section
503 {
504 $$.sections = script_string_sort_list_add($1.sections, &$3);
505 $$.exclude = $1.exclude;
506 }
507 | wildcard_section
508 {
509 $$.sections = script_new_string_sort_list(&$1);
510 $$.exclude = NULL;
511 }
512 | wildcard_sections opt_comma EXCLUDE_FILE '(' exclude_names ')'
513 {
514 $$.sections = $1.sections;
515 $$.exclude = script_string_list_append($1.exclude, $5);
516 }
517 | EXCLUDE_FILE '(' exclude_names ')'
518 {
519 $$.sections = NULL;
520 $$.exclude = $3;
521 }
522 ;
523
524/* A single wild card specification. */
525wildcard_section:
526 wildcard_name
527 {
528 $$.name = $1;
529 $$.sort = SORT_WILDCARD_NONE;
530 }
531 | SORT_BY_NAME '(' wildcard_section ')'
532 {
533 $$.name = $3.name;
534 switch ($3.sort)
535 {
536 case SORT_WILDCARD_NONE:
537 $$.sort = SORT_WILDCARD_BY_NAME;
538 break;
539 case SORT_WILDCARD_BY_NAME:
540 case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
541 break;
542 case SORT_WILDCARD_BY_ALIGNMENT:
543 case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
544 $$.sort = SORT_WILDCARD_BY_NAME_BY_ALIGNMENT;
545 break;
546 default:
547 abort();
548 }
549 }
550 | SORT_BY_ALIGNMENT '(' wildcard_section ')'
551 {
552 $$.name = $3.name;
553 switch ($3.sort)
554 {
555 case SORT_WILDCARD_NONE:
556 $$.sort = SORT_WILDCARD_BY_ALIGNMENT;
557 break;
558 case SORT_WILDCARD_BY_ALIGNMENT:
559 case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
560 break;
561 case SORT_WILDCARD_BY_NAME:
562 case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
563 $$.sort = SORT_WILDCARD_BY_ALIGNMENT_BY_NAME;
564 break;
565 default:
566 abort();
567 }
568 }
569 ;
570
571/* A list of file names to exclude. */
572exclude_names:
573 exclude_names opt_comma wildcard_name
574 { $$ = script_string_list_push_back($1, $3.value, $3.length); }
575 | wildcard_name
576 { $$ = script_new_string_list($1.value, $1.length); }
577 ;
578
579/* A single wildcard name. We recognize '*' and '?' specially since
580 they are expression tokens. */
581wildcard_name:
e4967d85 582 string
494e05f4
ILT
583 { $$ = $1; }
584 | '*'
585 {
586 $$.value = "*";
587 $$.length = 1;
588 }
589 | '?'
590 {
591 $$.value = "?";
592 $$.length = 1;
593 }
594 ;
595
d391083d
ILT
596/* A command which may appear at the top level of a linker script, or
597 within a SECTIONS block. */
598file_or_sections_cmd:
10600224 599 ENTRY '(' string ')'
e5756efb
ILT
600 { script_set_entry(closure, $3.value, $3.length); }
601 | assignment end
e4967d85 602 | ASSERT_K '(' parse_exp ',' string ')'
494e05f4 603 { script_add_assertion(closure, $3, $5.value, $5.length); }
e5756efb
ILT
604 ;
605
1c4f3631
ILT
606/* A list of program header definitions. */
607phdrs_defs:
608 phdrs_defs phdr_def
609 | /* empty */
610 ;
611
612/* A program header definition. */
613phdr_def:
614 string phdr_type phdr_info ';'
615 { script_add_phdr(closure, $1.value, $1.length, $2, &$3); }
616 ;
617
618/* A program header type. The GNU linker accepts a general expression
619 here, but that would be a pain because we would have to dig into
620 the expression structure. It's unlikely that anybody uses anything
621 other than a string or a number here, so that is all we expect. */
622phdr_type:
623 string
624 { $$ = script_phdr_string_to_type(closure, $1.value, $1.length); }
625 | INTEGER
626 { $$ = $1; }
627 ;
628
629/* Additional information for a program header. */
630phdr_info:
631 /* empty */
632 { memset(&$$, 0, sizeof(struct Phdr_info)); }
633 | string phdr_info
634 {
635 $$ = $2;
636 if ($1.length == 7 && strncmp($1.value, "FILEHDR", 7) == 0)
637 $$.includes_filehdr = 1;
638 else
639 yyerror(closure, "PHDRS syntax error");
640 }
641 | PHDRS phdr_info
642 {
643 $$ = $2;
644 $$.includes_phdrs = 1;
645 }
646 | string '(' INTEGER ')' phdr_info
647 {
648 $$ = $5;
649 if ($1.length == 5 && strncmp($1.value, "FLAGS", 5) == 0)
650 {
651 $$.is_flags_valid = 1;
652 $$.flags = $3;
653 }
654 else
655 yyerror(closure, "PHDRS syntax error");
656 }
657 | AT '(' parse_exp ')' phdr_info
658 {
659 $$ = $5;
660 $$.load_address = $3;
661 }
662 ;
663
e5756efb
ILT
664/* Set a symbol to a value. */
665assignment:
10600224 666 string '=' parse_exp
e5756efb 667 { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
10600224 668 | string PLUSEQ parse_exp
e5756efb
ILT
669 {
670 Expression_ptr s = script_exp_string($1.value, $1.length);
671 Expression_ptr e = script_exp_binary_add(s, $3);
672 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
673 }
10600224 674 | string MINUSEQ parse_exp
e5756efb
ILT
675 {
676 Expression_ptr s = script_exp_string($1.value, $1.length);
677 Expression_ptr e = script_exp_binary_sub(s, $3);
678 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
679 }
10600224 680 | string MULTEQ parse_exp
e5756efb
ILT
681 {
682 Expression_ptr s = script_exp_string($1.value, $1.length);
683 Expression_ptr e = script_exp_binary_mult(s, $3);
684 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
685 }
10600224 686 | string DIVEQ parse_exp
e5756efb
ILT
687 {
688 Expression_ptr s = script_exp_string($1.value, $1.length);
689 Expression_ptr e = script_exp_binary_div(s, $3);
690 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
691 }
10600224 692 | string LSHIFTEQ parse_exp
e5756efb
ILT
693 {
694 Expression_ptr s = script_exp_string($1.value, $1.length);
695 Expression_ptr e = script_exp_binary_lshift(s, $3);
696 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
697 }
10600224 698 | string RSHIFTEQ parse_exp
e5756efb
ILT
699 {
700 Expression_ptr s = script_exp_string($1.value, $1.length);
701 Expression_ptr e = script_exp_binary_rshift(s, $3);
702 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
703 }
10600224 704 | string ANDEQ parse_exp
e5756efb
ILT
705 {
706 Expression_ptr s = script_exp_string($1.value, $1.length);
707 Expression_ptr e = script_exp_binary_bitwise_and(s, $3);
708 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
709 }
10600224 710 | string OREQ parse_exp
e5756efb
ILT
711 {
712 Expression_ptr s = script_exp_string($1.value, $1.length);
713 Expression_ptr e = script_exp_binary_bitwise_or(s, $3);
714 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
715 }
10600224 716 | PROVIDE '(' string '=' parse_exp ')'
e5756efb 717 { script_set_symbol(closure, $3.value, $3.length, $5, 1, 0); }
10600224 718 | PROVIDE_HIDDEN '(' string '=' parse_exp ')'
e5756efb
ILT
719 { script_set_symbol(closure, $3.value, $3.length, $5, 1, 1); }
720 ;
721
722/* Parse an expression, putting the lexer into the right mode. */
723parse_exp:
724 { script_push_lex_into_expression_mode(closure); }
725 exp
726 {
727 script_pop_lex_mode(closure);
728 $$ = $2;
729 }
730 ;
731
732/* An expression. */
733exp:
734 '(' exp ')'
735 { $$ = $2; }
736 | '-' exp %prec UNARY
737 { $$ = script_exp_unary_minus($2); }
738 | '!' exp %prec UNARY
739 { $$ = script_exp_unary_logical_not($2); }
740 | '~' exp %prec UNARY
741 { $$ = script_exp_unary_bitwise_not($2); }
742 | '+' exp %prec UNARY
743 { $$ = $2; }
744 | exp '*' exp
745 { $$ = script_exp_binary_mult($1, $3); }
746 | exp '/' exp
747 { $$ = script_exp_binary_div($1, $3); }
748 | exp '%' exp
749 { $$ = script_exp_binary_mod($1, $3); }
750 | exp '+' exp
751 { $$ = script_exp_binary_add($1, $3); }
752 | exp '-' exp
753 { $$ = script_exp_binary_sub($1, $3); }
754 | exp LSHIFT exp
755 { $$ = script_exp_binary_lshift($1, $3); }
756 | exp RSHIFT exp
757 { $$ = script_exp_binary_rshift($1, $3); }
758 | exp EQ exp
759 { $$ = script_exp_binary_eq($1, $3); }
760 | exp NE exp
761 { $$ = script_exp_binary_ne($1, $3); }
762 | exp LE exp
763 { $$ = script_exp_binary_le($1, $3); }
764 | exp GE exp
765 { $$ = script_exp_binary_ge($1, $3); }
766 | exp '<' exp
767 { $$ = script_exp_binary_lt($1, $3); }
768 | exp '>' exp
769 { $$ = script_exp_binary_gt($1, $3); }
770 | exp '&' exp
771 { $$ = script_exp_binary_bitwise_and($1, $3); }
772 | exp '^' exp
773 { $$ = script_exp_binary_bitwise_xor($1, $3); }
774 | exp '|' exp
775 { $$ = script_exp_binary_bitwise_or($1, $3); }
776 | exp ANDAND exp
777 { $$ = script_exp_binary_logical_and($1, $3); }
778 | exp OROR exp
779 { $$ = script_exp_binary_logical_or($1, $3); }
780 | exp '?' exp ':' exp
781 { $$ = script_exp_trinary_cond($1, $3, $5); }
782 | INTEGER
783 { $$ = script_exp_integer($1); }
e4967d85 784 | string
10600224 785 { $$ = script_exp_string($1.value, $1.length); }
e5756efb
ILT
786 | MAX_K '(' exp ',' exp ')'
787 { $$ = script_exp_function_max($3, $5); }
788 | MIN_K '(' exp ',' exp ')'
789 { $$ = script_exp_function_min($3, $5); }
10600224 790 | DEFINED '(' string ')'
e5756efb
ILT
791 { $$ = script_exp_function_defined($3.value, $3.length); }
792 | SIZEOF_HEADERS
793 { $$ = script_exp_function_sizeof_headers(); }
10600224 794 | ALIGNOF '(' string ')'
e5756efb 795 { $$ = script_exp_function_alignof($3.value, $3.length); }
10600224 796 | SIZEOF '(' string ')'
e5756efb 797 { $$ = script_exp_function_sizeof($3.value, $3.length); }
10600224 798 | ADDR '(' string ')'
e5756efb 799 { $$ = script_exp_function_addr($3.value, $3.length); }
10600224 800 | LOADADDR '(' string ')'
e5756efb 801 { $$ = script_exp_function_loadaddr($3.value, $3.length); }
10600224 802 | ORIGIN '(' string ')'
e5756efb 803 { $$ = script_exp_function_origin($3.value, $3.length); }
10600224 804 | LENGTH '(' string ')'
e5756efb 805 { $$ = script_exp_function_length($3.value, $3.length); }
10600224 806 | CONSTANT '(' string ')'
e5756efb
ILT
807 { $$ = script_exp_function_constant($3.value, $3.length); }
808 | ABSOLUTE '(' exp ')'
809 { $$ = script_exp_function_absolute($3); }
810 | ALIGN_K '(' exp ')'
811 { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
812 | ALIGN_K '(' exp ',' exp ')'
813 { $$ = script_exp_function_align($3, $5); }
814 | BLOCK '(' exp ')'
815 { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
816 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
2d924fd9
ILT
817 {
818 script_data_segment_align(closure);
819 $$ = script_exp_function_data_segment_align($3, $5);
820 }
e5756efb 821 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
2d924fd9
ILT
822 {
823 script_data_segment_relro_end(closure);
824 $$ = script_exp_function_data_segment_relro_end($3, $5);
825 }
e5756efb
ILT
826 | DATA_SEGMENT_END '(' exp ')'
827 { $$ = script_exp_function_data_segment_end($3); }
10600224 828 | SEGMENT_START '(' string ',' exp ')'
e5756efb
ILT
829 {
830 $$ = script_exp_function_segment_start($3.value, $3.length, $5);
831 }
10600224 832 | ASSERT_K '(' exp ',' string ')'
e5756efb
ILT
833 { $$ = script_exp_function_assert($3, $5.value, $5.length); }
834 ;
835
836/* Handle the --defsym option. */
837defsym_expr:
10600224 838 string '=' parse_exp
e5756efb
ILT
839 { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
840 ;
841
c82fbeee
CS
842/* Handle the --dynamic-list option. A dynamic list has the format
843 { sym1; sym2; extern "C++" { namespace::sym3 }; };
844 We store the symbol we see in the "local" list; that is where
845 Command_line::in_dynamic_list() will look to do its check.
846 TODO(csilvers): More than one of these brace-lists can appear, and
847 should just be merged and treated as a single list. */
848dynamic_list_expr: dynamic_list_nodes ;
849
850dynamic_list_nodes:
851 dynamic_list_node
852 | dynamic_list_nodes dynamic_list_node
853 ;
854
855dynamic_list_node:
856 '{' vers_defns ';' '}' ';'
857 { script_new_vers_node (closure, NULL, $2); }
858 ;
859
09124467 860/* A version script. */
e5756efb 861version_script:
09124467
ILT
862 vers_nodes
863 ;
864
865vers_nodes:
866 vers_node
867 | vers_nodes vers_node
868 ;
869
870vers_node:
871 '{' vers_tag '}' ';'
872 {
873 script_register_vers_node (closure, NULL, 0, $2, NULL);
874 }
10600224 875 | string '{' vers_tag '}' ';'
09124467
ILT
876 {
877 script_register_vers_node (closure, $1.value, $1.length, $3,
878 NULL);
879 }
10600224 880 | string '{' vers_tag '}' verdep ';'
09124467
ILT
881 {
882 script_register_vers_node (closure, $1.value, $1.length, $3, $5);
883 }
884 ;
885
886verdep:
10600224 887 string
09124467
ILT
888 {
889 $$ = script_add_vers_depend (closure, NULL, $1.value, $1.length);
890 }
10600224 891 | verdep string
09124467
ILT
892 {
893 $$ = script_add_vers_depend (closure, $1, $2.value, $2.length);
894 }
895 ;
896
897vers_tag:
898 /* empty */
899 { $$ = script_new_vers_node (closure, NULL, NULL); }
900 | vers_defns ';'
901 { $$ = script_new_vers_node (closure, $1, NULL); }
902 | GLOBAL ':' vers_defns ';'
903 { $$ = script_new_vers_node (closure, $3, NULL); }
904 | LOCAL ':' vers_defns ';'
905 { $$ = script_new_vers_node (closure, NULL, $3); }
906 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
907 { $$ = script_new_vers_node (closure, $3, $7); }
908 ;
909
10600224
ILT
910/* Here is one of the rare places we care about the distinction
911 between STRING and QUOTED_STRING. For QUOTED_STRING, we do exact
912 matching on the pattern, so we pass in true for the exact_match
913 parameter. For STRING, we do glob matching and pass in false. */
09124467
ILT
914vers_defns:
915 STRING
916 {
917 $$ = script_new_vers_pattern (closure, NULL, $1.value,
10600224
ILT
918 $1.length, 0);
919 }
920 | QUOTED_STRING
921 {
922 $$ = script_new_vers_pattern (closure, NULL, $1.value,
923 $1.length, 1);
09124467
ILT
924 }
925 | vers_defns ';' STRING
926 {
10600224
ILT
927 $$ = script_new_vers_pattern (closure, $1, $3.value,
928 $3.length, 0);
929 }
930 | vers_defns ';' QUOTED_STRING
931 {
932 $$ = script_new_vers_pattern (closure, $1, $3.value,
933 $3.length, 1);
09124467 934 }
10600224
ILT
935 | /* Push string on the language stack. */
936 EXTERN string '{'
937 { version_script_push_lang (closure, $2.value, $2.length); }
09124467
ILT
938 vers_defns opt_semicolon '}'
939 {
940 $$ = $5;
941 version_script_pop_lang(closure);
942 }
10600224
ILT
943 | /* Push string on the language stack. This is more complicated
944 than the other cases because we need to merge the linked-list
945 state from the pre-EXTERN defns and the post-EXTERN defns. */
946 vers_defns ';' EXTERN string '{'
947 { version_script_push_lang (closure, $4.value, $4.length); }
948 vers_defns opt_semicolon '}'
949 {
950 $$ = script_merge_expressions ($1, $7);
951 version_script_pop_lang(closure);
952 }
09124467
ILT
953 | EXTERN // "extern" as a symbol name
954 {
955 $$ = script_new_vers_pattern (closure, NULL, "extern",
10600224 956 sizeof("extern") - 1, 1);
09124467
ILT
957 }
958 | vers_defns ';' EXTERN
959 {
960 $$ = script_new_vers_pattern (closure, $1, "extern",
10600224 961 sizeof("extern") - 1, 1);
09124467 962 }
e5756efb
ILT
963 ;
964
10600224
ILT
965/* A string can be either a STRING or a QUOTED_STRING. Almost all the
966 time we don't care, and we use this rule. */
967string:
968 STRING
969 { $$ = $1; }
970 | QUOTED_STRING
971 { $$ = $1; }
972 ;
973
e5756efb
ILT
974/* Some statements require a terminator, which may be a semicolon or a
975 comma. */
976end:
977 ';'
978 | ','
d391083d
ILT
979 ;
980
09124467
ILT
981/* An optional semicolon. */
982opt_semicolon:
983 ';'
984 | /* empty */
985 ;
986
d391083d 987/* An optional comma. */
dbe717ef
ILT
988opt_comma:
989 ','
990 | /* empty */
991 ;
992
993%%
This page took 0.189494 seconds and 4 git commands to generate.