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;
39 lang_memory_region_type *region;
42 lang_memory_region_type *lang_memory_region_lookup();
43 lang_output_section_statement_type *lang_output_section_statement_lookup();
47 void lang_add_data(int type, union etree_union *exp);
48 void lang_enter_output_section_statement(char *output_section_statement_name, etree_type *address_exp, bfd_vma block_value);
53 void lang_enter_output_section_statement();
57 extern args_type command_line;
59 boolean ldgram_want_filename = true;
60 boolean had_script = false;
61 boolean force_make_executable = false;
62 boolean ldgram_in_expression = false;
63 boolean ldgram_in_script = false;
64 boolean ldgram_in_defsym = false;
76 union etree_union *etree;
78 struct lang_output_section_statement_struct *output_section_statement;
79 union lang_statement_union **statement_ptr;
90 %type <etree> exp opt_exp exp_head
91 %type <integer> fill_opt opt_block
92 %type <name> memspec_opt
93 %token <integer> INT CHAR
95 %type <integer> length
97 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
98 %right <token> '?' ':'
105 %left <token> '<' '>' LE GE
106 %left <token> LSHIFT RSHIFT
107 %left <token> '+' '-'
108 %left <token> '*' '/' '%'
111 %token <token> ALIGN_K BLOCK LONG SHORT BYTE
114 %token ALIGNMENT SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION
115 %token NEXT SIZEOF ADDR SCRIPT ENDSCRIPT
117 %token DSECT NOLOAD COPY INFO OVERLAY
118 %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
119 %token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S
120 %token OPTION_format OPTION_F OPTION_u
122 %token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X
123 %token OPTION_v OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT NOFLOAT OPTION_defsym
124 %token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_A OPTION_R
125 %token <name> OPTION_l OPTION_L OPTION_T OPTION_Aarch OPTION_Tfile OPTION_Texp
127 %token ORIGIN FILL OPTION_g
128 %token LENGTH BIND SUBSECTION_ALIGN CREATE_OBJECT_SYMBOLS INPUT OUTPUT
129 %type <token> assign_op SIZEOF NEXT ADDR
130 %type <etree> assignment
131 %type <name> filename
134 ld_config_type config;
141 file: command_line { lang_final(); };
148 command_line command_line_option
153 SCRIPT ifile_list ENDSCRIPT
166 config.magic_demand_paged = false;
167 config.make_executable = false;
170 strip_symbols = STRIP_ALL;
173 strip_symbols = STRIP_DEBUGGER;
176 ldlang_add_undef($2);
180 config.relocateable_output = true;
181 config.build_constructors = false;
182 config.magic_demand_paged = false;
185 config.relocateable_output = true;
186 config.build_constructors = true;
187 config.magic_demand_paged = false;
194 { lang_add_entry($2);
197 discard_locals = DISCARD_L;
200 discard_locals = DISCARD_ALL;
203 | OPTION_noinhibit_exec
205 force_make_executable = true;
208 command_line.force_common_definition = true;
212 command_line.force_common_definition = true;
220 command_line.force_common_definition = true;
232 lang_section_start($1,exp_intop($3));
246 ldfile_add_library_path($1);
253 { lang_add_input_file($1,lang_input_file_is_file_enum,
255 | OPTION_c filename script_file
256 { ldfile_open_command_file($2); }
258 { ldfile_open_command_file($1); } script_file
261 { ldfile_open_command_file($2); } script_file
265 lang_add_input_file($1,
266 lang_input_file_is_l_enum,
271 lang_add_input_file($2,
272 lang_input_file_is_symbols_only_enum,
277 ldgram_in_defsym = true;
278 ldgram_in_expression = true;
283 ldgram_in_defsym = false;
284 ldgram_in_expression = false;
287 { info("%P%F Unrecognised option -%s\n", $2); }
299 { ldgram_in_script = true; }
301 { ldgram_in_script = false; }
319 | floating_point_support
321 | TARGET_K '(' NAME ')'
322 { lang_add_target($3); }
323 | SEARCH_DIR '(' filename ')'
324 { ldfile_add_library_path($3); }
325 | OUTPUT '(' filename ')'
326 { lang_add_output($3); }
327 | OUTPUT_FORMAT '(' NAME ')'
328 { lang_add_output_format($3); }
329 | FORCE_COMMON_ALLOCATION
330 { command_line.force_common_definition = true ; }
331 | INPUT '(' input_list ')'
332 | MAP '(' filename ')'
333 { lang_add_map($3); }
338 { lang_add_input_file($1,lang_input_file_is_file_enum,
340 | input_list ',' NAME
341 { lang_add_input_file($3,lang_input_file_is_file_enum,
344 { lang_add_input_file($2, lang_input_file_is_file_enum,
349 SECTIONS '{'sec_or_group_p1 '}'
353 sec_or_group_p1 section
354 | sec_or_group_p1 statement_anywhere
360 { lang_add_entry($3); }
366 { lang_add_wild($1, current_file); }
367 | file_NAME_list opt_comma NAME
368 { lang_add_wild($3, current_file); }
374 lang_add_wild((char *)NULL, $1);
378 current_file = (char *)NULL;
386 '(' file_NAME_list ')'
389 current_file = (char *)NULL;
391 '(' file_NAME_list ')'
395 statement assignment end
396 | statement CREATE_OBJECT_SYMBOLS
398 lang_add_attribute(lang_object_symbols_statement_enum); }
400 | statement input_section_spec
401 | statement length '(' exp_head ')'
403 lang_add_data($2,$4);
406 | statement FILL '(' exp_head ')'
409 (exp_get_value_int($4,
412 lang_first_phase_enum));
429 $$ = exp_get_value_int($2,
432 lang_first_phase_enum);
467 lang_add_assignment(exp_assop($2,$1,$3));
469 | NAME assign_op exp_head
471 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
482 MEMORY '{' memory_spec memory_spec_list '}'
486 memory_spec_list memory_spec
487 | memory_spec_list ',' memory_spec
494 { region = lang_memory_region_lookup($1); }
495 attributes_opt ':' origin_spec opt_comma length_spec
506 exp_get_vma($3, 0L,"origin", lang_first_phase_enum); }
510 { region->length = exp_get_vma($3,
513 lang_first_phase_enum);
520 lang_set_flags(®ion->flags, $2);
527 STARTUP '(' filename ')'
528 { lang_startup($3); }
532 HLL '(' high_level_library_NAME_list ')'
534 { ldemul_hll((char *)NULL); }
537 high_level_library_NAME_list:
538 high_level_library_NAME_list opt_comma filename
546 SYSLIB '(' low_level_library_NAME_list ')'
548 low_level_library_NAME_list:
549 low_level_library_NAME_list opt_comma filename
550 { ldemul_syslib($3); }
554 floating_point_support:
556 { lang_float(true); }
558 { lang_float(false); }
566 { $$ = exp_unop('-', $2); }
569 | NEXT '(' exp ')' %prec UNARY
570 { $$ = exp_unop($1,$3); }
571 | '!' exp %prec UNARY
572 { $$ = exp_unop('!', $2); }
573 | '+' exp %prec UNARY
575 | '~' exp %prec UNARY
576 { $$ = exp_unop('~', $2);}
579 { $$ = exp_binop('*', $1, $3); }
581 { $$ = exp_binop('/', $1, $3); }
583 { $$ = exp_binop('%', $1, $3); }
585 { $$ = exp_binop('+', $1, $3); }
587 { $$ = exp_binop('-' , $1, $3); }
589 { $$ = exp_binop(LSHIFT , $1, $3); }
591 { $$ = exp_binop(RSHIFT , $1, $3); }
593 { $$ = exp_binop(EQ , $1, $3); }
595 { $$ = exp_binop(NE , $1, $3); }
597 { $$ = exp_binop(LE , $1, $3); }
599 { $$ = exp_binop(GE , $1, $3); }
601 { $$ = exp_binop('<' , $1, $3); }
603 { $$ = exp_binop('>' , $1, $3); }
605 { $$ = exp_binop('&' , $1, $3); }
607 { $$ = exp_binop('^' , $1, $3); }
609 { $$ = exp_binop('|' , $1, $3); }
610 | exp '?' exp ':' exp
611 { $$ = exp_trinop('?' , $1, $3, $5); }
613 { $$ = exp_binop(ANDAND , $1, $3); }
615 { $$ = exp_binop(OROR , $1, $3); }
616 | DEFINED '(' NAME ')'
617 { $$ = exp_nameop(DEFINED, $3); }
619 { $$ = exp_intop($1); }
621 | SIZEOF '(' NAME ')'
622 { $$ = exp_nameop($1,$3); }
624 { $$ = exp_nameop($1,$3); }
625 | ALIGN_K '(' exp ')'
626 { $$ = exp_unop($1,$3); }
628 { $$ = exp_nameop(NAME,$1); }
634 section: NAME opt_exp opt_block ':' opt_things'{'
636 lang_enter_output_section_statement($1,$2,$3);
638 statement '}' fill_opt memspec_opt
640 lang_leave_output_section_statement($10, $11);
653 ldgram_in_expression = true;
657 ldgram_in_expression = false;
665 | { $$= (etree_type *)NULL; }
669 BLOCK '(' exp_head ')'
670 { $$ = exp_get_value_int($3,
673 lang_first_phase_enum);
681 | { $$ = "*default*"; }