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;
251 { lang_section_start($1, $3);
255 { ldfile_add_arch($1); }
262 ldfile_add_library_path($1);
272 { ldfile_open_command_file($2); }
274 { ldfile_open_command_file($1); }
277 { ldfile_open_command_file($2); }
281 lang_add_input_file($1,
282 lang_input_file_is_l_enum,
287 lang_add_input_file($2,
288 lang_input_file_is_symbols_only_enum,
293 ldgram_in_defsym = true;
299 ldgram_in_defsym = false;
308 lang_add_wild((char *)NULL, $1);
312 current_file = (char *)NULL;
320 '(' file_NAME_list ')'
323 current_file = (char *)NULL;
325 '(' file_NAME_list ')'
332 { lang_add_wild($1, current_file); }
333 | file_NAME_list opt_comma NAME
334 { lang_add_wild($3, current_file); }
345 | floating_point_support
347 | TARGET_K '(' NAME ')'
348 { lang_add_target($3); }
349 | SEARCH_DIR '(' filename ')'
350 { ldfile_add_library_path($3); }
351 | OUTPUT '(' filename ')'
352 { lang_add_output($3); }
353 | INPUT '(' input_list ')'
354 | MAP '(' filename ')'
355 { lang_add_map($3); }
360 { lang_add_input_file($1,lang_input_file_is_file_enum,
362 | input_list ',' NAME
363 { lang_add_input_file($3,lang_input_file_is_file_enum,
366 { lang_add_input_file($2, lang_input_file_is_file_enum,
371 SECTIONS '{'sec_or_group_p1 '}'
375 sec_or_group_p1 section
376 | sec_or_group_p1 statement_anywhere
382 { lang_add_entry($3); }
387 statement assignment end
388 | statement CREATE_OBJECT_SYMBOLS
389 { lang_add_attribute(lang_object_symbols_statement_enum); }
390 | statement input_section_spec
391 | statement length '(' exp_head ')'
393 lang_add_data($2,$4);
396 | statement FILL '(' exp_head ')'
399 (exp_get_value_int($4,
402 lang_first_phase_enum));
419 $$ = exp_get_value_int($2,
422 lang_first_phase_enum);
457 lang_add_assignment(exp_assop($2,$1,$3));
459 | NAME assign_op exp_head
461 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
472 MEMORY '{' memory_spec memory_spec_list '}'
476 memory_spec_list memory_spec
477 | memory_spec_list ',' memory_spec
484 { region = lang_memory_region_lookup($1); }
485 attributes_opt ':' origin_spec opt_comma length_spec
496 exp_get_vma($3, 0L,"origin", lang_first_phase_enum); }
500 { region->length = exp_get_vma($3,
503 lang_first_phase_enum);
510 lang_set_flags(®ion->flags, $2);
517 STARTUP '(' filename ')'
518 { lang_startup($3); }
522 HLL '(' high_level_library_NAME_list ')'
524 { ldemul_hll((char *)NULL); }
527 high_level_library_NAME_list:
528 high_level_library_NAME_list opt_comma filename
536 SYSLIB '(' low_level_library_NAME_list ')'
538 low_level_library_NAME_list:
539 low_level_library_NAME_list opt_comma filename
540 { ldemul_syslib($3); }
544 floating_point_support:
546 { lang_float(true); }
548 { lang_float(false); }
556 { $$ = exp_unop('-', $2); }
559 | NEXT '(' exp ')' %prec UNARY
560 { $$ = exp_unop($1,$3); }
561 | '!' exp %prec UNARY
562 { $$ = exp_unop('!', $2); }
563 | '+' exp %prec UNARY
565 | '~' exp %prec UNARY
566 { $$ = exp_unop('~', $2);}
569 { $$ = exp_binop('*', $1, $3); }
571 { $$ = exp_binop('/', $1, $3); }
573 { $$ = exp_binop('%', $1, $3); }
575 { $$ = exp_binop('+', $1, $3); }
577 { $$ = exp_binop('-' , $1, $3); }
579 { $$ = exp_binop(LSHIFT , $1, $3); }
581 { $$ = exp_binop(RSHIFT , $1, $3); }
583 { $$ = exp_binop(EQ , $1, $3); }
585 { $$ = exp_binop(NE , $1, $3); }
587 { $$ = exp_binop(LE , $1, $3); }
589 { $$ = exp_binop(GE , $1, $3); }
591 { $$ = exp_binop('<' , $1, $3); }
593 { $$ = exp_binop('>' , $1, $3); }
595 { $$ = exp_binop('&' , $1, $3); }
597 { $$ = exp_binop('^' , $1, $3); }
599 { $$ = exp_binop('|' , $1, $3); }
600 | exp '?' exp ':' exp
601 { $$ = exp_trinop('?' , $1, $3, $5); }
603 { $$ = exp_binop(ANDAND , $1, $3); }
605 { $$ = exp_binop(OROR , $1, $3); }
606 | DEFINED '(' NAME ')'
607 { $$ = exp_nameop(DEFINED, $3); }
609 { $$ = exp_intop($1); }
611 | SIZEOF '(' NAME ')'
612 { $$ = exp_nameop($1,$3); }
614 { $$ = exp_nameop($1,$3); }
615 | ALIGN_K '(' exp ')'
616 { $$ = exp_unop($1,$3); }
618 { $$ = exp_nameop(NAME,$1); }
624 section: NAME opt_exp opt_block ':' opt_things'{'
626 lang_enter_output_section_statement($1,$2,$3);
628 statement '}' fill_opt memspec_opt
630 lang_leave_output_section_statement($10, $11);
643 ldgram_in_expression = true;
647 ldgram_in_expression = false;
655 | { $$= (etree_type *)NULL; }
659 BLOCK '(' exp_head ')'
660 { $$ = exp_get_value_int($3,
663 lang_first_phase_enum);
671 | { $$ = "*default*"; }