Checkpoint before a merge
[deliverable/binutils-gdb.git] / ld / ldgram.y
CommitLineData
1418c83b 1%{
2fa0b342
DHW
2/*
3 * $Id$
4 *
2fa0b342
DHW
5 *
6*/
7
8/*
9 This is a YACC grammer intended to parse a superset of the AT&T
10 linker scripting languaue.
11
12
13 Written by Steve Chamberlain steve@cygnus.com
14*/
15
16
2fa0b342
DHW
17
18#include "sysdep.h"
19#include "bfd.h"
2fa0b342
DHW
20#include "ld.h"
21#include "ldexp.h"
22#include "ldversion.h"
23#include "ldlang.h"
24#include "ld-emul.h"
25#include "ldfile.h"
26#include "ldmisc.h"
27#define YYDEBUG 1
28
29boolean option_v;
2fa0b342
DHW
30extern unsigned int lineno;
31extern boolean trace_files;
32extern boolean write_map;
33
34boolean hex_mode;
35
36
37
38
39lang_memory_region_type *region;
40
41
42lang_memory_region_type *lang_memory_region_lookup();
43lang_output_section_statement_type *lang_output_section_statement_lookup();
44
45#ifdef __STDC__
46
47void lang_add_data(int type, union etree_union *exp);
48void lang_enter_output_section_statement(char *output_section_statement_name, etree_type *address_exp, bfd_vma block_value);
49
50#else
51
52void lang_add_data();
53void lang_enter_output_section_statement();
54
55#endif /* __STDC__ */
56
57extern args_type command_line;
58char *current_file;
59boolean ldgram_want_filename = true;
60boolean had_script = false;
61boolean force_make_executable = false;
7ca04d28 62boolean ldgram_in_expression = false;
1418c83b 63boolean ldgram_in_script = false;
7ca04d28 64boolean ldgram_in_defsym = false;
2fa0b342
DHW
65/* LOCALS */
66
67
68
69
70%}
71%union {
72 bfd_vma integer;
73 int voidval;
74 char *name;
75 int token;
76 union etree_union *etree;
77 asection *section;
78 struct lang_output_section_statement_struct *output_section_statement;
79 union lang_statement_union **statement_ptr;
80 int lineno;
81 struct {
82 FILE *file;
83 char *name;
84 unsigned int lineno;
85 } state;
86
87
88}
89
90%type <etree> exp opt_exp exp_head
91%type <integer> fill_opt opt_block
92%type <name> memspec_opt
93%token <integer> INT CHAR
94%token <name> NAME
95%type <integer> length
96
97%right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
98%right <token> '?' ':'
99%left <token> OROR
100%left <token> ANDAND
101%left <token> '|'
102%left <token> '^'
103%left <token> '&'
104%left <token> EQ NE
105%left <token> '<' '>' LE GE
106%left <token> LSHIFT RSHIFT
107%left <token> '+' '-'
108%left <token> '*' '/' '%'
109%right UNARY
110%left <token> '('
111%token <token> ALIGN_K BLOCK LONG SHORT BYTE
112%token SECTIONS
113%token '{' '}'
114%token ALIGNMENT SIZEOF_HEADERS
1418c83b 115%token NEXT SIZEOF ADDR SCRIPT ENDSCRIPT
2fa0b342
DHW
116%token MEMORY
117%token DSECT NOLOAD COPY INFO OVERLAY
118%token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
7ca04d28 119%token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S
1418c83b 120%token OPTION_format OPTION_F OPTION_u
7ca04d28 121
2fa0b342
DHW
122%token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X
123%token OPTION_v OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT NOFLOAT OPTION_defsym
1418c83b 124%token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_A OPTION_R
2fa0b342
DHW
125%token <name> OPTION_l OPTION_L OPTION_T OPTION_Aarch OPTION_Tfile OPTION_Texp
126%token OPTION_Ur
127%token ORIGIN FILL OPTION_g
128%token LENGTH BIND SUBSECTION_ALIGN CREATE_OBJECT_SYMBOLS INPUT OUTPUT
129%type <token> assign_op SIZEOF NEXT ADDR
130%type <etree> assignment
131%type <name> filename
132
133%{
134ld_config_type config;
135%}
136
137%%
138
139
140
141file: command_line { lang_final(); };
142
143
144filename:
7ca04d28 145 NAME;
2fa0b342
DHW
146
147command_line:
148 command_line command_line_option
149 |
150 ;
151
152command_line_option:
1418c83b
SC
153 SCRIPT ifile_list ENDSCRIPT
154 | OPTION_v
2fa0b342
DHW
155 {
156 ldversion();
157 option_v = true;
158 }
159 | OPTION_t {
160 trace_files = true;
161 }
162 | OPTION_M {
163 write_map = true;
164 }
165 | OPTION_n {
166 config.magic_demand_paged = false;
167 config.make_executable = false;
168 }
169 | OPTION_s {
170 strip_symbols = STRIP_ALL;
171 }
172 | OPTION_S {
173 strip_symbols = STRIP_DEBUGGER;
174 }
1418c83b
SC
175 | OPTION_u NAME {
176 ldlang_add_undef($2);
177 }
178
2fa0b342
DHW
179 | OPTION_r {
180 config.relocateable_output = true;
181 config.build_constructors = false;
182 config.magic_demand_paged = false;
183 }
184 | OPTION_Ur {
185 config.relocateable_output = true;
186 config.build_constructors = true;
187 config.magic_demand_paged = false;
188 }
189 | OPTION_o filename
190 {
191 lang_add_output($2);
192 }
193 | OPTION_e NAME
194 { lang_add_entry($2);
195 }
196 | OPTION_X {
197 discard_locals = DISCARD_L;
198 }
199 | OPTION_x {
200 discard_locals = DISCARD_ALL;
201 }
202
203 | OPTION_noinhibit_exec
204 {
205 force_make_executable = true;
206 }
1418c83b 207 | OPTION_d {
2fa0b342
DHW
208 command_line.force_common_definition = true;
209 }
1418c83b 210 | OPTION_dc
2fa0b342
DHW
211 {
212 command_line.force_common_definition = true;
213 }
214 | OPTION_g
215 {
216 /* Ignored */
217 }
1418c83b 218 | OPTION_dp
2fa0b342
DHW
219 {
220 command_line.force_common_definition = true;
221 }
1418c83b 222 | OPTION_format NAME
7ca04d28
SC
223 {
224 lang_add_target($2);
225 }
de7c1ff6 226 | OPTION_Texp
1418c83b
SC
227 {
228 hex_mode =true;
229 }
230 INT
231 {
232 lang_section_start($1,exp_intop($3));
233 hex_mode = false;
234 }
2fa0b342 235
7ca04d28 236 | OPTION_Aarch
1418c83b
SC
237 {
238 ldfile_add_arch($1);
239 }
7ca04d28 240 | OPTION_b NAME
2fa0b342
DHW
241 {
242 lang_add_target($2);
243 }
244 | OPTION_L
245 {
246 ldfile_add_library_path($1);
1418c83b 247 }
7ca04d28
SC
248 | OPTION_F
249 {
250 /* Ignore */
251 }
1418c83b
SC
252 | NAME
253 { lang_add_input_file($1,lang_input_file_is_file_enum,
254 (char *)NULL); }
255 | OPTION_c filename script_file
2fa0b342 256 { ldfile_open_command_file($2); }
1418c83b
SC
257 | OPTION_Tfile
258 { ldfile_open_command_file($1); } script_file
2fa0b342 259
1418c83b
SC
260 | OPTION_T filename
261 { ldfile_open_command_file($2); } script_file
2fa0b342
DHW
262
263 | OPTION_l
264 {
265 lang_add_input_file($1,
266 lang_input_file_is_l_enum,
267 (char *)NULL);
268 }
1418c83b 269 | OPTION_R filename
2fa0b342
DHW
270 {
271 lang_add_input_file($2,
272 lang_input_file_is_symbols_only_enum,
273 (char *)NULL);
274 }
7ca04d28
SC
275 | OPTION_defsym
276 {
277 ldgram_in_defsym = true;
1418c83b 278 ldgram_in_expression = true;
de7c1ff6 279 hex_mode = true;
7ca04d28
SC
280 }
281 assignment
282 {
de7c1ff6 283 hex_mode = false;
7ca04d28 284 ldgram_in_defsym = false;
1418c83b 285 ldgram_in_expression = false;
7ca04d28 286 }
1418c83b
SC
287 | '-' NAME
288 { info("%P%F Unrecognised option -%s\n", $2); }
7ca04d28 289
2fa0b342
DHW
290 ;
291
292
1418c83b 293
2fa0b342
DHW
294
295
296
1418c83b
SC
297
298
299script_file:
300 { ldgram_in_script = true; }
301 ifile_list ENDSCRIPT
302 { ldgram_in_script = false; }
303
304 ;
305
306
307ifile_list:
308 ifile_list ifile_p1
309 |
2fa0b342
DHW
310 ;
311
312
313
314ifile_p1:
315 memory
316 | sections
317 | startup
318 | high_level_library
319 | low_level_library
320 | floating_point_support
321 | assignment end
322 | TARGET_K '(' NAME ')'
323 { lang_add_target($3); }
324 | SEARCH_DIR '(' filename ')'
325 { ldfile_add_library_path($3); }
326 | OUTPUT '(' filename ')'
327 { lang_add_output($3); }
328 | INPUT '(' input_list ')'
329 | MAP '(' filename ')'
330 { lang_add_map($3); }
331 ;
332
333input_list:
334 NAME
335 { lang_add_input_file($1,lang_input_file_is_file_enum,
336 (char *)NULL); }
337 | input_list ',' NAME
338 { lang_add_input_file($3,lang_input_file_is_file_enum,
339 (char *)NULL); }
340 | input_list NAME
341 { lang_add_input_file($2, lang_input_file_is_file_enum,
342 (char *)NULL); }
343 ;
344
345sections:
346 SECTIONS '{'sec_or_group_p1 '}'
347 ;
348
349sec_or_group_p1:
350 sec_or_group_p1 section
351 | sec_or_group_p1 statement_anywhere
352 |
353 ;
354
355statement_anywhere:
356 ENTRY '(' NAME ')'
357 { lang_add_entry($3); }
358 | assignment end
359 ;
360
1418c83b
SC
361file_NAME_list:
362 NAME
363 { lang_add_wild($1, current_file); }
364 | file_NAME_list opt_comma NAME
365 { lang_add_wild($3, current_file); }
366 ;
367
368input_section_spec:
369 NAME
370 {
371 lang_add_wild((char *)NULL, $1);
372 }
373 | '['
374 {
375 current_file = (char *)NULL;
376 }
377 file_NAME_list
378 ']'
379 | NAME
380 {
381 current_file =$1;
382 }
383 '(' file_NAME_list ')'
384 | '*'
385 {
386 current_file = (char *)NULL;
387 }
388 '(' file_NAME_list ')'
389 ;
390
2fa0b342
DHW
391statement:
392 statement assignment end
393 | statement CREATE_OBJECT_SYMBOLS
394 { lang_add_attribute(lang_object_symbols_statement_enum); }
395 | statement input_section_spec
396 | statement length '(' exp_head ')'
397 {
398 lang_add_data($2,$4);
399 }
400
401 | statement FILL '(' exp_head ')'
402 {
403 lang_add_fill
404 (exp_get_value_int($4,
405 0,
406 "fill value",
407 lang_first_phase_enum));
408 }
409 |
410 ;
411
412length:
413 LONG
414 { $$ = $1; }
415 | SHORT
416 { $$ = $1; }
417 | BYTE
418 { $$ = $1; }
419 ;
420
421fill_opt:
422 '=' exp_head
423 {
424 $$ = exp_get_value_int($2,
425 0,
426 "fill value",
427 lang_first_phase_enum);
428 }
429 | { $$ = 0; }
430 ;
431
432
433
434assign_op:
435 PLUSEQ
436 { $$ = '+'; }
437 | MINUSEQ
438 { $$ = '-'; }
439 | MULTEQ
440 { $$ = '*'; }
441 | DIVEQ
442 { $$ = '/'; }
443 | LSHIFTEQ
444 { $$ = LSHIFT; }
445 | RSHIFTEQ
446 { $$ = RSHIFT; }
447 | ANDEQ
448 { $$ = '&'; }
449 | OREQ
450 { $$ = '|'; }
451
452 ;
453
454end: ';' | ','
455 ;
456
2fa0b342
DHW
457
458assignment:
459
460 NAME '=' exp_head
461 {
462 lang_add_assignment(exp_assop($2,$1,$3));
463 }
464 | NAME assign_op exp_head
465 {
466 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
467 }
468
469 ;
470
471
472opt_comma:
473 ',' | ;
474
475
476memory:
477 MEMORY '{' memory_spec memory_spec_list '}'
478 ;
479
480memory_spec_list:
481 memory_spec_list memory_spec
482 | memory_spec_list ',' memory_spec
483 |
484 ;
485
486
487memory_spec:
488 NAME
489 { region = lang_memory_region_lookup($1); }
490 attributes_opt ':' origin_spec opt_comma length_spec
491
492 {
493
494
495 }
496 ;
497origin_spec:
498 ORIGIN '=' exp
499 { region->current =
500 region->origin =
501 exp_get_vma($3, 0L,"origin", lang_first_phase_enum); }
502 ;
503length_spec:
504 LENGTH '=' exp
505 { region->length = exp_get_vma($3,
506 ~((bfd_vma)0),
507 "length",
508 lang_first_phase_enum);
509 }
510
511
512attributes_opt:
513 '(' NAME ')'
514 {
515 lang_set_flags(&region->flags, $2);
516 }
517 |
518
519 ;
520
521startup:
522 STARTUP '(' filename ')'
523 { lang_startup($3); }
524 ;
525
526high_level_library:
527 HLL '(' high_level_library_NAME_list ')'
528 | HLL '(' ')'
529 { ldemul_hll((char *)NULL); }
530 ;
531
532high_level_library_NAME_list:
533 high_level_library_NAME_list opt_comma filename
534 { ldemul_hll($3); }
535 | filename
536 { ldemul_hll($1); }
537
538 ;
539
540low_level_library:
541 SYSLIB '(' low_level_library_NAME_list ')'
542 ;
543low_level_library_NAME_list:
544 low_level_library_NAME_list opt_comma filename
545 { ldemul_syslib($3); }
546 |
547 ;
548
549floating_point_support:
550 FLOAT
551 { lang_float(true); }
552 | NOFLOAT
553 { lang_float(false); }
554 ;
555
556
557
558
559exp :
560 '-' exp %prec UNARY
561 { $$ = exp_unop('-', $2); }
562 | '(' exp ')'
563 { $$ = $2; }
564 | NEXT '(' exp ')' %prec UNARY
565 { $$ = exp_unop($1,$3); }
566 | '!' exp %prec UNARY
567 { $$ = exp_unop('!', $2); }
568 | '+' exp %prec UNARY
569 { $$ = $2; }
570 | '~' exp %prec UNARY
571 { $$ = exp_unop('~', $2);}
572
573 | exp '*' exp
574 { $$ = exp_binop('*', $1, $3); }
575 | exp '/' exp
576 { $$ = exp_binop('/', $1, $3); }
577 | exp '%' exp
578 { $$ = exp_binop('%', $1, $3); }
579 | exp '+' exp
580 { $$ = exp_binop('+', $1, $3); }
581 | exp '-' exp
582 { $$ = exp_binop('-' , $1, $3); }
583 | exp LSHIFT exp
584 { $$ = exp_binop(LSHIFT , $1, $3); }
585 | exp RSHIFT exp
586 { $$ = exp_binop(RSHIFT , $1, $3); }
587 | exp EQ exp
588 { $$ = exp_binop(EQ , $1, $3); }
589 | exp NE exp
590 { $$ = exp_binop(NE , $1, $3); }
591 | exp LE exp
592 { $$ = exp_binop(LE , $1, $3); }
593 | exp GE exp
594 { $$ = exp_binop(GE , $1, $3); }
595 | exp '<' exp
596 { $$ = exp_binop('<' , $1, $3); }
597 | exp '>' exp
598 { $$ = exp_binop('>' , $1, $3); }
599 | exp '&' exp
600 { $$ = exp_binop('&' , $1, $3); }
601 | exp '^' exp
602 { $$ = exp_binop('^' , $1, $3); }
603 | exp '|' exp
604 { $$ = exp_binop('|' , $1, $3); }
605 | exp '?' exp ':' exp
606 { $$ = exp_trinop('?' , $1, $3, $5); }
607 | exp ANDAND exp
608 { $$ = exp_binop(ANDAND , $1, $3); }
609 | exp OROR exp
610 { $$ = exp_binop(OROR , $1, $3); }
611 | DEFINED '(' NAME ')'
612 { $$ = exp_nameop(DEFINED, $3); }
613 | INT
614 { $$ = exp_intop($1); }
615
616 | SIZEOF '(' NAME ')'
617 { $$ = exp_nameop($1,$3); }
618 | ADDR '(' NAME ')'
619 { $$ = exp_nameop($1,$3); }
620 | ALIGN_K '(' exp ')'
621 { $$ = exp_unop($1,$3); }
622 | NAME
623 { $$ = exp_nameop(NAME,$1); }
624 ;
625
626
627
628
629section: NAME opt_exp opt_block ':' opt_things'{'
630 {
631 lang_enter_output_section_statement($1,$2,$3);
632 }
633 statement '}' fill_opt memspec_opt
634 {
635 lang_leave_output_section_statement($10, $11);
636 }
637
638 ;
639
640opt_things:
641 {
642
643 }
644 ;
645
646exp_head:
7ca04d28
SC
647 {
648 ldgram_in_expression = true;
649 }
2fa0b342 650 exp
7ca04d28
SC
651 {
652 ldgram_in_expression = false;
653 $$ = $2;
654 }
655 ;
2fa0b342
DHW
656
657opt_exp:
7ca04d28 658 exp_head
2fa0b342
DHW
659 { $$ = $1; }
660 | { $$= (etree_type *)NULL; }
661 ;
662
663opt_block:
664 BLOCK '(' exp_head ')'
665 { $$ = exp_get_value_int($3,
666 1L,
667 "block",
668 lang_first_phase_enum);
669 }
670 | { $$ = 1; }
671 ;
672
673memspec_opt:
674 '>' NAME
675 { $$ = $2; }
676 | { $$ = "*default*"; }
677 ;
678
This page took 0.048176 seconds and 4 git commands to generate.