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