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