]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gold/yyscript.y
Update stored rendition of varobj value when format changes.
[thirdparty/binutils-gdb.git] / gold / yyscript.y
CommitLineData
dbe717ef
ILT
1/* yyscript.y -- linker script grammer for gold. */
2
e5756efb 3/* Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
6cb15b7f
ILT
4 Written by Ian Lance Taylor <iant@google.com>.
5
6 This file is part of gold.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
22
dbe717ef
ILT
23/* This is a bison grammar to parse a subset of the original GNU ld
24 linker script language. */
25
26%{
27
28#include "config.h"
29
30#include <stddef.h>
31#include <stdint.h>
494e05f4 32#include <stdlib.h>
dbe717ef
ILT
33
34#include "script-c.h"
35
36%}
37
38/* We need to use a pure parser because we might be multi-threaded.
39 We pass some arguments through the parser to the lexer. */
40
41%pure-parser
42
43%parse-param {void* closure}
44%lex-param {void* closure}
45
46/* Since we require bison anyhow, we take advantage of it. */
47
48%error-verbose
49
50/* The values associated with tokens. */
51
52%union {
e5756efb
ILT
53 /* A string. */
54 struct Parser_string string;
55 /* A number. */
56 uint64_t integer;
57 /* An expression. */
58 Expression_ptr expr;
494e05f4
ILT
59 /* An output section header. */
60 struct Parser_output_section_header output_section_header;
61 /* An output section trailer. */
62 struct Parser_output_section_trailer output_section_trailer;
63 /* A complete input section specification. */
64 struct Input_section_spec input_section_spec;
65 /* A list of wildcard specifications, with exclusions. */
66 struct Wildcard_sections wildcard_sections;
67 /* A single wildcard specification. */
68 struct Wildcard_section wildcard_section;
69 /* A list of strings. */
70 String_list_ptr string_list;
71 /* Used for version scripts and within VERSION {}. */
09124467
ILT
72 struct Version_dependency_list* deplist;
73 struct Version_expression_list* versyms;
74 struct Version_tree* versnode;
dbe717ef
ILT
75}
76
77/* Operators, including a precedence table for expressions. */
78
79%right PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
80%right '?' ':'
81%left OROR
82%left ANDAND
83%left '|'
84%left '^'
85%left '&'
86%left EQ NE
87%left '<' '>' LE GE
88%left LSHIFT RSHIFT
89%left '+' '-'
90%left '*' '/' '%'
91
e5756efb
ILT
92/* A fake operator used to indicate unary operator precedence. */
93%right UNARY
94
dbe717ef
ILT
95/* Constants. */
96
97%token <string> STRING
10600224 98%token <string> QUOTED_STRING
dbe717ef
ILT
99%token <integer> INTEGER
100
101/* Keywords. This list is taken from ldgram.y and ldlex.l in the old
102 GNU linker, with the keywords which only appear in MRI mode
103 removed. Not all these keywords are actually used in this grammar.
104 In most cases the keyword is recognized as the token name in upper
105 case. The comments indicate where this is not the case. */
106
107%token ABSOLUTE
108%token ADDR
109%token ALIGN_K /* ALIGN */
e5756efb 110%token ALIGNOF
dbe717ef
ILT
111%token ASSERT_K /* ASSERT */
112%token AS_NEEDED
113%token AT
114%token BIND
115%token BLOCK
116%token BYTE
117%token CONSTANT
118%token CONSTRUCTORS
dbe717ef
ILT
119%token CREATE_OBJECT_SYMBOLS
120%token DATA_SEGMENT_ALIGN
121%token DATA_SEGMENT_END
122%token DATA_SEGMENT_RELRO_END
123%token DEFINED
dbe717ef
ILT
124%token ENTRY
125%token EXCLUDE_FILE
126%token EXTERN
127%token FILL
128%token FLOAT
129%token FORCE_COMMON_ALLOCATION
130%token GLOBAL /* global */
131%token GROUP
132%token HLL
133%token INCLUDE
dbe717ef
ILT
134%token INHIBIT_COMMON_ALLOCATION
135%token INPUT
136%token KEEP
137%token LENGTH /* LENGTH, l, len */
138%token LOADADDR
139%token LOCAL /* local */
140%token LONG
141%token MAP
142%token MAX_K /* MAX */
143%token MEMORY
144%token MIN_K /* MIN */
145%token NEXT
146%token NOCROSSREFS
147%token NOFLOAT
dbe717ef
ILT
148%token ONLY_IF_RO
149%token ONLY_IF_RW
150%token ORIGIN /* ORIGIN, o, org */
151%token OUTPUT
152%token OUTPUT_ARCH
153%token OUTPUT_FORMAT
154%token OVERLAY
155%token PHDRS
156%token PROVIDE
157%token PROVIDE_HIDDEN
158%token QUAD
159%token SEARCH_DIR
160%token SECTIONS
161%token SEGMENT_START
162%token SHORT
163%token SIZEOF
164%token SIZEOF_HEADERS /* SIZEOF_HEADERS, sizeof_headers */
165%token SORT_BY_ALIGNMENT
166%token SORT_BY_NAME
167%token SPECIAL
168%token SQUAD
169%token STARTUP
170%token SUBALIGN
171%token SYSLIB
172%token TARGET_K /* TARGET */
173%token TRUNCATE
174%token VERSIONK /* VERSION */
175
195e7dc6
ILT
176/* Keywords, part 2. These are keywords that are unique to gold,
177 and not present in the old GNU linker. As before, unless the
178 comments say otherwise, the keyword is recognized as the token
179 name in upper case. */
180
181%token OPTION
182
e5756efb
ILT
183/* Special tokens used to tell the grammar what type of tokens we are
184 parsing. The token stream always begins with one of these tokens.
185 We do this because version scripts can appear embedded within
186 linker scripts, and because --defsym uses the expression
187 parser. */
188%token PARSING_LINKER_SCRIPT
189%token PARSING_VERSION_SCRIPT
190%token PARSING_DEFSYM
191
192/* Non-terminal types, where needed. */
193
494e05f4
ILT
194%type <expr> parse_exp exp opt_address_and_section_type
195%type <expr> opt_at opt_align opt_subalign opt_fill
196%type <output_section_header> section_header
197%type <output_section_trailer> section_trailer
198%type <integer> data_length
199%type <input_section_spec> input_section_no_keep
200%type <wildcard_sections> wildcard_sections
201%type <wildcard_section> wildcard_file wildcard_section
202%type <string_list> exclude_names
203%type <string> wildcard_name
09124467
ILT
204%type <versyms> vers_defns
205%type <versnode> vers_tag
206%type <deplist> verdep
10600224 207%type <string> string
e5756efb 208
dbe717ef
ILT
209%%
210
e5756efb
ILT
211/* Read the special token to see what to read next. */
212top:
213 PARSING_LINKER_SCRIPT linker_script
214 | PARSING_VERSION_SCRIPT version_script
215 | PARSING_DEFSYM defsym_expr
216 ;
217
d391083d 218/* A file contains a list of commands. */
e5756efb
ILT
219linker_script:
220 linker_script file_cmd
dbe717ef
ILT
221 | /* empty */
222 ;
223
d391083d 224/* A command which may appear at top level of a linker script. */
dbe717ef 225file_cmd:
2dd3e587 226 GROUP
dbe717ef
ILT
227 { script_start_group(closure); }
228 '(' input_list ')'
229 { script_end_group(closure); }
10600224 230 | OPTION '(' string ')'
e5756efb 231 { script_parse_option(closure, $3.value, $3.length); }
494e05f4
ILT
232 | SECTIONS '{'
233 { script_start_sections(closure); }
234 sections_block '}'
235 { script_finish_sections(closure); }
09124467
ILT
236 | VERSIONK '{'
237 { script_push_lex_into_version_mode(closure); }
238 version_script '}'
239 { script_pop_lex_mode(closure); }
d391083d 240 | file_or_sections_cmd
2dd3e587
ILT
241 | ignore_cmd
242 ;
243
244/* Top level commands which we ignore. The GNU linker uses these to
245 select the output format, but we don't offer a choice. Ignoring
246 these is more-or-less OK since most scripts simply explicitly
247 choose the default. */
248ignore_cmd:
10600224
ILT
249 OUTPUT_FORMAT '(' string ')'
250 | OUTPUT_FORMAT '(' string ',' string ',' string ')'
251 | OUTPUT_ARCH '(' string ')'
dbe717ef
ILT
252 ;
253
d391083d 254/* A list of input file names. */
dbe717ef
ILT
255input_list:
256 input_list_element
257 | input_list opt_comma input_list_element
258 ;
259
d391083d 260/* An input file name. */
dbe717ef 261input_list_element:
10600224 262 string
e5756efb 263 { script_add_file(closure, $1.value, $1.length); }
dbe717ef
ILT
264 | AS_NEEDED
265 { script_start_as_needed(closure); }
266 '(' input_list ')'
267 { script_end_as_needed(closure); }
268 ;
269
494e05f4
ILT
270/* Commands in a SECTIONS block. */
271sections_block:
272 sections_block section_block_cmd
273 | /* empty */
274 ;
275
276/* A command which may appear within a SECTIONS block. */
277section_block_cmd:
278 file_or_sections_cmd
e4967d85 279 | string section_header
494e05f4
ILT
280 { script_start_output_section(closure, $1.value, $1.length, &$2); }
281 '{' section_cmds '}' section_trailer
282 { script_finish_output_section(closure, &$7); }
283 ;
284
285/* The header of an output section in a SECTIONS block--everything
286 after the name. */
287section_header:
288 { script_push_lex_into_expression_mode(closure); }
289 opt_address_and_section_type opt_at opt_align opt_subalign
290 {
291 $$.address = $2;
292 $$.load_address = $3;
293 $$.align = $4;
294 $$.subalign = $5;
295 script_pop_lex_mode(closure);
296 }
297 ;
298
299/* The optional address followed by the optional section type. This
300 is a separate nonterminal to avoid a shift/reduce conflict on
301 '(' in section_header. */
302
303opt_address_and_section_type:
304 ':'
305 { $$ = NULL; }
306 | '(' ')' ':'
307 { $$ = NULL; }
308 | exp ':'
309 { $$ = $1; }
310 | exp '(' ')' ':'
311 { $$ = $1; }
e4967d85 312 | exp '(' string ')' ':'
494e05f4
ILT
313 {
314 yyerror(closure, "section types are not supported");
315 $$ = $1;
316 }
317 ;
318
319/* The address at which an output section should be loaded. */
320opt_at:
321 /* empty */
322 { $$ = NULL; }
323 | AT '(' exp ')'
324 { $$ = $3; }
325 ;
326
327/* The alignment of an output section. */
328opt_align:
329 /* empty */
330 { $$ = NULL; }
331 | ALIGN_K '(' exp ')'
332 { $$ = $3; }
333 ;
334
335/* The input section alignment within an output section. */
336opt_subalign:
337 /* empty */
338 { $$ = NULL; }
339 | SUBALIGN '(' exp ')'
340 { $$ = $3; }
341 ;
342
343/* The trailer of an output section in a SECTIONS block. */
344section_trailer:
345 { script_push_lex_into_expression_mode(closure); }
346 opt_memspec opt_at_memspec opt_phdr opt_fill opt_comma
347 {
348 $$.fill = $5;
349 script_pop_lex_mode(closure);
350 }
351 ;
352
353/* A memory specification for an output section. */
354opt_memspec:
e4967d85 355 '>' string
494e05f4
ILT
356 { yyerror(closure, "memory regions are not supported"); }
357 | /* empty */
358 ;
359
360/* A memory specification for where to load an output section. */
361opt_at_memspec:
e4967d85 362 AT '>' string
494e05f4
ILT
363 { yyerror(closure, "memory regions are not supported"); }
364 | /* empty */
365 ;
366
367/* The program segment an output section should go into. */
368opt_phdr:
e4967d85 369 opt_phdr ':' string
494e05f4
ILT
370 { yyerror(closure, "program headers are not supported"); }
371 | /* empty */
372 ;
373
a445fddf
ILT
374/* The value to use to fill an output section. FIXME: This does not
375 handle a string of arbitrary length. */
494e05f4
ILT
376opt_fill:
377 '=' exp
378 { $$ = $2; }
379 | /* empty */
380 { $$ = NULL; }
381 ;
382
383/* Commands which may appear within the description of an output
384 section in a SECTIONS block. */
385section_cmds:
386 /* empty */
387 | section_cmds section_cmd
388 ;
389
390/* A command which may appear within the description of an output
391 section in a SECTIONS block. */
392section_cmd:
393 assignment end
394 | input_section_spec
395 | data_length '(' parse_exp ')'
396 { script_add_data(closure, $1, $3); }
e4967d85 397 | ASSERT_K '(' parse_exp ',' string ')'
494e05f4
ILT
398 { script_add_assertion(closure, $3, $5.value, $5.length); }
399 | FILL '(' parse_exp ')'
400 { script_add_fill(closure, $3); }
401 | CONSTRUCTORS
402 {
403 /* The GNU linker uses CONSTRUCTORS for the a.out object
404 file format. It does nothing when using ELF. Since
405 some ELF linker scripts use it although it does
406 nothing, we accept it and ignore it. */
407 }
408 | ';'
409 ;
410
411/* The length of data which may appear within the description of an
412 output section in a SECTIONS block. */
413data_length:
414 QUAD
415 { $$ = QUAD; }
416 | SQUAD
417 { $$ = SQUAD; }
418 | LONG
419 { $$ = LONG; }
420 | SHORT
421 { $$ = SHORT; }
422 | BYTE
423 { $$ = BYTE; }
424 ;
425
426/* An input section specification. This may appear within the
427 description of an output section in a SECTIONS block. */
428input_section_spec:
429 input_section_no_keep
430 { script_add_input_section(closure, &$1, 0); }
431 | KEEP '(' input_section_no_keep ')'
432 { script_add_input_section(closure, &$3, 1); }
433 ;
434
435/* An input section specification within a KEEP clause. */
436input_section_no_keep:
e4967d85 437 string
494e05f4
ILT
438 {
439 $$.file.name = $1;
440 $$.file.sort = SORT_WILDCARD_NONE;
441 $$.input_sections.sections = NULL;
442 $$.input_sections.exclude = NULL;
443 }
444 | wildcard_file '(' wildcard_sections ')'
445 {
446 $$.file = $1;
447 $$.input_sections = $3;
448 }
449 ;
450
451/* A wildcard file specification. */
452wildcard_file:
453 wildcard_name
454 {
455 $$.name = $1;
456 $$.sort = SORT_WILDCARD_NONE;
457 }
458 | SORT_BY_NAME '(' wildcard_name ')'
459 {
460 $$.name = $3;
461 $$.sort = SORT_WILDCARD_BY_NAME;
462 }
463 ;
464
465/* A list of wild card section specifications. */
466wildcard_sections:
467 wildcard_sections opt_comma wildcard_section
468 {
469 $$.sections = script_string_sort_list_add($1.sections, &$3);
470 $$.exclude = $1.exclude;
471 }
472 | wildcard_section
473 {
474 $$.sections = script_new_string_sort_list(&$1);
475 $$.exclude = NULL;
476 }
477 | wildcard_sections opt_comma EXCLUDE_FILE '(' exclude_names ')'
478 {
479 $$.sections = $1.sections;
480 $$.exclude = script_string_list_append($1.exclude, $5);
481 }
482 | EXCLUDE_FILE '(' exclude_names ')'
483 {
484 $$.sections = NULL;
485 $$.exclude = $3;
486 }
487 ;
488
489/* A single wild card specification. */
490wildcard_section:
491 wildcard_name
492 {
493 $$.name = $1;
494 $$.sort = SORT_WILDCARD_NONE;
495 }
496 | SORT_BY_NAME '(' wildcard_section ')'
497 {
498 $$.name = $3.name;
499 switch ($3.sort)
500 {
501 case SORT_WILDCARD_NONE:
502 $$.sort = SORT_WILDCARD_BY_NAME;
503 break;
504 case SORT_WILDCARD_BY_NAME:
505 case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
506 break;
507 case SORT_WILDCARD_BY_ALIGNMENT:
508 case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
509 $$.sort = SORT_WILDCARD_BY_NAME_BY_ALIGNMENT;
510 break;
511 default:
512 abort();
513 }
514 }
515 | SORT_BY_ALIGNMENT '(' wildcard_section ')'
516 {
517 $$.name = $3.name;
518 switch ($3.sort)
519 {
520 case SORT_WILDCARD_NONE:
521 $$.sort = SORT_WILDCARD_BY_ALIGNMENT;
522 break;
523 case SORT_WILDCARD_BY_ALIGNMENT:
524 case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
525 break;
526 case SORT_WILDCARD_BY_NAME:
527 case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
528 $$.sort = SORT_WILDCARD_BY_ALIGNMENT_BY_NAME;
529 break;
530 default:
531 abort();
532 }
533 }
534 ;
535
536/* A list of file names to exclude. */
537exclude_names:
538 exclude_names opt_comma wildcard_name
539 { $$ = script_string_list_push_back($1, $3.value, $3.length); }
540 | wildcard_name
541 { $$ = script_new_string_list($1.value, $1.length); }
542 ;
543
544/* A single wildcard name. We recognize '*' and '?' specially since
545 they are expression tokens. */
546wildcard_name:
e4967d85 547 string
494e05f4
ILT
548 { $$ = $1; }
549 | '*'
550 {
551 $$.value = "*";
552 $$.length = 1;
553 }
554 | '?'
555 {
556 $$.value = "?";
557 $$.length = 1;
558 }
559 ;
560
d391083d
ILT
561/* A command which may appear at the top level of a linker script, or
562 within a SECTIONS block. */
563file_or_sections_cmd:
10600224 564 ENTRY '(' string ')'
e5756efb
ILT
565 { script_set_entry(closure, $3.value, $3.length); }
566 | assignment end
e4967d85 567 | ASSERT_K '(' parse_exp ',' string ')'
494e05f4 568 { script_add_assertion(closure, $3, $5.value, $5.length); }
e5756efb
ILT
569 ;
570
571/* Set a symbol to a value. */
572assignment:
10600224 573 string '=' parse_exp
e5756efb 574 { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
10600224 575 | string PLUSEQ parse_exp
e5756efb
ILT
576 {
577 Expression_ptr s = script_exp_string($1.value, $1.length);
578 Expression_ptr e = script_exp_binary_add(s, $3);
579 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
580 }
10600224 581 | string MINUSEQ parse_exp
e5756efb
ILT
582 {
583 Expression_ptr s = script_exp_string($1.value, $1.length);
584 Expression_ptr e = script_exp_binary_sub(s, $3);
585 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
586 }
10600224 587 | string MULTEQ parse_exp
e5756efb
ILT
588 {
589 Expression_ptr s = script_exp_string($1.value, $1.length);
590 Expression_ptr e = script_exp_binary_mult(s, $3);
591 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
592 }
10600224 593 | string DIVEQ parse_exp
e5756efb
ILT
594 {
595 Expression_ptr s = script_exp_string($1.value, $1.length);
596 Expression_ptr e = script_exp_binary_div(s, $3);
597 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
598 }
10600224 599 | string LSHIFTEQ parse_exp
e5756efb
ILT
600 {
601 Expression_ptr s = script_exp_string($1.value, $1.length);
602 Expression_ptr e = script_exp_binary_lshift(s, $3);
603 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
604 }
10600224 605 | string RSHIFTEQ parse_exp
e5756efb
ILT
606 {
607 Expression_ptr s = script_exp_string($1.value, $1.length);
608 Expression_ptr e = script_exp_binary_rshift(s, $3);
609 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
610 }
10600224 611 | string ANDEQ parse_exp
e5756efb
ILT
612 {
613 Expression_ptr s = script_exp_string($1.value, $1.length);
614 Expression_ptr e = script_exp_binary_bitwise_and(s, $3);
615 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
616 }
10600224 617 | string OREQ parse_exp
e5756efb
ILT
618 {
619 Expression_ptr s = script_exp_string($1.value, $1.length);
620 Expression_ptr e = script_exp_binary_bitwise_or(s, $3);
621 script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
622 }
10600224 623 | PROVIDE '(' string '=' parse_exp ')'
e5756efb 624 { script_set_symbol(closure, $3.value, $3.length, $5, 1, 0); }
10600224 625 | PROVIDE_HIDDEN '(' string '=' parse_exp ')'
e5756efb
ILT
626 { script_set_symbol(closure, $3.value, $3.length, $5, 1, 1); }
627 ;
628
629/* Parse an expression, putting the lexer into the right mode. */
630parse_exp:
631 { script_push_lex_into_expression_mode(closure); }
632 exp
633 {
634 script_pop_lex_mode(closure);
635 $$ = $2;
636 }
637 ;
638
639/* An expression. */
640exp:
641 '(' exp ')'
642 { $$ = $2; }
643 | '-' exp %prec UNARY
644 { $$ = script_exp_unary_minus($2); }
645 | '!' exp %prec UNARY
646 { $$ = script_exp_unary_logical_not($2); }
647 | '~' exp %prec UNARY
648 { $$ = script_exp_unary_bitwise_not($2); }
649 | '+' exp %prec UNARY
650 { $$ = $2; }
651 | exp '*' exp
652 { $$ = script_exp_binary_mult($1, $3); }
653 | exp '/' exp
654 { $$ = script_exp_binary_div($1, $3); }
655 | exp '%' exp
656 { $$ = script_exp_binary_mod($1, $3); }
657 | exp '+' exp
658 { $$ = script_exp_binary_add($1, $3); }
659 | exp '-' exp
660 { $$ = script_exp_binary_sub($1, $3); }
661 | exp LSHIFT exp
662 { $$ = script_exp_binary_lshift($1, $3); }
663 | exp RSHIFT exp
664 { $$ = script_exp_binary_rshift($1, $3); }
665 | exp EQ exp
666 { $$ = script_exp_binary_eq($1, $3); }
667 | exp NE exp
668 { $$ = script_exp_binary_ne($1, $3); }
669 | exp LE exp
670 { $$ = script_exp_binary_le($1, $3); }
671 | exp GE exp
672 { $$ = script_exp_binary_ge($1, $3); }
673 | exp '<' exp
674 { $$ = script_exp_binary_lt($1, $3); }
675 | exp '>' exp
676 { $$ = script_exp_binary_gt($1, $3); }
677 | exp '&' exp
678 { $$ = script_exp_binary_bitwise_and($1, $3); }
679 | exp '^' exp
680 { $$ = script_exp_binary_bitwise_xor($1, $3); }
681 | exp '|' exp
682 { $$ = script_exp_binary_bitwise_or($1, $3); }
683 | exp ANDAND exp
684 { $$ = script_exp_binary_logical_and($1, $3); }
685 | exp OROR exp
686 { $$ = script_exp_binary_logical_or($1, $3); }
687 | exp '?' exp ':' exp
688 { $$ = script_exp_trinary_cond($1, $3, $5); }
689 | INTEGER
690 { $$ = script_exp_integer($1); }
e4967d85 691 | string
10600224 692 { $$ = script_exp_string($1.value, $1.length); }
e5756efb
ILT
693 | MAX_K '(' exp ',' exp ')'
694 { $$ = script_exp_function_max($3, $5); }
695 | MIN_K '(' exp ',' exp ')'
696 { $$ = script_exp_function_min($3, $5); }
10600224 697 | DEFINED '(' string ')'
e5756efb
ILT
698 { $$ = script_exp_function_defined($3.value, $3.length); }
699 | SIZEOF_HEADERS
700 { $$ = script_exp_function_sizeof_headers(); }
10600224 701 | ALIGNOF '(' string ')'
e5756efb 702 { $$ = script_exp_function_alignof($3.value, $3.length); }
10600224 703 | SIZEOF '(' string ')'
e5756efb 704 { $$ = script_exp_function_sizeof($3.value, $3.length); }
10600224 705 | ADDR '(' string ')'
e5756efb 706 { $$ = script_exp_function_addr($3.value, $3.length); }
10600224 707 | LOADADDR '(' string ')'
e5756efb 708 { $$ = script_exp_function_loadaddr($3.value, $3.length); }
10600224 709 | ORIGIN '(' string ')'
e5756efb 710 { $$ = script_exp_function_origin($3.value, $3.length); }
10600224 711 | LENGTH '(' string ')'
e5756efb 712 { $$ = script_exp_function_length($3.value, $3.length); }
10600224 713 | CONSTANT '(' string ')'
e5756efb
ILT
714 { $$ = script_exp_function_constant($3.value, $3.length); }
715 | ABSOLUTE '(' exp ')'
716 { $$ = script_exp_function_absolute($3); }
717 | ALIGN_K '(' exp ')'
718 { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
719 | ALIGN_K '(' exp ',' exp ')'
720 { $$ = script_exp_function_align($3, $5); }
721 | BLOCK '(' exp ')'
722 { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
723 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
724 { $$ = script_exp_function_data_segment_align($3, $5); }
725 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
726 { $$ = script_exp_function_data_segment_relro_end($3, $5); }
727 | DATA_SEGMENT_END '(' exp ')'
728 { $$ = script_exp_function_data_segment_end($3); }
10600224 729 | SEGMENT_START '(' string ',' exp ')'
e5756efb
ILT
730 {
731 $$ = script_exp_function_segment_start($3.value, $3.length, $5);
732 }
10600224 733 | ASSERT_K '(' exp ',' string ')'
e5756efb
ILT
734 { $$ = script_exp_function_assert($3, $5.value, $5.length); }
735 ;
736
737/* Handle the --defsym option. */
738defsym_expr:
10600224 739 string '=' parse_exp
e5756efb
ILT
740 { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
741 ;
742
09124467 743/* A version script. */
e5756efb 744version_script:
09124467
ILT
745 vers_nodes
746 ;
747
748vers_nodes:
749 vers_node
750 | vers_nodes vers_node
751 ;
752
753vers_node:
754 '{' vers_tag '}' ';'
755 {
756 script_register_vers_node (closure, NULL, 0, $2, NULL);
757 }
10600224 758 | string '{' vers_tag '}' ';'
09124467
ILT
759 {
760 script_register_vers_node (closure, $1.value, $1.length, $3,
761 NULL);
762 }
10600224 763 | string '{' vers_tag '}' verdep ';'
09124467
ILT
764 {
765 script_register_vers_node (closure, $1.value, $1.length, $3, $5);
766 }
767 ;
768
769verdep:
10600224 770 string
09124467
ILT
771 {
772 $$ = script_add_vers_depend (closure, NULL, $1.value, $1.length);
773 }
10600224 774 | verdep string
09124467
ILT
775 {
776 $$ = script_add_vers_depend (closure, $1, $2.value, $2.length);
777 }
778 ;
779
780vers_tag:
781 /* empty */
782 { $$ = script_new_vers_node (closure, NULL, NULL); }
783 | vers_defns ';'
784 { $$ = script_new_vers_node (closure, $1, NULL); }
785 | GLOBAL ':' vers_defns ';'
786 { $$ = script_new_vers_node (closure, $3, NULL); }
787 | LOCAL ':' vers_defns ';'
788 { $$ = script_new_vers_node (closure, NULL, $3); }
789 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
790 { $$ = script_new_vers_node (closure, $3, $7); }
791 ;
792
10600224
ILT
793/* Here is one of the rare places we care about the distinction
794 between STRING and QUOTED_STRING. For QUOTED_STRING, we do exact
795 matching on the pattern, so we pass in true for the exact_match
796 parameter. For STRING, we do glob matching and pass in false. */
09124467
ILT
797vers_defns:
798 STRING
799 {
800 $$ = script_new_vers_pattern (closure, NULL, $1.value,
10600224
ILT
801 $1.length, 0);
802 }
803 | QUOTED_STRING
804 {
805 $$ = script_new_vers_pattern (closure, NULL, $1.value,
806 $1.length, 1);
09124467
ILT
807 }
808 | vers_defns ';' STRING
809 {
10600224
ILT
810 $$ = script_new_vers_pattern (closure, $1, $3.value,
811 $3.length, 0);
812 }
813 | vers_defns ';' QUOTED_STRING
814 {
815 $$ = script_new_vers_pattern (closure, $1, $3.value,
816 $3.length, 1);
09124467 817 }
10600224
ILT
818 | /* Push string on the language stack. */
819 EXTERN string '{'
820 { version_script_push_lang (closure, $2.value, $2.length); }
09124467
ILT
821 vers_defns opt_semicolon '}'
822 {
823 $$ = $5;
824 version_script_pop_lang(closure);
825 }
10600224
ILT
826 | /* Push string on the language stack. This is more complicated
827 than the other cases because we need to merge the linked-list
828 state from the pre-EXTERN defns and the post-EXTERN defns. */
829 vers_defns ';' EXTERN string '{'
830 { version_script_push_lang (closure, $4.value, $4.length); }
831 vers_defns opt_semicolon '}'
832 {
833 $$ = script_merge_expressions ($1, $7);
834 version_script_pop_lang(closure);
835 }
09124467
ILT
836 | EXTERN // "extern" as a symbol name
837 {
838 $$ = script_new_vers_pattern (closure, NULL, "extern",
10600224 839 sizeof("extern") - 1, 1);
09124467
ILT
840 }
841 | vers_defns ';' EXTERN
842 {
843 $$ = script_new_vers_pattern (closure, $1, "extern",
10600224 844 sizeof("extern") - 1, 1);
09124467 845 }
e5756efb
ILT
846 ;
847
10600224
ILT
848/* A string can be either a STRING or a QUOTED_STRING. Almost all the
849 time we don't care, and we use this rule. */
850string:
851 STRING
852 { $$ = $1; }
853 | QUOTED_STRING
854 { $$ = $1; }
855 ;
856
e5756efb
ILT
857/* Some statements require a terminator, which may be a semicolon or a
858 comma. */
859end:
860 ';'
861 | ','
d391083d
ILT
862 ;
863
09124467
ILT
864/* An optional semicolon. */
865opt_semicolon:
866 ';'
867 | /* empty */
868 ;
869
d391083d 870/* An optional comma. */
dbe717ef
ILT
871opt_comma:
872 ','
873 | /* empty */
874 ;
875
876%%