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).
5 This file is part of GNU ld.
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.
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.
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
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #define DONTDECLARE_MALLOC
42 extern unsigned int lineno;
43 extern boolean trace_files;
44 extern boolean write_map;
45 extern boolean option_longmap;
48 strip_symbols_type strip_symbols=STRIP_NONE;
49 discard_locals_type discard_locals=DISCARD_NONE;
52 lang_memory_region_type *region;
55 lang_memory_region_type *lang_memory_region_lookup();
56 lang_output_section_statement_type *lang_output_section_statement_lookup();
60 void lang_add_data(int type, union etree_union *exp);
61 void lang_enter_output_section_statement(char *output_section_statement_name, etree_type *address_exp, int flags, bfd_vma block_value);
66 void lang_enter_output_section_statement();
70 extern args_type command_line;
72 boolean ldgram_want_filename = true;
73 boolean had_script = false;
74 boolean force_make_executable = false;
76 boolean ldgram_in_script = false;
77 boolean ldgram_had_equals = false;
89 union etree_union *etree;
91 struct lang_output_section_statement_struct *output_section_statement;
92 union lang_statement_union **statement_ptr;
103 %type <etree> exp opt_exp
104 %type <integer> fill_opt opt_block opt_type
105 %type <name> memspec_opt
108 %type <integer> length
110 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
111 %right <token> '?' ':'
118 %left <token> '<' '>' LE GE
119 %left <token> LSHIFT RSHIFT
121 %left <token> '+' '-'
122 %left <token> '*' '/' '%'
124 /*%token <token> '+' '-' '*' '/' '%'*/
127 %token <token> ALIGN_K BLOCK LONG SHORT BYTE
130 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
131 %token SIZEOF_HEADERS
133 %token NOLOAD DSECT COPY INFO OVERLAY
134 %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
135 %token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S OPTION_sort_common
136 %token OPTION_format OPTION_F OPTION_u OPTION_Bstatic OPTION_N
137 %token <integer> SIZEOF NEXT ADDR
138 %token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X OPTION_defsym
139 %token OPTION_v OPTION_V OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT NOFLOAT
141 %token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_R OPTION_relax
142 %token <name> OPTION_l OPTION_L OPTION_T OPTION_Aarch OPTION_Tfile OPTION_Texp
144 %token ORIGIN FILL OPTION_g
145 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT OUTPUT CONSTRUCTORS
146 %type <token> assign_op
148 %type <name> filename
151 ld_config_type config;
158 file: command_line { lang_final(); };
165 command_line command_line_option
171 { ldgram_in_script = true; }
173 { ldgram_in_script = false; }
192 config.map_filename = $2;
197 option_longmap = true;
203 config.magic_demand_paged = false;
206 config.text_read_only = false;
207 config.magic_demand_paged = false;
210 strip_symbols = STRIP_ALL;
213 strip_symbols = STRIP_DEBUGGER;
216 ldlang_add_undef($2);
220 config.relocateable_output = true;
221 config.build_constructors = false;
222 config.magic_demand_paged = false;
223 config.text_read_only = false;
226 config.relocateable_output = true;
227 config.build_constructors = true;
228 config.magic_demand_paged = false;
229 config.text_read_only = false;
236 { lang_add_entry($2);
239 discard_locals = DISCARD_L;
242 discard_locals = DISCARD_ALL;
245 | OPTION_noinhibit_exec
247 force_make_executable = true;
249 | OPTION_sort_common {
250 config.sort_common = true;
253 command_line.force_common_definition = true;
257 command_line.relax = true;
261 command_line.force_common_definition = true;
269 command_line.force_common_definition = true;
281 lang_section_start($1,exp_intop($3));
295 ldfile_add_library_path($1);
302 { lang_add_input_file($1,lang_input_file_is_file_enum,
305 { ldfile_open_command_file($2); } script_file
307 { ldfile_open_command_file($1); } script_file
310 { ldfile_open_command_file($2); } script_file
314 lang_add_input_file($1,
315 lang_input_file_is_l_enum,
320 lang_add_input_file($2,
321 lang_input_file_is_symbols_only_enum,
330 lang_add_assignment(exp_assop($4,$3,$5));
333 { info("%P%F Unrecognised option -%s\n", $2); }
345 { ldgram_in_script = true; }
347 { ldgram_in_script = false; }
365 | floating_point_support
368 | TARGET_K '(' NAME ')'
369 { lang_add_target($3); }
370 | SEARCH_DIR '(' filename ')'
371 { ldfile_add_library_path($3); }
372 | OUTPUT '(' filename ')'
373 { lang_add_output($3); }
374 | OUTPUT_FORMAT '(' NAME ')'
375 { lang_add_output_format($3); }
376 | OUTPUT_ARCH '(' NAME ')'
377 { ldfile_set_output_arch($3); }
378 | FORCE_COMMON_ALLOCATION
379 { command_line.force_common_definition = true ; }
380 | INPUT '(' input_list ')'
381 | MAP '(' filename ')'
382 { lang_add_map($3); }
387 { lang_add_input_file($1,lang_input_file_is_file_enum,
389 | input_list ',' NAME
390 { lang_add_input_file($3,lang_input_file_is_file_enum,
393 { lang_add_input_file($2, lang_input_file_is_file_enum,
398 SECTIONS '{'sec_or_group_p1 '}'
402 sec_or_group_p1 section
403 | sec_or_group_p1 statement_anywhere
409 { lang_add_entry($3); }
415 { lang_add_wild($1, current_file); }
416 | file_NAME_list opt_comma NAME
417 { lang_add_wild($3, current_file); }
423 lang_add_wild((char *)NULL, $1);
427 current_file = (char *)NULL;
435 '(' file_NAME_list ')'
438 current_file = (char *)NULL;
440 '(' file_NAME_list ')'
444 statement assignment end
445 | statement CREATE_OBJECT_SYMBOLS
447 lang_add_attribute(lang_object_symbols_statement_enum); }
449 | statement CONSTRUCTORS
451 lang_add_attribute(lang_constructors_statement_enum); }
453 | statement input_section_spec
454 | statement length '(' exp ')'
456 lang_add_data($2,$4);
459 | statement FILL '(' exp ')'
462 (exp_get_value_int($4,
465 lang_first_phase_enum));
482 $$ = exp_get_value_int($2,
485 lang_first_phase_enum);
519 lang_add_assignment(exp_assop($2,$1,$3));
523 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
534 MEMORY '{' memory_spec memory_spec_list '}'
538 memory_spec_list memory_spec
539 | memory_spec_list ',' memory_spec
546 { region = lang_memory_region_lookup($1); }
547 attributes_opt ':' origin_spec opt_comma length_spec
558 exp_get_vma($3, 0L,"origin", lang_first_phase_enum); }
562 { region->length = exp_get_vma($3,
565 lang_first_phase_enum);
572 lang_set_flags(®ion->flags, $2);
579 STARTUP '(' filename ')'
580 { lang_startup($3); }
584 HLL '(' high_level_library_NAME_list ')'
586 { ldemul_hll((char *)NULL); }
589 high_level_library_NAME_list:
590 high_level_library_NAME_list opt_comma filename
598 SYSLIB '(' low_level_library_NAME_list ')'
600 low_level_library_NAME_list:
601 low_level_library_NAME_list opt_comma filename
602 { ldemul_syslib($3); }
606 floating_point_support:
608 { lang_float(true); }
610 { lang_float(false); }
618 { $$ = exp_unop('-', $2); }
621 | NEXT '(' exp ')' %prec UNARY
622 { $$ = exp_unop($1,$3); }
623 | '!' exp %prec UNARY
624 { $$ = exp_unop('!', $2); }
625 | '+' exp %prec UNARY
627 | '~' exp %prec UNARY
628 { $$ = exp_unop('~', $2);}
631 { $$ = exp_binop('*', $1, $3); }
633 { $$ = exp_binop('/', $1, $3); }
635 { $$ = exp_binop('%', $1, $3); }
637 { $$ = exp_binop('+', $1, $3); }
639 { $$ = exp_binop('-' , $1, $3); }
641 { $$ = exp_binop(LSHIFT , $1, $3); }
643 { $$ = exp_binop(RSHIFT , $1, $3); }
645 { $$ = exp_binop(EQ , $1, $3); }
647 { $$ = exp_binop(NE , $1, $3); }
649 { $$ = exp_binop(LE , $1, $3); }
651 { $$ = exp_binop(GE , $1, $3); }
653 { $$ = exp_binop('<' , $1, $3); }
655 { $$ = exp_binop('>' , $1, $3); }
657 { $$ = exp_binop('&' , $1, $3); }
659 { $$ = exp_binop('^' , $1, $3); }
661 { $$ = exp_binop('|' , $1, $3); }
662 | exp '?' exp ':' exp
663 { $$ = exp_trinop('?' , $1, $3, $5); }
665 { $$ = exp_binop(ANDAND , $1, $3); }
667 { $$ = exp_binop(OROR , $1, $3); }
668 | DEFINED '(' NAME ')'
669 { $$ = exp_nameop(DEFINED, $3); }
671 { $$ = exp_intop($1); }
673 { $$ = exp_nameop(SIZEOF_HEADERS,0); }
675 | SIZEOF '(' NAME ')'
676 { $$ = exp_nameop(SIZEOF,$3); }
678 { $$ = exp_nameop(ADDR,$3); }
679 | ALIGN_K '(' exp ')'
680 { $$ = exp_unop(ALIGN_K,$3); }
682 { $$ = exp_nameop(NAME,$1); }
688 section: NAME opt_exp opt_type opt_block ':' opt_things'{'
690 lang_enter_output_section_statement($1,$2,$3,$4);
692 statement '}' fill_opt memspec_opt
694 lang_leave_output_section_statement($11, $12);
700 '(' NOLOAD ')' { $$ = SEC_NO_FLAGS; }
701 | '(' DSECT ')' { $$ = 0; }
702 | '(' COPY ')' { $$ = 0; }
703 | '(' INFO ')' { $$ = 0; }
704 | '(' OVERLAY ')' { $$ = 0; }
705 | { $$ = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; }
721 | { $$= (etree_type *)NULL; }
726 { $$ = exp_get_value_int($3,
729 lang_first_phase_enum);
737 | { $$ = "*default*"; }