Fully implement the SECTIONS clause.
[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 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 {}. */
72 struct Version_dependency_list* deplist;
73 struct Version_expression_list* versyms;
74 struct Version_tree* versnode;
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
92 /* A fake operator used to indicate unary operator precedence. */
93 %right UNARY
94
95 /* Constants. */
96
97 %token <string> STRING
98 %token <string> QUOTED_STRING
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 */
110 %token ALIGNOF
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
119 %token CREATE_OBJECT_SYMBOLS
120 %token DATA_SEGMENT_ALIGN
121 %token DATA_SEGMENT_END
122 %token DATA_SEGMENT_RELRO_END
123 %token DEFINED
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
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
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
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
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
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
204 %type <versyms> vers_defns
205 %type <versnode> vers_tag
206 %type <deplist> verdep
207 %type <string> string
208
209 %%
210
211 /* Read the special token to see what to read next. */
212 top:
213 PARSING_LINKER_SCRIPT linker_script
214 | PARSING_VERSION_SCRIPT version_script
215 | PARSING_DEFSYM defsym_expr
216 ;
217
218 /* A file contains a list of commands. */
219 linker_script:
220 linker_script file_cmd
221 | /* empty */
222 ;
223
224 /* A command which may appear at top level of a linker script. */
225 file_cmd:
226 GROUP
227 { script_start_group(closure); }
228 '(' input_list ')'
229 { script_end_group(closure); }
230 | OPTION '(' string ')'
231 { script_parse_option(closure, $3.value, $3.length); }
232 | SECTIONS '{'
233 { script_start_sections(closure); }
234 sections_block '}'
235 { script_finish_sections(closure); }
236 | VERSIONK '{'
237 { script_push_lex_into_version_mode(closure); }
238 version_script '}'
239 { script_pop_lex_mode(closure); }
240 | file_or_sections_cmd
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. */
248 ignore_cmd:
249 OUTPUT_FORMAT '(' string ')'
250 | OUTPUT_FORMAT '(' string ',' string ',' string ')'
251 | OUTPUT_ARCH '(' string ')'
252 ;
253
254 /* A list of input file names. */
255 input_list:
256 input_list_element
257 | input_list opt_comma input_list_element
258 ;
259
260 /* An input file name. */
261 input_list_element:
262 string
263 { script_add_file(closure, $1.value, $1.length); }
264 | AS_NEEDED
265 { script_start_as_needed(closure); }
266 '(' input_list ')'
267 { script_end_as_needed(closure); }
268 ;
269
270 /* Commands in a SECTIONS block. */
271 sections_block:
272 sections_block section_block_cmd
273 | /* empty */
274 ;
275
276 /* A command which may appear within a SECTIONS block. */
277 section_block_cmd:
278 file_or_sections_cmd
279 | string section_header
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. */
287 section_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
303 opt_address_and_section_type:
304 ':'
305 { $$ = NULL; }
306 | '(' ')' ':'
307 { $$ = NULL; }
308 | exp ':'
309 { $$ = $1; }
310 | exp '(' ')' ':'
311 { $$ = $1; }
312 | exp '(' string ')' ':'
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. */
320 opt_at:
321 /* empty */
322 { $$ = NULL; }
323 | AT '(' exp ')'
324 { $$ = $3; }
325 ;
326
327 /* The alignment of an output section. */
328 opt_align:
329 /* empty */
330 { $$ = NULL; }
331 | ALIGN_K '(' exp ')'
332 { $$ = $3; }
333 ;
334
335 /* The input section alignment within an output section. */
336 opt_subalign:
337 /* empty */
338 { $$ = NULL; }
339 | SUBALIGN '(' exp ')'
340 { $$ = $3; }
341 ;
342
343 /* The trailer of an output section in a SECTIONS block. */
344 section_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. */
354 opt_memspec:
355 '>' string
356 { yyerror(closure, "memory regions are not supported"); }
357 | /* empty */
358 ;
359
360 /* A memory specification for where to load an output section. */
361 opt_at_memspec:
362 AT '>' string
363 { yyerror(closure, "memory regions are not supported"); }
364 | /* empty */
365 ;
366
367 /* The program segment an output section should go into. */
368 opt_phdr:
369 opt_phdr ':' string
370 { yyerror(closure, "program headers are not supported"); }
371 | /* empty */
372 ;
373
374 /* The value to use to fill an output section. FIXME: This does not
375 handle a string of arbitrary length. */
376 opt_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. */
385 section_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. */
392 section_cmd:
393 assignment end
394 | input_section_spec
395 | data_length '(' parse_exp ')'
396 { script_add_data(closure, $1, $3); }
397 | ASSERT_K '(' parse_exp ',' string ')'
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. */
413 data_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. */
428 input_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. */
436 input_section_no_keep:
437 string
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. */
452 wildcard_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. */
466 wildcard_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. */
490 wildcard_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. */
537 exclude_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. */
546 wildcard_name:
547 string
548 { $$ = $1; }
549 | '*'
550 {
551 $$.value = "*";
552 $$.length = 1;
553 }
554 | '?'
555 {
556 $$.value = "?";
557 $$.length = 1;
558 }
559 ;
560
561 /* A command which may appear at the top level of a linker script, or
562 within a SECTIONS block. */
563 file_or_sections_cmd:
564 ENTRY '(' string ')'
565 { script_set_entry(closure, $3.value, $3.length); }
566 | assignment end
567 | ASSERT_K '(' parse_exp ',' string ')'
568 { script_add_assertion(closure, $3, $5.value, $5.length); }
569 ;
570
571 /* Set a symbol to a value. */
572 assignment:
573 string '=' parse_exp
574 { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
575 | string PLUSEQ parse_exp
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 }
581 | string MINUSEQ parse_exp
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 }
587 | string MULTEQ parse_exp
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 }
593 | string DIVEQ parse_exp
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 }
599 | string LSHIFTEQ parse_exp
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 }
605 | string RSHIFTEQ parse_exp
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 }
611 | string ANDEQ parse_exp
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 }
617 | string OREQ parse_exp
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 }
623 | PROVIDE '(' string '=' parse_exp ')'
624 { script_set_symbol(closure, $3.value, $3.length, $5, 1, 0); }
625 | PROVIDE_HIDDEN '(' string '=' parse_exp ')'
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. */
630 parse_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. */
640 exp:
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); }
691 | string
692 { $$ = script_exp_string($1.value, $1.length); }
693 | MAX_K '(' exp ',' exp ')'
694 { $$ = script_exp_function_max($3, $5); }
695 | MIN_K '(' exp ',' exp ')'
696 { $$ = script_exp_function_min($3, $5); }
697 | DEFINED '(' string ')'
698 { $$ = script_exp_function_defined($3.value, $3.length); }
699 | SIZEOF_HEADERS
700 { $$ = script_exp_function_sizeof_headers(); }
701 | ALIGNOF '(' string ')'
702 { $$ = script_exp_function_alignof($3.value, $3.length); }
703 | SIZEOF '(' string ')'
704 { $$ = script_exp_function_sizeof($3.value, $3.length); }
705 | ADDR '(' string ')'
706 { $$ = script_exp_function_addr($3.value, $3.length); }
707 | LOADADDR '(' string ')'
708 { $$ = script_exp_function_loadaddr($3.value, $3.length); }
709 | ORIGIN '(' string ')'
710 { $$ = script_exp_function_origin($3.value, $3.length); }
711 | LENGTH '(' string ')'
712 { $$ = script_exp_function_length($3.value, $3.length); }
713 | CONSTANT '(' string ')'
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); }
729 | SEGMENT_START '(' string ',' exp ')'
730 {
731 $$ = script_exp_function_segment_start($3.value, $3.length, $5);
732 }
733 | ASSERT_K '(' exp ',' string ')'
734 { $$ = script_exp_function_assert($3, $5.value, $5.length); }
735 ;
736
737 /* Handle the --defsym option. */
738 defsym_expr:
739 string '=' parse_exp
740 { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
741 ;
742
743 /* A version script. */
744 version_script:
745 vers_nodes
746 ;
747
748 vers_nodes:
749 vers_node
750 | vers_nodes vers_node
751 ;
752
753 vers_node:
754 '{' vers_tag '}' ';'
755 {
756 script_register_vers_node (closure, NULL, 0, $2, NULL);
757 }
758 | string '{' vers_tag '}' ';'
759 {
760 script_register_vers_node (closure, $1.value, $1.length, $3,
761 NULL);
762 }
763 | string '{' vers_tag '}' verdep ';'
764 {
765 script_register_vers_node (closure, $1.value, $1.length, $3, $5);
766 }
767 ;
768
769 verdep:
770 string
771 {
772 $$ = script_add_vers_depend (closure, NULL, $1.value, $1.length);
773 }
774 | verdep string
775 {
776 $$ = script_add_vers_depend (closure, $1, $2.value, $2.length);
777 }
778 ;
779
780 vers_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
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. */
797 vers_defns:
798 STRING
799 {
800 $$ = script_new_vers_pattern (closure, NULL, $1.value,
801 $1.length, 0);
802 }
803 | QUOTED_STRING
804 {
805 $$ = script_new_vers_pattern (closure, NULL, $1.value,
806 $1.length, 1);
807 }
808 | vers_defns ';' STRING
809 {
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);
817 }
818 | /* Push string on the language stack. */
819 EXTERN string '{'
820 { version_script_push_lang (closure, $2.value, $2.length); }
821 vers_defns opt_semicolon '}'
822 {
823 $$ = $5;
824 version_script_pop_lang(closure);
825 }
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 }
836 | EXTERN // "extern" as a symbol name
837 {
838 $$ = script_new_vers_pattern (closure, NULL, "extern",
839 sizeof("extern") - 1, 1);
840 }
841 | vers_defns ';' EXTERN
842 {
843 $$ = script_new_vers_pattern (closure, $1, "extern",
844 sizeof("extern") - 1, 1);
845 }
846 ;
847
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. */
850 string:
851 STRING
852 { $$ = $1; }
853 | QUOTED_STRING
854 { $$ = $1; }
855 ;
856
857 /* Some statements require a terminator, which may be a semicolon or a
858 comma. */
859 end:
860 ';'
861 | ','
862 ;
863
864 /* An optional semicolon. */
865 opt_semicolon:
866 ';'
867 | /* empty */
868 ;
869
870 /* An optional comma. */
871 opt_comma:
872 ','
873 | /* empty */
874 ;
875
876 %%
This page took 0.050029 seconds and 5 git commands to generate.