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
17 #define DONTDECLARE_MALLOC
33 extern unsigned int lineno;
34 extern boolean trace_files;
35 extern boolean write_map;
39 strip_symbols_type strip_symbols=STRIP_NONE;
40 discard_locals_type discard_locals=DISCARD_NONE;
43 lang_memory_region_type *region;
46 lang_memory_region_type *lang_memory_region_lookup();
47 lang_output_section_statement_type *lang_output_section_statement_lookup();
51 void lang_add_data(int type, union etree_union *exp);
52 void lang_enter_output_section_statement(char *output_section_statement_name, etree_type *address_exp, int flags, bfd_vma block_value);
57 void lang_enter_output_section_statement();
61 extern args_type command_line;
63 boolean ldgram_want_filename = true;
64 boolean had_script = false;
65 boolean force_make_executable = false;
67 boolean ldgram_in_script = false;
68 boolean ldgram_had_equals = false;
80 union etree_union *etree;
82 struct lang_output_section_statement_struct *output_section_statement;
83 union lang_statement_union **statement_ptr;
94 %type <etree> exp opt_exp
95 %type <integer> fill_opt opt_block opt_type
96 %type <name> memspec_opt
99 %type <integer> length
101 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
102 %right <token> '?' ':'
109 %left <token> '<' '>' LE GE
110 %left <token> LSHIFT RSHIFT
112 %left <token> '+' '-'
113 %left <token> '*' '/' '%'
115 /*%token <token> '+' '-' '*' '/' '%'*/
118 %token <token> ALIGN_K BLOCK LONG SHORT BYTE
121 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
122 %token SIZEOF_HEADERS
124 %token NOLOAD DSECT COPY INFO OVERLAY
125 %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
126 %token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S OPTION_sort_common
127 %token OPTION_format OPTION_F OPTION_u OPTION_Bstatic OPTION_N
128 %token <integer> SIZEOF NEXT ADDR
129 %token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X OPTION_defsym
130 %token OPTION_v OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT NOFLOAT
131 %token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_R
132 %token <name> OPTION_l OPTION_L OPTION_T OPTION_Aarch OPTION_Tfile OPTION_Texp
134 %token ORIGIN FILL OPTION_g
135 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT OUTPUT CONSTRUCTORS
136 %type <token> assign_op
138 %type <name> filename
141 ld_config_type config;
148 file: command_line { lang_final(); };
155 command_line command_line_option
161 { ldgram_in_script = true; }
163 { ldgram_in_script = false; }
178 config.magic_demand_paged = false;
179 config.text_read_only = true;
182 config.magic_demand_paged = false;
185 strip_symbols = STRIP_ALL;
188 strip_symbols = STRIP_DEBUGGER;
191 ldlang_add_undef($2);
195 config.relocateable_output = true;
196 config.build_constructors = false;
197 config.magic_demand_paged = false;
200 config.relocateable_output = true;
201 config.build_constructors = true;
202 config.magic_demand_paged = false;
209 { lang_add_entry($2);
212 discard_locals = DISCARD_L;
215 discard_locals = DISCARD_ALL;
218 | OPTION_noinhibit_exec
220 force_make_executable = true;
222 | OPTION_sort_common {
223 config.sort_common = true;
226 command_line.force_common_definition = true;
230 command_line.force_common_definition = true;
238 command_line.force_common_definition = true;
250 lang_section_start($1,exp_intop($3));
264 ldfile_add_library_path($1);
271 { lang_add_input_file($1,lang_input_file_is_file_enum,
274 { ldfile_open_command_file($2); } script_file
276 { ldfile_open_command_file($1); } script_file
279 { ldfile_open_command_file($2); } script_file
283 lang_add_input_file($1,
284 lang_input_file_is_l_enum,
289 lang_add_input_file($2,
290 lang_input_file_is_symbols_only_enum,
299 lang_add_assignment(exp_assop($4,$3,$5));
302 { info("%P%F Unrecognised option -%s\n", $2); }
314 { ldgram_in_script = true; }
316 { ldgram_in_script = false; }
334 | floating_point_support
337 | TARGET_K '(' NAME ')'
338 { lang_add_target($3); }
339 | SEARCH_DIR '(' filename ')'
340 { ldfile_add_library_path($3); }
341 | OUTPUT '(' filename ')'
342 { lang_add_output($3); }
343 | OUTPUT_FORMAT '(' NAME ')'
344 { lang_add_output_format($3); }
345 | OUTPUT_ARCH '(' NAME ')'
346 { ldfile_set_output_arch($3); }
347 | FORCE_COMMON_ALLOCATION
348 { command_line.force_common_definition = true ; }
349 | INPUT '(' input_list ')'
350 | MAP '(' filename ')'
351 { lang_add_map($3); }
356 { lang_add_input_file($1,lang_input_file_is_file_enum,
358 | input_list ',' NAME
359 { lang_add_input_file($3,lang_input_file_is_file_enum,
362 { lang_add_input_file($2, lang_input_file_is_file_enum,
367 SECTIONS '{'sec_or_group_p1 '}'
371 sec_or_group_p1 section
372 | sec_or_group_p1 statement_anywhere
378 { lang_add_entry($3); }
384 { lang_add_wild($1, current_file); }
385 | file_NAME_list opt_comma NAME
386 { lang_add_wild($3, current_file); }
392 lang_add_wild((char *)NULL, $1);
396 current_file = (char *)NULL;
404 '(' file_NAME_list ')'
407 current_file = (char *)NULL;
409 '(' file_NAME_list ')'
413 statement assignment end
414 | statement CREATE_OBJECT_SYMBOLS
416 lang_add_attribute(lang_object_symbols_statement_enum); }
418 | statement CONSTRUCTORS
420 lang_add_attribute(lang_constructors_statement_enum); }
422 | statement input_section_spec
423 | statement length '(' exp ')'
425 lang_add_data($2,$4);
428 | statement FILL '(' exp ')'
431 (exp_get_value_int($4,
434 lang_first_phase_enum));
451 $$ = exp_get_value_int($2,
454 lang_first_phase_enum);
488 lang_add_assignment(exp_assop($2,$1,$3));
492 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
503 MEMORY '{' memory_spec memory_spec_list '}'
507 memory_spec_list memory_spec
508 | memory_spec_list ',' memory_spec
515 { region = lang_memory_region_lookup($1); }
516 attributes_opt ':' origin_spec opt_comma length_spec
527 exp_get_vma($3, 0L,"origin", lang_first_phase_enum); }
531 { region->length = exp_get_vma($3,
534 lang_first_phase_enum);
541 lang_set_flags(®ion->flags, $2);
548 STARTUP '(' filename ')'
549 { lang_startup($3); }
553 HLL '(' high_level_library_NAME_list ')'
555 { ldemul_hll((char *)NULL); }
558 high_level_library_NAME_list:
559 high_level_library_NAME_list opt_comma filename
567 SYSLIB '(' low_level_library_NAME_list ')'
569 low_level_library_NAME_list:
570 low_level_library_NAME_list opt_comma filename
571 { ldemul_syslib($3); }
575 floating_point_support:
577 { lang_float(true); }
579 { lang_float(false); }
587 { $$ = exp_unop('-', $2); }
590 | NEXT '(' exp ')' %prec UNARY
591 { $$ = exp_unop($1,$3); }
592 | '!' exp %prec UNARY
593 { $$ = exp_unop('!', $2); }
594 | '+' exp %prec UNARY
596 | '~' exp %prec UNARY
597 { $$ = exp_unop('~', $2);}
600 { $$ = exp_binop('*', $1, $3); }
602 { $$ = exp_binop('/', $1, $3); }
604 { $$ = exp_binop('%', $1, $3); }
606 { $$ = exp_binop('+', $1, $3); }
608 { $$ = exp_binop('-' , $1, $3); }
610 { $$ = exp_binop(LSHIFT , $1, $3); }
612 { $$ = exp_binop(RSHIFT , $1, $3); }
614 { $$ = exp_binop(EQ , $1, $3); }
616 { $$ = exp_binop(NE , $1, $3); }
618 { $$ = exp_binop(LE , $1, $3); }
620 { $$ = exp_binop(GE , $1, $3); }
622 { $$ = exp_binop('<' , $1, $3); }
624 { $$ = exp_binop('>' , $1, $3); }
626 { $$ = exp_binop('&' , $1, $3); }
628 { $$ = exp_binop('^' , $1, $3); }
630 { $$ = exp_binop('|' , $1, $3); }
631 | exp '?' exp ':' exp
632 { $$ = exp_trinop('?' , $1, $3, $5); }
634 { $$ = exp_binop(ANDAND , $1, $3); }
636 { $$ = exp_binop(OROR , $1, $3); }
637 | DEFINED '(' NAME ')'
638 { $$ = exp_nameop(DEFINED, $3); }
640 { $$ = exp_intop($1); }
642 { $$ = exp_nameop(SIZEOF_HEADERS,0); }
644 | SIZEOF '(' NAME ')'
645 { $$ = exp_nameop(SIZEOF,$3); }
647 { $$ = exp_nameop(ADDR,$3); }
648 | ALIGN_K '(' exp ')'
649 { $$ = exp_unop(ALIGN_K,$3); }
651 { $$ = exp_nameop(NAME,$1); }
657 section: NAME opt_exp opt_type opt_block ':' opt_things'{'
659 lang_enter_output_section_statement($1,$2,$3,$4);
661 statement '}' fill_opt memspec_opt
663 lang_leave_output_section_statement($11, $12);
669 '(' NOLOAD ')' { $$ = SEC_NO_FLAGS; }
670 | '(' DSECT ')' { $$ = 0; }
671 | '(' COPY ')' { $$ = 0; }
672 | '(' INFO ')' { $$ = 0; }
673 | '(' OVERLAY ')' { $$ = 0; }
674 | { $$ = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; }
690 | { $$= (etree_type *)NULL; }
695 { $$ = exp_get_value_int($3,
698 lang_first_phase_enum);
706 | { $$ = "*default*"; }