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