2 /* Copyright (C) 1991 Free Software Foundation, Inc.
4 This file is part of GLD, the Gnu Linker.
6 GLD is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GLD is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GLD; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 This is a YACC grammer intended to parse a superset of the AT&T
28 linker scripting languaue.
31 Written by Steve Chamberlain steve@cygnus.com
43 #include "ldversion.h"
53 extern unsigned int lineno;
54 extern boolean trace_files;
55 extern boolean write_map;
62 lang_memory_region_type *region;
65 lang_memory_region_type *lang_memory_region_lookup();
66 lang_output_section_statement_type *lang_output_section_statement_lookup();
70 void lang_add_data(int type, union etree_union *exp);
71 void lang_enter_output_section_statement(char *output_section_statement_name, etree_type *address_exp, bfd_vma block_value);
76 void lang_enter_output_section_statement();
80 extern args_type command_line;
82 boolean ldgram_want_filename = true;
83 boolean had_script = false;
84 boolean force_make_executable = false;
85 boolean ldgram_has_inputfile = false;
87 boolean ldgram_in_expression = false;
89 boolean ldgram_in_defsym = false;
101 union etree_union *etree;
103 struct lang_output_section_statement_struct *output_section_statement;
104 union lang_statement_union **statement_ptr;
115 %type <etree> exp opt_exp exp_head
116 %type <integer> fill_opt opt_block
117 %type <name> memspec_opt
118 %token <integer> INT CHAR
120 %type <integer> length
122 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
123 %right <token> '?' ':'
130 %left <token> '<' '>' LE GE
131 %left <token> LSHIFT RSHIFT
132 %left <token> '+' '-'
133 %left <token> '*' '/' '%'
136 %token <token> ALIGN_K BLOCK LONG SHORT BYTE
139 %token ALIGNMENT SIZEOF_HEADERS
140 %token NEXT SIZEOF ADDR
142 %token DSECT NOLOAD COPY INFO OVERLAY
143 %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
144 %token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S
145 %token OPTION_format OPTION_F
147 %token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X
148 %token OPTION_v OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT NOFLOAT OPTION_defsym
149 %token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_A
150 %token <name> OPTION_l OPTION_L OPTION_T OPTION_Aarch OPTION_Tfile OPTION_Texp
152 %token ORIGIN FILL OPTION_g
153 %token LENGTH BIND SUBSECTION_ALIGN CREATE_OBJECT_SYMBOLS INPUT OUTPUT
154 %type <token> assign_op SIZEOF NEXT ADDR
155 %type <etree> assignment
156 %type <name> filename
159 ld_config_type config;
166 file: command_line { lang_final(); };
173 command_line command_line_option
190 config.magic_demand_paged = false;
191 config.make_executable = false;
194 strip_symbols = STRIP_ALL;
197 strip_symbols = STRIP_DEBUGGER;
201 config.relocateable_output = true;
202 config.build_constructors = false;
203 config.magic_demand_paged = false;
206 config.relocateable_output = true;
207 config.build_constructors = true;
208 config.magic_demand_paged = false;
215 { lang_add_entry($2);
218 discard_locals = DISCARD_L;
221 discard_locals = DISCARD_ALL;
224 | OPTION_noinhibit_exec
226 force_make_executable = true;
229 command_line.force_common_definition = true;
233 command_line.force_common_definition = true;
241 command_line.force_common_definition = true;
248 | OPTION_Texp { hex_mode =true; }
250 { lang_section_start($1, $3);
254 { ldfile_add_arch($1); }
261 ldfile_add_library_path($1);
271 { ldfile_open_command_file($2); }
273 { ldfile_open_command_file($1); }
276 { ldfile_open_command_file($2); }
280 lang_add_input_file($1,
281 lang_input_file_is_l_enum,
286 lang_add_input_file($2,
287 lang_input_file_is_symbols_only_enum,
292 ldgram_in_defsym = true;
296 ldgram_in_defsym = false;
305 lang_add_wild((char *)NULL, $1);
309 current_file = (char *)NULL;
317 '(' file_NAME_list ')'
320 current_file = (char *)NULL;
322 '(' file_NAME_list ')'
329 { lang_add_wild($1, current_file); }
330 | file_NAME_list opt_comma NAME
331 { lang_add_wild($3, current_file); }
342 | floating_point_support
344 | TARGET_K '(' NAME ')'
345 { lang_add_target($3); }
346 | SEARCH_DIR '(' filename ')'
347 { ldfile_add_library_path($3); }
348 | OUTPUT '(' filename ')'
349 { lang_add_output($3); }
350 | INPUT '(' input_list ')'
351 | MAP '(' filename ')'
352 { lang_add_map($3); }
357 { lang_add_input_file($1,lang_input_file_is_file_enum,
359 | input_list ',' NAME
360 { lang_add_input_file($3,lang_input_file_is_file_enum,
363 { lang_add_input_file($2, lang_input_file_is_file_enum,
368 SECTIONS '{'sec_or_group_p1 '}'
372 sec_or_group_p1 section
373 | sec_or_group_p1 statement_anywhere
379 { lang_add_entry($3); }
384 statement assignment end
385 | statement CREATE_OBJECT_SYMBOLS
386 { lang_add_attribute(lang_object_symbols_statement_enum); }
387 | statement input_section_spec
388 | statement length '(' exp_head ')'
390 lang_add_data($2,$4);
393 | statement FILL '(' exp_head ')'
396 (exp_get_value_int($4,
399 lang_first_phase_enum));
416 $$ = exp_get_value_int($2,
419 lang_first_phase_enum);
454 lang_add_assignment(exp_assop($2,$1,$3));
456 | NAME assign_op exp_head
458 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
469 MEMORY '{' memory_spec memory_spec_list '}'
473 memory_spec_list memory_spec
474 | memory_spec_list ',' memory_spec
481 { region = lang_memory_region_lookup($1); }
482 attributes_opt ':' origin_spec opt_comma length_spec
493 exp_get_vma($3, 0L,"origin", lang_first_phase_enum); }
497 { region->length = exp_get_vma($3,
500 lang_first_phase_enum);
507 lang_set_flags(®ion->flags, $2);
514 STARTUP '(' filename ')'
515 { lang_startup($3); }
519 HLL '(' high_level_library_NAME_list ')'
521 { ldemul_hll((char *)NULL); }
524 high_level_library_NAME_list:
525 high_level_library_NAME_list opt_comma filename
533 SYSLIB '(' low_level_library_NAME_list ')'
535 low_level_library_NAME_list:
536 low_level_library_NAME_list opt_comma filename
537 { ldemul_syslib($3); }
541 floating_point_support:
543 { lang_float(true); }
545 { lang_float(false); }
553 { $$ = exp_unop('-', $2); }
556 | NEXT '(' exp ')' %prec UNARY
557 { $$ = exp_unop($1,$3); }
558 | '!' exp %prec UNARY
559 { $$ = exp_unop('!', $2); }
560 | '+' exp %prec UNARY
562 | '~' exp %prec UNARY
563 { $$ = exp_unop('~', $2);}
566 { $$ = exp_binop('*', $1, $3); }
568 { $$ = exp_binop('/', $1, $3); }
570 { $$ = exp_binop('%', $1, $3); }
572 { $$ = exp_binop('+', $1, $3); }
574 { $$ = exp_binop('-' , $1, $3); }
576 { $$ = exp_binop(LSHIFT , $1, $3); }
578 { $$ = exp_binop(RSHIFT , $1, $3); }
580 { $$ = exp_binop(EQ , $1, $3); }
582 { $$ = exp_binop(NE , $1, $3); }
584 { $$ = exp_binop(LE , $1, $3); }
586 { $$ = exp_binop(GE , $1, $3); }
588 { $$ = exp_binop('<' , $1, $3); }
590 { $$ = exp_binop('>' , $1, $3); }
592 { $$ = exp_binop('&' , $1, $3); }
594 { $$ = exp_binop('^' , $1, $3); }
596 { $$ = exp_binop('|' , $1, $3); }
597 | exp '?' exp ':' exp
598 { $$ = exp_trinop('?' , $1, $3, $5); }
600 { $$ = exp_binop(ANDAND , $1, $3); }
602 { $$ = exp_binop(OROR , $1, $3); }
603 | DEFINED '(' NAME ')'
604 { $$ = exp_nameop(DEFINED, $3); }
606 { $$ = exp_intop($1); }
608 | SIZEOF '(' NAME ')'
609 { $$ = exp_nameop($1,$3); }
611 { $$ = exp_nameop($1,$3); }
612 | ALIGN_K '(' exp ')'
613 { $$ = exp_unop($1,$3); }
615 { $$ = exp_nameop(NAME,$1); }
621 section: NAME opt_exp opt_block ':' opt_things'{'
623 lang_enter_output_section_statement($1,$2,$3);
625 statement '}' fill_opt memspec_opt
627 lang_leave_output_section_statement($10, $11);
640 ldgram_in_expression = true;
644 ldgram_in_expression = false;
652 | { $$= (etree_type *)NULL; }
656 BLOCK '(' exp_head ')'
657 { $$ = exp_get_value_int($3,
660 lang_first_phase_enum);
668 | { $$ = "*default*"; }