9 This is a YACC grammer intended to parse a superset of the AT&T
10 linker scripting languaue.
13 Written by Steve Chamberlain steve@cygnus.com
22 #include "ldversion.h"
30 extern unsigned int lineno;
31 extern boolean trace_files;
32 extern boolean write_map;
36 strip_symbols_type strip_symbols=STRIP_NONE;
37 discard_locals_type discard_locals=DISCARD_NONE;
40 lang_memory_region_type *region;
43 lang_memory_region_type *lang_memory_region_lookup();
44 lang_output_section_statement_type *lang_output_section_statement_lookup();
48 void lang_add_data(int type, union etree_union *exp);
49 void lang_enter_output_section_statement(char *output_section_statement_name, etree_type *address_exp, bfd_vma block_value);
54 void lang_enter_output_section_statement();
58 extern args_type command_line;
60 boolean ldgram_want_filename = true;
61 boolean had_script = false;
62 boolean force_make_executable = false;
64 boolean ldgram_in_script = false;
65 boolean ldgram_in_defsym = false;
66 boolean ldgram_had_equals = false;
78 union etree_union *etree;
80 struct lang_output_section_statement_struct *output_section_statement;
81 union lang_statement_union **statement_ptr;
92 %type <etree> exp opt_exp exp_head
93 %type <integer> fill_opt opt_block
94 %type <name> memspec_opt
95 %token <integer> INT CHAR
97 %type <integer> length
99 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
100 %right <token> '?' ':'
107 %left <token> '<' '>' LE GE
108 %left <token> LSHIFT RSHIFT
109 %left <token> '+' '-'
110 %left <token> '*' '/' '%'
113 %token <token> ALIGN_K BLOCK LONG SHORT BYTE
116 %token ALIGNMENT SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION
117 %token NEXT SIZEOF ADDR SCRIPT ENDSCRIPT
119 %token DSECT NOLOAD COPY INFO OVERLAY
120 %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
121 %token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S
122 %token OPTION_format OPTION_F OPTION_u
124 %token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X
125 %token OPTION_v OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT NOFLOAT OPTION_defsym
126 %token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_A OPTION_R
127 %token <name> OPTION_l OPTION_L OPTION_T OPTION_Aarch OPTION_Tfile OPTION_Texp
129 %token ORIGIN FILL OPTION_g
130 %token LENGTH BIND SUBSECTION_ALIGN CREATE_OBJECT_SYMBOLS INPUT OUTPUT
131 %type <token> assign_op SIZEOF NEXT ADDR
132 %type <etree> assignment
133 %type <name> filename
136 ld_config_type config;
143 file: command_line { lang_final(); };
150 command_line command_line_option
156 { ldgram_in_script = true; }
158 { ldgram_in_script = false; }
172 config.magic_demand_paged = false;
173 config.make_executable = false;
176 strip_symbols = STRIP_ALL;
179 strip_symbols = STRIP_DEBUGGER;
182 ldlang_add_undef($2);
186 config.relocateable_output = true;
187 config.build_constructors = false;
188 config.magic_demand_paged = false;
191 config.relocateable_output = true;
192 config.build_constructors = true;
193 config.magic_demand_paged = false;
200 { lang_add_entry($2);
203 discard_locals = DISCARD_L;
206 discard_locals = DISCARD_ALL;
209 | OPTION_noinhibit_exec
211 force_make_executable = true;
214 command_line.force_common_definition = true;
218 command_line.force_common_definition = true;
226 command_line.force_common_definition = true;
238 lang_section_start($1,exp_intop($3));
252 ldfile_add_library_path($1);
259 { lang_add_input_file($1,lang_input_file_is_file_enum,
261 | OPTION_c filename script_file
262 { ldfile_open_command_file($2); }
264 { ldfile_open_command_file($1); } script_file
267 { ldfile_open_command_file($2); } script_file
271 lang_add_input_file($1,
272 lang_input_file_is_l_enum,
277 lang_add_input_file($2,
278 lang_input_file_is_symbols_only_enum,
283 ldgram_in_defsym = true;
284 ldgram_had_equals = false;
289 lang_add_assignment(exp_assop($4,$3,$5));
290 ldgram_in_defsym = false;
293 { info("%P%F Unrecognised option -%s\n", $2); }
305 { ldgram_in_script = true; }
307 { ldgram_in_script = false; }
325 | floating_point_support
327 | TARGET_K '(' NAME ')'
328 { lang_add_target($3); }
329 | SEARCH_DIR '(' filename ')'
330 { ldfile_add_library_path($3); }
331 | OUTPUT '(' filename ')'
332 { lang_add_output($3); }
333 | OUTPUT_FORMAT '(' NAME ')'
334 { lang_add_output_format($3); }
335 | FORCE_COMMON_ALLOCATION
336 { command_line.force_common_definition = true ; }
337 | INPUT '(' input_list ')'
338 | MAP '(' filename ')'
339 { lang_add_map($3); }
344 { lang_add_input_file($1,lang_input_file_is_file_enum,
346 | input_list ',' NAME
347 { lang_add_input_file($3,lang_input_file_is_file_enum,
350 { lang_add_input_file($2, lang_input_file_is_file_enum,
355 SECTIONS '{'sec_or_group_p1 '}'
359 sec_or_group_p1 section
360 | sec_or_group_p1 statement_anywhere
366 { lang_add_entry($3); }
372 { lang_add_wild($1, current_file); }
373 | file_NAME_list opt_comma NAME
374 { lang_add_wild($3, current_file); }
380 lang_add_wild((char *)NULL, $1);
384 current_file = (char *)NULL;
392 '(' file_NAME_list ')'
395 current_file = (char *)NULL;
397 '(' file_NAME_list ')'
401 statement assignment end
402 | statement CREATE_OBJECT_SYMBOLS
404 lang_add_attribute(lang_object_symbols_statement_enum); }
406 | statement input_section_spec
407 | statement length '(' exp_head ')'
409 lang_add_data($2,$4);
412 | statement FILL '(' exp_head ')'
415 (exp_get_value_int($4,
418 lang_first_phase_enum));
435 $$ = exp_get_value_int($2,
438 lang_first_phase_enum);
473 lang_add_assignment(exp_assop($2,$1,$3));
475 | NAME assign_op exp_head
477 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
488 MEMORY '{' memory_spec memory_spec_list '}'
492 memory_spec_list memory_spec
493 | memory_spec_list ',' memory_spec
500 { region = lang_memory_region_lookup($1); }
501 attributes_opt ':' origin_spec opt_comma length_spec
512 exp_get_vma($3, 0L,"origin", lang_first_phase_enum); }
516 { region->length = exp_get_vma($3,
519 lang_first_phase_enum);
526 lang_set_flags(®ion->flags, $2);
533 STARTUP '(' filename ')'
534 { lang_startup($3); }
538 HLL '(' high_level_library_NAME_list ')'
540 { ldemul_hll((char *)NULL); }
543 high_level_library_NAME_list:
544 high_level_library_NAME_list opt_comma filename
552 SYSLIB '(' low_level_library_NAME_list ')'
554 low_level_library_NAME_list:
555 low_level_library_NAME_list opt_comma filename
556 { ldemul_syslib($3); }
560 floating_point_support:
562 { lang_float(true); }
564 { lang_float(false); }
572 { $$ = exp_unop('-', $2); }
575 | NEXT '(' exp ')' %prec UNARY
576 { $$ = exp_unop($1,$3); }
577 | '!' exp %prec UNARY
578 { $$ = exp_unop('!', $2); }
579 | '+' exp %prec UNARY
581 | '~' exp %prec UNARY
582 { $$ = exp_unop('~', $2);}
585 { $$ = exp_binop('*', $1, $3); }
587 { $$ = exp_binop('/', $1, $3); }
589 { $$ = exp_binop('%', $1, $3); }
591 { $$ = exp_binop('+', $1, $3); }
593 { $$ = exp_binop('-' , $1, $3); }
595 { $$ = exp_binop(LSHIFT , $1, $3); }
597 { $$ = exp_binop(RSHIFT , $1, $3); }
599 { $$ = exp_binop(EQ , $1, $3); }
601 { $$ = exp_binop(NE , $1, $3); }
603 { $$ = exp_binop(LE , $1, $3); }
605 { $$ = exp_binop(GE , $1, $3); }
607 { $$ = exp_binop('<' , $1, $3); }
609 { $$ = exp_binop('>' , $1, $3); }
611 { $$ = exp_binop('&' , $1, $3); }
613 { $$ = exp_binop('^' , $1, $3); }
615 { $$ = exp_binop('|' , $1, $3); }
616 | exp '?' exp ':' exp
617 { $$ = exp_trinop('?' , $1, $3, $5); }
619 { $$ = exp_binop(ANDAND , $1, $3); }
621 { $$ = exp_binop(OROR , $1, $3); }
622 | DEFINED '(' NAME ')'
623 { $$ = exp_nameop(DEFINED, $3); }
625 { $$ = exp_intop($1); }
627 | SIZEOF '(' NAME ')'
628 { $$ = exp_nameop($1,$3); }
630 { $$ = exp_nameop($1,$3); }
631 | ALIGN_K '(' exp ')'
632 { $$ = exp_unop($1,$3); }
634 { $$ = exp_nameop(NAME,$1); }
640 section: NAME opt_exp opt_block ':' opt_things'{'
642 lang_enter_output_section_statement($1,$2,$3);
644 statement '}' fill_opt memspec_opt
646 lang_leave_output_section_statement($10, $11);
664 | { $$= (etree_type *)NULL; }
668 BLOCK '(' exp_head ')'
669 { $$ = exp_get_value_int($3,
672 lang_first_phase_enum);
680 | { $$ = "*default*"; }