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