9 This is a YACC grammer intended to parse a superset of the AT&T
10 linker scripting languaue.
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_had_equals = false;
77 union etree_union *etree;
79 struct lang_output_section_statement_struct *output_section_statement;
80 union lang_statement_union **statement_ptr;
91 %type <etree> exp opt_exp exp_head
92 %type <integer> fill_opt opt_block
93 %type <name> memspec_opt
94 %token <integer> INT CHAR
96 %type <integer> length
98 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
99 %right <token> '?' ':'
106 %left <token> '<' '>' LE GE
107 %left <token> LSHIFT RSHIFT
108 %left <token> '+' '-'
109 %left <token> '*' '/' '%'
112 %token <token> ALIGN_K BLOCK LONG SHORT BYTE
115 %token ALIGNMENT SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
116 %token NEXT SIZEOF ADDR SCRIPT ENDSCRIPT SIZEOF_HEADERS
118 %token DSECT NOLOAD COPY INFO OVERLAY
119 %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
120 %token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S OPTION_sort_common
121 %token OPTION_format OPTION_F OPTION_u
123 %token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X OPTION_defsym
124 %token OPTION_v OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT NOFLOAT
125 %token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_A OPTION_R
126 %token <name> OPTION_l OPTION_L OPTION_T OPTION_Aarch OPTION_Tfile OPTION_Texp
128 %token ORIGIN FILL OPTION_g
129 %token LENGTH BIND SUBSECTION_ALIGN CREATE_OBJECT_SYMBOLS INPUT OUTPUT
130 %type <token> assign_op SIZEOF NEXT ADDR
131 %type <etree> assignment
132 %type <name> filename
135 ld_config_type config;
142 file: command_line { lang_final(); };
149 command_line command_line_option
155 { ldgram_in_script = true; }
157 { ldgram_in_script = false; }
171 config.magic_demand_paged = false;
172 config.make_executable = false;
175 strip_symbols = STRIP_ALL;
178 strip_symbols = STRIP_DEBUGGER;
181 ldlang_add_undef($2);
185 config.relocateable_output = true;
186 config.build_constructors = false;
187 config.magic_demand_paged = false;
190 config.relocateable_output = true;
191 config.build_constructors = true;
192 config.magic_demand_paged = false;
199 { lang_add_entry($2);
202 discard_locals = DISCARD_L;
205 discard_locals = DISCARD_ALL;
208 | OPTION_noinhibit_exec
210 force_make_executable = true;
212 | OPTION_sort_common {
213 config.sort_common = true;
216 command_line.force_common_definition = true;
220 command_line.force_common_definition = true;
228 command_line.force_common_definition = true;
240 lang_section_start($1,exp_intop($3));
254 ldfile_add_library_path($1);
261 { lang_add_input_file($1,lang_input_file_is_file_enum,
263 | OPTION_c filename script_file
264 { ldfile_open_command_file($2); }
266 { ldfile_open_command_file($1); } script_file
269 { ldfile_open_command_file($2); } script_file
273 lang_add_input_file($1,
274 lang_input_file_is_l_enum,
279 lang_add_input_file($2,
280 lang_input_file_is_symbols_only_enum,
289 lang_add_assignment(exp_assop($4,$3,$5));
292 { info("%P%F Unrecognised option -%s\n", $2); }
304 { ldgram_in_script = true; }
306 { ldgram_in_script = false; }
324 | floating_point_support
326 | TARGET_K '(' NAME ')'
327 { lang_add_target($3); }
328 | SEARCH_DIR '(' filename ')'
329 { ldfile_add_library_path($3); }
330 | OUTPUT '(' filename ')'
331 { lang_add_output($3); }
332 | OUTPUT_FORMAT '(' NAME ')'
333 { lang_add_output_format($3); }
334 | OUTPUT_ARCH '(' NAME ')'
335 { ldfile_set_output_arch($3); }
336 | FORCE_COMMON_ALLOCATION
337 { command_line.force_common_definition = true ; }
338 | INPUT '(' input_list ')'
339 | MAP '(' filename ')'
340 { lang_add_map($3); }
345 { lang_add_input_file($1,lang_input_file_is_file_enum,
347 | input_list ',' NAME
348 { lang_add_input_file($3,lang_input_file_is_file_enum,
351 { lang_add_input_file($2, lang_input_file_is_file_enum,
356 SECTIONS '{'sec_or_group_p1 '}'
360 sec_or_group_p1 section
361 | sec_or_group_p1 statement_anywhere
367 { lang_add_entry($3); }
373 { lang_add_wild($1, current_file); }
374 | file_NAME_list opt_comma NAME
375 { lang_add_wild($3, current_file); }
381 lang_add_wild((char *)NULL, $1);
385 current_file = (char *)NULL;
393 '(' file_NAME_list ')'
396 current_file = (char *)NULL;
398 '(' file_NAME_list ')'
402 statement assignment end
403 | statement CREATE_OBJECT_SYMBOLS
405 lang_add_attribute(lang_object_symbols_statement_enum); }
407 | statement input_section_spec
408 | statement length '(' exp_head ')'
410 lang_add_data($2,$4);
413 | statement FILL '(' exp_head ')'
416 (exp_get_value_int($4,
419 lang_first_phase_enum));
436 $$ = exp_get_value_int($2,
439 lang_first_phase_enum);
474 lang_add_assignment(exp_assop($2,$1,$3));
476 | NAME assign_op exp_head
478 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
489 MEMORY '{' memory_spec memory_spec_list '}'
493 memory_spec_list memory_spec
494 | memory_spec_list ',' memory_spec
501 { region = lang_memory_region_lookup($1); }
502 attributes_opt ':' origin_spec opt_comma length_spec
513 exp_get_vma($3, 0L,"origin", lang_first_phase_enum); }
517 { region->length = exp_get_vma($3,
520 lang_first_phase_enum);
527 lang_set_flags(®ion->flags, $2);
534 STARTUP '(' filename ')'
535 { lang_startup($3); }
539 HLL '(' high_level_library_NAME_list ')'
541 { ldemul_hll((char *)NULL); }
544 high_level_library_NAME_list:
545 high_level_library_NAME_list opt_comma filename
553 SYSLIB '(' low_level_library_NAME_list ')'
555 low_level_library_NAME_list:
556 low_level_library_NAME_list opt_comma filename
557 { ldemul_syslib($3); }
561 floating_point_support:
563 { lang_float(true); }
565 { lang_float(false); }
573 { $$ = exp_unop('-', $2); }
576 | NEXT '(' exp ')' %prec UNARY
577 { $$ = exp_unop($1,$3); }
578 | '!' exp %prec UNARY
579 { $$ = exp_unop('!', $2); }
580 | '+' exp %prec UNARY
582 | '~' exp %prec UNARY
583 { $$ = exp_unop('~', $2);}
586 { $$ = exp_binop('*', $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(LSHIFT , $1, $3); }
598 { $$ = exp_binop(RSHIFT , $1, $3); }
600 { $$ = exp_binop(EQ , $1, $3); }
602 { $$ = exp_binop(NE , $1, $3); }
604 { $$ = exp_binop(LE , $1, $3); }
606 { $$ = exp_binop(GE , $1, $3); }
608 { $$ = exp_binop('<' , $1, $3); }
610 { $$ = exp_binop('>' , $1, $3); }
612 { $$ = exp_binop('&' , $1, $3); }
614 { $$ = exp_binop('^' , $1, $3); }
616 { $$ = exp_binop('|' , $1, $3); }
617 | exp '?' exp ':' exp
618 { $$ = exp_trinop('?' , $1, $3, $5); }
620 { $$ = exp_binop(ANDAND , $1, $3); }
622 { $$ = exp_binop(OROR , $1, $3); }
623 | DEFINED '(' NAME ')'
624 { $$ = exp_nameop(DEFINED, $3); }
626 { $$ = exp_intop($1); }
628 { $$ = exp_nameop(SIZEOF_HEADERS,0); }
630 | SIZEOF '(' NAME ')'
631 { $$ = exp_nameop($1,$3); }
633 { $$ = exp_nameop($1,$3); }
634 | ALIGN_K '(' exp ')'
635 { $$ = exp_unop($1,$3); }
637 { $$ = exp_nameop(NAME,$1); }
643 section: NAME opt_exp opt_block ':' opt_things'{'
645 lang_enter_output_section_statement($1,$2,$3);
647 statement '}' fill_opt memspec_opt
649 lang_leave_output_section_statement($10, $11);
667 | { $$= (etree_type *)NULL; }
671 BLOCK '(' exp_head ')'
672 { $$ = exp_get_value_int($3,
675 lang_first_phase_enum);
683 | { $$ = "*default*"; }