Don't pass around the target in order to define symbols; get it from
[external/binutils.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.  */
375 opt_fill:
376           '=' exp
377             { $$ = $2; }
378         | /* empty */
379             { $$ = NULL; }
380         ;
381
382 /* Commands which may appear within the description of an output
383    section in a SECTIONS block.  */
384 section_cmds:
385           /* empty */
386         | section_cmds section_cmd
387         ;
388
389 /* A command which may appear within the description of an output
390    section in a SECTIONS block.  */
391 section_cmd:
392           assignment end
393         | input_section_spec
394         | data_length '(' parse_exp ')'
395             { script_add_data(closure, $1, $3); }
396         | ASSERT_K '(' parse_exp ',' string ')'
397             { script_add_assertion(closure, $3, $5.value, $5.length); }
398         | FILL '(' parse_exp ')'
399             { script_add_fill(closure, $3); }
400         | CONSTRUCTORS
401             {
402               /* The GNU linker uses CONSTRUCTORS for the a.out object
403                  file format.  It does nothing when using ELF.  Since
404                  some ELF linker scripts use it although it does
405                  nothing, we accept it and ignore it.  */
406             }
407         | ';'
408         ;
409
410 /* The length of data which may appear within the description of an
411    output section in a SECTIONS block.  */
412 data_length:
413           QUAD
414             { $$ = QUAD; }
415         | SQUAD
416             { $$ = SQUAD; }
417         | LONG
418             { $$ = LONG; }
419         | SHORT
420             { $$ = SHORT; }
421         | BYTE
422             { $$ = BYTE; }
423         ;
424
425 /* An input section specification.  This may appear within the
426    description of an output section in a SECTIONS block.  */
427 input_section_spec:
428           input_section_no_keep
429             { script_add_input_section(closure, &$1, 0); }
430         | KEEP '(' input_section_no_keep ')'
431             { script_add_input_section(closure, &$3, 1); }
432         ;
433
434 /* An input section specification within a KEEP clause.  */
435 input_section_no_keep:
436           string
437             {
438               $$.file.name = $1;
439               $$.file.sort = SORT_WILDCARD_NONE;
440               $$.input_sections.sections = NULL;
441               $$.input_sections.exclude = NULL;
442             }
443         | wildcard_file '(' wildcard_sections ')'
444             {
445               $$.file = $1;
446               $$.input_sections = $3;
447             }
448         ;
449
450 /* A wildcard file specification.  */
451 wildcard_file:
452           wildcard_name
453             {
454               $$.name = $1;
455               $$.sort = SORT_WILDCARD_NONE;
456             }
457         | SORT_BY_NAME '(' wildcard_name ')'
458             {
459               $$.name = $3;
460               $$.sort = SORT_WILDCARD_BY_NAME;
461             }
462         ;
463
464 /* A list of wild card section specifications.  */
465 wildcard_sections:
466           wildcard_sections opt_comma wildcard_section
467             {
468               $$.sections = script_string_sort_list_add($1.sections, &$3);
469               $$.exclude = $1.exclude;
470             }
471         | wildcard_section
472             {
473               $$.sections = script_new_string_sort_list(&$1);
474               $$.exclude = NULL;
475             }
476         | wildcard_sections opt_comma EXCLUDE_FILE '(' exclude_names ')'
477             {
478               $$.sections = $1.sections;
479               $$.exclude = script_string_list_append($1.exclude, $5);
480             }
481         | EXCLUDE_FILE '(' exclude_names ')'
482             {
483               $$.sections = NULL;
484               $$.exclude = $3;
485             }
486         ;
487
488 /* A single wild card specification.  */
489 wildcard_section:
490           wildcard_name
491             {
492               $$.name = $1;
493               $$.sort = SORT_WILDCARD_NONE;
494             }
495         | SORT_BY_NAME '(' wildcard_section ')'
496             {
497               $$.name = $3.name;
498               switch ($3.sort)
499                 {
500                 case SORT_WILDCARD_NONE:
501                   $$.sort = SORT_WILDCARD_BY_NAME;
502                   break;
503                 case SORT_WILDCARD_BY_NAME:
504                 case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
505                   break;
506                 case SORT_WILDCARD_BY_ALIGNMENT:
507                 case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
508                   $$.sort = SORT_WILDCARD_BY_NAME_BY_ALIGNMENT;
509                   break;
510                 default:
511                   abort();
512                 }
513             }
514         | SORT_BY_ALIGNMENT '(' wildcard_section ')'
515             {
516               $$.name = $3.name;
517               switch ($3.sort)
518                 {
519                 case SORT_WILDCARD_NONE:
520                   $$.sort = SORT_WILDCARD_BY_ALIGNMENT;
521                   break;
522                 case SORT_WILDCARD_BY_ALIGNMENT:
523                 case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
524                   break;
525                 case SORT_WILDCARD_BY_NAME:
526                 case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
527                   $$.sort = SORT_WILDCARD_BY_ALIGNMENT_BY_NAME;
528                   break;
529                 default:
530                   abort();
531                 }
532             }
533         ;
534
535 /* A list of file names to exclude.  */
536 exclude_names:
537           exclude_names opt_comma wildcard_name
538             { $$ = script_string_list_push_back($1, $3.value, $3.length); }
539         | wildcard_name
540             { $$ = script_new_string_list($1.value, $1.length); }
541         ;
542
543 /* A single wildcard name.  We recognize '*' and '?' specially since
544    they are expression tokens.  */
545 wildcard_name:
546           string
547             { $$ = $1; }
548         | '*'
549             {
550               $$.value = "*";
551               $$.length = 1;
552             }
553         | '?'
554             {
555               $$.value = "?";
556               $$.length = 1;
557             }
558         ;
559
560 /* A command which may appear at the top level of a linker script, or
561    within a SECTIONS block.  */
562 file_or_sections_cmd:
563           ENTRY '(' string ')'
564             { script_set_entry(closure, $3.value, $3.length); }
565         | assignment end
566         | ASSERT_K '(' parse_exp ',' string ')'
567             { script_add_assertion(closure, $3, $5.value, $5.length); }
568         ;
569
570 /* Set a symbol to a value.  */
571 assignment:
572           string '=' parse_exp
573             { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
574         | string PLUSEQ parse_exp
575             {
576               Expression_ptr s = script_exp_string($1.value, $1.length);
577               Expression_ptr e = script_exp_binary_add(s, $3);
578               script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
579             }
580         | string MINUSEQ parse_exp
581             {
582               Expression_ptr s = script_exp_string($1.value, $1.length);
583               Expression_ptr e = script_exp_binary_sub(s, $3);
584               script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
585             }
586         | string MULTEQ parse_exp
587             {
588               Expression_ptr s = script_exp_string($1.value, $1.length);
589               Expression_ptr e = script_exp_binary_mult(s, $3);
590               script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
591             }
592         | string DIVEQ parse_exp
593             {
594               Expression_ptr s = script_exp_string($1.value, $1.length);
595               Expression_ptr e = script_exp_binary_div(s, $3);
596               script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
597             }
598         | string LSHIFTEQ parse_exp
599             {
600               Expression_ptr s = script_exp_string($1.value, $1.length);
601               Expression_ptr e = script_exp_binary_lshift(s, $3);
602               script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
603             }
604         | string RSHIFTEQ parse_exp
605             {
606               Expression_ptr s = script_exp_string($1.value, $1.length);
607               Expression_ptr e = script_exp_binary_rshift(s, $3);
608               script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
609             }
610         | string ANDEQ parse_exp
611             {
612               Expression_ptr s = script_exp_string($1.value, $1.length);
613               Expression_ptr e = script_exp_binary_bitwise_and(s, $3);
614               script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
615             }
616         | string OREQ parse_exp
617             {
618               Expression_ptr s = script_exp_string($1.value, $1.length);
619               Expression_ptr e = script_exp_binary_bitwise_or(s, $3);
620               script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
621             }
622         | PROVIDE '(' string '=' parse_exp ')'
623             { script_set_symbol(closure, $3.value, $3.length, $5, 1, 0); }
624         | PROVIDE_HIDDEN '(' string '=' parse_exp ')'
625             { script_set_symbol(closure, $3.value, $3.length, $5, 1, 1); }
626         ;
627
628 /* Parse an expression, putting the lexer into the right mode.  */
629 parse_exp:
630             { script_push_lex_into_expression_mode(closure); }
631           exp
632             {
633               script_pop_lex_mode(closure);
634               $$ = $2;
635             }
636         ;
637
638 /* An expression.  */
639 exp:
640           '(' exp ')'
641             { $$ = $2; }
642         | '-' exp %prec UNARY
643             { $$ = script_exp_unary_minus($2); }
644         | '!' exp %prec UNARY
645             { $$ = script_exp_unary_logical_not($2); }
646         | '~' exp %prec UNARY
647             { $$ = script_exp_unary_bitwise_not($2); }
648         | '+' exp %prec UNARY
649             { $$ = $2; }
650         | exp '*' exp
651             { $$ = script_exp_binary_mult($1, $3); }
652         | exp '/' exp
653             { $$ = script_exp_binary_div($1, $3); }
654         | exp '%' exp
655             { $$ = script_exp_binary_mod($1, $3); }
656         | exp '+' exp
657             { $$ = script_exp_binary_add($1, $3); }
658         | exp '-' exp
659             { $$ = script_exp_binary_sub($1, $3); }
660         | exp LSHIFT exp
661             { $$ = script_exp_binary_lshift($1, $3); }
662         | exp RSHIFT exp
663             { $$ = script_exp_binary_rshift($1, $3); }
664         | exp EQ exp
665             { $$ = script_exp_binary_eq($1, $3); }
666         | exp NE exp
667             { $$ = script_exp_binary_ne($1, $3); }
668         | exp LE exp
669             { $$ = script_exp_binary_le($1, $3); }
670         | exp GE exp
671             { $$ = script_exp_binary_ge($1, $3); }
672         | exp '<' exp
673             { $$ = script_exp_binary_lt($1, $3); }
674         | exp '>' exp
675             { $$ = script_exp_binary_gt($1, $3); }
676         | exp '&' exp
677             { $$ = script_exp_binary_bitwise_and($1, $3); }
678         | exp '^' exp
679             { $$ = script_exp_binary_bitwise_xor($1, $3); }
680         | exp '|' exp
681             { $$ = script_exp_binary_bitwise_or($1, $3); }
682         | exp ANDAND exp
683             { $$ = script_exp_binary_logical_and($1, $3); }
684         | exp OROR exp
685             { $$ = script_exp_binary_logical_or($1, $3); }
686         | exp '?' exp ':' exp
687             { $$ = script_exp_trinary_cond($1, $3, $5); }
688         | INTEGER
689             { $$ = script_exp_integer($1); }
690         | string
691             { $$ = script_exp_string($1.value, $1.length); }
692         | MAX_K '(' exp ',' exp ')'
693             { $$ = script_exp_function_max($3, $5); }
694         | MIN_K '(' exp ',' exp ')'
695             { $$ = script_exp_function_min($3, $5); }
696         | DEFINED '(' string ')'
697             { $$ = script_exp_function_defined($3.value, $3.length); }
698         | SIZEOF_HEADERS
699             { $$ = script_exp_function_sizeof_headers(); }
700         | ALIGNOF '(' string ')'
701             { $$ = script_exp_function_alignof($3.value, $3.length); }
702         | SIZEOF '(' string ')'
703             { $$ = script_exp_function_sizeof($3.value, $3.length); }
704         | ADDR '(' string ')'
705             { $$ = script_exp_function_addr($3.value, $3.length); }
706         | LOADADDR '(' string ')'
707             { $$ = script_exp_function_loadaddr($3.value, $3.length); }
708         | ORIGIN '(' string ')'
709             { $$ = script_exp_function_origin($3.value, $3.length); }
710         | LENGTH '(' string ')'
711             { $$ = script_exp_function_length($3.value, $3.length); }
712         | CONSTANT '(' string ')'
713             { $$ = script_exp_function_constant($3.value, $3.length); }
714         | ABSOLUTE '(' exp ')'
715             { $$ = script_exp_function_absolute($3); }
716         | ALIGN_K '(' exp ')'
717             { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
718         | ALIGN_K '(' exp ',' exp ')'
719             { $$ = script_exp_function_align($3, $5); }
720         | BLOCK '(' exp ')'
721             { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
722         | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
723             { $$ = script_exp_function_data_segment_align($3, $5); }
724         | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
725             { $$ = script_exp_function_data_segment_relro_end($3, $5); }
726         | DATA_SEGMENT_END '(' exp ')'
727             { $$ = script_exp_function_data_segment_end($3); }
728         | SEGMENT_START '(' string ',' exp ')'
729             {
730               $$ = script_exp_function_segment_start($3.value, $3.length, $5);
731             }
732         | ASSERT_K '(' exp ',' string ')'
733             { $$ = script_exp_function_assert($3, $5.value, $5.length); }
734         ;
735
736 /* Handle the --defsym option.  */
737 defsym_expr:
738           string '=' parse_exp
739             { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
740         ;
741
742 /* A version script.  */
743 version_script:
744           vers_nodes
745         ;
746
747 vers_nodes:
748           vers_node
749         | vers_nodes vers_node
750         ;
751
752 vers_node:
753           '{' vers_tag '}' ';'
754             {
755               script_register_vers_node (closure, NULL, 0, $2, NULL);
756             }
757         | string '{' vers_tag '}' ';'
758             {
759               script_register_vers_node (closure, $1.value, $1.length, $3,
760                                          NULL);
761             }
762         | string '{' vers_tag '}' verdep ';'
763             {
764               script_register_vers_node (closure, $1.value, $1.length, $3, $5);
765             }
766         ;
767
768 verdep:
769           string
770             {
771               $$ = script_add_vers_depend (closure, NULL, $1.value, $1.length);
772             }
773         | verdep string
774             {
775               $$ = script_add_vers_depend (closure, $1, $2.value, $2.length);
776             }
777         ;
778
779 vers_tag:
780           /* empty */
781             { $$ = script_new_vers_node (closure, NULL, NULL); }
782         | vers_defns ';'
783             { $$ = script_new_vers_node (closure, $1, NULL); }
784         | GLOBAL ':' vers_defns ';'
785             { $$ = script_new_vers_node (closure, $3, NULL); }
786         | LOCAL ':' vers_defns ';'
787             { $$ = script_new_vers_node (closure, NULL, $3); }
788         | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
789             { $$ = script_new_vers_node (closure, $3, $7); }
790         ;
791
792 /* Here is one of the rare places we care about the distinction
793    between STRING and QUOTED_STRING.  For QUOTED_STRING, we do exact
794    matching on the pattern, so we pass in true for the exact_match
795    parameter.  For STRING, we do glob matching and pass in false.  */
796 vers_defns:
797           STRING
798             {
799               $$ = script_new_vers_pattern (closure, NULL, $1.value,
800                                             $1.length, 0);
801             }
802         | QUOTED_STRING
803             {
804               $$ = script_new_vers_pattern (closure, NULL, $1.value,
805                                             $1.length, 1);
806             }
807         | vers_defns ';' STRING
808             {
809               $$ = script_new_vers_pattern (closure, $1, $3.value,
810                                             $3.length, 0);
811             }
812         | vers_defns ';' QUOTED_STRING
813             {
814               $$ = script_new_vers_pattern (closure, $1, $3.value,
815                                             $3.length, 1);
816             }
817         | /* Push string on the language stack. */
818           EXTERN string '{'
819             { version_script_push_lang (closure, $2.value, $2.length); }
820           vers_defns opt_semicolon '}'
821             {
822               $$ = $5;
823               version_script_pop_lang(closure);
824             }
825         | /* Push string on the language stack.  This is more complicated
826              than the other cases because we need to merge the linked-list
827              state from the pre-EXTERN defns and the post-EXTERN defns.  */
828           vers_defns ';' EXTERN string '{'
829             { version_script_push_lang (closure, $4.value, $4.length); }
830           vers_defns opt_semicolon '}'
831             {
832               $$ = script_merge_expressions ($1, $7);
833               version_script_pop_lang(closure);
834             }
835         | EXTERN  // "extern" as a symbol name
836             {
837               $$ = script_new_vers_pattern (closure, NULL, "extern",
838                                             sizeof("extern") - 1, 1);
839             }
840         | vers_defns ';' EXTERN
841             {
842               $$ = script_new_vers_pattern (closure, $1, "extern",
843                                             sizeof("extern") - 1, 1);
844             }
845         ;
846
847 /* A string can be either a STRING or a QUOTED_STRING.  Almost all the
848    time we don't care, and we use this rule.  */
849 string:
850           STRING
851             { $$ = $1; }
852         | QUOTED_STRING
853             { $$ = $1; }
854         ;
855
856 /* Some statements require a terminator, which may be a semicolon or a
857    comma.  */
858 end:
859           ';'
860         | ','
861         ;
862
863 /* An optional semicolon.  */
864 opt_semicolon:
865           ';'
866         |  /* empty */
867         ;
868
869 /* An optional comma.  */
870 opt_comma:
871           ','
872         | /* empty */
873         ;
874
875 %%