]>
Commit | Line | Data |
---|---|---|
c611e285 | 1 | /* A YACC grammer to parse a superset of the AT&T linker scripting languaue. |
4a6afc88 | 2 | Copyright (C) 1991, 1993 Free Software Foundation, Inc. |
c611e285 | 3 | Written by Steve Chamberlain of Cygnus Support ([email protected]). |
2fa0b342 | 4 | |
c611e285 | 5 | This file is part of GNU ld. |
2fa0b342 | 6 | |
c611e285 SC |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
2fa0b342 | 11 | |
c611e285 SC |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
2fa0b342 | 16 | |
c611e285 SC |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
3a473096 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
c611e285 SC |
20 | |
21 | %{ | |
22 | /* | |
2e2bf962 | 23 | |
c611e285 | 24 | */ |
2fa0b342 | 25 | |
f177a611 | 26 | #define DONTDECLARE_MALLOC |
2fa0b342 | 27 | |
2fa0b342 | 28 | #include "bfd.h" |
f177a611 | 29 | #include "sysdep.h" |
4a6afc88 | 30 | #include "bfdlink.h" |
2fa0b342 DHW |
31 | #include "ld.h" |
32 | #include "ldexp.h" | |
7cb9aa50 | 33 | #include "ldver.h" |
2fa0b342 | 34 | #include "ldlang.h" |
f177a611 | 35 | #include "ldemul.h" |
2fa0b342 DHW |
36 | #include "ldfile.h" |
37 | #include "ldmisc.h" | |
fcf276c4 | 38 | #include "ldmain.h" |
3d2b83ea | 39 | #include "mri.h" |
6232b6c4 | 40 | #include "ldlex.h" |
f177a611 | 41 | |
3a473096 ILT |
42 | #ifndef YYDEBUG |
43 | #define YYDEBUG 1 | |
44 | #endif | |
45 | ||
dadd414a | 46 | static int typebits; |
2fa0b342 | 47 | |
2fa0b342 DHW |
48 | lang_memory_region_type *region; |
49 | ||
50 | ||
2fa0b342 DHW |
51 | char *current_file; |
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; |
2fa0b342 DHW |
58 | |
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 DHW |
68 | char *name; |
69 | int token; | |
70 | union etree_union *etree; | |
2fa0b342 DHW |
71 | } |
72 | ||
9fce28ed | 73 | %type <etree> exp opt_exp_with_type mustbe_exp opt_at |
dadd414a | 74 | %type <integer> fill_opt |
9b222190 | 75 | %type <name> memspec_opt casesymlist |
6812f0e8 | 76 | %token <integer> INT |
3a473096 | 77 | %token <name> NAME LNAME |
2fa0b342 DHW |
78 | %type <integer> length |
79 | ||
a37cc0c0 | 80 | %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ |
2fa0b342 DHW |
81 | %right <token> '?' ':' |
82 | %left <token> OROR | |
83 | %left <token> ANDAND | |
84 | %left <token> '|' | |
85 | %left <token> '^' | |
86 | %left <token> '&' | |
87 | %left <token> EQ NE | |
88 | %left <token> '<' '>' LE GE | |
89 | %left <token> LSHIFT RSHIFT | |
6812f0e8 | 90 | |
2fa0b342 DHW |
91 | %left <token> '+' '-' |
92 | %left <token> '*' '/' '%' | |
6812f0e8 | 93 | |
2fa0b342 | 94 | %right UNARY |
2e38b71d | 95 | %token END |
2fa0b342 | 96 | %left <token> '(' |
c477527c | 97 | %token <token> ALIGN_K BLOCK QUAD LONG SHORT BYTE |
d4e5e3c3 | 98 | %token SECTIONS |
2fa0b342 | 99 | %token '{' '}' |
6812f0e8 SC |
100 | %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH |
101 | %token SIZEOF_HEADERS | |
dadd414a | 102 | %token INCLUDE |
d4e5e3c3 | 103 | %token MEMORY DEFSYMEND |
f177a611 | 104 | %token NOLOAD DSECT COPY INFO OVERLAY |
3a473096 | 105 | %token NAME LNAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY |
d4e5e3c3 DM |
106 | %token <integer> SIZEOF NEXT ADDR |
107 | %token STARTUP HLL SYSLIB FLOAT NOFLOAT | |
108 | %token ORIGIN FILL | |
0b3499f6 ILT |
109 | %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS |
110 | %token ALIGNMOD AT PROVIDE | |
6812f0e8 | 111 | %type <token> assign_op |
2fa0b342 | 112 | %type <name> filename |
e14a43bf | 113 | %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD |
4a6afc88 | 114 | %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL |
3a473096 | 115 | %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START |
3d2b83ea | 116 | |
2fa0b342 DHW |
117 | %% |
118 | ||
d4e5e3c3 DM |
119 | file: |
120 | INPUT_SCRIPT script_file | |
121 | | INPUT_MRI_SCRIPT mri_script_file | |
122 | | INPUT_DEFSYM defsym_expr | |
2fa0b342 DHW |
123 | ; |
124 | ||
2fa0b342 | 125 | |
d4e5e3c3 | 126 | filename: NAME; |
2fa0b342 | 127 | |
e14a43bf | 128 | |
d4e5e3c3 DM |
129 | defsym_expr: |
130 | { ldlex_defsym(); } | |
131 | NAME '=' exp | |
8ddef552 | 132 | { |
d4e5e3c3 DM |
133 | ldlex_popstate(); |
134 | lang_add_assignment(exp_assop($3,$2,$4)); | |
8ddef552 | 135 | } |
2fa0b342 | 136 | |
3d2b83ea SC |
137 | /* SYNTAX WITHIN AN MRI SCRIPT FILE */ |
138 | mri_script_file: | |
139 | { ldlex_mri_script(); | |
140 | PUSH_ERROR("MRI style script"); | |
141 | } | |
142 | mri_script_lines | |
143 | { ldlex_popstate(); | |
144 | POP_ERROR(); | |
145 | } | |
146 | ; | |
2fa0b342 | 147 | |
3d2b83ea | 148 | mri_script_lines: |
2e38b71d SC |
149 | mri_script_lines mri_script_command NEWLINE |
150 | | | |
3d2b83ea | 151 | ; |
2fa0b342 | 152 | |
2e38b71d | 153 | mri_script_command: |
3d2b83ea SC |
154 | CHIP exp |
155 | | CHIP exp ',' exp | |
156 | | NAME { | |
2e38b71d | 157 | einfo("%P%F: unrecognised keyword in MRI style script '%s'\n",$1); |
3d2b83ea SC |
158 | } |
159 | | LIST { | |
3d2b83ea SC |
160 | config.map_filename = "-"; |
161 | } | |
2e38b71d SC |
162 | | ORDER ordernamelist |
163 | | ENDWORD | |
3a473096 | 164 | | PUBLIC NAME '=' exp |
e14a43bf | 165 | { mri_public($2, $4); } |
3a473096 | 166 | | PUBLIC NAME ',' exp |
e14a43bf SC |
167 | { mri_public($2, $4); } |
168 | | PUBLIC NAME exp | |
169 | { mri_public($2, $3); } | |
2e38b71d SC |
170 | | FORMAT NAME |
171 | { mri_format($2); } | |
3a473096 | 172 | | SECT NAME ',' exp |
3d2b83ea SC |
173 | { mri_output_section($2, $4);} |
174 | | SECT NAME exp | |
175 | { mri_output_section($2, $3);} | |
176 | | SECT NAME '=' exp | |
177 | { mri_output_section($2, $4);} | |
dadd414a SC |
178 | | ALIGN_K NAME '=' exp |
179 | { mri_align($2,$4); } | |
180 | | ALIGNMOD NAME '=' exp | |
181 | { mri_alignmod($2,$4); } | |
3d2b83ea SC |
182 | | ABSOLUTE mri_abs_name_list |
183 | | LOAD mri_load_name_list | |
2e38b71d SC |
184 | | NAMEWORD NAME |
185 | { mri_name($2); } | |
e14a43bf SC |
186 | | ALIAS NAME ',' NAME |
187 | { mri_alias($2,$4,0);} | |
188 | | ALIAS NAME ',' INT | |
4a6afc88 | 189 | { mri_alias($2,0,(int) $4);} |
e14a43bf SC |
190 | | BASE exp |
191 | { mri_base($2); } | |
dadd414a | 192 | | TRUNCATE INT |
4a6afc88 | 193 | { mri_truncate((unsigned int) $2); } |
3a473096 ILT |
194 | | CASE casesymlist |
195 | | EXTERN extern_name_list | |
196 | | INCLUDE filename | |
197 | { ldfile_open_command_file ($2); } mri_script_lines END | |
198 | | START NAME | |
199 | { lang_add_entry ($2, 0); } | |
2e38b71d SC |
200 | | |
201 | ; | |
202 | ||
203 | ordernamelist: | |
204 | ordernamelist ',' NAME { mri_order($3); } | |
205 | | ordernamelist NAME { mri_order($2); } | |
206 | | | |
3d2b83ea | 207 | ; |
2fa0b342 | 208 | |
3d2b83ea SC |
209 | mri_load_name_list: |
210 | NAME | |
211 | { mri_load($1); } | |
212 | | mri_load_name_list ',' NAME { mri_load($3); } | |
213 | ; | |
1418c83b | 214 | |
3d2b83ea SC |
215 | mri_abs_name_list: |
216 | NAME | |
217 | { mri_only_load($1); } | |
218 | | mri_abs_name_list ',' NAME | |
219 | { mri_only_load($3); } | |
220 | ; | |
1418c83b | 221 | |
3a473096 | 222 | casesymlist: |
9b222190 | 223 | /* empty */ { $$ = NULL; } |
3a473096 ILT |
224 | | NAME |
225 | | casesymlist ',' NAME | |
226 | ; | |
227 | ||
228 | extern_name_list: | |
229 | NAME | |
230 | { ldlang_add_undef ($1); } | |
231 | | extern_name_list ',' NAME | |
232 | { ldlang_add_undef ($3); } | |
233 | ; | |
234 | ||
3d2b83ea | 235 | script_file: |
9d1fe8a4 SC |
236 | { |
237 | ldlex_both(); | |
238 | } | |
3d2b83ea | 239 | ifile_list |
9d1fe8a4 SC |
240 | { |
241 | ldlex_popstate(); | |
242 | } | |
1418c83b SC |
243 | ; |
244 | ||
245 | ||
246 | ifile_list: | |
3d2b83ea | 247 | ifile_list ifile_p1 |
13a0e8d7 | 248 | | |
2fa0b342 DHW |
249 | ; |
250 | ||
251 | ||
252 | ||
253 | ifile_p1: | |
254 | memory | |
255 | | sections | |
256 | | startup | |
257 | | high_level_library | |
258 | | low_level_library | |
259 | | floating_point_support | |
ac004870 | 260 | | statement_anywhere |
9d1fe8a4 | 261 | | ';' |
2fa0b342 DHW |
262 | | TARGET_K '(' NAME ')' |
263 | { lang_add_target($3); } | |
264 | | SEARCH_DIR '(' filename ')' | |
0cd82d00 | 265 | { ldfile_add_library_path ($3, false); } |
2fa0b342 | 266 | | OUTPUT '(' filename ')' |
f651733a ILT |
267 | { lang_add_output($3, 1); } |
268 | | OUTPUT_FORMAT '(' NAME ')' | |
3a473096 ILT |
269 | { lang_add_output_format ($3, (char *) NULL, |
270 | (char *) NULL, 1); } | |
271 | | OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')' | |
272 | { lang_add_output_format ($3, $5, $7, 1); } | |
f651733a | 273 | | OUTPUT_ARCH '(' NAME ')' |
a37cc0c0 | 274 | { ldfile_set_output_arch($3); } |
13a0e8d7 SC |
275 | | FORCE_COMMON_ALLOCATION |
276 | { command_line.force_common_definition = true ; } | |
2fa0b342 | 277 | | INPUT '(' input_list ')' |
0b3499f6 ILT |
278 | | GROUP |
279 | { lang_enter_group (); } | |
280 | '(' input_list ')' | |
281 | { lang_leave_group (); } | |
2fa0b342 DHW |
282 | | MAP '(' filename ')' |
283 | { lang_add_map($3); } | |
dadd414a SC |
284 | | INCLUDE filename |
285 | { ldfile_open_command_file($2); } ifile_list END | |
2fa0b342 DHW |
286 | ; |
287 | ||
288 | input_list: | |
289 | NAME | |
f651733a | 290 | { lang_add_input_file($1,lang_input_file_is_search_file_enum, |
2fa0b342 DHW |
291 | (char *)NULL); } |
292 | | input_list ',' NAME | |
f651733a | 293 | { lang_add_input_file($3,lang_input_file_is_search_file_enum, |
2fa0b342 | 294 | (char *)NULL); } |
3d2b83ea | 295 | | input_list NAME |
f651733a | 296 | { lang_add_input_file($2,lang_input_file_is_search_file_enum, |
2fa0b342 | 297 | (char *)NULL); } |
3a473096 ILT |
298 | | LNAME |
299 | { lang_add_input_file($1,lang_input_file_is_l_enum, | |
300 | (char *)NULL); } | |
301 | | input_list ',' LNAME | |
302 | { lang_add_input_file($3,lang_input_file_is_l_enum, | |
303 | (char *)NULL); } | |
304 | | input_list LNAME | |
305 | { lang_add_input_file($2,lang_input_file_is_l_enum, | |
306 | (char *)NULL); } | |
2fa0b342 DHW |
307 | ; |
308 | ||
309 | sections: | |
3d2b83ea | 310 | SECTIONS '{' sec_or_group_p1 '}' |
2fa0b342 DHW |
311 | ; |
312 | ||
313 | sec_or_group_p1: | |
314 | sec_or_group_p1 section | |
315 | | sec_or_group_p1 statement_anywhere | |
316 | | | |
317 | ; | |
318 | ||
319 | statement_anywhere: | |
320 | ENTRY '(' NAME ')' | |
60e8a534 | 321 | { lang_add_entry ($3, 0); } |
2fa0b342 DHW |
322 | | assignment end |
323 | ; | |
324 | ||
1418c83b SC |
325 | file_NAME_list: |
326 | NAME | |
327 | { lang_add_wild($1, current_file); } | |
3d2b83ea | 328 | | file_NAME_list opt_comma NAME |
1418c83b SC |
329 | { lang_add_wild($3, current_file); } |
330 | ; | |
331 | ||
332 | input_section_spec: | |
333 | NAME | |
334 | { | |
335 | lang_add_wild((char *)NULL, $1); | |
336 | } | |
3d2b83ea | 337 | | '[' |
1418c83b SC |
338 | { |
339 | current_file = (char *)NULL; | |
340 | } | |
3d2b83ea SC |
341 | file_NAME_list |
342 | ']' | |
1418c83b SC |
343 | | NAME |
344 | { | |
3d2b83ea SC |
345 | current_file =$1; |
346 | } | |
1418c83b | 347 | '(' file_NAME_list ')' |
3d2b83ea SC |
348 | | '*' |
349 | { | |
1418c83b | 350 | current_file = (char *)NULL; |
3d2b83ea | 351 | } |
1418c83b SC |
352 | '(' file_NAME_list ')' |
353 | ; | |
354 | ||
2fa0b342 | 355 | statement: |
9fce28ed SC |
356 | assignment end |
357 | | CREATE_OBJECT_SYMBOLS | |
13a0e8d7 | 358 | { |
9fce28ed SC |
359 | lang_add_attribute(lang_object_symbols_statement_enum); |
360 | } | |
361 | | ';' | |
362 | | CONSTRUCTORS | |
f177a611 | 363 | { |
3d2b83ea | 364 | |
9fce28ed SC |
365 | lang_add_attribute(lang_constructors_statement_enum); |
366 | } | |
367 | | input_section_spec | |
368 | | length '(' exp ')' | |
2fa0b342 | 369 | { |
4a6afc88 | 370 | lang_add_data((int) $1,$3); |
2fa0b342 DHW |
371 | } |
372 | ||
9fce28ed | 373 | | FILL '(' exp ')' |
2fa0b342 DHW |
374 | { |
375 | lang_add_fill | |
9fce28ed | 376 | (exp_get_value_int($3, |
2fa0b342 DHW |
377 | 0, |
378 | "fill value", | |
9fce28ed | 379 | lang_first_phase_enum)); |
2fa0b342 | 380 | } |
2fa0b342 DHW |
381 | ; |
382 | ||
9fce28ed SC |
383 | statement_list: |
384 | statement_list statement | |
385 | | statement | |
386 | ; | |
387 | ||
8ddef552 DM |
388 | statement_list_opt: |
389 | /* empty */ | |
390 | | statement_list | |
391 | ; | |
392 | ||
2fa0b342 | 393 | length: |
c477527c ILT |
394 | QUAD |
395 | { $$ = $1; } | |
396 | | LONG | |
2fa0b342 | 397 | { $$ = $1; } |
3d2b83ea | 398 | | SHORT |
2fa0b342 | 399 | { $$ = $1; } |
3d2b83ea | 400 | | BYTE |
2fa0b342 DHW |
401 | { $$ = $1; } |
402 | ; | |
403 | ||
404 | fill_opt: | |
9d1fe8a4 | 405 | '=' mustbe_exp |
2fa0b342 DHW |
406 | { |
407 | $$ = exp_get_value_int($2, | |
408 | 0, | |
409 | "fill value", | |
3d2b83ea | 410 | lang_first_phase_enum); |
2fa0b342 | 411 | } |
3d2b83ea | 412 | | { $$ = 0; } |
2fa0b342 DHW |
413 | ; |
414 | ||
415 | ||
416 | ||
417 | assign_op: | |
418 | PLUSEQ | |
419 | { $$ = '+'; } | |
3d2b83ea | 420 | | MINUSEQ |
2fa0b342 DHW |
421 | { $$ = '-'; } |
422 | | MULTEQ | |
423 | { $$ = '*'; } | |
424 | | DIVEQ | |
425 | { $$ = '/'; } | |
426 | | LSHIFTEQ | |
427 | { $$ = LSHIFT; } | |
428 | | RSHIFTEQ | |
429 | { $$ = RSHIFT; } | |
430 | | ANDEQ | |
431 | { $$ = '&'; } | |
432 | | OREQ | |
433 | { $$ = '|'; } | |
434 | ||
435 | ; | |
436 | ||
9d1fe8a4 | 437 | end: ';' | ',' |
2fa0b342 DHW |
438 | ; |
439 | ||
2fa0b342 DHW |
440 | |
441 | assignment: | |
3d2b83ea | 442 | NAME '=' mustbe_exp |
2fa0b342 | 443 | { |
0b3499f6 | 444 | lang_add_assignment (exp_assop ($2, $1, $3)); |
2fa0b342 | 445 | } |
3d2b83ea | 446 | | NAME assign_op mustbe_exp |
2fa0b342 | 447 | { |
0b3499f6 ILT |
448 | lang_add_assignment (exp_assop ('=', $1, |
449 | exp_binop ($2, | |
450 | exp_nameop (NAME, | |
451 | $1), | |
452 | $3))); | |
453 | } | |
454 | | PROVIDE '(' NAME '=' mustbe_exp ')' | |
455 | { | |
456 | lang_add_assignment (exp_provide ($3, $5)); | |
2fa0b342 | 457 | } |
2fa0b342 DHW |
458 | ; |
459 | ||
460 | ||
461 | opt_comma: | |
462 | ',' | ; | |
463 | ||
464 | ||
465 | memory: | |
3d2b83ea | 466 | MEMORY '{' memory_spec memory_spec_list '}' |
2fa0b342 DHW |
467 | ; |
468 | ||
469 | memory_spec_list: | |
3d2b83ea | 470 | memory_spec_list memory_spec |
2fa0b342 DHW |
471 | | memory_spec_list ',' memory_spec |
472 | | | |
473 | ; | |
474 | ||
475 | ||
3d2b83ea | 476 | memory_spec: NAME |
2fa0b342 | 477 | { region = lang_memory_region_lookup($1); } |
3d2b83ea | 478 | attributes_opt ':' |
9d1fe8a4 | 479 | origin_spec opt_comma length_spec |
2fa0b342 | 480 | |
3d2b83ea | 481 | ; origin_spec: |
9d1fe8a4 | 482 | ORIGIN '=' mustbe_exp |
2fa0b342 DHW |
483 | { region->current = |
484 | region->origin = | |
3d2b83ea SC |
485 | exp_get_vma($3, 0L,"origin", lang_first_phase_enum); |
486 | } | |
487 | ; length_spec: | |
488 | LENGTH '=' mustbe_exp | |
489 | { region->length = exp_get_vma($3, | |
2fa0b342 DHW |
490 | ~((bfd_vma)0), |
491 | "length", | |
492 | lang_first_phase_enum); | |
493 | } | |
494 | ||
495 | ||
496 | attributes_opt: | |
497 | '(' NAME ')' | |
498 | { | |
499 | lang_set_flags(®ion->flags, $2); | |
500 | } | |
501 | | | |
502 | ||
503 | ; | |
504 | ||
505 | startup: | |
506 | STARTUP '(' filename ')' | |
507 | { lang_startup($3); } | |
508 | ; | |
509 | ||
510 | high_level_library: | |
3d2b83ea SC |
511 | HLL '(' high_level_library_NAME_list ')' |
512 | | HLL '(' ')' | |
2fa0b342 DHW |
513 | { ldemul_hll((char *)NULL); } |
514 | ; | |
515 | ||
516 | high_level_library_NAME_list: | |
3d2b83ea | 517 | high_level_library_NAME_list opt_comma filename |
2fa0b342 DHW |
518 | { ldemul_hll($3); } |
519 | | filename | |
520 | { ldemul_hll($1); } | |
521 | ||
522 | ; | |
523 | ||
524 | low_level_library: | |
525 | SYSLIB '(' low_level_library_NAME_list ')' | |
3d2b83ea | 526 | ; low_level_library_NAME_list: |
2fa0b342 | 527 | low_level_library_NAME_list opt_comma filename |
3d2b83ea | 528 | { ldemul_syslib($3); } |
2fa0b342 DHW |
529 | | |
530 | ; | |
531 | ||
532 | floating_point_support: | |
533 | FLOAT | |
534 | { lang_float(true); } | |
535 | | NOFLOAT | |
3d2b83ea | 536 | { lang_float(false); } |
2fa0b342 DHW |
537 | ; |
538 | ||
539 | ||
3d2b83ea | 540 | mustbe_exp: { ldlex_expression(); } |
9d1fe8a4 SC |
541 | exp |
542 | { ldlex_popstate(); $$=$2;} | |
543 | ; | |
2fa0b342 DHW |
544 | |
545 | exp : | |
3d2b83ea | 546 | '-' exp %prec UNARY |
2fa0b342 | 547 | { $$ = exp_unop('-', $2); } |
9d1fe8a4 | 548 | | '(' exp ')' |
2fa0b342 DHW |
549 | { $$ = $2; } |
550 | | NEXT '(' exp ')' %prec UNARY | |
4a6afc88 | 551 | { $$ = exp_unop((int) $1,$3); } |
3d2b83ea | 552 | | '!' exp %prec UNARY |
2fa0b342 | 553 | { $$ = exp_unop('!', $2); } |
3d2b83ea | 554 | | '+' exp %prec UNARY |
2fa0b342 | 555 | { $$ = $2; } |
3d2b83ea | 556 | | '~' exp %prec UNARY |
2fa0b342 DHW |
557 | { $$ = exp_unop('~', $2);} |
558 | ||
559 | | exp '*' exp | |
560 | { $$ = exp_binop('*', $1, $3); } | |
561 | | exp '/' exp | |
562 | { $$ = exp_binop('/', $1, $3); } | |
563 | | exp '%' exp | |
564 | { $$ = exp_binop('%', $1, $3); } | |
565 | | exp '+' exp | |
566 | { $$ = exp_binop('+', $1, $3); } | |
567 | | exp '-' exp | |
3d2b83ea | 568 | { $$ = exp_binop('-' , $1, $3); } |
2fa0b342 DHW |
569 | | exp LSHIFT exp |
570 | { $$ = exp_binop(LSHIFT , $1, $3); } | |
571 | | exp RSHIFT exp | |
572 | { $$ = exp_binop(RSHIFT , $1, $3); } | |
573 | | exp EQ exp | |
574 | { $$ = exp_binop(EQ , $1, $3); } | |
575 | | exp NE exp | |
576 | { $$ = exp_binop(NE , $1, $3); } | |
577 | | exp LE exp | |
578 | { $$ = exp_binop(LE , $1, $3); } | |
3d2b83ea | 579 | | exp GE exp |
2fa0b342 DHW |
580 | { $$ = exp_binop(GE , $1, $3); } |
581 | | exp '<' exp | |
582 | { $$ = exp_binop('<' , $1, $3); } | |
583 | | exp '>' exp | |
584 | { $$ = exp_binop('>' , $1, $3); } | |
585 | | exp '&' exp | |
586 | { $$ = exp_binop('&' , $1, $3); } | |
587 | | exp '^' exp | |
588 | { $$ = exp_binop('^' , $1, $3); } | |
589 | | exp '|' exp | |
590 | { $$ = exp_binop('|' , $1, $3); } | |
591 | | exp '?' exp ':' exp | |
592 | { $$ = exp_trinop('?' , $1, $3, $5); } | |
593 | | exp ANDAND exp | |
594 | { $$ = exp_binop(ANDAND , $1, $3); } | |
595 | | exp OROR exp | |
596 | { $$ = exp_binop(OROR , $1, $3); } | |
597 | | DEFINED '(' NAME ')' | |
598 | { $$ = exp_nameop(DEFINED, $3); } | |
599 | | INT | |
600 | { $$ = exp_intop($1); } | |
3d2b83ea | 601 | | SIZEOF_HEADERS |
65c552e3 | 602 | { $$ = exp_nameop(SIZEOF_HEADERS,0); } |
2fa0b342 | 603 | |
3d2b83ea | 604 | | SIZEOF '(' NAME ')' |
f177a611 | 605 | { $$ = exp_nameop(SIZEOF,$3); } |
2fa0b342 | 606 | | ADDR '(' NAME ')' |
f177a611 | 607 | { $$ = exp_nameop(ADDR,$3); } |
ae475b39 SC |
608 | | ABSOLUTE '(' exp ')' |
609 | { $$ = exp_unop(ABSOLUTE, $3); } | |
2fa0b342 | 610 | | ALIGN_K '(' exp ')' |
f177a611 | 611 | { $$ = exp_unop(ALIGN_K,$3); } |
0b3499f6 ILT |
612 | | BLOCK '(' exp ')' |
613 | { $$ = exp_unop(ALIGN_K,$3); } | |
2fa0b342 DHW |
614 | | NAME |
615 | { $$ = exp_nameop(NAME,$1); } | |
616 | ; | |
617 | ||
618 | ||
9fce28ed SC |
619 | opt_at: |
620 | AT '(' exp ')' { $$ = $3; } | |
621 | | { $$ = 0; } | |
622 | ; | |
2fa0b342 | 623 | |
3d2b83ea | 624 | section: NAME { ldlex_expression(); } |
9fce28ed SC |
625 | opt_exp_with_type |
626 | opt_at { ldlex_popstate(); } | |
dadd414a | 627 | '{' |
9fce28ed SC |
628 | { |
629 | lang_enter_output_section_statement($1,$3,typebits,0,0,0,$4); | |
630 | } | |
8ddef552 | 631 | statement_list_opt |
27baca71 | 632 | '}' {ldlex_expression();} memspec_opt fill_opt |
2fa0b342 | 633 | { |
e14a43bf | 634 | ldlex_popstate(); |
27baca71 | 635 | lang_leave_output_section_statement($12, $11); |
2fa0b342 | 636 | } |
e14a43bf | 637 | opt_comma |
2fa0b342 DHW |
638 | |
639 | ; | |
640 | ||
dadd414a SC |
641 | type: |
642 | NOLOAD { typebits = SEC_NEVER_LOAD; } | |
643 | | DSECT { typebits = 0; } | |
644 | | COPY { typebits = 0; } | |
645 | | INFO { typebits = 0; } | |
646 | | OVERLAY { typebits = 0; } | |
647 | | { typebits = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; } | |
f177a611 JG |
648 | ; |
649 | ||
6812f0e8 | 650 | |
dadd414a | 651 | opt_exp_with_type: |
9fce28ed SC |
652 | exp ':' { $$ = $1; typebits =0;} |
653 | | exp '(' type ')' ':' { $$ = $1; } | |
654 | | ':' { $$= (etree_type *)NULL; typebits = 0; } | |
655 | | '(' type ')' ':' { $$= (etree_type *)NULL; } | |
2fa0b342 DHW |
656 | ; |
657 | ||
2fa0b342 | 658 | memspec_opt: |
9d1fe8a4 | 659 | '>' NAME |
2fa0b342 DHW |
660 | { $$ = $2; } |
661 | | { $$ = "*default*"; } | |
662 | ; | |
3d2b83ea SC |
663 | %% |
664 | void | |
665 | yyerror(arg) | |
c477527c | 666 | const char *arg; |
3d2b83ea | 667 | { |
0b3499f6 ILT |
668 | if (ldfile_assumed_script) |
669 | einfo ("%P:%s: file format not recognized; treating as linker script\n", | |
670 | ldfile_input_filename); | |
c477527c | 671 | if (error_index > 0 && error_index < ERROR_NAME_MAX) |
0b3499f6 | 672 | einfo ("%P%F:%S: %s in %s\n", arg, error_names[error_index-1]); |
3d2b83ea | 673 | else |
0b3499f6 | 674 | einfo ("%P%F:%S: %s\n", arg); |
3d2b83ea | 675 | } |