Removed extern declarations
[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 '{' '}'
13a0e8d7 114%token ALIGNMENT SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION
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;
070aa819 279
7ca04d28
SC
280 }
281 assignment
282 {
283 ldgram_in_defsym = false;
1418c83b 284 ldgram_in_expression = false;
7ca04d28 285 }
1418c83b
SC
286 | '-' NAME
287 { info("%P%F Unrecognised option -%s\n", $2); }
7ca04d28 288
2fa0b342
DHW
289 ;
290
291
1418c83b 292
2fa0b342
DHW
293
294
295
1418c83b
SC
296
297
298script_file:
299 { ldgram_in_script = true; }
300 ifile_list ENDSCRIPT
301 { ldgram_in_script = false; }
302
303 ;
304
305
306ifile_list:
307 ifile_list ifile_p1
13a0e8d7 308 |
2fa0b342
DHW
309 ;
310
311
312
313ifile_p1:
314 memory
315 | sections
316 | startup
317 | high_level_library
318 | low_level_library
319 | floating_point_support
320 | assignment end
321 | TARGET_K '(' NAME ')'
322 { lang_add_target($3); }
323 | SEARCH_DIR '(' filename ')'
324 { ldfile_add_library_path($3); }
325 | OUTPUT '(' filename ')'
326 { lang_add_output($3); }
13a0e8d7
SC
327 | OUTPUT_FORMAT '(' NAME ')'
328 { lang_add_output_format($3); }
329 | FORCE_COMMON_ALLOCATION
330 { command_line.force_common_definition = true ; }
2fa0b342
DHW
331 | INPUT '(' input_list ')'
332 | MAP '(' filename ')'
333 { lang_add_map($3); }
334 ;
335
336input_list:
337 NAME
338 { lang_add_input_file($1,lang_input_file_is_file_enum,
339 (char *)NULL); }
340 | input_list ',' NAME
341 { lang_add_input_file($3,lang_input_file_is_file_enum,
342 (char *)NULL); }
343 | input_list NAME
344 { lang_add_input_file($2, lang_input_file_is_file_enum,
345 (char *)NULL); }
346 ;
347
348sections:
349 SECTIONS '{'sec_or_group_p1 '}'
350 ;
351
352sec_or_group_p1:
353 sec_or_group_p1 section
354 | sec_or_group_p1 statement_anywhere
355 |
356 ;
357
358statement_anywhere:
359 ENTRY '(' NAME ')'
360 { lang_add_entry($3); }
361 | assignment end
362 ;
363
1418c83b
SC
364file_NAME_list:
365 NAME
366 { lang_add_wild($1, current_file); }
367 | file_NAME_list opt_comma NAME
368 { lang_add_wild($3, current_file); }
369 ;
370
371input_section_spec:
372 NAME
373 {
374 lang_add_wild((char *)NULL, $1);
375 }
376 | '['
377 {
378 current_file = (char *)NULL;
379 }
380 file_NAME_list
381 ']'
382 | NAME
383 {
384 current_file =$1;
385 }
386 '(' file_NAME_list ')'
387 | '*'
388 {
389 current_file = (char *)NULL;
390 }
391 '(' file_NAME_list ')'
392 ;
393
2fa0b342
DHW
394statement:
395 statement assignment end
396 | statement CREATE_OBJECT_SYMBOLS
13a0e8d7
SC
397 {
398 lang_add_attribute(lang_object_symbols_statement_enum); }
399
2fa0b342
DHW
400 | statement input_section_spec
401 | statement length '(' exp_head ')'
402 {
403 lang_add_data($2,$4);
404 }
405
406 | statement FILL '(' exp_head ')'
407 {
408 lang_add_fill
409 (exp_get_value_int($4,
410 0,
411 "fill value",
412 lang_first_phase_enum));
413 }
414 |
415 ;
416
417length:
418 LONG
419 { $$ = $1; }
420 | SHORT
421 { $$ = $1; }
422 | BYTE
423 { $$ = $1; }
424 ;
425
426fill_opt:
427 '=' exp_head
428 {
429 $$ = exp_get_value_int($2,
430 0,
431 "fill value",
432 lang_first_phase_enum);
433 }
434 | { $$ = 0; }
435 ;
436
437
438
439assign_op:
440 PLUSEQ
441 { $$ = '+'; }
442 | MINUSEQ
443 { $$ = '-'; }
444 | MULTEQ
445 { $$ = '*'; }
446 | DIVEQ
447 { $$ = '/'; }
448 | LSHIFTEQ
449 { $$ = LSHIFT; }
450 | RSHIFTEQ
451 { $$ = RSHIFT; }
452 | ANDEQ
453 { $$ = '&'; }
454 | OREQ
455 { $$ = '|'; }
456
457 ;
458
459end: ';' | ','
460 ;
461
2fa0b342
DHW
462
463assignment:
464
465 NAME '=' exp_head
466 {
467 lang_add_assignment(exp_assop($2,$1,$3));
468 }
469 | NAME assign_op exp_head
470 {
471 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
472 }
473
474 ;
475
476
477opt_comma:
478 ',' | ;
479
480
481memory:
482 MEMORY '{' memory_spec memory_spec_list '}'
483 ;
484
485memory_spec_list:
486 memory_spec_list memory_spec
487 | memory_spec_list ',' memory_spec
488 |
489 ;
490
491
492memory_spec:
493 NAME
494 { region = lang_memory_region_lookup($1); }
495 attributes_opt ':' origin_spec opt_comma length_spec
496
497 {
498
499
500 }
501 ;
502origin_spec:
503 ORIGIN '=' exp
504 { region->current =
505 region->origin =
506 exp_get_vma($3, 0L,"origin", lang_first_phase_enum); }
507 ;
508length_spec:
509 LENGTH '=' exp
510 { region->length = exp_get_vma($3,
511 ~((bfd_vma)0),
512 "length",
513 lang_first_phase_enum);
514 }
515
516
517attributes_opt:
518 '(' NAME ')'
519 {
520 lang_set_flags(&region->flags, $2);
521 }
522 |
523
524 ;
525
526startup:
527 STARTUP '(' filename ')'
528 { lang_startup($3); }
529 ;
530
531high_level_library:
532 HLL '(' high_level_library_NAME_list ')'
533 | HLL '(' ')'
534 { ldemul_hll((char *)NULL); }
535 ;
536
537high_level_library_NAME_list:
538 high_level_library_NAME_list opt_comma filename
539 { ldemul_hll($3); }
540 | filename
541 { ldemul_hll($1); }
542
543 ;
544
545low_level_library:
546 SYSLIB '(' low_level_library_NAME_list ')'
547 ;
548low_level_library_NAME_list:
549 low_level_library_NAME_list opt_comma filename
550 { ldemul_syslib($3); }
551 |
552 ;
553
554floating_point_support:
555 FLOAT
556 { lang_float(true); }
557 | NOFLOAT
558 { lang_float(false); }
559 ;
560
561
562
563
564exp :
565 '-' exp %prec UNARY
566 { $$ = exp_unop('-', $2); }
567 | '(' exp ')'
568 { $$ = $2; }
569 | NEXT '(' exp ')' %prec UNARY
570 { $$ = exp_unop($1,$3); }
571 | '!' exp %prec UNARY
572 { $$ = exp_unop('!', $2); }
573 | '+' exp %prec UNARY
574 { $$ = $2; }
575 | '~' exp %prec UNARY
576 { $$ = exp_unop('~', $2);}
577
578 | exp '*' exp
579 { $$ = exp_binop('*', $1, $3); }
580 | exp '/' exp
581 { $$ = exp_binop('/', $1, $3); }
582 | exp '%' exp
583 { $$ = exp_binop('%', $1, $3); }
584 | exp '+' exp
585 { $$ = exp_binop('+', $1, $3); }
586 | exp '-' exp
587 { $$ = exp_binop('-' , $1, $3); }
588 | exp LSHIFT exp
589 { $$ = exp_binop(LSHIFT , $1, $3); }
590 | exp RSHIFT exp
591 { $$ = exp_binop(RSHIFT , $1, $3); }
592 | exp EQ exp
593 { $$ = exp_binop(EQ , $1, $3); }
594 | exp NE exp
595 { $$ = exp_binop(NE , $1, $3); }
596 | exp LE exp
597 { $$ = exp_binop(LE , $1, $3); }
598 | exp GE exp
599 { $$ = exp_binop(GE , $1, $3); }
600 | exp '<' exp
601 { $$ = exp_binop('<' , $1, $3); }
602 | exp '>' exp
603 { $$ = exp_binop('>' , $1, $3); }
604 | exp '&' exp
605 { $$ = exp_binop('&' , $1, $3); }
606 | exp '^' exp
607 { $$ = exp_binop('^' , $1, $3); }
608 | exp '|' exp
609 { $$ = exp_binop('|' , $1, $3); }
610 | exp '?' exp ':' exp
611 { $$ = exp_trinop('?' , $1, $3, $5); }
612 | exp ANDAND exp
613 { $$ = exp_binop(ANDAND , $1, $3); }
614 | exp OROR exp
615 { $$ = exp_binop(OROR , $1, $3); }
616 | DEFINED '(' NAME ')'
617 { $$ = exp_nameop(DEFINED, $3); }
618 | INT
619 { $$ = exp_intop($1); }
620
621 | SIZEOF '(' NAME ')'
622 { $$ = exp_nameop($1,$3); }
623 | ADDR '(' NAME ')'
624 { $$ = exp_nameop($1,$3); }
625 | ALIGN_K '(' exp ')'
626 { $$ = exp_unop($1,$3); }
627 | NAME
628 { $$ = exp_nameop(NAME,$1); }
629 ;
630
631
632
633
634section: NAME opt_exp opt_block ':' opt_things'{'
635 {
636 lang_enter_output_section_statement($1,$2,$3);
637 }
638 statement '}' fill_opt memspec_opt
639 {
640 lang_leave_output_section_statement($10, $11);
641 }
642
643 ;
644
645opt_things:
646 {
647
648 }
649 ;
650
651exp_head:
7ca04d28
SC
652 {
653 ldgram_in_expression = true;
654 }
2fa0b342 655 exp
7ca04d28
SC
656 {
657 ldgram_in_expression = false;
658 $$ = $2;
659 }
660 ;
2fa0b342
DHW
661
662opt_exp:
7ca04d28 663 exp_head
2fa0b342
DHW
664 { $$ = $1; }
665 | { $$= (etree_type *)NULL; }
666 ;
667
668opt_block:
669 BLOCK '(' exp_head ')'
670 { $$ = exp_get_value_int($3,
671 1L,
672 "block",
673 lang_first_phase_enum);
674 }
675 | { $$ = 1; }
676 ;
677
678memspec_opt:
679 '>' NAME
680 { $$ = $2; }
681 | { $$ = "*default*"; }
682 ;
683
This page took 0.081252 seconds and 4 git commands to generate.