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