Implement SIZEOF_HEADERS, section constraints, other minor linker
[deliverable/binutils-gdb.git] / gold / yyscript.y
1 /* yyscript.y -- linker script grammer for gold. */
2
3 /* Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
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
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>
32 #include <stdlib.h>
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 {
53 /* A string. */
54 struct Parser_string string;
55 /* A number. */
56 uint64_t integer;
57 /* An expression. */
58 Expression_ptr expr;
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 section constraint. */
64 enum Section_constraint constraint;
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 {}. */
74 struct Version_dependency_list* deplist;
75 struct Version_expression_list* versyms;
76 struct Version_tree* versnode;
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
94 /* A fake operator used to indicate unary operator precedence. */
95 %right UNARY
96
97 /* Constants. */
98
99 %token <string> STRING
100 %token <string> QUOTED_STRING
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 */
112 %token ALIGNOF
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
121 %token CREATE_OBJECT_SYMBOLS
122 %token DATA_SEGMENT_ALIGN
123 %token DATA_SEGMENT_END
124 %token DATA_SEGMENT_RELRO_END
125 %token DEFINED
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
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
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
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
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
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
200 %type <constraint> opt_constraint
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
207 %type <versyms> vers_defns
208 %type <versnode> vers_tag
209 %type <deplist> verdep
210 %type <string> string
211
212 %%
213
214 /* Read the special token to see what to read next. */
215 top:
216 PARSING_LINKER_SCRIPT linker_script
217 | PARSING_VERSION_SCRIPT version_script
218 | PARSING_DEFSYM defsym_expr
219 ;
220
221 /* A file contains a list of commands. */
222 linker_script:
223 linker_script file_cmd
224 | /* empty */
225 ;
226
227 /* A command which may appear at top level of a linker script. */
228 file_cmd:
229 GROUP
230 { script_start_group(closure); }
231 '(' input_list ')'
232 { script_end_group(closure); }
233 | OPTION '(' string ')'
234 { script_parse_option(closure, $3.value, $3.length); }
235 | SEARCH_DIR '(' string ')'
236 { script_add_search_dir(closure, $3.value, $3.length); }
237 | SECTIONS '{'
238 { script_start_sections(closure); }
239 sections_block '}'
240 { script_finish_sections(closure); }
241 | VERSIONK '{'
242 { script_push_lex_into_version_mode(closure); }
243 version_script '}'
244 { script_pop_lex_mode(closure); }
245 | file_or_sections_cmd
246 | ignore_cmd
247 | ';'
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. */
254 ignore_cmd:
255 OUTPUT_FORMAT '(' string ')'
256 | OUTPUT_FORMAT '(' string ',' string ',' string ')'
257 | OUTPUT_ARCH '(' string ')'
258 ;
259
260 /* A list of input file names. */
261 input_list:
262 input_list_element
263 | input_list opt_comma input_list_element
264 ;
265
266 /* An input file name. */
267 input_list_element:
268 string
269 { script_add_file(closure, $1.value, $1.length); }
270 | AS_NEEDED
271 { script_start_as_needed(closure); }
272 '(' input_list ')'
273 { script_end_as_needed(closure); }
274 ;
275
276 /* Commands in a SECTIONS block. */
277 sections_block:
278 sections_block section_block_cmd
279 | /* empty */
280 ;
281
282 /* A command which may appear within a SECTIONS block. */
283 section_block_cmd:
284 file_or_sections_cmd
285 | string section_header
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. */
293 section_header:
294 { script_push_lex_into_expression_mode(closure); }
295 opt_address_and_section_type opt_at opt_align opt_subalign
296 { script_pop_lex_mode(closure); }
297 opt_constraint
298 {
299 $$.address = $2;
300 $$.load_address = $3;
301 $$.align = $4;
302 $$.subalign = $5;
303 $$.constraint = $7;
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
311 opt_address_and_section_type:
312 ':'
313 { $$ = NULL; }
314 | '(' ')' ':'
315 { $$ = NULL; }
316 | exp ':'
317 { $$ = $1; }
318 | exp '(' ')' ':'
319 { $$ = $1; }
320 | exp '(' string ')' ':'
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. */
328 opt_at:
329 /* empty */
330 { $$ = NULL; }
331 | AT '(' exp ')'
332 { $$ = $3; }
333 ;
334
335 /* The alignment of an output section. */
336 opt_align:
337 /* empty */
338 { $$ = NULL; }
339 | ALIGN_K '(' exp ')'
340 { $$ = $3; }
341 ;
342
343 /* The input section alignment within an output section. */
344 opt_subalign:
345 /* empty */
346 { $$ = NULL; }
347 | SUBALIGN '(' exp ')'
348 { $$ = $3; }
349 ;
350
351 /* A section constraint. */
352 opt_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
363 /* The trailer of an output section in a SECTIONS block. */
364 section_trailer:
365 opt_memspec opt_at_memspec opt_phdr opt_fill opt_comma
366 {
367 $$.fill = $4;
368 }
369 ;
370
371 /* A memory specification for an output section. */
372 opt_memspec:
373 '>' string
374 { yyerror(closure, "memory regions are not supported"); }
375 | /* empty */
376 ;
377
378 /* A memory specification for where to load an output section. */
379 opt_at_memspec:
380 AT '>' string
381 { yyerror(closure, "memory regions are not supported"); }
382 | /* empty */
383 ;
384
385 /* The program segment an output section should go into. */
386 opt_phdr:
387 opt_phdr ':' string
388 { yyerror(closure, "program headers are not supported"); }
389 | /* empty */
390 ;
391
392 /* The value to use to fill an output section. FIXME: This does not
393 handle a string of arbitrary length. */
394 opt_fill:
395 '=' parse_exp
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. */
403 section_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. */
410 section_cmd:
411 assignment end
412 | input_section_spec
413 | data_length '(' parse_exp ')'
414 { script_add_data(closure, $1, $3); }
415 | ASSERT_K '(' parse_exp ',' string ')'
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 }
426 | SORT_BY_NAME '(' CONSTRUCTORS ')'
427 | ';'
428 ;
429
430 /* The length of data which may appear within the description of an
431 output section in a SECTIONS block. */
432 data_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. */
447 input_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. */
455 input_section_no_keep:
456 string
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. */
471 wildcard_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. */
485 wildcard_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. */
509 wildcard_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. */
556 exclude_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. */
565 wildcard_name:
566 string
567 { $$ = $1; }
568 | '*'
569 {
570 $$.value = "*";
571 $$.length = 1;
572 }
573 | '?'
574 {
575 $$.value = "?";
576 $$.length = 1;
577 }
578 ;
579
580 /* A command which may appear at the top level of a linker script, or
581 within a SECTIONS block. */
582 file_or_sections_cmd:
583 ENTRY '(' string ')'
584 { script_set_entry(closure, $3.value, $3.length); }
585 | assignment end
586 | ASSERT_K '(' parse_exp ',' string ')'
587 { script_add_assertion(closure, $3, $5.value, $5.length); }
588 ;
589
590 /* Set a symbol to a value. */
591 assignment:
592 string '=' parse_exp
593 { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
594 | string PLUSEQ parse_exp
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 }
600 | string MINUSEQ parse_exp
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 }
606 | string MULTEQ parse_exp
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 }
612 | string DIVEQ parse_exp
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 }
618 | string LSHIFTEQ parse_exp
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 }
624 | string RSHIFTEQ parse_exp
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 }
630 | string ANDEQ parse_exp
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 }
636 | string OREQ parse_exp
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 }
642 | PROVIDE '(' string '=' parse_exp ')'
643 { script_set_symbol(closure, $3.value, $3.length, $5, 1, 0); }
644 | PROVIDE_HIDDEN '(' string '=' parse_exp ')'
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. */
649 parse_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. */
659 exp:
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); }
710 | string
711 { $$ = script_exp_string($1.value, $1.length); }
712 | MAX_K '(' exp ',' exp ')'
713 { $$ = script_exp_function_max($3, $5); }
714 | MIN_K '(' exp ',' exp ')'
715 { $$ = script_exp_function_min($3, $5); }
716 | DEFINED '(' string ')'
717 { $$ = script_exp_function_defined($3.value, $3.length); }
718 | SIZEOF_HEADERS
719 { $$ = script_exp_function_sizeof_headers(); }
720 | ALIGNOF '(' string ')'
721 { $$ = script_exp_function_alignof($3.value, $3.length); }
722 | SIZEOF '(' string ')'
723 { $$ = script_exp_function_sizeof($3.value, $3.length); }
724 | ADDR '(' string ')'
725 { $$ = script_exp_function_addr($3.value, $3.length); }
726 | LOADADDR '(' string ')'
727 { $$ = script_exp_function_loadaddr($3.value, $3.length); }
728 | ORIGIN '(' string ')'
729 { $$ = script_exp_function_origin($3.value, $3.length); }
730 | LENGTH '(' string ')'
731 { $$ = script_exp_function_length($3.value, $3.length); }
732 | CONSTANT '(' string ')'
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); }
748 | SEGMENT_START '(' string ',' exp ')'
749 {
750 $$ = script_exp_function_segment_start($3.value, $3.length, $5);
751 }
752 | ASSERT_K '(' exp ',' string ')'
753 { $$ = script_exp_function_assert($3, $5.value, $5.length); }
754 ;
755
756 /* Handle the --defsym option. */
757 defsym_expr:
758 string '=' parse_exp
759 { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
760 ;
761
762 /* A version script. */
763 version_script:
764 vers_nodes
765 ;
766
767 vers_nodes:
768 vers_node
769 | vers_nodes vers_node
770 ;
771
772 vers_node:
773 '{' vers_tag '}' ';'
774 {
775 script_register_vers_node (closure, NULL, 0, $2, NULL);
776 }
777 | string '{' vers_tag '}' ';'
778 {
779 script_register_vers_node (closure, $1.value, $1.length, $3,
780 NULL);
781 }
782 | string '{' vers_tag '}' verdep ';'
783 {
784 script_register_vers_node (closure, $1.value, $1.length, $3, $5);
785 }
786 ;
787
788 verdep:
789 string
790 {
791 $$ = script_add_vers_depend (closure, NULL, $1.value, $1.length);
792 }
793 | verdep string
794 {
795 $$ = script_add_vers_depend (closure, $1, $2.value, $2.length);
796 }
797 ;
798
799 vers_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
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. */
816 vers_defns:
817 STRING
818 {
819 $$ = script_new_vers_pattern (closure, NULL, $1.value,
820 $1.length, 0);
821 }
822 | QUOTED_STRING
823 {
824 $$ = script_new_vers_pattern (closure, NULL, $1.value,
825 $1.length, 1);
826 }
827 | vers_defns ';' STRING
828 {
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);
836 }
837 | /* Push string on the language stack. */
838 EXTERN string '{'
839 { version_script_push_lang (closure, $2.value, $2.length); }
840 vers_defns opt_semicolon '}'
841 {
842 $$ = $5;
843 version_script_pop_lang(closure);
844 }
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 }
855 | EXTERN // "extern" as a symbol name
856 {
857 $$ = script_new_vers_pattern (closure, NULL, "extern",
858 sizeof("extern") - 1, 1);
859 }
860 | vers_defns ';' EXTERN
861 {
862 $$ = script_new_vers_pattern (closure, $1, "extern",
863 sizeof("extern") - 1, 1);
864 }
865 ;
866
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. */
869 string:
870 STRING
871 { $$ = $1; }
872 | QUOTED_STRING
873 { $$ = $1; }
874 ;
875
876 /* Some statements require a terminator, which may be a semicolon or a
877 comma. */
878 end:
879 ';'
880 | ','
881 ;
882
883 /* An optional semicolon. */
884 opt_semicolon:
885 ';'
886 | /* empty */
887 ;
888
889 /* An optional comma. */
890 opt_comma:
891 ','
892 | /* empty */
893 ;
894
895 %%
This page took 0.049552 seconds and 5 git commands to generate.