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