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, | |
3db64b00 | 3 | 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
252b5132 RH |
4 | Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com). |
5 | ||
f96b4a7b | 6 | This file is part of the GNU Binutils. |
252b5132 | 7 | |
3ec57632 NC |
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 | |
f96b4a7b | 10 | the Free Software Foundation; either version 3 of the License, or |
3ec57632 | 11 | (at your option) any later version. |
252b5132 | 12 | |
3ec57632 NC |
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. | |
252b5132 | 17 | |
3ec57632 NC |
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 | |
f96b4a7b NC |
20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
21 | MA 02110-1301, USA. */ | |
252b5132 RH |
22 | |
23 | %{ | |
24 | /* | |
25 | ||
26 | */ | |
27 | ||
28 | #define DONTDECLARE_MALLOC | |
29 | ||
252b5132 | 30 | #include "sysdep.h" |
3db64b00 | 31 | #include "bfd.h" |
252b5132 | 32 | #include "bfdlink.h" |
d038301c | 33 | #include "ld.h" |
252b5132 RH |
34 | #include "ldexp.h" |
35 | #include "ldver.h" | |
36 | #include "ldlang.h" | |
252b5132 | 37 | #include "ldfile.h" |
b71e2778 | 38 | #include "ldemul.h" |
252b5132 RH |
39 | #include "ldmisc.h" |
40 | #include "ldmain.h" | |
41 | #include "mri.h" | |
42 | #include "ldctor.h" | |
43 | #include "ldlex.h" | |
44 | ||
45 | #ifndef YYDEBUG | |
46 | #define YYDEBUG 1 | |
47 | #endif | |
48 | ||
49 | static enum section_type sectype; | |
279e75dc | 50 | static lang_memory_region_type *region; |
252b5132 | 51 | |
b34976b6 | 52 | bfd_boolean ldgram_had_keep = FALSE; |
252b5132 RH |
53 | char *ldgram_vers_current_lang = NULL; |
54 | ||
55 | #define ERROR_NAME_MAX 20 | |
56 | static char *error_names[ERROR_NAME_MAX]; | |
57 | static int error_index; | |
58 | #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++; | |
59 | #define POP_ERROR() error_index--; | |
60 | %} | |
61 | %union { | |
62 | bfd_vma integer; | |
2c382fb6 AM |
63 | struct big_int |
64 | { | |
65 | bfd_vma integer; | |
66 | char *str; | |
67 | } bigint; | |
68 | fill_type *fill; | |
252b5132 RH |
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 | { | |
b34976b6 AM |
78 | bfd_boolean filehdr; |
79 | bfd_boolean phdrs; | |
252b5132 RH |
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 | |
bbf115d3 | 91 | %type <etree> opt_exp_without_type opt_subalign opt_align |
2c382fb6 | 92 | %type <fill> fill_opt fill_exp |
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 | |
d038301c | 99 | %token <bigint> INT |
252b5132 RH |
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 | ||
d038301c | 107 | %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ |
252b5132 RH |
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 | |
d038301c | 122 | %token END |
252b5132 RH |
123 | %left <token> '(' |
124 | %token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE | |
53d25da6 AM |
125 | %token SECTIONS PHDRS INSERT_K AFTER BEFORE |
126 | %token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END | |
bcaa7b3e | 127 | %token SORT_BY_NAME SORT_BY_ALIGNMENT |
252b5132 RH |
128 | %token '{' '}' |
129 | %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH | |
4818e05f | 130 | %token INHIBIT_COMMON_ALLOCATION |
ba916c8a | 131 | %token SEGMENT_START |
252b5132 | 132 | %token INCLUDE |
ed9ef263 | 133 | %token MEMORY |
252b5132 | 134 | %token NOLOAD DSECT COPY INFO OVERLAY |
ed9ef263 | 135 | %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY |
252b5132 | 136 | %token <integer> NEXT |
5d41b3ef | 137 | %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K |
252b5132 RH |
138 | %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS |
139 | %token ORIGIN FILL | |
140 | %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS | |
7af8e998 | 141 | %token ALIGNMOD AT SUBALIGN PROVIDE PROVIDE_HIDDEN AS_NEEDED |
0841712e | 142 | %type <token> assign_op atype attributes_opt sect_constraint |
252b5132 RH |
143 | %type <name> filename |
144 | %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K | |
145 | %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL | |
146 | %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START | |
147 | %token <name> VERS_TAG VERS_IDENTIFIER | |
148 | %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT | |
0cf7d72c | 149 | %token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL |
252b5132 | 150 | %token EXCLUDE_FILE |
24718e3b | 151 | %token CONSTANT |
252b5132 RH |
152 | %type <versyms> vers_defns |
153 | %type <versnode> vers_tag | |
154 | %type <deflist> verdep | |
55255dae | 155 | %token INPUT_DYNAMIC_LIST |
252b5132 RH |
156 | |
157 | %% | |
158 | ||
d038301c | 159 | file: |
252b5132 RH |
160 | INPUT_SCRIPT script_file |
161 | | INPUT_MRI_SCRIPT mri_script_file | |
162 | | INPUT_VERSION_SCRIPT version_script_file | |
55255dae | 163 | | INPUT_DYNAMIC_LIST dynamic_list_file |
252b5132 RH |
164 | | INPUT_DEFSYM defsym_expr |
165 | ; | |
166 | ||
167 | ||
168 | filename: NAME; | |
169 | ||
170 | ||
171 | defsym_expr: | |
172 | { ldlex_defsym(); } | |
173 | NAME '=' exp | |
174 | { | |
175 | ldlex_popstate(); | |
176 | lang_add_assignment(exp_assop($3,$2,$4)); | |
177 | } | |
944cd72c | 178 | ; |
252b5132 | 179 | |
d038301c | 180 | /* SYNTAX WITHIN AN MRI SCRIPT FILE */ |
252b5132 RH |
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: | |
d038301c | 200 | CHIP exp |
252b5132 RH |
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 | |
d038301c | 209 | | ENDWORD |
252b5132 RH |
210 | | PUBLIC NAME '=' exp |
211 | { mri_public($2, $4); } | |
212 | | PUBLIC NAME ',' exp | |
213 | { mri_public($2, $4); } | |
d038301c | 214 | | PUBLIC NAME exp |
252b5132 RH |
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 | |
d038301c RM |
234 | | NAMEWORD NAME |
235 | { mri_name($2); } | |
252b5132 RH |
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 | 250 | | START NAME |
b34976b6 | 251 | { lang_add_entry ($2, FALSE); } |
252b5132 RH |
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 | ||
8545d1a9 | 280 | /* Parsed as expressions so that commas separate entries */ |
252b5132 | 281 | extern_name_list: |
8545d1a9 NS |
282 | { ldlex_expression (); } |
283 | extern_name_list_body | |
284 | { ldlex_popstate (); } | |
285 | ||
286 | extern_name_list_body: | |
252b5132 RH |
287 | NAME |
288 | { ldlang_add_undef ($1); } | |
8545d1a9 | 289 | | extern_name_list_body NAME |
252b5132 | 290 | { ldlang_add_undef ($2); } |
8545d1a9 | 291 | | extern_name_list_body ',' NAME |
252b5132 RH |
292 | { ldlang_add_undef ($3); } |
293 | ; | |
294 | ||
295 | script_file: | |
8545d1a9 NS |
296 | { ldlex_both(); } |
297 | ifile_list | |
298 | { ldlex_popstate(); } | |
252b5132 RH |
299 | ; |
300 | ||
252b5132 | 301 | ifile_list: |
8545d1a9 | 302 | ifile_list ifile_p1 |
252b5132 RH |
303 | | |
304 | ; | |
305 | ||
306 | ||
252b5132 RH |
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 ')' | |
b34976b6 | 321 | { ldfile_add_library_path ($3, FALSE); } |
252b5132 RH |
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 ')' | |
5e2f1575 | 330 | { ldfile_set_output_arch ($3, bfd_arch_unknown); } |
252b5132 | 331 | | FORCE_COMMON_ALLOCATION |
b34976b6 | 332 | { command_line.force_common_definition = TRUE ; } |
4818e05f | 333 | | INHIBIT_COMMON_ALLOCATION |
b34976b6 | 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); } | |
d038301c | 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 ')' | |
53d25da6 AM |
351 | | INSERT_K AFTER NAME |
352 | { lang_add_insert ($3, 0); } | |
353 | | INSERT_K BEFORE NAME | |
354 | { lang_add_insert ($3, 1); } | |
252b5132 RH |
355 | ; |
356 | ||
357 | input_list: | |
358 | NAME | |
359 | { lang_add_input_file($1,lang_input_file_is_search_file_enum, | |
360 | (char *)NULL); } | |
361 | | input_list ',' NAME | |
362 | { lang_add_input_file($3,lang_input_file_is_search_file_enum, | |
363 | (char *)NULL); } | |
364 | | input_list NAME | |
365 | { lang_add_input_file($2,lang_input_file_is_search_file_enum, | |
366 | (char *)NULL); } | |
367 | | LNAME | |
368 | { lang_add_input_file($1,lang_input_file_is_l_enum, | |
369 | (char *)NULL); } | |
370 | | input_list ',' LNAME | |
371 | { lang_add_input_file($3,lang_input_file_is_l_enum, | |
372 | (char *)NULL); } | |
373 | | input_list LNAME | |
374 | { lang_add_input_file($2,lang_input_file_is_l_enum, | |
375 | (char *)NULL); } | |
b717d30e JJ |
376 | | AS_NEEDED '(' |
377 | { $<integer>$ = as_needed; as_needed = TRUE; } | |
378 | input_list ')' | |
379 | { as_needed = $<integer>3; } | |
380 | | input_list ',' AS_NEEDED '(' | |
381 | { $<integer>$ = as_needed; as_needed = TRUE; } | |
382 | input_list ')' | |
383 | { as_needed = $<integer>5; } | |
384 | | input_list AS_NEEDED '(' | |
385 | { $<integer>$ = as_needed; as_needed = TRUE; } | |
386 | input_list ')' | |
387 | { as_needed = $<integer>4; } | |
252b5132 RH |
388 | ; |
389 | ||
390 | sections: | |
391 | SECTIONS '{' sec_or_group_p1 '}' | |
392 | ; | |
393 | ||
394 | sec_or_group_p1: | |
395 | sec_or_group_p1 section | |
396 | | sec_or_group_p1 statement_anywhere | |
397 | | | |
398 | ; | |
399 | ||
400 | statement_anywhere: | |
401 | ENTRY '(' NAME ')' | |
b34976b6 | 402 | { lang_add_entry ($3, FALSE); } |
252b5132 | 403 | | assignment end |
b6ca8815 NS |
404 | | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')' |
405 | { ldlex_popstate (); | |
406 | lang_add_assignment (exp_assert ($4, $6)); } | |
252b5132 RH |
407 | ; |
408 | ||
409 | /* The '*' and '?' cases are there because the lexer returns them as | |
410 | separate tokens rather than as NAME. */ | |
411 | wildcard_name: | |
412 | NAME | |
413 | { | |
414 | $$ = $1; | |
415 | } | |
416 | | '*' | |
417 | { | |
418 | $$ = "*"; | |
419 | } | |
420 | | '?' | |
421 | { | |
422 | $$ = "?"; | |
423 | } | |
424 | ; | |
425 | ||
426 | wildcard_spec: | |
427 | wildcard_name | |
428 | { | |
429 | $$.name = $1; | |
bcaa7b3e | 430 | $$.sorted = none; |
18625d54 | 431 | $$.exclude_name_list = NULL; |
252b5132 | 432 | } |
18625d54 | 433 | | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name |
252b5132 RH |
434 | { |
435 | $$.name = $5; | |
bcaa7b3e | 436 | $$.sorted = none; |
18625d54 | 437 | $$.exclude_name_list = $3; |
252b5132 | 438 | } |
bcaa7b3e | 439 | | SORT_BY_NAME '(' wildcard_name ')' |
252b5132 RH |
440 | { |
441 | $$.name = $3; | |
bcaa7b3e | 442 | $$.sorted = by_name; |
18625d54 | 443 | $$.exclude_name_list = NULL; |
252b5132 | 444 | } |
bcaa7b3e L |
445 | | SORT_BY_ALIGNMENT '(' wildcard_name ')' |
446 | { | |
447 | $$.name = $3; | |
448 | $$.sorted = by_alignment; | |
449 | $$.exclude_name_list = NULL; | |
450 | } | |
451 | | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')' | |
452 | { | |
453 | $$.name = $5; | |
454 | $$.sorted = by_name_alignment; | |
455 | $$.exclude_name_list = NULL; | |
456 | } | |
457 | | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_name ')' ')' | |
458 | { | |
459 | $$.name = $5; | |
460 | $$.sorted = by_name; | |
461 | $$.exclude_name_list = NULL; | |
462 | } | |
463 | | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_name ')' ')' | |
464 | { | |
465 | $$.name = $5; | |
466 | $$.sorted = by_alignment_name; | |
467 | $$.exclude_name_list = NULL; | |
468 | } | |
469 | | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')' | |
470 | { | |
471 | $$.name = $5; | |
472 | $$.sorted = by_alignment; | |
473 | $$.exclude_name_list = NULL; | |
474 | } | |
475 | | SORT_BY_NAME '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')' | |
252b5132 RH |
476 | { |
477 | $$.name = $7; | |
bcaa7b3e | 478 | $$.sorted = by_name; |
18625d54 | 479 | $$.exclude_name_list = $5; |
252b5132 RH |
480 | } |
481 | ; | |
482 | ||
18625d54 | 483 | exclude_name_list: |
765b7cbe | 484 | exclude_name_list wildcard_name |
18625d54 CM |
485 | { |
486 | struct name_list *tmp; | |
487 | tmp = (struct name_list *) xmalloc (sizeof *tmp); | |
765b7cbe | 488 | tmp->name = $2; |
18625d54 | 489 | tmp->next = $1; |
d038301c | 490 | $$ = tmp; |
18625d54 CM |
491 | } |
492 | | | |
493 | wildcard_name | |
494 | { | |
495 | struct name_list *tmp; | |
496 | tmp = (struct name_list *) xmalloc (sizeof *tmp); | |
497 | tmp->name = $1; | |
498 | tmp->next = NULL; | |
499 | $$ = tmp; | |
500 | } | |
501 | ; | |
502 | ||
252b5132 | 503 | file_NAME_list: |
b6bf44ba | 504 | file_NAME_list opt_comma wildcard_spec |
252b5132 | 505 | { |
b6bf44ba AM |
506 | struct wildcard_list *tmp; |
507 | tmp = (struct wildcard_list *) xmalloc (sizeof *tmp); | |
508 | tmp->next = $1; | |
509 | tmp->spec = $3; | |
510 | $$ = tmp; | |
252b5132 | 511 | } |
b6bf44ba AM |
512 | | |
513 | wildcard_spec | |
252b5132 | 514 | { |
b6bf44ba AM |
515 | struct wildcard_list *tmp; |
516 | tmp = (struct wildcard_list *) xmalloc (sizeof *tmp); | |
517 | tmp->next = NULL; | |
518 | tmp->spec = $1; | |
519 | $$ = tmp; | |
252b5132 RH |
520 | } |
521 | ; | |
522 | ||
523 | input_section_spec_no_keep: | |
524 | NAME | |
525 | { | |
b6bf44ba AM |
526 | struct wildcard_spec tmp; |
527 | tmp.name = $1; | |
528 | tmp.exclude_name_list = NULL; | |
bcaa7b3e | 529 | tmp.sorted = none; |
b6bf44ba | 530 | lang_add_wild (&tmp, NULL, ldgram_had_keep); |
252b5132 | 531 | } |
b6bf44ba | 532 | | '[' file_NAME_list ']' |
252b5132 | 533 | { |
b6bf44ba | 534 | lang_add_wild (NULL, $2, ldgram_had_keep); |
252b5132 | 535 | } |
b6bf44ba | 536 | | wildcard_spec '(' file_NAME_list ')' |
252b5132 | 537 | { |
b6bf44ba | 538 | lang_add_wild (&$1, $3, ldgram_had_keep); |
252b5132 | 539 | } |
252b5132 RH |
540 | ; |
541 | ||
542 | input_section_spec: | |
543 | input_section_spec_no_keep | |
544 | | KEEP '(' | |
b34976b6 | 545 | { ldgram_had_keep = TRUE; } |
252b5132 | 546 | input_section_spec_no_keep ')' |
b34976b6 | 547 | { ldgram_had_keep = FALSE; } |
252b5132 RH |
548 | ; |
549 | ||
550 | statement: | |
551 | assignment end | |
552 | | CREATE_OBJECT_SYMBOLS | |
553 | { | |
d038301c | 554 | lang_add_attribute(lang_object_symbols_statement_enum); |
252b5132 RH |
555 | } |
556 | | ';' | |
557 | | CONSTRUCTORS | |
558 | { | |
d038301c RM |
559 | |
560 | lang_add_attribute(lang_constructors_statement_enum); | |
252b5132 | 561 | } |
bcaa7b3e | 562 | | SORT_BY_NAME '(' CONSTRUCTORS ')' |
252b5132 | 563 | { |
b34976b6 | 564 | constructors_sorted = TRUE; |
252b5132 RH |
565 | lang_add_attribute (lang_constructors_statement_enum); |
566 | } | |
567 | | input_section_spec | |
568 | | length '(' mustbe_exp ')' | |
569 | { | |
2c382fb6 | 570 | lang_add_data ((int) $1, $3); |
252b5132 | 571 | } |
d038301c | 572 | |
2c382fb6 | 573 | | FILL '(' fill_exp ')' |
252b5132 | 574 | { |
2c382fb6 | 575 | lang_add_fill ($3); |
252b5132 | 576 | } |
8545d1a9 NS |
577 | | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')' end |
578 | { ldlex_popstate (); | |
579 | lang_add_assignment (exp_assert ($4, $6)); } | |
252b5132 RH |
580 | ; |
581 | ||
582 | statement_list: | |
583 | statement_list statement | |
584 | | statement | |
585 | ; | |
d038301c | 586 | |
252b5132 RH |
587 | statement_list_opt: |
588 | /* empty */ | |
589 | | statement_list | |
590 | ; | |
591 | ||
592 | length: | |
593 | QUAD | |
594 | { $$ = $1; } | |
595 | | SQUAD | |
596 | { $$ = $1; } | |
597 | | LONG | |
598 | { $$ = $1; } | |
599 | | SHORT | |
600 | { $$ = $1; } | |
601 | | BYTE | |
602 | { $$ = $1; } | |
603 | ; | |
604 | ||
2c382fb6 AM |
605 | fill_exp: |
606 | mustbe_exp | |
252b5132 | 607 | { |
e9ee469a | 608 | $$ = exp_get_fill ($1, 0, "fill value"); |
252b5132 | 609 | } |
252b5132 RH |
610 | ; |
611 | ||
2c382fb6 AM |
612 | fill_opt: |
613 | '=' fill_exp | |
614 | { $$ = $2; } | |
615 | | { $$ = (fill_type *) 0; } | |
616 | ; | |
252b5132 RH |
617 | |
618 | assign_op: | |
619 | PLUSEQ | |
620 | { $$ = '+'; } | |
621 | | MINUSEQ | |
622 | { $$ = '-'; } | |
623 | | MULTEQ | |
624 | { $$ = '*'; } | |
625 | | DIVEQ | |
626 | { $$ = '/'; } | |
627 | | LSHIFTEQ | |
628 | { $$ = LSHIFT; } | |
629 | | RSHIFTEQ | |
630 | { $$ = RSHIFT; } | |
631 | | ANDEQ | |
632 | { $$ = '&'; } | |
633 | | OREQ | |
634 | { $$ = '|'; } | |
635 | ||
636 | ; | |
637 | ||
638 | end: ';' | ',' | |
639 | ; | |
640 | ||
641 | ||
642 | assignment: | |
643 | NAME '=' mustbe_exp | |
644 | { | |
645 | lang_add_assignment (exp_assop ($2, $1, $3)); | |
646 | } | |
647 | | NAME assign_op mustbe_exp | |
648 | { | |
649 | lang_add_assignment (exp_assop ('=', $1, | |
650 | exp_binop ($2, | |
651 | exp_nameop (NAME, | |
652 | $1), | |
653 | $3))); | |
654 | } | |
655 | | PROVIDE '(' NAME '=' mustbe_exp ')' | |
656 | { | |
7af8e998 L |
657 | lang_add_assignment (exp_provide ($3, $5, FALSE)); |
658 | } | |
659 | | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')' | |
660 | { | |
661 | lang_add_assignment (exp_provide ($3, $5, TRUE)); | |
252b5132 RH |
662 | } |
663 | ; | |
664 | ||
665 | ||
666 | opt_comma: | |
667 | ',' | ; | |
668 | ||
669 | ||
670 | memory: | |
671 | MEMORY '{' memory_spec memory_spec_list '}' | |
672 | ; | |
673 | ||
674 | memory_spec_list: | |
675 | memory_spec_list memory_spec | |
676 | | memory_spec_list ',' memory_spec | |
677 | | | |
678 | ; | |
679 | ||
680 | ||
2d801b0f | 681 | memory_spec: NAME |
a747ee4d | 682 | { region = lang_memory_region_lookup ($1, TRUE); } |
252b5132 RH |
683 | attributes_opt ':' |
684 | origin_spec opt_comma length_spec | |
2d801b0f | 685 | {} |
74459f0e TW |
686 | ; |
687 | ||
688 | origin_spec: | |
252b5132 | 689 | ORIGIN '=' mustbe_exp |
e9ee469a AM |
690 | { |
691 | region->origin = exp_get_vma ($3, 0, "origin"); | |
692 | region->current = region->origin; | |
693 | } | |
252b5132 RH |
694 | ; |
695 | ||
696 | length_spec: | |
697 | LENGTH '=' mustbe_exp | |
e9ee469a AM |
698 | { |
699 | region->length = exp_get_vma ($3, -1, "length"); | |
252b5132 | 700 | } |
aa8804e4 | 701 | ; |
252b5132 RH |
702 | |
703 | attributes_opt: | |
aa8804e4 ILT |
704 | /* empty */ |
705 | { /* dummy action to avoid bison 1.25 error message */ } | |
706 | | '(' attributes_list ')' | |
707 | ; | |
708 | ||
709 | attributes_list: | |
710 | attributes_string | |
711 | | attributes_list attributes_string | |
712 | ; | |
713 | ||
714 | attributes_string: | |
715 | NAME | |
716 | { lang_set_flags (region, $1, 0); } | |
717 | | '!' NAME | |
718 | { lang_set_flags (region, $2, 1); } | |
252b5132 RH |
719 | ; |
720 | ||
721 | startup: | |
722 | STARTUP '(' filename ')' | |
723 | { lang_startup($3); } | |
724 | ; | |
725 | ||
726 | high_level_library: | |
727 | HLL '(' high_level_library_NAME_list ')' | |
728 | | HLL '(' ')' | |
729 | { ldemul_hll((char *)NULL); } | |
730 | ; | |
731 | ||
732 | high_level_library_NAME_list: | |
733 | high_level_library_NAME_list opt_comma filename | |
734 | { ldemul_hll($3); } | |
735 | | filename | |
736 | { ldemul_hll($1); } | |
737 | ||
738 | ; | |
739 | ||
740 | low_level_library: | |
741 | SYSLIB '(' low_level_library_NAME_list ')' | |
742 | ; low_level_library_NAME_list: | |
743 | low_level_library_NAME_list opt_comma filename | |
744 | { ldemul_syslib($3); } | |
745 | | | |
746 | ; | |
747 | ||
748 | floating_point_support: | |
749 | FLOAT | |
b34976b6 | 750 | { lang_float(TRUE); } |
252b5132 | 751 | | NOFLOAT |
b34976b6 | 752 | { lang_float(FALSE); } |
252b5132 | 753 | ; |
d038301c | 754 | |
252b5132 RH |
755 | nocrossref_list: |
756 | /* empty */ | |
757 | { | |
758 | $$ = NULL; | |
759 | } | |
760 | | NAME nocrossref_list | |
761 | { | |
762 | struct lang_nocrossref *n; | |
763 | ||
764 | n = (struct lang_nocrossref *) xmalloc (sizeof *n); | |
765 | n->name = $1; | |
766 | n->next = $2; | |
767 | $$ = n; | |
768 | } | |
769 | | NAME ',' nocrossref_list | |
770 | { | |
771 | struct lang_nocrossref *n; | |
772 | ||
773 | n = (struct lang_nocrossref *) xmalloc (sizeof *n); | |
774 | n->name = $1; | |
775 | n->next = $3; | |
776 | $$ = n; | |
777 | } | |
778 | ; | |
779 | ||
3ec57632 | 780 | mustbe_exp: { ldlex_expression (); } |
252b5132 | 781 | exp |
3ec57632 | 782 | { ldlex_popstate (); $$=$2;} |
252b5132 RH |
783 | ; |
784 | ||
785 | exp : | |
786 | '-' exp %prec UNARY | |
3ec57632 | 787 | { $$ = exp_unop ('-', $2); } |
252b5132 RH |
788 | | '(' exp ')' |
789 | { $$ = $2; } | |
790 | | NEXT '(' exp ')' %prec UNARY | |
3ec57632 | 791 | { $$ = exp_unop ((int) $1,$3); } |
252b5132 | 792 | | '!' exp %prec UNARY |
3ec57632 | 793 | { $$ = exp_unop ('!', $2); } |
252b5132 RH |
794 | | '+' exp %prec UNARY |
795 | { $$ = $2; } | |
796 | | '~' exp %prec UNARY | |
3ec57632 | 797 | { $$ = exp_unop ('~', $2);} |
252b5132 RH |
798 | |
799 | | exp '*' exp | |
3ec57632 | 800 | { $$ = exp_binop ('*', $1, $3); } |
252b5132 | 801 | | exp '/' exp |
3ec57632 | 802 | { $$ = exp_binop ('/', $1, $3); } |
252b5132 | 803 | | exp '%' exp |
3ec57632 | 804 | { $$ = exp_binop ('%', $1, $3); } |
252b5132 | 805 | | exp '+' exp |
3ec57632 | 806 | { $$ = exp_binop ('+', $1, $3); } |
252b5132 | 807 | | exp '-' exp |
3ec57632 | 808 | { $$ = exp_binop ('-' , $1, $3); } |
252b5132 | 809 | | exp LSHIFT exp |
3ec57632 | 810 | { $$ = exp_binop (LSHIFT , $1, $3); } |
252b5132 | 811 | | exp RSHIFT exp |
3ec57632 | 812 | { $$ = exp_binop (RSHIFT , $1, $3); } |
252b5132 | 813 | | exp EQ exp |
3ec57632 | 814 | { $$ = exp_binop (EQ , $1, $3); } |
252b5132 | 815 | | exp NE exp |
3ec57632 | 816 | { $$ = exp_binop (NE , $1, $3); } |
252b5132 | 817 | | exp LE exp |
3ec57632 | 818 | { $$ = exp_binop (LE , $1, $3); } |
252b5132 | 819 | | exp GE exp |
3ec57632 | 820 | { $$ = exp_binop (GE , $1, $3); } |
252b5132 | 821 | | exp '<' exp |
3ec57632 | 822 | { $$ = exp_binop ('<' , $1, $3); } |
252b5132 | 823 | | exp '>' exp |
3ec57632 | 824 | { $$ = exp_binop ('>' , $1, $3); } |
252b5132 | 825 | | exp '&' exp |
3ec57632 | 826 | { $$ = exp_binop ('&' , $1, $3); } |
252b5132 | 827 | | exp '^' exp |
3ec57632 | 828 | { $$ = exp_binop ('^' , $1, $3); } |
252b5132 | 829 | | exp '|' exp |
3ec57632 | 830 | { $$ = exp_binop ('|' , $1, $3); } |
252b5132 | 831 | | exp '?' exp ':' exp |
3ec57632 | 832 | { $$ = exp_trinop ('?' , $1, $3, $5); } |
252b5132 | 833 | | exp ANDAND exp |
3ec57632 | 834 | { $$ = exp_binop (ANDAND , $1, $3); } |
252b5132 | 835 | | exp OROR exp |
3ec57632 | 836 | { $$ = exp_binop (OROR , $1, $3); } |
252b5132 | 837 | | DEFINED '(' NAME ')' |
3ec57632 | 838 | { $$ = exp_nameop (DEFINED, $3); } |
252b5132 | 839 | | INT |
2c382fb6 | 840 | { $$ = exp_bigintop ($1.integer, $1.str); } |
252b5132 | 841 | | SIZEOF_HEADERS |
3ec57632 | 842 | { $$ = exp_nameop (SIZEOF_HEADERS,0); } |
252b5132 | 843 | |
5d41b3ef NS |
844 | | ALIGNOF '(' NAME ')' |
845 | { $$ = exp_nameop (ALIGNOF,$3); } | |
252b5132 | 846 | | SIZEOF '(' NAME ')' |
3ec57632 | 847 | { $$ = exp_nameop (SIZEOF,$3); } |
252b5132 | 848 | | ADDR '(' NAME ')' |
3ec57632 | 849 | { $$ = exp_nameop (ADDR,$3); } |
252b5132 | 850 | | LOADADDR '(' NAME ')' |
3ec57632 | 851 | { $$ = exp_nameop (LOADADDR,$3); } |
24718e3b L |
852 | | CONSTANT '(' NAME ')' |
853 | { $$ = exp_nameop (CONSTANT,$3); } | |
252b5132 | 854 | | ABSOLUTE '(' exp ')' |
3ec57632 | 855 | { $$ = exp_unop (ABSOLUTE, $3); } |
252b5132 | 856 | | ALIGN_K '(' exp ')' |
3ec57632 | 857 | { $$ = exp_unop (ALIGN_K,$3); } |
876f4090 | 858 | | ALIGN_K '(' exp ',' exp ')' |
3ec57632 | 859 | { $$ = exp_binop (ALIGN_K,$3,$5); } |
2d20f7bf JJ |
860 | | DATA_SEGMENT_ALIGN '(' exp ',' exp ')' |
861 | { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); } | |
a4f5ad88 JJ |
862 | | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')' |
863 | { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); } | |
2d20f7bf | 864 | | DATA_SEGMENT_END '(' exp ')' |
3ec57632 | 865 | { $$ = exp_unop (DATA_SEGMENT_END, $3); } |
ba916c8a MM |
866 | | SEGMENT_START '(' NAME ',' exp ')' |
867 | { /* The operands to the expression node are | |
868 | placed in the opposite order from the way | |
869 | in which they appear in the script as | |
870 | that allows us to reuse more code in | |
871 | fold_binary. */ | |
872 | $$ = exp_binop (SEGMENT_START, | |
873 | $5, | |
874 | exp_nameop (NAME, $3)); } | |
252b5132 | 875 | | BLOCK '(' exp ')' |
3ec57632 | 876 | { $$ = exp_unop (ALIGN_K,$3); } |
252b5132 | 877 | | NAME |
3ec57632 | 878 | { $$ = exp_nameop (NAME,$1); } |
252b5132 RH |
879 | | MAX_K '(' exp ',' exp ')' |
880 | { $$ = exp_binop (MAX_K, $3, $5 ); } | |
881 | | MIN_K '(' exp ',' exp ')' | |
882 | { $$ = exp_binop (MIN_K, $3, $5 ); } | |
883 | | ASSERT_K '(' exp ',' NAME ')' | |
884 | { $$ = exp_assert ($3, $5); } | |
3ec57632 NC |
885 | | ORIGIN '(' NAME ')' |
886 | { $$ = exp_nameop (ORIGIN, $3); } | |
887 | | LENGTH '(' NAME ')' | |
888 | { $$ = exp_nameop (LENGTH, $3); } | |
252b5132 RH |
889 | ; |
890 | ||
891 | ||
562d3460 TW |
892 | memspec_at_opt: |
893 | AT '>' NAME { $$ = $3; } | |
9f88b410 | 894 | | { $$ = 0; } |
562d3460 TW |
895 | ; |
896 | ||
252b5132 RH |
897 | opt_at: |
898 | AT '(' exp ')' { $$ = $3; } | |
899 | | { $$ = 0; } | |
900 | ; | |
901 | ||
bbf115d3 L |
902 | opt_align: |
903 | ALIGN_K '(' exp ')' { $$ = $3; } | |
904 | | { $$ = 0; } | |
905 | ; | |
906 | ||
7e7d5768 AM |
907 | opt_subalign: |
908 | SUBALIGN '(' exp ')' { $$ = $3; } | |
909 | | { $$ = 0; } | |
910 | ; | |
911 | ||
0841712e JJ |
912 | sect_constraint: |
913 | ONLY_IF_RO { $$ = ONLY_IF_RO; } | |
914 | | ONLY_IF_RW { $$ = ONLY_IF_RW; } | |
0cf7d72c | 915 | | SPECIAL { $$ = SPECIAL; } |
0841712e JJ |
916 | | { $$ = 0; } |
917 | ; | |
918 | ||
252b5132 | 919 | section: NAME { ldlex_expression(); } |
d038301c | 920 | opt_exp_with_type |
7e7d5768 | 921 | opt_at |
bbf115d3 | 922 | opt_align |
7e7d5768 | 923 | opt_subalign { ldlex_popstate (); ldlex_script (); } |
0841712e | 924 | sect_constraint |
252b5132 RH |
925 | '{' |
926 | { | |
927 | lang_enter_output_section_statement($1, $3, | |
928 | sectype, | |
bbf115d3 | 929 | $5, $6, $4, $8); |
252b5132 | 930 | } |
d038301c | 931 | statement_list_opt |
252b5132 | 932 | '}' { ldlex_popstate (); ldlex_expression (); } |
562d3460 | 933 | memspec_opt memspec_at_opt phdr_opt fill_opt |
252b5132 RH |
934 | { |
935 | ldlex_popstate (); | |
bbf115d3 | 936 | lang_leave_output_section_statement ($17, $14, $16, $15); |
252b5132 RH |
937 | } |
938 | opt_comma | |
2d801b0f | 939 | {} |
252b5132 RH |
940 | | OVERLAY |
941 | { ldlex_expression (); } | |
7e7d5768 | 942 | opt_exp_without_type opt_nocrossrefs opt_at opt_subalign |
252b5132 | 943 | { ldlex_popstate (); ldlex_script (); } |
d038301c | 944 | '{' |
252b5132 | 945 | { |
7e7d5768 | 946 | lang_enter_overlay ($3, $6); |
252b5132 RH |
947 | } |
948 | overlay_section | |
949 | '}' | |
950 | { ldlex_popstate (); ldlex_expression (); } | |
562d3460 | 951 | memspec_opt memspec_at_opt phdr_opt fill_opt |
252b5132 RH |
952 | { |
953 | ldlex_popstate (); | |
9f88b410 | 954 | lang_leave_overlay ($5, (int) $4, |
7e7d5768 | 955 | $16, $13, $15, $14); |
252b5132 RH |
956 | } |
957 | opt_comma | |
958 | | /* The GROUP case is just enough to support the gcc | |
959 | svr3.ifile script. It is not intended to be full | |
960 | support. I'm not even sure what GROUP is supposed | |
961 | to mean. */ | |
962 | GROUP { ldlex_expression (); } | |
963 | opt_exp_with_type | |
964 | { | |
965 | ldlex_popstate (); | |
966 | lang_add_assignment (exp_assop ('=', ".", $3)); | |
967 | } | |
968 | '{' sec_or_group_p1 '}' | |
969 | ; | |
970 | ||
971 | type: | |
972 | NOLOAD { sectype = noload_section; } | |
02a38f92 AM |
973 | | DSECT { sectype = noalloc_section; } |
974 | | COPY { sectype = noalloc_section; } | |
975 | | INFO { sectype = noalloc_section; } | |
976 | | OVERLAY { sectype = noalloc_section; } | |
252b5132 RH |
977 | ; |
978 | ||
979 | atype: | |
980 | '(' type ')' | |
981 | | /* EMPTY */ { sectype = normal_section; } | |
982 | | '(' ')' { sectype = normal_section; } | |
983 | ; | |
984 | ||
985 | opt_exp_with_type: | |
986 | exp atype ':' { $$ = $1; } | |
987 | | atype ':' { $$ = (etree_type *)NULL; } | |
988 | | /* The BIND cases are to support the gcc svr3.ifile | |
989 | script. They aren't intended to implement full | |
990 | support for the BIND keyword. I'm not even sure | |
991 | what BIND is supposed to mean. */ | |
992 | BIND '(' exp ')' atype ':' { $$ = $3; } | |
993 | | BIND '(' exp ')' BLOCK '(' exp ')' atype ':' | |
994 | { $$ = $3; } | |
995 | ; | |
996 | ||
997 | opt_exp_without_type: | |
998 | exp ':' { $$ = $1; } | |
999 | | ':' { $$ = (etree_type *) NULL; } | |
1000 | ; | |
1001 | ||
1002 | opt_nocrossrefs: | |
1003 | /* empty */ | |
1004 | { $$ = 0; } | |
1005 | | NOCROSSREFS | |
1006 | { $$ = 1; } | |
1007 | ; | |
1008 | ||
1009 | memspec_opt: | |
1010 | '>' NAME | |
1011 | { $$ = $2; } | |
a747ee4d | 1012 | | { $$ = DEFAULT_MEMORY_REGION; } |
252b5132 RH |
1013 | ; |
1014 | ||
1015 | phdr_opt: | |
1016 | /* empty */ | |
1017 | { | |
1018 | $$ = NULL; | |
1019 | } | |
1020 | | phdr_opt ':' NAME | |
1021 | { | |
1022 | struct lang_output_section_phdr_list *n; | |
1023 | ||
1024 | n = ((struct lang_output_section_phdr_list *) | |
1025 | xmalloc (sizeof *n)); | |
1026 | n->name = $3; | |
b34976b6 | 1027 | n->used = FALSE; |
252b5132 RH |
1028 | n->next = $1; |
1029 | $$ = n; | |
1030 | } | |
1031 | ; | |
1032 | ||
1033 | overlay_section: | |
1034 | /* empty */ | |
1035 | | overlay_section | |
1036 | NAME | |
1037 | { | |
1038 | ldlex_script (); | |
1039 | lang_enter_overlay_section ($2); | |
1040 | } | |
1041 | '{' statement_list_opt '}' | |
1042 | { ldlex_popstate (); ldlex_expression (); } | |
1043 | phdr_opt fill_opt | |
1044 | { | |
1045 | ldlex_popstate (); | |
1046 | lang_leave_overlay_section ($9, $8); | |
1047 | } | |
1048 | opt_comma | |
1049 | ; | |
1050 | ||
1051 | phdrs: | |
1052 | PHDRS '{' phdr_list '}' | |
1053 | ; | |
1054 | ||
1055 | phdr_list: | |
1056 | /* empty */ | |
1057 | | phdr_list phdr | |
1058 | ; | |
1059 | ||
1060 | phdr: | |
1061 | NAME { ldlex_expression (); } | |
1062 | phdr_type phdr_qualifiers { ldlex_popstate (); } | |
1063 | ';' | |
1064 | { | |
1065 | lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at, | |
1066 | $4.flags); | |
1067 | } | |
1068 | ; | |
1069 | ||
1070 | phdr_type: | |
1071 | exp | |
1072 | { | |
1073 | $$ = $1; | |
1074 | ||
1075 | if ($1->type.node_class == etree_name | |
1076 | && $1->type.node_code == NAME) | |
1077 | { | |
1078 | const char *s; | |
1079 | unsigned int i; | |
1080 | static const char * const phdr_types[] = | |
1081 | { | |
1082 | "PT_NULL", "PT_LOAD", "PT_DYNAMIC", | |
1083 | "PT_INTERP", "PT_NOTE", "PT_SHLIB", | |
d038301c | 1084 | "PT_PHDR", "PT_TLS" |
252b5132 RH |
1085 | }; |
1086 | ||
1087 | s = $1->name.name; | |
1088 | for (i = 0; | |
1089 | i < sizeof phdr_types / sizeof phdr_types[0]; | |
1090 | i++) | |
1091 | if (strcmp (s, phdr_types[i]) == 0) | |
1092 | { | |
1093 | $$ = exp_intop (i); | |
1094 | break; | |
1095 | } | |
d038301c RM |
1096 | if (i == sizeof phdr_types / sizeof phdr_types[0]) |
1097 | { | |
1098 | if (strcmp (s, "PT_GNU_EH_FRAME") == 0) | |
1099 | $$ = exp_intop (0x6474e550); | |
9ee5e499 JJ |
1100 | else if (strcmp (s, "PT_GNU_STACK") == 0) |
1101 | $$ = exp_intop (0x6474e551); | |
d038301c RM |
1102 | else |
1103 | { | |
1104 | einfo (_("\ | |
1105 | %X%P:%S: unknown phdr type `%s' (try integer literal)\n"), | |
1106 | s); | |
1107 | $$ = exp_intop (0); | |
1108 | } | |
1109 | } | |
252b5132 RH |
1110 | } |
1111 | } | |
1112 | ; | |
1113 | ||
1114 | phdr_qualifiers: | |
1115 | /* empty */ | |
1116 | { | |
1117 | memset (&$$, 0, sizeof (struct phdr_info)); | |
1118 | } | |
1119 | | NAME phdr_val phdr_qualifiers | |
1120 | { | |
1121 | $$ = $3; | |
1122 | if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL) | |
b34976b6 | 1123 | $$.filehdr = TRUE; |
252b5132 | 1124 | else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL) |
b34976b6 | 1125 | $$.phdrs = TRUE; |
252b5132 RH |
1126 | else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL) |
1127 | $$.flags = $2; | |
1128 | else | |
1129 | einfo (_("%X%P:%S: PHDRS syntax error at `%s'\n"), $1); | |
1130 | } | |
1131 | | AT '(' exp ')' phdr_qualifiers | |
1132 | { | |
1133 | $$ = $5; | |
1134 | $$.at = $3; | |
1135 | } | |
1136 | ; | |
1137 | ||
1138 | phdr_val: | |
1139 | /* empty */ | |
1140 | { | |
1141 | $$ = NULL; | |
1142 | } | |
1143 | | '(' exp ')' | |
1144 | { | |
1145 | $$ = $2; | |
1146 | } | |
1147 | ; | |
1148 | ||
55255dae L |
1149 | dynamic_list_file: |
1150 | { | |
1151 | ldlex_version_file (); | |
1152 | PUSH_ERROR (_("dynamic list")); | |
1153 | } | |
1154 | dynamic_list_nodes | |
1155 | { | |
1156 | ldlex_popstate (); | |
1157 | POP_ERROR (); | |
1158 | } | |
1159 | ; | |
1160 | ||
1161 | dynamic_list_nodes: | |
1162 | dynamic_list_node | |
1163 | | dynamic_list_nodes dynamic_list_node | |
1164 | ; | |
1165 | ||
1166 | dynamic_list_node: | |
1167 | '{' dynamic_list_tag '}' ';' | |
1168 | ; | |
1169 | ||
1170 | dynamic_list_tag: | |
1171 | vers_defns ';' | |
1172 | { | |
1173 | lang_append_dynamic_list ($1); | |
1174 | } | |
1175 | ; | |
1176 | ||
252b5132 RH |
1177 | /* This syntax is used within an external version script file. */ |
1178 | ||
1179 | version_script_file: | |
1180 | { | |
1181 | ldlex_version_file (); | |
1182 | PUSH_ERROR (_("VERSION script")); | |
1183 | } | |
1184 | vers_nodes | |
1185 | { | |
1186 | ldlex_popstate (); | |
1187 | POP_ERROR (); | |
1188 | } | |
1189 | ; | |
1190 | ||
1191 | /* This is used within a normal linker script file. */ | |
1192 | ||
1193 | version: | |
1194 | { | |
1195 | ldlex_version_script (); | |
1196 | } | |
1197 | VERSIONK '{' vers_nodes '}' | |
1198 | { | |
1199 | ldlex_popstate (); | |
1200 | } | |
1201 | ; | |
1202 | ||
1203 | vers_nodes: | |
1204 | vers_node | |
1205 | | vers_nodes vers_node | |
1206 | ; | |
1207 | ||
1208 | vers_node: | |
6b9b879a JJ |
1209 | '{' vers_tag '}' ';' |
1210 | { | |
1211 | lang_register_vers_node (NULL, $2, NULL); | |
1212 | } | |
1213 | | VERS_TAG '{' vers_tag '}' ';' | |
252b5132 RH |
1214 | { |
1215 | lang_register_vers_node ($1, $3, NULL); | |
1216 | } | |
1217 | | VERS_TAG '{' vers_tag '}' verdep ';' | |
1218 | { | |
1219 | lang_register_vers_node ($1, $3, $5); | |
1220 | } | |
1221 | ; | |
1222 | ||
1223 | verdep: | |
1224 | VERS_TAG | |
1225 | { | |
1226 | $$ = lang_add_vers_depend (NULL, $1); | |
1227 | } | |
1228 | | verdep VERS_TAG | |
1229 | { | |
1230 | $$ = lang_add_vers_depend ($1, $2); | |
1231 | } | |
1232 | ; | |
1233 | ||
1234 | vers_tag: | |
1235 | /* empty */ | |
1236 | { | |
1237 | $$ = lang_new_vers_node (NULL, NULL); | |
1238 | } | |
1239 | | vers_defns ';' | |
1240 | { | |
1241 | $$ = lang_new_vers_node ($1, NULL); | |
1242 | } | |
1243 | | GLOBAL ':' vers_defns ';' | |
1244 | { | |
1245 | $$ = lang_new_vers_node ($3, NULL); | |
1246 | } | |
1247 | | LOCAL ':' vers_defns ';' | |
1248 | { | |
1249 | $$ = lang_new_vers_node (NULL, $3); | |
1250 | } | |
1251 | | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';' | |
1252 | { | |
1253 | $$ = lang_new_vers_node ($3, $7); | |
1254 | } | |
1255 | ; | |
1256 | ||
1257 | vers_defns: | |
1258 | VERS_IDENTIFIER | |
1259 | { | |
86043bbb MM |
1260 | $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, FALSE); |
1261 | } | |
1262 | | NAME | |
1263 | { | |
1264 | $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, TRUE); | |
252b5132 RH |
1265 | } |
1266 | | vers_defns ';' VERS_IDENTIFIER | |
1267 | { | |
86043bbb MM |
1268 | $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, FALSE); |
1269 | } | |
1270 | | vers_defns ';' NAME | |
1271 | { | |
1272 | $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, TRUE); | |
252b5132 | 1273 | } |
8e23b15d AM |
1274 | | vers_defns ';' EXTERN NAME '{' |
1275 | { | |
1276 | $<name>$ = ldgram_vers_current_lang; | |
1277 | ldgram_vers_current_lang = $4; | |
1278 | } | |
1279 | vers_defns opt_semicolon '}' | |
1280 | { | |
96f8ade5 JJ |
1281 | struct bfd_elf_version_expr *pat; |
1282 | for (pat = $7; pat->next != NULL; pat = pat->next); | |
1283 | pat->next = $1; | |
8e23b15d AM |
1284 | $$ = $7; |
1285 | ldgram_vers_current_lang = $<name>6; | |
1286 | } | |
252b5132 RH |
1287 | | EXTERN NAME '{' |
1288 | { | |
1289 | $<name>$ = ldgram_vers_current_lang; | |
1290 | ldgram_vers_current_lang = $2; | |
1291 | } | |
8e23b15d | 1292 | vers_defns opt_semicolon '}' |
252b5132 | 1293 | { |
e06cae36 | 1294 | $$ = $5; |
252b5132 RH |
1295 | ldgram_vers_current_lang = $<name>4; |
1296 | } | |
96f8ade5 JJ |
1297 | | GLOBAL |
1298 | { | |
86043bbb | 1299 | $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, FALSE); |
96f8ade5 JJ |
1300 | } |
1301 | | vers_defns ';' GLOBAL | |
1302 | { | |
86043bbb | 1303 | $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, FALSE); |
96f8ade5 JJ |
1304 | } |
1305 | | LOCAL | |
1306 | { | |
86043bbb | 1307 | $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, FALSE); |
96f8ade5 JJ |
1308 | } |
1309 | | vers_defns ';' LOCAL | |
1310 | { | |
86043bbb | 1311 | $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, FALSE); |
96f8ade5 JJ |
1312 | } |
1313 | | EXTERN | |
1314 | { | |
86043bbb | 1315 | $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, FALSE); |
96f8ade5 JJ |
1316 | } |
1317 | | vers_defns ';' EXTERN | |
1318 | { | |
86043bbb | 1319 | $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, FALSE); |
96f8ade5 | 1320 | } |
252b5132 RH |
1321 | ; |
1322 | ||
8e23b15d AM |
1323 | opt_semicolon: |
1324 | /* empty */ | |
1325 | | ';' | |
1326 | ; | |
1327 | ||
252b5132 RH |
1328 | %% |
1329 | void | |
d038301c | 1330 | yyerror(arg) |
252b5132 | 1331 | const char *arg; |
d038301c | 1332 | { |
252b5132 RH |
1333 | if (ldfile_assumed_script) |
1334 | einfo (_("%P:%s: file format not recognized; treating as linker script\n"), | |
1335 | ldfile_input_filename); | |
1336 | if (error_index > 0 && error_index < ERROR_NAME_MAX) | |
1337 | einfo ("%P%F:%S: %s in %s\n", arg, error_names[error_index-1]); | |
1338 | else | |
1339 | einfo ("%P%F:%S: %s\n", arg); | |
1340 | } |