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