]>
Commit | Line | Data |
---|---|---|
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 <[email protected]>. |
5 | ||
6 | This file is part of gold. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 3 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
21 | MA 02110-1301, USA. */ | |
22 | ||
dbe717ef ILT |
23 | /* This is a bison grammar to parse a subset of the original GNU ld |
24 | linker script language. */ | |
25 | ||
26 | %{ | |
27 | ||
28 | #include "config.h" | |
29 | ||
30 | #include <stddef.h> | |
31 | #include <stdint.h> | |
494e05f4 | 32 | #include <stdlib.h> |
dbe717ef ILT |
33 | |
34 | #include "script-c.h" | |
35 | ||
36 | %} | |
37 | ||
38 | /* We need to use a pure parser because we might be multi-threaded. | |
39 | We pass some arguments through the parser to the lexer. */ | |
40 | ||
41 | %pure-parser | |
42 | ||
43 | %parse-param {void* closure} | |
44 | %lex-param {void* closure} | |
45 | ||
46 | /* Since we require bison anyhow, we take advantage of it. */ | |
47 | ||
48 | %error-verbose | |
49 | ||
50 | /* The values associated with tokens. */ | |
51 | ||
52 | %union { | |
e5756efb ILT |
53 | /* A string. */ |
54 | struct Parser_string string; | |
55 | /* A number. */ | |
56 | uint64_t integer; | |
57 | /* An expression. */ | |
58 | Expression_ptr expr; | |
494e05f4 ILT |
59 | /* An output section header. */ |
60 | struct Parser_output_section_header output_section_header; | |
61 | /* An output section trailer. */ | |
62 | struct Parser_output_section_trailer output_section_trailer; | |
63 | /* A complete input section specification. */ | |
64 | struct Input_section_spec input_section_spec; | |
65 | /* A list of wildcard specifications, with exclusions. */ | |
66 | struct Wildcard_sections wildcard_sections; | |
67 | /* A single wildcard specification. */ | |
68 | struct Wildcard_section wildcard_section; | |
69 | /* A list of strings. */ | |
70 | String_list_ptr string_list; | |
71 | /* Used for version scripts and within VERSION {}. */ | |
09124467 ILT |
72 | struct Version_dependency_list* deplist; |
73 | struct Version_expression_list* versyms; | |
74 | struct Version_tree* versnode; | |
dbe717ef ILT |
75 | } |
76 | ||
77 | /* Operators, including a precedence table for expressions. */ | |
78 | ||
79 | %right PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ | |
80 | %right '?' ':' | |
81 | %left OROR | |
82 | %left ANDAND | |
83 | %left '|' | |
84 | %left '^' | |
85 | %left '&' | |
86 | %left EQ NE | |
87 | %left '<' '>' LE GE | |
88 | %left LSHIFT RSHIFT | |
89 | %left '+' '-' | |
90 | %left '*' '/' '%' | |
91 | ||
e5756efb ILT |
92 | /* A fake operator used to indicate unary operator precedence. */ |
93 | %right UNARY | |
94 | ||
dbe717ef ILT |
95 | /* Constants. */ |
96 | ||
97 | %token <string> STRING | |
10600224 | 98 | %token <string> QUOTED_STRING |
dbe717ef ILT |
99 | %token <integer> INTEGER |
100 | ||
101 | /* Keywords. This list is taken from ldgram.y and ldlex.l in the old | |
102 | GNU linker, with the keywords which only appear in MRI mode | |
103 | removed. Not all these keywords are actually used in this grammar. | |
104 | In most cases the keyword is recognized as the token name in upper | |
105 | case. The comments indicate where this is not the case. */ | |
106 | ||
107 | %token ABSOLUTE | |
108 | %token ADDR | |
109 | %token ALIGN_K /* ALIGN */ | |
e5756efb | 110 | %token ALIGNOF |
dbe717ef ILT |
111 | %token ASSERT_K /* ASSERT */ |
112 | %token AS_NEEDED | |
113 | %token AT | |
114 | %token BIND | |
115 | %token BLOCK | |
116 | %token BYTE | |
117 | %token CONSTANT | |
118 | %token CONSTRUCTORS | |
dbe717ef ILT |
119 | %token CREATE_OBJECT_SYMBOLS |
120 | %token DATA_SEGMENT_ALIGN | |
121 | %token DATA_SEGMENT_END | |
122 | %token DATA_SEGMENT_RELRO_END | |
123 | %token DEFINED | |
dbe717ef ILT |
124 | %token ENTRY |
125 | %token EXCLUDE_FILE | |
126 | %token EXTERN | |
127 | %token FILL | |
128 | %token FLOAT | |
129 | %token FORCE_COMMON_ALLOCATION | |
130 | %token GLOBAL /* global */ | |
131 | %token GROUP | |
132 | %token HLL | |
133 | %token INCLUDE | |
dbe717ef ILT |
134 | %token INHIBIT_COMMON_ALLOCATION |
135 | %token INPUT | |
136 | %token KEEP | |
137 | %token LENGTH /* LENGTH, l, len */ | |
138 | %token LOADADDR | |
139 | %token LOCAL /* local */ | |
140 | %token LONG | |
141 | %token MAP | |
142 | %token MAX_K /* MAX */ | |
143 | %token MEMORY | |
144 | %token MIN_K /* MIN */ | |
145 | %token NEXT | |
146 | %token NOCROSSREFS | |
147 | %token NOFLOAT | |
dbe717ef ILT |
148 | %token ONLY_IF_RO |
149 | %token ONLY_IF_RW | |
150 | %token ORIGIN /* ORIGIN, o, org */ | |
151 | %token OUTPUT | |
152 | %token OUTPUT_ARCH | |
153 | %token OUTPUT_FORMAT | |
154 | %token OVERLAY | |
155 | %token PHDRS | |
156 | %token PROVIDE | |
157 | %token PROVIDE_HIDDEN | |
158 | %token QUAD | |
159 | %token SEARCH_DIR | |
160 | %token SECTIONS | |
161 | %token SEGMENT_START | |
162 | %token SHORT | |
163 | %token SIZEOF | |
164 | %token SIZEOF_HEADERS /* SIZEOF_HEADERS, sizeof_headers */ | |
165 | %token SORT_BY_ALIGNMENT | |
166 | %token SORT_BY_NAME | |
167 | %token SPECIAL | |
168 | %token SQUAD | |
169 | %token STARTUP | |
170 | %token SUBALIGN | |
171 | %token SYSLIB | |
172 | %token TARGET_K /* TARGET */ | |
173 | %token TRUNCATE | |
174 | %token VERSIONK /* VERSION */ | |
175 | ||
195e7dc6 ILT |
176 | /* Keywords, part 2. These are keywords that are unique to gold, |
177 | and not present in the old GNU linker. As before, unless the | |
178 | comments say otherwise, the keyword is recognized as the token | |
179 | name in upper case. */ | |
180 | ||
181 | %token OPTION | |
182 | ||
e5756efb ILT |
183 | /* Special tokens used to tell the grammar what type of tokens we are |
184 | parsing. The token stream always begins with one of these tokens. | |
185 | We do this because version scripts can appear embedded within | |
186 | linker scripts, and because --defsym uses the expression | |
187 | parser. */ | |
188 | %token PARSING_LINKER_SCRIPT | |
189 | %token PARSING_VERSION_SCRIPT | |
190 | %token PARSING_DEFSYM | |
191 | ||
192 | /* Non-terminal types, where needed. */ | |
193 | ||
494e05f4 ILT |
194 | %type <expr> parse_exp exp opt_address_and_section_type |
195 | %type <expr> opt_at opt_align opt_subalign opt_fill | |
196 | %type <output_section_header> section_header | |
197 | %type <output_section_trailer> section_trailer | |
198 | %type <integer> data_length | |
199 | %type <input_section_spec> input_section_no_keep | |
200 | %type <wildcard_sections> wildcard_sections | |
201 | %type <wildcard_section> wildcard_file wildcard_section | |
202 | %type <string_list> exclude_names | |
203 | %type <string> wildcard_name | |
09124467 ILT |
204 | %type <versyms> vers_defns |
205 | %type <versnode> vers_tag | |
206 | %type <deplist> verdep | |
10600224 | 207 | %type <string> string |
e5756efb | 208 | |
dbe717ef ILT |
209 | %% |
210 | ||
e5756efb ILT |
211 | /* Read the special token to see what to read next. */ |
212 | top: | |
213 | PARSING_LINKER_SCRIPT linker_script | |
214 | | PARSING_VERSION_SCRIPT version_script | |
215 | | PARSING_DEFSYM defsym_expr | |
216 | ; | |
217 | ||
d391083d | 218 | /* A file contains a list of commands. */ |
e5756efb ILT |
219 | linker_script: |
220 | linker_script file_cmd | |
dbe717ef ILT |
221 | | /* empty */ |
222 | ; | |
223 | ||
d391083d | 224 | /* A command which may appear at top level of a linker script. */ |
dbe717ef | 225 | file_cmd: |
2dd3e587 | 226 | GROUP |
dbe717ef ILT |
227 | { script_start_group(closure); } |
228 | '(' input_list ')' | |
229 | { script_end_group(closure); } | |
10600224 | 230 | | OPTION '(' string ')' |
e5756efb | 231 | { script_parse_option(closure, $3.value, $3.length); } |
494e05f4 ILT |
232 | | SECTIONS '{' |
233 | { script_start_sections(closure); } | |
234 | sections_block '}' | |
235 | { script_finish_sections(closure); } | |
09124467 ILT |
236 | | VERSIONK '{' |
237 | { script_push_lex_into_version_mode(closure); } | |
238 | version_script '}' | |
239 | { script_pop_lex_mode(closure); } | |
d391083d | 240 | | file_or_sections_cmd |
2dd3e587 ILT |
241 | | ignore_cmd |
242 | ; | |
243 | ||
244 | /* Top level commands which we ignore. The GNU linker uses these to | |
245 | select the output format, but we don't offer a choice. Ignoring | |
246 | these is more-or-less OK since most scripts simply explicitly | |
247 | choose the default. */ | |
248 | ignore_cmd: | |
10600224 ILT |
249 | OUTPUT_FORMAT '(' string ')' |
250 | | OUTPUT_FORMAT '(' string ',' string ',' string ')' | |
251 | | OUTPUT_ARCH '(' string ')' | |
dbe717ef ILT |
252 | ; |
253 | ||
d391083d | 254 | /* A list of input file names. */ |
dbe717ef ILT |
255 | input_list: |
256 | input_list_element | |
257 | | input_list opt_comma input_list_element | |
258 | ; | |
259 | ||
d391083d | 260 | /* An input file name. */ |
dbe717ef | 261 | input_list_element: |
10600224 | 262 | string |
e5756efb | 263 | { script_add_file(closure, $1.value, $1.length); } |
dbe717ef ILT |
264 | | AS_NEEDED |
265 | { script_start_as_needed(closure); } | |
266 | '(' input_list ')' | |
267 | { script_end_as_needed(closure); } | |
268 | ; | |
269 | ||
494e05f4 ILT |
270 | /* Commands in a SECTIONS block. */ |
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 | ||
d391083d ILT |
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: | |
10600224 | 563 | ENTRY '(' string ')' |
e5756efb ILT |
564 | { script_set_entry(closure, $3.value, $3.length); } |
565 | | assignment end | |
494e05f4 ILT |
566 | | ASSERT_K '(' parse_exp ',' STRING ')' |
567 | { script_add_assertion(closure, $3, $5.value, $5.length); } | |
e5756efb ILT |
568 | ; |
569 | ||
570 | /* Set a symbol to a value. */ | |
571 | assignment: | |
10600224 | 572 | string '=' parse_exp |
e5756efb | 573 | { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); } |
10600224 | 574 | | string PLUSEQ parse_exp |
e5756efb ILT |
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 | } | |
10600224 | 580 | | string MINUSEQ parse_exp |
e5756efb ILT |
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 | } | |
10600224 | 586 | | string MULTEQ parse_exp |
e5756efb ILT |
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 | } | |
10600224 | 592 | | string DIVEQ parse_exp |
e5756efb ILT |
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 | } | |
10600224 | 598 | | string LSHIFTEQ parse_exp |
e5756efb ILT |
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 | } | |
10600224 | 604 | | string RSHIFTEQ parse_exp |
e5756efb ILT |
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 | } | |
10600224 | 610 | | string ANDEQ parse_exp |
e5756efb ILT |
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 | } | |
10600224 | 616 | | string OREQ parse_exp |
e5756efb ILT |
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 | } | |
10600224 | 622 | | PROVIDE '(' string '=' parse_exp ')' |
e5756efb | 623 | { script_set_symbol(closure, $3.value, $3.length, $5, 1, 0); } |
10600224 | 624 | | PROVIDE_HIDDEN '(' string '=' parse_exp ')' |
e5756efb ILT |
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); } | |
10600224 ILT |
692 | | QUOTED_STRING |
693 | { $$ = script_exp_string($1.value, $1.length); } | |
e5756efb ILT |
694 | | MAX_K '(' exp ',' exp ')' |
695 | { $$ = script_exp_function_max($3, $5); } | |
696 | | MIN_K '(' exp ',' exp ')' | |
697 | { $$ = script_exp_function_min($3, $5); } | |
10600224 | 698 | | DEFINED '(' string ')' |
e5756efb ILT |
699 | { $$ = script_exp_function_defined($3.value, $3.length); } |
700 | | SIZEOF_HEADERS | |
701 | { $$ = script_exp_function_sizeof_headers(); } | |
10600224 | 702 | | ALIGNOF '(' string ')' |
e5756efb | 703 | { $$ = script_exp_function_alignof($3.value, $3.length); } |
10600224 | 704 | | SIZEOF '(' string ')' |
e5756efb | 705 | { $$ = script_exp_function_sizeof($3.value, $3.length); } |
10600224 | 706 | | ADDR '(' string ')' |
e5756efb | 707 | { $$ = script_exp_function_addr($3.value, $3.length); } |
10600224 | 708 | | LOADADDR '(' string ')' |
e5756efb | 709 | { $$ = script_exp_function_loadaddr($3.value, $3.length); } |
10600224 | 710 | | ORIGIN '(' string ')' |
e5756efb | 711 | { $$ = script_exp_function_origin($3.value, $3.length); } |
10600224 | 712 | | LENGTH '(' string ')' |
e5756efb | 713 | { $$ = script_exp_function_length($3.value, $3.length); } |
10600224 | 714 | | CONSTANT '(' string ')' |
e5756efb ILT |
715 | { $$ = script_exp_function_constant($3.value, $3.length); } |
716 | | ABSOLUTE '(' exp ')' | |
717 | { $$ = script_exp_function_absolute($3); } | |
718 | | ALIGN_K '(' exp ')' | |
719 | { $$ = script_exp_function_align(script_exp_string(".", 1), $3); } | |
720 | | ALIGN_K '(' exp ',' exp ')' | |
721 | { $$ = script_exp_function_align($3, $5); } | |
722 | | BLOCK '(' exp ')' | |
723 | { $$ = script_exp_function_align(script_exp_string(".", 1), $3); } | |
724 | | DATA_SEGMENT_ALIGN '(' exp ',' exp ')' | |
725 | { $$ = script_exp_function_data_segment_align($3, $5); } | |
726 | | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')' | |
727 | { $$ = script_exp_function_data_segment_relro_end($3, $5); } | |
728 | | DATA_SEGMENT_END '(' exp ')' | |
729 | { $$ = script_exp_function_data_segment_end($3); } | |
10600224 | 730 | | SEGMENT_START '(' string ',' exp ')' |
e5756efb ILT |
731 | { |
732 | $$ = script_exp_function_segment_start($3.value, $3.length, $5); | |
733 | } | |
10600224 | 734 | | ASSERT_K '(' exp ',' string ')' |
e5756efb ILT |
735 | { $$ = script_exp_function_assert($3, $5.value, $5.length); } |
736 | ; | |
737 | ||
738 | /* Handle the --defsym option. */ | |
739 | defsym_expr: | |
10600224 | 740 | string '=' parse_exp |
e5756efb ILT |
741 | { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); } |
742 | ; | |
743 | ||
09124467 | 744 | /* A version script. */ |
e5756efb | 745 | version_script: |
09124467 ILT |
746 | vers_nodes |
747 | ; | |
748 | ||
749 | vers_nodes: | |
750 | vers_node | |
751 | | vers_nodes vers_node | |
752 | ; | |
753 | ||
754 | vers_node: | |
755 | '{' vers_tag '}' ';' | |
756 | { | |
757 | script_register_vers_node (closure, NULL, 0, $2, NULL); | |
758 | } | |
10600224 | 759 | | string '{' vers_tag '}' ';' |
09124467 ILT |
760 | { |
761 | script_register_vers_node (closure, $1.value, $1.length, $3, | |
762 | NULL); | |
763 | } | |
10600224 | 764 | | string '{' vers_tag '}' verdep ';' |
09124467 ILT |
765 | { |
766 | script_register_vers_node (closure, $1.value, $1.length, $3, $5); | |
767 | } | |
768 | ; | |
769 | ||
770 | verdep: | |
10600224 | 771 | string |
09124467 ILT |
772 | { |
773 | $$ = script_add_vers_depend (closure, NULL, $1.value, $1.length); | |
774 | } | |
10600224 | 775 | | verdep string |
09124467 ILT |
776 | { |
777 | $$ = script_add_vers_depend (closure, $1, $2.value, $2.length); | |
778 | } | |
779 | ; | |
780 | ||
781 | vers_tag: | |
782 | /* empty */ | |
783 | { $$ = script_new_vers_node (closure, NULL, NULL); } | |
784 | | vers_defns ';' | |
785 | { $$ = script_new_vers_node (closure, $1, NULL); } | |
786 | | GLOBAL ':' vers_defns ';' | |
787 | { $$ = script_new_vers_node (closure, $3, NULL); } | |
788 | | LOCAL ':' vers_defns ';' | |
789 | { $$ = script_new_vers_node (closure, NULL, $3); } | |
790 | | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';' | |
791 | { $$ = script_new_vers_node (closure, $3, $7); } | |
792 | ; | |
793 | ||
10600224 ILT |
794 | /* Here is one of the rare places we care about the distinction |
795 | between STRING and QUOTED_STRING. For QUOTED_STRING, we do exact | |
796 | matching on the pattern, so we pass in true for the exact_match | |
797 | parameter. For STRING, we do glob matching and pass in false. */ | |
09124467 ILT |
798 | vers_defns: |
799 | STRING | |
800 | { | |
801 | $$ = script_new_vers_pattern (closure, NULL, $1.value, | |
10600224 ILT |
802 | $1.length, 0); |
803 | } | |
804 | | QUOTED_STRING | |
805 | { | |
806 | $$ = script_new_vers_pattern (closure, NULL, $1.value, | |
807 | $1.length, 1); | |
09124467 ILT |
808 | } |
809 | | vers_defns ';' STRING | |
810 | { | |
10600224 ILT |
811 | $$ = script_new_vers_pattern (closure, $1, $3.value, |
812 | $3.length, 0); | |
813 | } | |
814 | | vers_defns ';' QUOTED_STRING | |
815 | { | |
816 | $$ = script_new_vers_pattern (closure, $1, $3.value, | |
817 | $3.length, 1); | |
09124467 | 818 | } |
10600224 ILT |
819 | | /* Push string on the language stack. */ |
820 | EXTERN string '{' | |
821 | { version_script_push_lang (closure, $2.value, $2.length); } | |
09124467 ILT |
822 | vers_defns opt_semicolon '}' |
823 | { | |
824 | $$ = $5; | |
825 | version_script_pop_lang(closure); | |
826 | } | |
10600224 ILT |
827 | | /* Push string on the language stack. This is more complicated |
828 | than the other cases because we need to merge the linked-list | |
829 | state from the pre-EXTERN defns and the post-EXTERN defns. */ | |
830 | vers_defns ';' EXTERN string '{' | |
831 | { version_script_push_lang (closure, $4.value, $4.length); } | |
832 | vers_defns opt_semicolon '}' | |
833 | { | |
834 | $$ = script_merge_expressions ($1, $7); | |
835 | version_script_pop_lang(closure); | |
836 | } | |
09124467 ILT |
837 | | EXTERN // "extern" as a symbol name |
838 | { | |
839 | $$ = script_new_vers_pattern (closure, NULL, "extern", | |
10600224 | 840 | sizeof("extern") - 1, 1); |
09124467 ILT |
841 | } |
842 | | vers_defns ';' EXTERN | |
843 | { | |
844 | $$ = script_new_vers_pattern (closure, $1, "extern", | |
10600224 | 845 | sizeof("extern") - 1, 1); |
09124467 | 846 | } |
e5756efb ILT |
847 | ; |
848 | ||
10600224 ILT |
849 | /* A string can be either a STRING or a QUOTED_STRING. Almost all the |
850 | time we don't care, and we use this rule. */ | |
851 | string: | |
852 | STRING | |
853 | { $$ = $1; } | |
854 | | QUOTED_STRING | |
855 | { $$ = $1; } | |
856 | ; | |
857 | ||
e5756efb ILT |
858 | /* Some statements require a terminator, which may be a semicolon or a |
859 | comma. */ | |
860 | end: | |
861 | ';' | |
862 | | ',' | |
d391083d ILT |
863 | ; |
864 | ||
09124467 ILT |
865 | /* An optional semicolon. */ |
866 | opt_semicolon: | |
867 | ';' | |
868 | | /* empty */ | |
869 | ; | |
870 | ||
d391083d | 871 | /* An optional comma. */ |
dbe717ef ILT |
872 | opt_comma: |
873 | ',' | |
874 | | /* empty */ | |
875 | ; | |
876 | ||
877 | %% |