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