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