Commit | Line | Data |
---|---|---|
8e5a525c AM |
1 | /* A YACC grammar to parse a superset of the AT&T linker scripting language. |
2 | Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, | |
3 | 2001 Free Software Foundation, Inc. | |
252b5132 RH |
4 | Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com). |
5 | ||
6 | This file is part of GNU ld. | |
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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | %{ | |
23 | /* | |
24 | ||
25 | */ | |
26 | ||
27 | #define DONTDECLARE_MALLOC | |
28 | ||
29 | #include "bfd.h" | |
30 | #include "sysdep.h" | |
31 | #include "bfdlink.h" | |
32 | #include "ld.h" | |
33 | #include "ldexp.h" | |
34 | #include "ldver.h" | |
35 | #include "ldlang.h" | |
252b5132 | 36 | #include "ldfile.h" |
b71e2778 | 37 | #include "ldemul.h" |
252b5132 RH |
38 | #include "ldmisc.h" |
39 | #include "ldmain.h" | |
40 | #include "mri.h" | |
41 | #include "ldctor.h" | |
42 | #include "ldlex.h" | |
43 | ||
44 | #ifndef YYDEBUG | |
45 | #define YYDEBUG 1 | |
46 | #endif | |
47 | ||
48 | static enum section_type sectype; | |
49 | ||
50 | lang_memory_region_type *region; | |
51 | ||
252b5132 | 52 | boolean ldgram_want_filename = true; |
b90e1c6f | 53 | FILE * saved_script_handle = NULL; |
252b5132 RH |
54 | boolean force_make_executable = false; |
55 | ||
56 | boolean ldgram_in_script = false; | |
57 | boolean ldgram_had_equals = false; | |
58 | boolean ldgram_had_keep = false; | |
59 | char *ldgram_vers_current_lang = NULL; | |
60 | ||
61 | #define ERROR_NAME_MAX 20 | |
62 | static char *error_names[ERROR_NAME_MAX]; | |
63 | static int error_index; | |
64 | #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++; | |
65 | #define POP_ERROR() error_index--; | |
66 | %} | |
67 | %union { | |
68 | bfd_vma integer; | |
69 | char *name; | |
70 | const char *cname; | |
71 | struct wildcard_spec wildcard; | |
b6bf44ba | 72 | struct wildcard_list *wildcard_list; |
18625d54 | 73 | struct name_list *name_list; |
252b5132 RH |
74 | int token; |
75 | union etree_union *etree; | |
76 | struct phdr_info | |
77 | { | |
78 | boolean filehdr; | |
79 | boolean phdrs; | |
80 | union etree_union *at; | |
81 | union etree_union *flags; | |
82 | } phdr; | |
83 | struct lang_nocrossref *nocrossref; | |
84 | struct lang_output_section_phdr_list *section_phdr; | |
85 | struct bfd_elf_version_deps *deflist; | |
86 | struct bfd_elf_version_expr *versyms; | |
87 | struct bfd_elf_version_tree *versnode; | |
88 | } | |
89 | ||
90 | %type <etree> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val | |
91 | %type <etree> opt_exp_without_type | |
92 | %type <integer> fill_opt | |
18625d54 | 93 | %type <name_list> exclude_name_list |
b6bf44ba | 94 | %type <wildcard_list> file_NAME_list |
252b5132 | 95 | %type <name> memspec_opt casesymlist |
562d3460 | 96 | %type <name> memspec_at_opt |
252b5132 RH |
97 | %type <cname> wildcard_name |
98 | %type <wildcard> wildcard_spec | |
99 | %token <integer> INT | |
100 | %token <name> NAME LNAME | |
101 | %type <integer> length | |
102 | %type <phdr> phdr_qualifiers | |
103 | %type <nocrossref> nocrossref_list | |
104 | %type <section_phdr> phdr_opt | |
105 | %type <integer> opt_nocrossrefs | |
106 | ||
107 | %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ | |
108 | %right <token> '?' ':' | |
109 | %left <token> OROR | |
110 | %left <token> ANDAND | |
111 | %left <token> '|' | |
112 | %left <token> '^' | |
113 | %left <token> '&' | |
114 | %left <token> EQ NE | |
115 | %left <token> '<' '>' LE GE | |
116 | %left <token> LSHIFT RSHIFT | |
117 | ||
118 | %left <token> '+' '-' | |
119 | %left <token> '*' '/' '%' | |
120 | ||
121 | %right UNARY | |
122 | %token END | |
123 | %left <token> '(' | |
124 | %token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE | |
125 | %token SECTIONS PHDRS SORT | |
126 | %token '{' '}' | |
127 | %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH | |
128 | %token SIZEOF_HEADERS | |
129 | %token INCLUDE | |
130 | %token MEMORY DEFSYMEND | |
131 | %token NOLOAD DSECT COPY INFO OVERLAY | |
132 | %token NAME LNAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY | |
133 | %token <integer> NEXT | |
134 | %token SIZEOF ADDR LOADADDR MAX_K MIN_K | |
135 | %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS | |
136 | %token ORIGIN FILL | |
137 | %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS | |
138 | %token ALIGNMOD AT PROVIDE | |
aa8804e4 | 139 | %type <token> assign_op atype attributes_opt |
252b5132 RH |
140 | %type <name> filename |
141 | %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K | |
142 | %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL | |
143 | %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START | |
144 | %token <name> VERS_TAG VERS_IDENTIFIER | |
145 | %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT | |
146 | %token KEEP | |
147 | %token EXCLUDE_FILE | |
148 | %type <versyms> vers_defns | |
149 | %type <versnode> vers_tag | |
150 | %type <deflist> verdep | |
151 | ||
152 | %% | |
153 | ||
154 | file: | |
155 | INPUT_SCRIPT script_file | |
156 | | INPUT_MRI_SCRIPT mri_script_file | |
157 | | INPUT_VERSION_SCRIPT version_script_file | |
158 | | INPUT_DEFSYM defsym_expr | |
159 | ; | |
160 | ||
161 | ||
162 | filename: NAME; | |
163 | ||
164 | ||
165 | defsym_expr: | |
166 | { ldlex_defsym(); } | |
167 | NAME '=' exp | |
168 | { | |
169 | ldlex_popstate(); | |
170 | lang_add_assignment(exp_assop($3,$2,$4)); | |
171 | } | |
172 | ||
173 | /* SYNTAX WITHIN AN MRI SCRIPT FILE */ | |
174 | mri_script_file: | |
175 | { | |
176 | ldlex_mri_script (); | |
177 | PUSH_ERROR (_("MRI style script")); | |
178 | } | |
179 | mri_script_lines | |
180 | { | |
181 | ldlex_popstate (); | |
182 | mri_draw_tree (); | |
183 | POP_ERROR (); | |
184 | } | |
185 | ; | |
186 | ||
187 | mri_script_lines: | |
188 | mri_script_lines mri_script_command NEWLINE | |
189 | | | |
190 | ; | |
191 | ||
192 | mri_script_command: | |
193 | CHIP exp | |
194 | | CHIP exp ',' exp | |
195 | | NAME { | |
196 | einfo(_("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1); | |
197 | } | |
198 | | LIST { | |
199 | config.map_filename = "-"; | |
200 | } | |
201 | | ORDER ordernamelist | |
202 | | ENDWORD | |
203 | | PUBLIC NAME '=' exp | |
204 | { mri_public($2, $4); } | |
205 | | PUBLIC NAME ',' exp | |
206 | { mri_public($2, $4); } | |
207 | | PUBLIC NAME exp | |
208 | { mri_public($2, $3); } | |
209 | | FORMAT NAME | |
210 | { mri_format($2); } | |
211 | | SECT NAME ',' exp | |
212 | { mri_output_section($2, $4);} | |
213 | | SECT NAME exp | |
214 | { mri_output_section($2, $3);} | |
215 | | SECT NAME '=' exp | |
216 | { mri_output_section($2, $4);} | |
217 | | ALIGN_K NAME '=' exp | |
218 | { mri_align($2,$4); } | |
219 | | ALIGN_K NAME ',' exp | |
220 | { mri_align($2,$4); } | |
221 | | ALIGNMOD NAME '=' exp | |
222 | { mri_alignmod($2,$4); } | |
223 | | ALIGNMOD NAME ',' exp | |
224 | { mri_alignmod($2,$4); } | |
225 | | ABSOLUTE mri_abs_name_list | |
226 | | LOAD mri_load_name_list | |
227 | | NAMEWORD NAME | |
228 | { mri_name($2); } | |
229 | | ALIAS NAME ',' NAME | |
230 | { mri_alias($2,$4,0);} | |
231 | | ALIAS NAME ',' INT | |
232 | { mri_alias($2,0,(int) $4);} | |
233 | | BASE exp | |
234 | { mri_base($2); } | |
235 | | TRUNCATE INT | |
236 | { mri_truncate((unsigned int) $2); } | |
237 | | CASE casesymlist | |
238 | | EXTERN extern_name_list | |
239 | | INCLUDE filename | |
240 | { ldfile_open_command_file ($2); } mri_script_lines END | |
241 | | START NAME | |
242 | { lang_add_entry ($2, false); } | |
243 | | | |
244 | ; | |
245 | ||
246 | ordernamelist: | |
247 | ordernamelist ',' NAME { mri_order($3); } | |
248 | | ordernamelist NAME { mri_order($2); } | |
249 | | | |
250 | ; | |
251 | ||
252 | mri_load_name_list: | |
253 | NAME | |
254 | { mri_load($1); } | |
255 | | mri_load_name_list ',' NAME { mri_load($3); } | |
256 | ; | |
257 | ||
258 | mri_abs_name_list: | |
259 | NAME | |
260 | { mri_only_load($1); } | |
261 | | mri_abs_name_list ',' NAME | |
262 | { mri_only_load($3); } | |
263 | ; | |
264 | ||
265 | casesymlist: | |
266 | /* empty */ { $$ = NULL; } | |
267 | | NAME | |
268 | | casesymlist ',' NAME | |
269 | ; | |
270 | ||
271 | extern_name_list: | |
272 | NAME | |
273 | { ldlang_add_undef ($1); } | |
274 | | extern_name_list NAME | |
275 | { ldlang_add_undef ($2); } | |
276 | | extern_name_list ',' NAME | |
277 | { ldlang_add_undef ($3); } | |
278 | ; | |
279 | ||
280 | script_file: | |
281 | { | |
282 | ldlex_both(); | |
283 | } | |
284 | ifile_list | |
285 | { | |
286 | ldlex_popstate(); | |
287 | } | |
288 | ; | |
289 | ||
290 | ||
291 | ifile_list: | |
292 | ifile_list ifile_p1 | |
293 | | | |
294 | ; | |
295 | ||
296 | ||
297 | ||
298 | ifile_p1: | |
299 | memory | |
300 | | sections | |
301 | | phdrs | |
302 | | startup | |
303 | | high_level_library | |
304 | | low_level_library | |
305 | | floating_point_support | |
306 | | statement_anywhere | |
307 | | version | |
308 | | ';' | |
309 | | TARGET_K '(' NAME ')' | |
310 | { lang_add_target($3); } | |
311 | | SEARCH_DIR '(' filename ')' | |
312 | { ldfile_add_library_path ($3, false); } | |
313 | | OUTPUT '(' filename ')' | |
314 | { lang_add_output($3, 1); } | |
315 | | OUTPUT_FORMAT '(' NAME ')' | |
316 | { lang_add_output_format ($3, (char *) NULL, | |
317 | (char *) NULL, 1); } | |
318 | | OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')' | |
319 | { lang_add_output_format ($3, $5, $7, 1); } | |
320 | | OUTPUT_ARCH '(' NAME ')' | |
321 | { ldfile_set_output_arch($3); } | |
322 | | FORCE_COMMON_ALLOCATION | |
323 | { command_line.force_common_definition = true ; } | |
324 | | INPUT '(' input_list ')' | |
325 | | GROUP | |
326 | { lang_enter_group (); } | |
327 | '(' input_list ')' | |
328 | { lang_leave_group (); } | |
329 | | MAP '(' filename ')' | |
330 | { lang_add_map($3); } | |
331 | | INCLUDE filename | |
332 | { ldfile_open_command_file($2); } ifile_list END | |
333 | | NOCROSSREFS '(' nocrossref_list ')' | |
334 | { | |
335 | lang_add_nocrossref ($3); | |
336 | } | |
337 | | EXTERN '(' extern_name_list ')' | |
338 | ; | |
339 | ||
340 | input_list: | |
341 | NAME | |
342 | { lang_add_input_file($1,lang_input_file_is_search_file_enum, | |
343 | (char *)NULL); } | |
344 | | input_list ',' NAME | |
345 | { lang_add_input_file($3,lang_input_file_is_search_file_enum, | |
346 | (char *)NULL); } | |
347 | | input_list NAME | |
348 | { lang_add_input_file($2,lang_input_file_is_search_file_enum, | |
349 | (char *)NULL); } | |
350 | | LNAME | |
351 | { lang_add_input_file($1,lang_input_file_is_l_enum, | |
352 | (char *)NULL); } | |
353 | | input_list ',' LNAME | |
354 | { lang_add_input_file($3,lang_input_file_is_l_enum, | |
355 | (char *)NULL); } | |
356 | | input_list LNAME | |
357 | { lang_add_input_file($2,lang_input_file_is_l_enum, | |
358 | (char *)NULL); } | |
359 | ; | |
360 | ||
361 | sections: | |
362 | SECTIONS '{' sec_or_group_p1 '}' | |
363 | ; | |
364 | ||
365 | sec_or_group_p1: | |
366 | sec_or_group_p1 section | |
367 | | sec_or_group_p1 statement_anywhere | |
368 | | | |
369 | ; | |
370 | ||
371 | statement_anywhere: | |
372 | ENTRY '(' NAME ')' | |
373 | { lang_add_entry ($3, false); } | |
374 | | assignment end | |
375 | ; | |
376 | ||
377 | /* The '*' and '?' cases are there because the lexer returns them as | |
378 | separate tokens rather than as NAME. */ | |
379 | wildcard_name: | |
380 | NAME | |
381 | { | |
382 | $$ = $1; | |
383 | } | |
384 | | '*' | |
385 | { | |
386 | $$ = "*"; | |
387 | } | |
388 | | '?' | |
389 | { | |
390 | $$ = "?"; | |
391 | } | |
392 | ; | |
393 | ||
394 | wildcard_spec: | |
395 | wildcard_name | |
396 | { | |
397 | $$.name = $1; | |
398 | $$.sorted = false; | |
18625d54 | 399 | $$.exclude_name_list = NULL; |
252b5132 | 400 | } |
18625d54 | 401 | | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name |
252b5132 RH |
402 | { |
403 | $$.name = $5; | |
404 | $$.sorted = false; | |
18625d54 | 405 | $$.exclude_name_list = $3; |
252b5132 RH |
406 | } |
407 | | SORT '(' wildcard_name ')' | |
408 | { | |
409 | $$.name = $3; | |
410 | $$.sorted = true; | |
18625d54 | 411 | $$.exclude_name_list = NULL; |
252b5132 | 412 | } |
18625d54 | 413 | | SORT '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')' |
252b5132 RH |
414 | { |
415 | $$.name = $7; | |
416 | $$.sorted = true; | |
18625d54 | 417 | $$.exclude_name_list = $5; |
252b5132 RH |
418 | } |
419 | ; | |
420 | ||
18625d54 | 421 | exclude_name_list: |
765b7cbe | 422 | exclude_name_list wildcard_name |
18625d54 CM |
423 | { |
424 | struct name_list *tmp; | |
425 | tmp = (struct name_list *) xmalloc (sizeof *tmp); | |
765b7cbe | 426 | tmp->name = $2; |
18625d54 CM |
427 | tmp->next = $1; |
428 | $$ = tmp; | |
429 | } | |
430 | | | |
431 | wildcard_name | |
432 | { | |
433 | struct name_list *tmp; | |
434 | tmp = (struct name_list *) xmalloc (sizeof *tmp); | |
435 | tmp->name = $1; | |
436 | tmp->next = NULL; | |
437 | $$ = tmp; | |
438 | } | |
439 | ; | |
440 | ||
252b5132 | 441 | file_NAME_list: |
b6bf44ba | 442 | file_NAME_list opt_comma wildcard_spec |
252b5132 | 443 | { |
b6bf44ba AM |
444 | struct wildcard_list *tmp; |
445 | tmp = (struct wildcard_list *) xmalloc (sizeof *tmp); | |
446 | tmp->next = $1; | |
447 | tmp->spec = $3; | |
448 | $$ = tmp; | |
252b5132 | 449 | } |
b6bf44ba AM |
450 | | |
451 | wildcard_spec | |
252b5132 | 452 | { |
b6bf44ba AM |
453 | struct wildcard_list *tmp; |
454 | tmp = (struct wildcard_list *) xmalloc (sizeof *tmp); | |
455 | tmp->next = NULL; | |
456 | tmp->spec = $1; | |
457 | $$ = tmp; | |
252b5132 RH |
458 | } |
459 | ; | |
460 | ||
461 | input_section_spec_no_keep: | |
462 | NAME | |
463 | { | |
b6bf44ba AM |
464 | struct wildcard_spec tmp; |
465 | tmp.name = $1; | |
466 | tmp.exclude_name_list = NULL; | |
467 | tmp.sorted = false; | |
468 | lang_add_wild (&tmp, NULL, ldgram_had_keep); | |
252b5132 | 469 | } |
b6bf44ba | 470 | | '[' file_NAME_list ']' |
252b5132 | 471 | { |
b6bf44ba | 472 | lang_add_wild (NULL, $2, ldgram_had_keep); |
252b5132 | 473 | } |
b6bf44ba | 474 | | wildcard_spec '(' file_NAME_list ')' |
252b5132 | 475 | { |
b6bf44ba | 476 | lang_add_wild (&$1, $3, ldgram_had_keep); |
252b5132 | 477 | } |
252b5132 RH |
478 | ; |
479 | ||
480 | input_section_spec: | |
481 | input_section_spec_no_keep | |
482 | | KEEP '(' | |
483 | { ldgram_had_keep = true; } | |
484 | input_section_spec_no_keep ')' | |
485 | { ldgram_had_keep = false; } | |
486 | ; | |
487 | ||
488 | statement: | |
489 | assignment end | |
490 | | CREATE_OBJECT_SYMBOLS | |
491 | { | |
492 | lang_add_attribute(lang_object_symbols_statement_enum); | |
493 | } | |
494 | | ';' | |
495 | | CONSTRUCTORS | |
496 | { | |
497 | ||
498 | lang_add_attribute(lang_constructors_statement_enum); | |
499 | } | |
500 | | SORT '(' CONSTRUCTORS ')' | |
501 | { | |
502 | constructors_sorted = true; | |
503 | lang_add_attribute (lang_constructors_statement_enum); | |
504 | } | |
505 | | input_section_spec | |
506 | | length '(' mustbe_exp ')' | |
507 | { | |
508 | lang_add_data((int) $1,$3); | |
509 | } | |
510 | ||
511 | | FILL '(' mustbe_exp ')' | |
512 | { | |
513 | lang_add_fill | |
514 | (exp_get_value_int($3, | |
515 | 0, | |
516 | "fill value", | |
517 | lang_first_phase_enum)); | |
518 | } | |
519 | ; | |
520 | ||
521 | statement_list: | |
522 | statement_list statement | |
523 | | statement | |
524 | ; | |
525 | ||
526 | statement_list_opt: | |
527 | /* empty */ | |
528 | | statement_list | |
529 | ; | |
530 | ||
531 | length: | |
532 | QUAD | |
533 | { $$ = $1; } | |
534 | | SQUAD | |
535 | { $$ = $1; } | |
536 | | LONG | |
537 | { $$ = $1; } | |
538 | | SHORT | |
539 | { $$ = $1; } | |
540 | | BYTE | |
541 | { $$ = $1; } | |
542 | ; | |
543 | ||
544 | fill_opt: | |
545 | '=' mustbe_exp | |
546 | { | |
547 | $$ = exp_get_value_int($2, | |
548 | 0, | |
549 | "fill value", | |
550 | lang_first_phase_enum); | |
551 | } | |
552 | | { $$ = 0; } | |
553 | ; | |
554 | ||
555 | ||
556 | ||
557 | assign_op: | |
558 | PLUSEQ | |
559 | { $$ = '+'; } | |
560 | | MINUSEQ | |
561 | { $$ = '-'; } | |
562 | | MULTEQ | |
563 | { $$ = '*'; } | |
564 | | DIVEQ | |
565 | { $$ = '/'; } | |
566 | | LSHIFTEQ | |
567 | { $$ = LSHIFT; } | |
568 | | RSHIFTEQ | |
569 | { $$ = RSHIFT; } | |
570 | | ANDEQ | |
571 | { $$ = '&'; } | |
572 | | OREQ | |
573 | { $$ = '|'; } | |
574 | ||
575 | ; | |
576 | ||
577 | end: ';' | ',' | |
578 | ; | |
579 | ||
580 | ||
581 | assignment: | |
582 | NAME '=' mustbe_exp | |
583 | { | |
584 | lang_add_assignment (exp_assop ($2, $1, $3)); | |
585 | } | |
586 | | NAME assign_op mustbe_exp | |
587 | { | |
588 | lang_add_assignment (exp_assop ('=', $1, | |
589 | exp_binop ($2, | |
590 | exp_nameop (NAME, | |
591 | $1), | |
592 | $3))); | |
593 | } | |
594 | | PROVIDE '(' NAME '=' mustbe_exp ')' | |
595 | { | |
596 | lang_add_assignment (exp_provide ($3, $5)); | |
597 | } | |
598 | ; | |
599 | ||
600 | ||
601 | opt_comma: | |
602 | ',' | ; | |
603 | ||
604 | ||
605 | memory: | |
606 | MEMORY '{' memory_spec memory_spec_list '}' | |
607 | ; | |
608 | ||
609 | memory_spec_list: | |
610 | memory_spec_list memory_spec | |
611 | | memory_spec_list ',' memory_spec | |
612 | | | |
613 | ; | |
614 | ||
615 | ||
616 | memory_spec: NAME | |
617 | { region = lang_memory_region_lookup($1); } | |
618 | attributes_opt ':' | |
619 | origin_spec opt_comma length_spec | |
620 | ||
74459f0e TW |
621 | ; |
622 | ||
623 | origin_spec: | |
252b5132 RH |
624 | ORIGIN '=' mustbe_exp |
625 | { region->current = | |
626 | region->origin = | |
627 | exp_get_vma($3, 0L,"origin", lang_first_phase_enum); | |
628 | } | |
629 | ; | |
630 | ||
631 | length_spec: | |
632 | LENGTH '=' mustbe_exp | |
633 | { region->length = exp_get_vma($3, | |
634 | ~((bfd_vma)0), | |
635 | "length", | |
636 | lang_first_phase_enum); | |
637 | } | |
aa8804e4 | 638 | ; |
252b5132 RH |
639 | |
640 | attributes_opt: | |
aa8804e4 ILT |
641 | /* empty */ |
642 | { /* dummy action to avoid bison 1.25 error message */ } | |
643 | | '(' attributes_list ')' | |
644 | ; | |
645 | ||
646 | attributes_list: | |
647 | attributes_string | |
648 | | attributes_list attributes_string | |
649 | ; | |
650 | ||
651 | attributes_string: | |
652 | NAME | |
653 | { lang_set_flags (region, $1, 0); } | |
654 | | '!' NAME | |
655 | { lang_set_flags (region, $2, 1); } | |
252b5132 RH |
656 | ; |
657 | ||
658 | startup: | |
659 | STARTUP '(' filename ')' | |
660 | { lang_startup($3); } | |
661 | ; | |
662 | ||
663 | high_level_library: | |
664 | HLL '(' high_level_library_NAME_list ')' | |
665 | | HLL '(' ')' | |
666 | { ldemul_hll((char *)NULL); } | |
667 | ; | |
668 | ||
669 | high_level_library_NAME_list: | |
670 | high_level_library_NAME_list opt_comma filename | |
671 | { ldemul_hll($3); } | |
672 | | filename | |
673 | { ldemul_hll($1); } | |
674 | ||
675 | ; | |
676 | ||
677 | low_level_library: | |
678 | SYSLIB '(' low_level_library_NAME_list ')' | |
679 | ; low_level_library_NAME_list: | |
680 | low_level_library_NAME_list opt_comma filename | |
681 | { ldemul_syslib($3); } | |
682 | | | |
683 | ; | |
684 | ||
685 | floating_point_support: | |
686 | FLOAT | |
687 | { lang_float(true); } | |
688 | | NOFLOAT | |
689 | { lang_float(false); } | |
690 | ; | |
691 | ||
692 | nocrossref_list: | |
693 | /* empty */ | |
694 | { | |
695 | $$ = NULL; | |
696 | } | |
697 | | NAME nocrossref_list | |
698 | { | |
699 | struct lang_nocrossref *n; | |
700 | ||
701 | n = (struct lang_nocrossref *) xmalloc (sizeof *n); | |
702 | n->name = $1; | |
703 | n->next = $2; | |
704 | $$ = n; | |
705 | } | |
706 | | NAME ',' nocrossref_list | |
707 | { | |
708 | struct lang_nocrossref *n; | |
709 | ||
710 | n = (struct lang_nocrossref *) xmalloc (sizeof *n); | |
711 | n->name = $1; | |
712 | n->next = $3; | |
713 | $$ = n; | |
714 | } | |
715 | ; | |
716 | ||
717 | mustbe_exp: { ldlex_expression(); } | |
718 | exp | |
719 | { ldlex_popstate(); $$=$2;} | |
720 | ; | |
721 | ||
722 | exp : | |
723 | '-' exp %prec UNARY | |
724 | { $$ = exp_unop('-', $2); } | |
725 | | '(' exp ')' | |
726 | { $$ = $2; } | |
727 | | NEXT '(' exp ')' %prec UNARY | |
728 | { $$ = exp_unop((int) $1,$3); } | |
729 | | '!' exp %prec UNARY | |
730 | { $$ = exp_unop('!', $2); } | |
731 | | '+' exp %prec UNARY | |
732 | { $$ = $2; } | |
733 | | '~' exp %prec UNARY | |
734 | { $$ = exp_unop('~', $2);} | |
735 | ||
736 | | exp '*' exp | |
737 | { $$ = exp_binop('*', $1, $3); } | |
738 | | exp '/' exp | |
739 | { $$ = exp_binop('/', $1, $3); } | |
740 | | exp '%' exp | |
741 | { $$ = exp_binop('%', $1, $3); } | |
742 | | exp '+' exp | |
743 | { $$ = exp_binop('+', $1, $3); } | |
744 | | exp '-' exp | |
745 | { $$ = exp_binop('-' , $1, $3); } | |
746 | | exp LSHIFT exp | |
747 | { $$ = exp_binop(LSHIFT , $1, $3); } | |
748 | | exp RSHIFT exp | |
749 | { $$ = exp_binop(RSHIFT , $1, $3); } | |
750 | | exp EQ exp | |
751 | { $$ = exp_binop(EQ , $1, $3); } | |
752 | | exp NE exp | |
753 | { $$ = exp_binop(NE , $1, $3); } | |
754 | | exp LE exp | |
755 | { $$ = exp_binop(LE , $1, $3); } | |
756 | | exp GE exp | |
757 | { $$ = exp_binop(GE , $1, $3); } | |
758 | | exp '<' exp | |
759 | { $$ = exp_binop('<' , $1, $3); } | |
760 | | exp '>' exp | |
761 | { $$ = exp_binop('>' , $1, $3); } | |
762 | | exp '&' exp | |
763 | { $$ = exp_binop('&' , $1, $3); } | |
764 | | exp '^' exp | |
765 | { $$ = exp_binop('^' , $1, $3); } | |
766 | | exp '|' exp | |
767 | { $$ = exp_binop('|' , $1, $3); } | |
768 | | exp '?' exp ':' exp | |
769 | { $$ = exp_trinop('?' , $1, $3, $5); } | |
770 | | exp ANDAND exp | |
771 | { $$ = exp_binop(ANDAND , $1, $3); } | |
772 | | exp OROR exp | |
773 | { $$ = exp_binop(OROR , $1, $3); } | |
774 | | DEFINED '(' NAME ')' | |
775 | { $$ = exp_nameop(DEFINED, $3); } | |
776 | | INT | |
777 | { $$ = exp_intop($1); } | |
778 | | SIZEOF_HEADERS | |
779 | { $$ = exp_nameop(SIZEOF_HEADERS,0); } | |
780 | ||
781 | | SIZEOF '(' NAME ')' | |
782 | { $$ = exp_nameop(SIZEOF,$3); } | |
783 | | ADDR '(' NAME ')' | |
784 | { $$ = exp_nameop(ADDR,$3); } | |
785 | | LOADADDR '(' NAME ')' | |
786 | { $$ = exp_nameop(LOADADDR,$3); } | |
787 | | ABSOLUTE '(' exp ')' | |
788 | { $$ = exp_unop(ABSOLUTE, $3); } | |
789 | | ALIGN_K '(' exp ')' | |
790 | { $$ = exp_unop(ALIGN_K,$3); } | |
791 | | BLOCK '(' exp ')' | |
792 | { $$ = exp_unop(ALIGN_K,$3); } | |
793 | | NAME | |
794 | { $$ = exp_nameop(NAME,$1); } | |
795 | | MAX_K '(' exp ',' exp ')' | |
796 | { $$ = exp_binop (MAX_K, $3, $5 ); } | |
797 | | MIN_K '(' exp ',' exp ')' | |
798 | { $$ = exp_binop (MIN_K, $3, $5 ); } | |
799 | | ASSERT_K '(' exp ',' NAME ')' | |
800 | { $$ = exp_assert ($3, $5); } | |
801 | ; | |
802 | ||
803 | ||
562d3460 TW |
804 | memspec_at_opt: |
805 | AT '>' NAME { $$ = $3; } | |
806 | | { $$ = "*default*"; } | |
807 | ; | |
808 | ||
252b5132 RH |
809 | opt_at: |
810 | AT '(' exp ')' { $$ = $3; } | |
811 | | { $$ = 0; } | |
812 | ; | |
813 | ||
814 | section: NAME { ldlex_expression(); } | |
815 | opt_exp_with_type | |
816 | opt_at { ldlex_popstate (); ldlex_script (); } | |
817 | '{' | |
818 | { | |
819 | lang_enter_output_section_statement($1, $3, | |
820 | sectype, | |
821 | 0, 0, 0, $4); | |
822 | } | |
823 | statement_list_opt | |
824 | '}' { ldlex_popstate (); ldlex_expression (); } | |
562d3460 | 825 | memspec_opt memspec_at_opt phdr_opt fill_opt |
252b5132 RH |
826 | { |
827 | ldlex_popstate (); | |
562d3460 | 828 | lang_leave_output_section_statement ($14, $11, $13, $12); |
252b5132 RH |
829 | } |
830 | opt_comma | |
831 | | OVERLAY | |
832 | { ldlex_expression (); } | |
833 | opt_exp_without_type opt_nocrossrefs opt_at | |
834 | { ldlex_popstate (); ldlex_script (); } | |
835 | '{' | |
836 | { | |
837 | lang_enter_overlay ($3, $5, (int) $4); | |
838 | } | |
839 | overlay_section | |
840 | '}' | |
841 | { ldlex_popstate (); ldlex_expression (); } | |
562d3460 | 842 | memspec_opt memspec_at_opt phdr_opt fill_opt |
252b5132 RH |
843 | { |
844 | ldlex_popstate (); | |
562d3460 | 845 | lang_leave_overlay ($15, $12, $14, $13); |
252b5132 RH |
846 | } |
847 | opt_comma | |
848 | | /* The GROUP case is just enough to support the gcc | |
849 | svr3.ifile script. It is not intended to be full | |
850 | support. I'm not even sure what GROUP is supposed | |
851 | to mean. */ | |
852 | GROUP { ldlex_expression (); } | |
853 | opt_exp_with_type | |
854 | { | |
855 | ldlex_popstate (); | |
856 | lang_add_assignment (exp_assop ('=', ".", $3)); | |
857 | } | |
858 | '{' sec_or_group_p1 '}' | |
859 | ; | |
860 | ||
861 | type: | |
862 | NOLOAD { sectype = noload_section; } | |
863 | | DSECT { sectype = dsect_section; } | |
864 | | COPY { sectype = copy_section; } | |
865 | | INFO { sectype = info_section; } | |
866 | | OVERLAY { sectype = overlay_section; } | |
867 | ; | |
868 | ||
869 | atype: | |
870 | '(' type ')' | |
871 | | /* EMPTY */ { sectype = normal_section; } | |
872 | | '(' ')' { sectype = normal_section; } | |
873 | ; | |
874 | ||
875 | opt_exp_with_type: | |
876 | exp atype ':' { $$ = $1; } | |
877 | | atype ':' { $$ = (etree_type *)NULL; } | |
878 | | /* The BIND cases are to support the gcc svr3.ifile | |
879 | script. They aren't intended to implement full | |
880 | support for the BIND keyword. I'm not even sure | |
881 | what BIND is supposed to mean. */ | |
882 | BIND '(' exp ')' atype ':' { $$ = $3; } | |
883 | | BIND '(' exp ')' BLOCK '(' exp ')' atype ':' | |
884 | { $$ = $3; } | |
885 | ; | |
886 | ||
887 | opt_exp_without_type: | |
888 | exp ':' { $$ = $1; } | |
889 | | ':' { $$ = (etree_type *) NULL; } | |
890 | ; | |
891 | ||
892 | opt_nocrossrefs: | |
893 | /* empty */ | |
894 | { $$ = 0; } | |
895 | | NOCROSSREFS | |
896 | { $$ = 1; } | |
897 | ; | |
898 | ||
899 | memspec_opt: | |
900 | '>' NAME | |
901 | { $$ = $2; } | |
902 | | { $$ = "*default*"; } | |
903 | ; | |
904 | ||
905 | phdr_opt: | |
906 | /* empty */ | |
907 | { | |
908 | $$ = NULL; | |
909 | } | |
910 | | phdr_opt ':' NAME | |
911 | { | |
912 | struct lang_output_section_phdr_list *n; | |
913 | ||
914 | n = ((struct lang_output_section_phdr_list *) | |
915 | xmalloc (sizeof *n)); | |
916 | n->name = $3; | |
917 | n->used = false; | |
918 | n->next = $1; | |
919 | $$ = n; | |
920 | } | |
921 | ; | |
922 | ||
923 | overlay_section: | |
924 | /* empty */ | |
925 | | overlay_section | |
926 | NAME | |
927 | { | |
928 | ldlex_script (); | |
929 | lang_enter_overlay_section ($2); | |
930 | } | |
931 | '{' statement_list_opt '}' | |
932 | { ldlex_popstate (); ldlex_expression (); } | |
933 | phdr_opt fill_opt | |
934 | { | |
935 | ldlex_popstate (); | |
936 | lang_leave_overlay_section ($9, $8); | |
937 | } | |
938 | opt_comma | |
939 | ; | |
940 | ||
941 | phdrs: | |
942 | PHDRS '{' phdr_list '}' | |
943 | ; | |
944 | ||
945 | phdr_list: | |
946 | /* empty */ | |
947 | | phdr_list phdr | |
948 | ; | |
949 | ||
950 | phdr: | |
951 | NAME { ldlex_expression (); } | |
952 | phdr_type phdr_qualifiers { ldlex_popstate (); } | |
953 | ';' | |
954 | { | |
955 | lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at, | |
956 | $4.flags); | |
957 | } | |
958 | ; | |
959 | ||
960 | phdr_type: | |
961 | exp | |
962 | { | |
963 | $$ = $1; | |
964 | ||
965 | if ($1->type.node_class == etree_name | |
966 | && $1->type.node_code == NAME) | |
967 | { | |
968 | const char *s; | |
969 | unsigned int i; | |
970 | static const char * const phdr_types[] = | |
971 | { | |
972 | "PT_NULL", "PT_LOAD", "PT_DYNAMIC", | |
973 | "PT_INTERP", "PT_NOTE", "PT_SHLIB", | |
974 | "PT_PHDR" | |
975 | }; | |
976 | ||
977 | s = $1->name.name; | |
978 | for (i = 0; | |
979 | i < sizeof phdr_types / sizeof phdr_types[0]; | |
980 | i++) | |
981 | if (strcmp (s, phdr_types[i]) == 0) | |
982 | { | |
983 | $$ = exp_intop (i); | |
984 | break; | |
985 | } | |
986 | } | |
987 | } | |
988 | ; | |
989 | ||
990 | phdr_qualifiers: | |
991 | /* empty */ | |
992 | { | |
993 | memset (&$$, 0, sizeof (struct phdr_info)); | |
994 | } | |
995 | | NAME phdr_val phdr_qualifiers | |
996 | { | |
997 | $$ = $3; | |
998 | if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL) | |
999 | $$.filehdr = true; | |
1000 | else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL) | |
1001 | $$.phdrs = true; | |
1002 | else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL) | |
1003 | $$.flags = $2; | |
1004 | else | |
1005 | einfo (_("%X%P:%S: PHDRS syntax error at `%s'\n"), $1); | |
1006 | } | |
1007 | | AT '(' exp ')' phdr_qualifiers | |
1008 | { | |
1009 | $$ = $5; | |
1010 | $$.at = $3; | |
1011 | } | |
1012 | ; | |
1013 | ||
1014 | phdr_val: | |
1015 | /* empty */ | |
1016 | { | |
1017 | $$ = NULL; | |
1018 | } | |
1019 | | '(' exp ')' | |
1020 | { | |
1021 | $$ = $2; | |
1022 | } | |
1023 | ; | |
1024 | ||
1025 | /* This syntax is used within an external version script file. */ | |
1026 | ||
1027 | version_script_file: | |
1028 | { | |
1029 | ldlex_version_file (); | |
1030 | PUSH_ERROR (_("VERSION script")); | |
1031 | } | |
1032 | vers_nodes | |
1033 | { | |
1034 | ldlex_popstate (); | |
1035 | POP_ERROR (); | |
1036 | } | |
1037 | ; | |
1038 | ||
1039 | /* This is used within a normal linker script file. */ | |
1040 | ||
1041 | version: | |
1042 | { | |
1043 | ldlex_version_script (); | |
1044 | } | |
1045 | VERSIONK '{' vers_nodes '}' | |
1046 | { | |
1047 | ldlex_popstate (); | |
1048 | } | |
1049 | ; | |
1050 | ||
1051 | vers_nodes: | |
1052 | vers_node | |
1053 | | vers_nodes vers_node | |
1054 | ; | |
1055 | ||
1056 | vers_node: | |
1057 | VERS_TAG '{' vers_tag '}' ';' | |
1058 | { | |
1059 | lang_register_vers_node ($1, $3, NULL); | |
1060 | } | |
1061 | | VERS_TAG '{' vers_tag '}' verdep ';' | |
1062 | { | |
1063 | lang_register_vers_node ($1, $3, $5); | |
1064 | } | |
1065 | ; | |
1066 | ||
1067 | verdep: | |
1068 | VERS_TAG | |
1069 | { | |
1070 | $$ = lang_add_vers_depend (NULL, $1); | |
1071 | } | |
1072 | | verdep VERS_TAG | |
1073 | { | |
1074 | $$ = lang_add_vers_depend ($1, $2); | |
1075 | } | |
1076 | ; | |
1077 | ||
1078 | vers_tag: | |
1079 | /* empty */ | |
1080 | { | |
1081 | $$ = lang_new_vers_node (NULL, NULL); | |
1082 | } | |
1083 | | vers_defns ';' | |
1084 | { | |
1085 | $$ = lang_new_vers_node ($1, NULL); | |
1086 | } | |
1087 | | GLOBAL ':' vers_defns ';' | |
1088 | { | |
1089 | $$ = lang_new_vers_node ($3, NULL); | |
1090 | } | |
1091 | | LOCAL ':' vers_defns ';' | |
1092 | { | |
1093 | $$ = lang_new_vers_node (NULL, $3); | |
1094 | } | |
1095 | | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';' | |
1096 | { | |
1097 | $$ = lang_new_vers_node ($3, $7); | |
1098 | } | |
1099 | ; | |
1100 | ||
1101 | vers_defns: | |
1102 | VERS_IDENTIFIER | |
1103 | { | |
1104 | $$ = lang_new_vers_regex (NULL, $1, ldgram_vers_current_lang); | |
1105 | } | |
1106 | | vers_defns ';' VERS_IDENTIFIER | |
1107 | { | |
1108 | $$ = lang_new_vers_regex ($1, $3, ldgram_vers_current_lang); | |
1109 | } | |
1110 | | EXTERN NAME '{' | |
1111 | { | |
1112 | $<name>$ = ldgram_vers_current_lang; | |
1113 | ldgram_vers_current_lang = $2; | |
1114 | } | |
1115 | vers_defns '}' | |
1116 | { | |
e06cae36 | 1117 | $$ = $5; |
252b5132 RH |
1118 | ldgram_vers_current_lang = $<name>4; |
1119 | } | |
1120 | ; | |
1121 | ||
1122 | %% | |
1123 | void | |
1124 | yyerror(arg) | |
1125 | const char *arg; | |
1126 | { | |
1127 | if (ldfile_assumed_script) | |
1128 | einfo (_("%P:%s: file format not recognized; treating as linker script\n"), | |
1129 | ldfile_input_filename); | |
1130 | if (error_index > 0 && error_index < ERROR_NAME_MAX) | |
1131 | einfo ("%P%F:%S: %s in %s\n", arg, error_names[error_index-1]); | |
1132 | else | |
1133 | einfo ("%P%F:%S: %s\n", arg); | |
1134 | } |