gas: avoid spurious failures in non-ELF targets in the SPARC testsuite.
[deliverable/binutils-gdb.git] / gold / yyscript.y
CommitLineData
bd52eafb 1/* yyscript.y -- linker script grammar for gold. */
dbe717ef 2
6f2750fe 3/* Copyright (C) 2006-2016 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;
1e5d2fb1 80 enum Script_section_type section_type;
dbe717ef
ILT
81}
82
83/* Operators, including a precedence table for expressions. */
84
85%right PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
86%right '?' ':'
87%left OROR
88%left ANDAND
89%left '|'
90%left '^'
91%left '&'
92%left EQ NE
93%left '<' '>' LE GE
94%left LSHIFT RSHIFT
95%left '+' '-'
96%left '*' '/' '%'
97
e5756efb
ILT
98/* A fake operator used to indicate unary operator precedence. */
99%right UNARY
100
dbe717ef
ILT
101/* Constants. */
102
103%token <string> STRING
10600224 104%token <string> QUOTED_STRING
dbe717ef
ILT
105%token <integer> INTEGER
106
107/* Keywords. This list is taken from ldgram.y and ldlex.l in the old
108 GNU linker, with the keywords which only appear in MRI mode
109 removed. Not all these keywords are actually used in this grammar.
110 In most cases the keyword is recognized as the token name in upper
111 case. The comments indicate where this is not the case. */
112
113%token ABSOLUTE
114%token ADDR
115%token ALIGN_K /* ALIGN */
e5756efb 116%token ALIGNOF
dbe717ef
ILT
117%token ASSERT_K /* ASSERT */
118%token AS_NEEDED
119%token AT
120%token BIND
121%token BLOCK
122%token BYTE
123%token CONSTANT
124%token CONSTRUCTORS
1e5d2fb1 125%token COPY
dbe717ef
ILT
126%token CREATE_OBJECT_SYMBOLS
127%token DATA_SEGMENT_ALIGN
128%token DATA_SEGMENT_END
129%token DATA_SEGMENT_RELRO_END
130%token DEFINED
1e5d2fb1 131%token DSECT
dbe717ef
ILT
132%token ENTRY
133%token EXCLUDE_FILE
134%token EXTERN
135%token FILL
136%token FLOAT
137%token FORCE_COMMON_ALLOCATION
138%token GLOBAL /* global */
139%token GROUP
140%token HLL
141%token INCLUDE
dbe717ef 142%token INHIBIT_COMMON_ALLOCATION
1e5d2fb1 143%token INFO
dbe717ef
ILT
144%token INPUT
145%token KEEP
7f8cd844 146%token LEN
dbe717ef
ILT
147%token LENGTH /* LENGTH, l, len */
148%token LOADADDR
149%token LOCAL /* local */
150%token LONG
151%token MAP
152%token MAX_K /* MAX */
153%token MEMORY
154%token MIN_K /* MIN */
155%token NEXT
156%token NOCROSSREFS
157%token NOFLOAT
1e5d2fb1 158%token NOLOAD
dbe717ef
ILT
159%token ONLY_IF_RO
160%token ONLY_IF_RW
7f8cd844 161%token ORG
dbe717ef
ILT
162%token ORIGIN /* ORIGIN, o, org */
163%token OUTPUT
164%token OUTPUT_ARCH
165%token OUTPUT_FORMAT
166%token OVERLAY
167%token PHDRS
168%token PROVIDE
169%token PROVIDE_HIDDEN
170%token QUAD
171%token SEARCH_DIR
172%token SECTIONS
173%token SEGMENT_START
174%token SHORT
175%token SIZEOF
176%token SIZEOF_HEADERS /* SIZEOF_HEADERS, sizeof_headers */
177%token SORT_BY_ALIGNMENT
f224a3c5 178%token SORT_BY_INIT_PRIORITY
dbe717ef
ILT
179%token SORT_BY_NAME
180%token SPECIAL
181%token SQUAD
182%token STARTUP
183%token SUBALIGN
184%token SYSLIB
185%token TARGET_K /* TARGET */
186%token TRUNCATE
187%token VERSIONK /* VERSION */
188
195e7dc6
ILT
189/* Keywords, part 2. These are keywords that are unique to gold,
190 and not present in the old GNU linker. As before, unless the
191 comments say otherwise, the keyword is recognized as the token
192 name in upper case. */
193
194%token OPTION
195
e5756efb
ILT
196/* Special tokens used to tell the grammar what type of tokens we are
197 parsing. The token stream always begins with one of these tokens.
198 We do this because version scripts can appear embedded within
199 linker scripts, and because --defsym uses the expression
200 parser. */
201%token PARSING_LINKER_SCRIPT
202%token PARSING_VERSION_SCRIPT
203%token PARSING_DEFSYM
c82fbeee 204%token PARSING_DYNAMIC_LIST
410da591
CC
205%token PARSING_SECTIONS_BLOCK
206%token PARSING_SECTION_COMMANDS
207%token PARSING_MEMORY_DEF
e5756efb
ILT
208
209/* Non-terminal types, where needed. */
210
1e5d2fb1 211%type <expr> parse_exp exp
494e05f4 212%type <expr> opt_at opt_align opt_subalign opt_fill
1e5d2fb1
DK
213%type <output_section_header> section_header opt_address_and_section_type
214%type <section_type> section_type
494e05f4 215%type <output_section_trailer> section_trailer
3802b2dd 216%type <constraint> opt_constraint
1c4f3631 217%type <string_list> opt_phdr
494e05f4
ILT
218%type <integer> data_length
219%type <input_section_spec> input_section_no_keep
220%type <wildcard_sections> wildcard_sections
221%type <wildcard_section> wildcard_file wildcard_section
222%type <string_list> exclude_names
223%type <string> wildcard_name
7f8cd844 224%type <integer> phdr_type memory_attr
1c4f3631 225%type <phdr_info> phdr_info
09124467
ILT
226%type <versyms> vers_defns
227%type <versnode> vers_tag
228%type <deplist> verdep
10600224 229%type <string> string
e5756efb 230
dbe717ef
ILT
231%%
232
e5756efb
ILT
233/* Read the special token to see what to read next. */
234top:
235 PARSING_LINKER_SCRIPT linker_script
236 | PARSING_VERSION_SCRIPT version_script
237 | PARSING_DEFSYM defsym_expr
c82fbeee 238 | PARSING_DYNAMIC_LIST dynamic_list_expr
410da591
CC
239 | PARSING_SECTIONS_BLOCK sections_block
240 | PARSING_SECTION_COMMANDS section_cmds
241 | PARSING_MEMORY_DEF memory_defs
e5756efb
ILT
242 ;
243
d391083d 244/* A file contains a list of commands. */
e5756efb
ILT
245linker_script:
246 linker_script file_cmd
dbe717ef
ILT
247 | /* empty */
248 ;
249
d391083d 250/* A command which may appear at top level of a linker script. */
dbe717ef 251file_cmd:
afc06bb8
ILT
252 EXTERN '(' extern_name_list ')'
253 | FORCE_COMMON_ALLOCATION
0dfbdef4
ILT
254 { script_set_common_allocation(closure, 1); }
255 | GROUP
dbe717ef
ILT
256 { script_start_group(closure); }
257 '(' input_list ')'
258 { script_end_group(closure); }
0dfbdef4
ILT
259 | INHIBIT_COMMON_ALLOCATION
260 { script_set_common_allocation(closure, 0); }
fbc558e1 261 | INPUT '(' input_list ')'
7f8cd844 262 | MEMORY '{' memory_defs '}'
10600224 263 | OPTION '(' string ')'
e5756efb 264 { script_parse_option(closure, $3.value, $3.length); }
15f8229b
ILT
265 | OUTPUT_FORMAT '(' string ')'
266 {
267 if (!script_check_output_format(closure, $3.value, $3.length,
268 NULL, 0, NULL, 0))
269 YYABORT;
270 }
271 | OUTPUT_FORMAT '(' string ',' string ',' string ')'
272 {
273 if (!script_check_output_format(closure, $3.value, $3.length,
274 $5.value, $5.length,
275 $7.value, $7.length))
276 YYABORT;
277 }
1c4f3631 278 | PHDRS '{' phdrs_defs '}'
3802b2dd
ILT
279 | SEARCH_DIR '(' string ')'
280 { script_add_search_dir(closure, $3.value, $3.length); }
494e05f4
ILT
281 | SECTIONS '{'
282 { script_start_sections(closure); }
283 sections_block '}'
284 { script_finish_sections(closure); }
e6a307ba
ILT
285 | TARGET_K '(' string ')'
286 { script_set_target(closure, $3.value, $3.length); }
09124467
ILT
287 | VERSIONK '{'
288 { script_push_lex_into_version_mode(closure); }
289 version_script '}'
290 { script_pop_lex_mode(closure); }
410da591
CC
291 | ENTRY '(' string ')'
292 { script_set_entry(closure, $3.value, $3.length); }
293 | assignment end
294 | ASSERT_K '(' parse_exp ',' string ')'
295 { script_add_assertion(closure, $3, $5.value, $5.length); }
296 | INCLUDE string
297 { script_include_directive(PARSING_LINKER_SCRIPT, closure,
298 $2.value, $2.length); }
2dd3e587 299 | ignore_cmd
3802b2dd 300 | ';'
2dd3e587
ILT
301 ;
302
303/* Top level commands which we ignore. The GNU linker uses these to
304 select the output format, but we don't offer a choice. Ignoring
305 these is more-or-less OK since most scripts simply explicitly
306 choose the default. */
307ignore_cmd:
15f8229b 308 OUTPUT_ARCH '(' string ')'
dbe717ef
ILT
309 ;
310
afc06bb8
ILT
311/* A list of external undefined symbols. We put the lexer into
312 expression mode so that commas separate names; this is what the GNU
313 linker does. */
314
315extern_name_list:
316 { script_push_lex_into_expression_mode(closure); }
317 extern_name_list_body
318 { script_pop_lex_mode(closure); }
319 ;
320
321extern_name_list_body:
322 string
323 { script_add_extern(closure, $1.value, $1.length); }
324 | extern_name_list_body string
325 { script_add_extern(closure, $2.value, $2.length); }
326 | extern_name_list_body ',' string
327 { script_add_extern(closure, $3.value, $3.length); }
328 ;
329
d391083d 330/* A list of input file names. */
dbe717ef
ILT
331input_list:
332 input_list_element
333 | input_list opt_comma input_list_element
334 ;
335
d391083d 336/* An input file name. */
dbe717ef 337input_list_element:
10600224 338 string
e5756efb 339 { script_add_file(closure, $1.value, $1.length); }
e1df38aa
NC
340 | '-' STRING
341 { script_add_library(closure, $2.value, $2.length); }
dbe717ef
ILT
342 | AS_NEEDED
343 { script_start_as_needed(closure); }
344 '(' input_list ')'
345 { script_end_as_needed(closure); }
346 ;
347
494e05f4
ILT
348/* Commands in a SECTIONS block. */
349sections_block:
350 sections_block section_block_cmd
351 | /* empty */
352 ;
353
354/* A command which may appear within a SECTIONS block. */
355section_block_cmd:
410da591
CC
356 ENTRY '(' string ')'
357 { script_set_entry(closure, $3.value, $3.length); }
358 | assignment end
359 | ASSERT_K '(' parse_exp ',' string ')'
360 { script_add_assertion(closure, $3, $5.value, $5.length); }
361 | INCLUDE string
362 { script_include_directive(PARSING_SECTIONS_BLOCK, closure,
363 $2.value, $2.length); }
e4967d85 364 | string section_header
494e05f4
ILT
365 { script_start_output_section(closure, $1.value, $1.length, &$2); }
366 '{' section_cmds '}' section_trailer
367 { script_finish_output_section(closure, &$7); }
368 ;
369
370/* The header of an output section in a SECTIONS block--everything
371 after the name. */
372section_header:
373 { script_push_lex_into_expression_mode(closure); }
374 opt_address_and_section_type opt_at opt_align opt_subalign
3802b2dd
ILT
375 { script_pop_lex_mode(closure); }
376 opt_constraint
494e05f4 377 {
1e5d2fb1
DK
378 $$.address = $2.address;
379 $$.section_type = $2.section_type;
494e05f4
ILT
380 $$.load_address = $3;
381 $$.align = $4;
382 $$.subalign = $5;
3802b2dd 383 $$.constraint = $7;
494e05f4
ILT
384 }
385 ;
386
387/* The optional address followed by the optional section type. This
388 is a separate nonterminal to avoid a shift/reduce conflict on
389 '(' in section_header. */
390
391opt_address_and_section_type:
1e5d2fb1
DK
392 ':'
393 {
394 $$.address = NULL;
395 $$.section_type = SCRIPT_SECTION_TYPE_NONE;
396 }
494e05f4 397 | '(' ')' ':'
1e5d2fb1
DK
398 {
399 $$.address = NULL;
400 $$.section_type = SCRIPT_SECTION_TYPE_NONE;
401 }
494e05f4 402 | exp ':'
1e5d2fb1
DK
403 {
404 $$.address = $1;
405 $$.section_type = SCRIPT_SECTION_TYPE_NONE;
406 }
494e05f4 407 | exp '(' ')' ':'
494e05f4 408 {
1e5d2fb1
DK
409 $$.address = $1;
410 $$.section_type = SCRIPT_SECTION_TYPE_NONE;
411 }
412 | '(' section_type ')' ':'
413 {
414 $$.address = NULL;
415 $$.section_type = $2;
416 }
417 | exp '(' section_type ')' ':'
418 {
419 $$.address = $1;
420 $$.section_type = $3;
421 }
422 ;
423
424/* We only support NOLOAD. */
425section_type:
426 NOLOAD
427 { $$ = SCRIPT_SECTION_TYPE_NOLOAD; }
428 | DSECT
429 {
430 yyerror(closure, "DSECT section type is unsupported");
431 $$ = SCRIPT_SECTION_TYPE_DSECT;
432 }
433 | COPY
434 {
435 yyerror(closure, "COPY section type is unsupported");
436 $$ = SCRIPT_SECTION_TYPE_COPY;
437 }
438 | INFO
439 {
440 yyerror(closure, "INFO section type is unsupported");
441 $$ = SCRIPT_SECTION_TYPE_INFO;
442 }
443 | OVERLAY
444 {
445 yyerror(closure, "OVERLAY section type is unsupported");
446 $$ = SCRIPT_SECTION_TYPE_OVERLAY;
494e05f4
ILT
447 }
448 ;
449
450/* The address at which an output section should be loaded. */
451opt_at:
452 /* empty */
453 { $$ = NULL; }
454 | AT '(' exp ')'
455 { $$ = $3; }
456 ;
457
458/* The alignment of an output section. */
459opt_align:
460 /* empty */
461 { $$ = NULL; }
462 | ALIGN_K '(' exp ')'
463 { $$ = $3; }
464 ;
465
466/* The input section alignment within an output section. */
467opt_subalign:
468 /* empty */
469 { $$ = NULL; }
470 | SUBALIGN '(' exp ')'
471 { $$ = $3; }
472 ;
473
3802b2dd
ILT
474/* A section constraint. */
475opt_constraint:
476 /* empty */
477 { $$ = CONSTRAINT_NONE; }
478 | ONLY_IF_RO
479 { $$ = CONSTRAINT_ONLY_IF_RO; }
480 | ONLY_IF_RW
481 { $$ = CONSTRAINT_ONLY_IF_RW; }
482 | SPECIAL
483 { $$ = CONSTRAINT_SPECIAL; }
484 ;
485
494e05f4
ILT
486/* The trailer of an output section in a SECTIONS block. */
487section_trailer:
494e05f4
ILT
488 opt_memspec opt_at_memspec opt_phdr opt_fill opt_comma
489 {
3802b2dd 490 $$.fill = $4;
1c4f3631 491 $$.phdrs = $3;
494e05f4
ILT
492 }
493 ;
494
495/* A memory specification for an output section. */
496opt_memspec:
e4967d85 497 '>' string
7f8cd844 498 { script_set_section_region(closure, $2.value, $2.length, 1); }
494e05f4
ILT
499 | /* empty */
500 ;
501
502/* A memory specification for where to load an output section. */
503opt_at_memspec:
e4967d85 504 AT '>' string
7f8cd844 505 { script_set_section_region(closure, $3.value, $3.length, 0); }
494e05f4
ILT
506 | /* empty */
507 ;
508
509/* The program segment an output section should go into. */
510opt_phdr:
e4967d85 511 opt_phdr ':' string
1c4f3631 512 { $$ = script_string_list_push_back($1, $3.value, $3.length); }
494e05f4 513 | /* empty */
1c4f3631 514 { $$ = NULL; }
494e05f4
ILT
515 ;
516
a445fddf
ILT
517/* The value to use to fill an output section. FIXME: This does not
518 handle a string of arbitrary length. */
494e05f4 519opt_fill:
3802b2dd 520 '=' parse_exp
494e05f4
ILT
521 { $$ = $2; }
522 | /* empty */
523 { $$ = NULL; }
524 ;
525
526/* Commands which may appear within the description of an output
527 section in a SECTIONS block. */
528section_cmds:
529 /* empty */
530 | section_cmds section_cmd
531 ;
532
533/* A command which may appear within the description of an output
534 section in a SECTIONS block. */
535section_cmd:
536 assignment end
537 | input_section_spec
538 | data_length '(' parse_exp ')'
539 { script_add_data(closure, $1, $3); }
e4967d85 540 | ASSERT_K '(' parse_exp ',' string ')'
494e05f4
ILT
541 { script_add_assertion(closure, $3, $5.value, $5.length); }
542 | FILL '(' parse_exp ')'
543 { script_add_fill(closure, $3); }
544 | CONSTRUCTORS
545 {
546 /* The GNU linker uses CONSTRUCTORS for the a.out object
547 file format. It does nothing when using ELF. Since
548 some ELF linker scripts use it although it does
549 nothing, we accept it and ignore it. */
550 }
3802b2dd 551 | SORT_BY_NAME '(' CONSTRUCTORS ')'
98ef3ea4 552 | INCLUDE string
410da591
CC
553 { script_include_directive(PARSING_SECTION_COMMANDS, closure,
554 $2.value, $2.length); }
494e05f4
ILT
555 | ';'
556 ;
557
558/* The length of data which may appear within the description of an
559 output section in a SECTIONS block. */
560data_length:
561 QUAD
562 { $$ = QUAD; }
563 | SQUAD
564 { $$ = SQUAD; }
565 | LONG
566 { $$ = LONG; }
567 | SHORT
568 { $$ = SHORT; }
569 | BYTE
570 { $$ = BYTE; }
571 ;
572
573/* An input section specification. This may appear within the
574 description of an output section in a SECTIONS block. */
575input_section_spec:
576 input_section_no_keep
577 { script_add_input_section(closure, &$1, 0); }
578 | KEEP '(' input_section_no_keep ')'
579 { script_add_input_section(closure, &$3, 1); }
580 ;
581
582/* An input section specification within a KEEP clause. */
583input_section_no_keep:
e4967d85 584 string
494e05f4
ILT
585 {
586 $$.file.name = $1;
587 $$.file.sort = SORT_WILDCARD_NONE;
588 $$.input_sections.sections = NULL;
589 $$.input_sections.exclude = NULL;
590 }
591 | wildcard_file '(' wildcard_sections ')'
592 {
593 $$.file = $1;
594 $$.input_sections = $3;
595 }
596 ;
597
598/* A wildcard file specification. */
599wildcard_file:
600 wildcard_name
601 {
602 $$.name = $1;
603 $$.sort = SORT_WILDCARD_NONE;
604 }
605 | SORT_BY_NAME '(' wildcard_name ')'
606 {
607 $$.name = $3;
608 $$.sort = SORT_WILDCARD_BY_NAME;
609 }
610 ;
611
612/* A list of wild card section specifications. */
613wildcard_sections:
614 wildcard_sections opt_comma wildcard_section
615 {
616 $$.sections = script_string_sort_list_add($1.sections, &$3);
617 $$.exclude = $1.exclude;
618 }
619 | wildcard_section
620 {
621 $$.sections = script_new_string_sort_list(&$1);
622 $$.exclude = NULL;
623 }
624 | wildcard_sections opt_comma EXCLUDE_FILE '(' exclude_names ')'
625 {
626 $$.sections = $1.sections;
627 $$.exclude = script_string_list_append($1.exclude, $5);
628 }
629 | EXCLUDE_FILE '(' exclude_names ')'
630 {
631 $$.sections = NULL;
632 $$.exclude = $3;
633 }
634 ;
635
636/* A single wild card specification. */
637wildcard_section:
638 wildcard_name
639 {
640 $$.name = $1;
641 $$.sort = SORT_WILDCARD_NONE;
642 }
643 | SORT_BY_NAME '(' wildcard_section ')'
644 {
645 $$.name = $3.name;
646 switch ($3.sort)
647 {
648 case SORT_WILDCARD_NONE:
649 $$.sort = SORT_WILDCARD_BY_NAME;
650 break;
651 case SORT_WILDCARD_BY_NAME:
652 case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
653 break;
654 case SORT_WILDCARD_BY_ALIGNMENT:
655 case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
656 $$.sort = SORT_WILDCARD_BY_NAME_BY_ALIGNMENT;
657 break;
658 default:
659 abort();
660 }
661 }
662 | SORT_BY_ALIGNMENT '(' wildcard_section ')'
663 {
664 $$.name = $3.name;
665 switch ($3.sort)
666 {
667 case SORT_WILDCARD_NONE:
668 $$.sort = SORT_WILDCARD_BY_ALIGNMENT;
669 break;
670 case SORT_WILDCARD_BY_ALIGNMENT:
671 case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
672 break;
673 case SORT_WILDCARD_BY_NAME:
674 case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
675 $$.sort = SORT_WILDCARD_BY_ALIGNMENT_BY_NAME;
676 break;
677 default:
678 abort();
679 }
680 }
f224a3c5
IK
681 | SORT_BY_INIT_PRIORITY '(' wildcard_name ')'
682 {
683 $$.name = $3;
684 $$.sort = SORT_WILDCARD_BY_INIT_PRIORITY;
685 }
494e05f4
ILT
686 ;
687
688/* A list of file names to exclude. */
689exclude_names:
690 exclude_names opt_comma wildcard_name
691 { $$ = script_string_list_push_back($1, $3.value, $3.length); }
692 | wildcard_name
693 { $$ = script_new_string_list($1.value, $1.length); }
694 ;
695
696/* A single wildcard name. We recognize '*' and '?' specially since
697 they are expression tokens. */
698wildcard_name:
e4967d85 699 string
494e05f4
ILT
700 { $$ = $1; }
701 | '*'
702 {
703 $$.value = "*";
704 $$.length = 1;
705 }
706 | '?'
707 {
708 $$.value = "?";
709 $$.length = 1;
710 }
711 ;
712
7f8cd844
NC
713/* A list of MEMORY definitions. */
714memory_defs:
715 memory_defs opt_comma memory_def
716 | /* empty */
717 ;
718
719/* A single MEMORY definition. */
720memory_def:
721 string memory_attr ':' memory_origin '=' parse_exp opt_comma memory_length '=' parse_exp
722 { script_add_memory(closure, $1.value, $1.length, $2, $6, $10); }
723 |
7f8cd844 724 INCLUDE string
410da591
CC
725 { script_include_directive(PARSING_MEMORY_DEF, closure,
726 $2.value, $2.length); }
7f8cd844
NC
727 |
728 ;
729
730/* The (optional) attributes of a MEMORY region. */
731memory_attr:
732 '(' string ')'
733 { $$ = script_parse_memory_attr(closure, $2.value, $2.length, 0); }
734 | /* Inverted attributes. */
735 '(' '!' string ')'
736 { $$ = script_parse_memory_attr(closure, $3.value, $3.length, 1); }
737 | /* empty */
738 { $$ = 0; }
739 ;
740
741memory_origin:
742 ORIGIN
743 |
744 ORG
745 |
746 'o'
747 ;
748
749memory_length:
750 LENGTH
751 |
752 LEN
753 |
754 'l'
755 ;
756
1c4f3631
ILT
757/* A list of program header definitions. */
758phdrs_defs:
759 phdrs_defs phdr_def
760 | /* empty */
761 ;
762
763/* A program header definition. */
764phdr_def:
765 string phdr_type phdr_info ';'
766 { script_add_phdr(closure, $1.value, $1.length, $2, &$3); }
767 ;
768
769/* A program header type. The GNU linker accepts a general expression
770 here, but that would be a pain because we would have to dig into
771 the expression structure. It's unlikely that anybody uses anything
772 other than a string or a number here, so that is all we expect. */
773phdr_type:
774 string
775 { $$ = script_phdr_string_to_type(closure, $1.value, $1.length); }
776 | INTEGER
777 { $$ = $1; }
778 ;
779
780/* Additional information for a program header. */
781phdr_info:
782 /* empty */
783 { memset(&$$, 0, sizeof(struct Phdr_info)); }
784 | string phdr_info
785 {
786 $$ = $2;
787 if ($1.length == 7 && strncmp($1.value, "FILEHDR", 7) == 0)
788 $$.includes_filehdr = 1;
789 else
790 yyerror(closure, "PHDRS syntax error");
791 }
792 | PHDRS phdr_info
793 {
794 $$ = $2;
795 $$.includes_phdrs = 1;
796 }
797 | string '(' INTEGER ')' phdr_info
798 {
799 $$ = $5;
800 if ($1.length == 5 && strncmp($1.value, "FLAGS", 5) == 0)
801 {
802 $$.is_flags_valid = 1;
803 $$.flags = $3;
804 }
805 else
806 yyerror(closure, "PHDRS syntax error");
807 }
808 | AT '(' parse_exp ')' phdr_info
809 {
810 $$ = $5;
811 $$.load_address = $3;
812 }
813 ;
814
e5756efb
ILT
815/* Set a symbol to a value. */
816assignment:
10600224 817 string '=' parse_exp
e5756efb 818 { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
10600224 819 | string PLUSEQ parse_exp
e5756efb
ILT
820 {
821 Expression_ptr s = script_exp_string($1.value, $1.length);
822 Expression_ptr e = script_exp_binary_add(s, $3);
823 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
824 }
10600224 825 | string MINUSEQ parse_exp
e5756efb
ILT
826 {
827 Expression_ptr s = script_exp_string($1.value, $1.length);
828 Expression_ptr e = script_exp_binary_sub(s, $3);
829 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
830 }
10600224 831 | string MULTEQ parse_exp
e5756efb
ILT
832 {
833 Expression_ptr s = script_exp_string($1.value, $1.length);
834 Expression_ptr e = script_exp_binary_mult(s, $3);
835 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
836 }
10600224 837 | string DIVEQ parse_exp
e5756efb
ILT
838 {
839 Expression_ptr s = script_exp_string($1.value, $1.length);
840 Expression_ptr e = script_exp_binary_div(s, $3);
841 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
842 }
10600224 843 | string LSHIFTEQ parse_exp
e5756efb
ILT
844 {
845 Expression_ptr s = script_exp_string($1.value, $1.length);
846 Expression_ptr e = script_exp_binary_lshift(s, $3);
847 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
848 }
10600224 849 | string RSHIFTEQ parse_exp
e5756efb
ILT
850 {
851 Expression_ptr s = script_exp_string($1.value, $1.length);
852 Expression_ptr e = script_exp_binary_rshift(s, $3);
853 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
854 }
10600224 855 | string ANDEQ parse_exp
e5756efb
ILT
856 {
857 Expression_ptr s = script_exp_string($1.value, $1.length);
858 Expression_ptr e = script_exp_binary_bitwise_and(s, $3);
859 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
860 }
10600224 861 | string OREQ parse_exp
e5756efb
ILT
862 {
863 Expression_ptr s = script_exp_string($1.value, $1.length);
864 Expression_ptr e = script_exp_binary_bitwise_or(s, $3);
865 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
866 }
10600224 867 | PROVIDE '(' string '=' parse_exp ')'
e5756efb 868 { script_set_symbol(closure, $3.value, $3.length, $5, 1, 0); }
10600224 869 | PROVIDE_HIDDEN '(' string '=' parse_exp ')'
e5756efb
ILT
870 { script_set_symbol(closure, $3.value, $3.length, $5, 1, 1); }
871 ;
872
873/* Parse an expression, putting the lexer into the right mode. */
874parse_exp:
875 { script_push_lex_into_expression_mode(closure); }
876 exp
877 {
878 script_pop_lex_mode(closure);
879 $$ = $2;
880 }
881 ;
882
883/* An expression. */
884exp:
885 '(' exp ')'
886 { $$ = $2; }
887 | '-' exp %prec UNARY
888 { $$ = script_exp_unary_minus($2); }
889 | '!' exp %prec UNARY
890 { $$ = script_exp_unary_logical_not($2); }
891 | '~' exp %prec UNARY
892 { $$ = script_exp_unary_bitwise_not($2); }
893 | '+' exp %prec UNARY
894 { $$ = $2; }
895 | exp '*' exp
896 { $$ = script_exp_binary_mult($1, $3); }
897 | exp '/' exp
898 { $$ = script_exp_binary_div($1, $3); }
899 | exp '%' exp
900 { $$ = script_exp_binary_mod($1, $3); }
901 | exp '+' exp
902 { $$ = script_exp_binary_add($1, $3); }
903 | exp '-' exp
904 { $$ = script_exp_binary_sub($1, $3); }
905 | exp LSHIFT exp
906 { $$ = script_exp_binary_lshift($1, $3); }
907 | exp RSHIFT exp
908 { $$ = script_exp_binary_rshift($1, $3); }
909 | exp EQ exp
910 { $$ = script_exp_binary_eq($1, $3); }
911 | exp NE exp
912 { $$ = script_exp_binary_ne($1, $3); }
913 | exp LE exp
914 { $$ = script_exp_binary_le($1, $3); }
915 | exp GE exp
916 { $$ = script_exp_binary_ge($1, $3); }
917 | exp '<' exp
918 { $$ = script_exp_binary_lt($1, $3); }
919 | exp '>' exp
920 { $$ = script_exp_binary_gt($1, $3); }
921 | exp '&' exp
922 { $$ = script_exp_binary_bitwise_and($1, $3); }
923 | exp '^' exp
924 { $$ = script_exp_binary_bitwise_xor($1, $3); }
925 | exp '|' exp
926 { $$ = script_exp_binary_bitwise_or($1, $3); }
927 | exp ANDAND exp
928 { $$ = script_exp_binary_logical_and($1, $3); }
929 | exp OROR exp
930 { $$ = script_exp_binary_logical_or($1, $3); }
931 | exp '?' exp ':' exp
932 { $$ = script_exp_trinary_cond($1, $3, $5); }
933 | INTEGER
934 { $$ = script_exp_integer($1); }
e4967d85 935 | string
88a4108b 936 { $$ = script_symbol(closure, $1.value, $1.length); }
e5756efb
ILT
937 | MAX_K '(' exp ',' exp ')'
938 { $$ = script_exp_function_max($3, $5); }
939 | MIN_K '(' exp ',' exp ')'
940 { $$ = script_exp_function_min($3, $5); }
10600224 941 | DEFINED '(' string ')'
e5756efb
ILT
942 { $$ = script_exp_function_defined($3.value, $3.length); }
943 | SIZEOF_HEADERS
944 { $$ = script_exp_function_sizeof_headers(); }
10600224 945 | ALIGNOF '(' string ')'
e5756efb 946 { $$ = script_exp_function_alignof($3.value, $3.length); }
10600224 947 | SIZEOF '(' string ')'
e5756efb 948 { $$ = script_exp_function_sizeof($3.value, $3.length); }
10600224 949 | ADDR '(' string ')'
e5756efb 950 { $$ = script_exp_function_addr($3.value, $3.length); }
10600224 951 | LOADADDR '(' string ')'
e5756efb 952 { $$ = script_exp_function_loadaddr($3.value, $3.length); }
10600224 953 | ORIGIN '(' string ')'
7f8cd844 954 { $$ = script_exp_function_origin(closure, $3.value, $3.length); }
10600224 955 | LENGTH '(' string ')'
7f8cd844 956 { $$ = script_exp_function_length(closure, $3.value, $3.length); }
10600224 957 | CONSTANT '(' string ')'
e5756efb
ILT
958 { $$ = script_exp_function_constant($3.value, $3.length); }
959 | ABSOLUTE '(' exp ')'
960 { $$ = script_exp_function_absolute($3); }
961 | ALIGN_K '(' exp ')'
962 { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
963 | ALIGN_K '(' exp ',' exp ')'
964 { $$ = script_exp_function_align($3, $5); }
965 | BLOCK '(' exp ')'
966 { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
967 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
2d924fd9
ILT
968 {
969 script_data_segment_align(closure);
970 $$ = script_exp_function_data_segment_align($3, $5);
971 }
e5756efb 972 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
2d924fd9
ILT
973 {
974 script_data_segment_relro_end(closure);
975 $$ = script_exp_function_data_segment_relro_end($3, $5);
976 }
e5756efb
ILT
977 | DATA_SEGMENT_END '(' exp ')'
978 { $$ = script_exp_function_data_segment_end($3); }
10600224 979 | SEGMENT_START '(' string ',' exp ')'
e5756efb
ILT
980 {
981 $$ = script_exp_function_segment_start($3.value, $3.length, $5);
3c12dcdb
DK
982 /* We need to take note of any SEGMENT_START expressions
983 because they change the behaviour of -Ttext, -Tdata and
984 -Tbss options. */
985 script_saw_segment_start_expression(closure);
e5756efb 986 }
10600224 987 | ASSERT_K '(' exp ',' string ')'
e5756efb
ILT
988 { $$ = script_exp_function_assert($3, $5.value, $5.length); }
989 ;
990
991/* Handle the --defsym option. */
992defsym_expr:
10600224 993 string '=' parse_exp
e5756efb
ILT
994 { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
995 ;
996
c82fbeee
CS
997/* Handle the --dynamic-list option. A dynamic list has the format
998 { sym1; sym2; extern "C++" { namespace::sym3 }; };
999 We store the symbol we see in the "local" list; that is where
1000 Command_line::in_dynamic_list() will look to do its check.
1001 TODO(csilvers): More than one of these brace-lists can appear, and
1002 should just be merged and treated as a single list. */
1003dynamic_list_expr: dynamic_list_nodes ;
1004
1005dynamic_list_nodes:
1006 dynamic_list_node
1007 | dynamic_list_nodes dynamic_list_node
1008 ;
1009
1010dynamic_list_node:
1011 '{' vers_defns ';' '}' ';'
1012 { script_new_vers_node (closure, NULL, $2); }
1013 ;
1014
09124467 1015/* A version script. */
e5756efb 1016version_script:
09124467
ILT
1017 vers_nodes
1018 ;
1019
1020vers_nodes:
1021 vers_node
1022 | vers_nodes vers_node
1023 ;
1024
1025vers_node:
1026 '{' vers_tag '}' ';'
1027 {
1028 script_register_vers_node (closure, NULL, 0, $2, NULL);
1029 }
10600224 1030 | string '{' vers_tag '}' ';'
09124467
ILT
1031 {
1032 script_register_vers_node (closure, $1.value, $1.length, $3,
1033 NULL);
1034 }
10600224 1035 | string '{' vers_tag '}' verdep ';'
09124467
ILT
1036 {
1037 script_register_vers_node (closure, $1.value, $1.length, $3, $5);
1038 }
1039 ;
1040
1041verdep:
10600224 1042 string
09124467
ILT
1043 {
1044 $$ = script_add_vers_depend (closure, NULL, $1.value, $1.length);
1045 }
10600224 1046 | verdep string
09124467
ILT
1047 {
1048 $$ = script_add_vers_depend (closure, $1, $2.value, $2.length);
1049 }
1050 ;
1051
1052vers_tag:
1053 /* empty */
1054 { $$ = script_new_vers_node (closure, NULL, NULL); }
1055 | vers_defns ';'
1056 { $$ = script_new_vers_node (closure, $1, NULL); }
1057 | GLOBAL ':' vers_defns ';'
1058 { $$ = script_new_vers_node (closure, $3, NULL); }
1059 | LOCAL ':' vers_defns ';'
1060 { $$ = script_new_vers_node (closure, NULL, $3); }
1061 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1062 { $$ = script_new_vers_node (closure, $3, $7); }
1063 ;
1064
10600224
ILT
1065/* Here is one of the rare places we care about the distinction
1066 between STRING and QUOTED_STRING. For QUOTED_STRING, we do exact
1067 matching on the pattern, so we pass in true for the exact_match
1068 parameter. For STRING, we do glob matching and pass in false. */
09124467
ILT
1069vers_defns:
1070 STRING
1071 {
1072 $$ = script_new_vers_pattern (closure, NULL, $1.value,
10600224
ILT
1073 $1.length, 0);
1074 }
1075 | QUOTED_STRING
1076 {
1077 $$ = script_new_vers_pattern (closure, NULL, $1.value,
1078 $1.length, 1);
09124467
ILT
1079 }
1080 | vers_defns ';' STRING
1081 {
10600224
ILT
1082 $$ = script_new_vers_pattern (closure, $1, $3.value,
1083 $3.length, 0);
1084 }
1085 | vers_defns ';' QUOTED_STRING
1086 {
1087 $$ = script_new_vers_pattern (closure, $1, $3.value,
1088 $3.length, 1);
09124467 1089 }
10600224
ILT
1090 | /* Push string on the language stack. */
1091 EXTERN string '{'
1092 { version_script_push_lang (closure, $2.value, $2.length); }
09124467
ILT
1093 vers_defns opt_semicolon '}'
1094 {
1095 $$ = $5;
1096 version_script_pop_lang(closure);
1097 }
10600224
ILT
1098 | /* Push string on the language stack. This is more complicated
1099 than the other cases because we need to merge the linked-list
1100 state from the pre-EXTERN defns and the post-EXTERN defns. */
1101 vers_defns ';' EXTERN string '{'
1102 { version_script_push_lang (closure, $4.value, $4.length); }
1103 vers_defns opt_semicolon '}'
1104 {
1105 $$ = script_merge_expressions ($1, $7);
1106 version_script_pop_lang(closure);
1107 }
09124467
ILT
1108 | EXTERN // "extern" as a symbol name
1109 {
1110 $$ = script_new_vers_pattern (closure, NULL, "extern",
10600224 1111 sizeof("extern") - 1, 1);
09124467
ILT
1112 }
1113 | vers_defns ';' EXTERN
1114 {
1115 $$ = script_new_vers_pattern (closure, $1, "extern",
10600224 1116 sizeof("extern") - 1, 1);
09124467 1117 }
e5756efb
ILT
1118 ;
1119
10600224
ILT
1120/* A string can be either a STRING or a QUOTED_STRING. Almost all the
1121 time we don't care, and we use this rule. */
1122string:
1123 STRING
1124 { $$ = $1; }
1125 | QUOTED_STRING
1126 { $$ = $1; }
1127 ;
1128
e5756efb
ILT
1129/* Some statements require a terminator, which may be a semicolon or a
1130 comma. */
1131end:
1132 ';'
1133 | ','
d391083d
ILT
1134 ;
1135
09124467
ILT
1136/* An optional semicolon. */
1137opt_semicolon:
1138 ';'
1139 | /* empty */
1140 ;
1141
d391083d 1142/* An optional comma. */
dbe717ef
ILT
1143opt_comma:
1144 ','
1145 | /* empty */
1146 ;
1147
1148%%
This page took 0.540966 seconds and 4 git commands to generate.