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