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
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;
213 command_line.force_common_definition = true;
217 command_line.force_common_definition = true;
225 command_line.force_common_definition = true;
237 lang_section_start($1,exp_intop($3));
251 ldfile_add_library_path($1);
258 { lang_add_input_file($1,lang_input_file_is_file_enum,
260 | OPTION_c filename script_file
261 { ldfile_open_command_file($2); }
263 { ldfile_open_command_file($1); } script_file
266 { ldfile_open_command_file($2); } script_file
270 lang_add_input_file($1,
271 lang_input_file_is_l_enum,
276 lang_add_input_file($2,
277 lang_input_file_is_symbols_only_enum,
286 lang_add_assignment(exp_assop($4,$3,$5));
289 { info("%P%F Unrecognised option -%s\n", $2); }
301 { ldgram_in_script = true; }
303 { ldgram_in_script = false; }
321 | floating_point_support
323 | TARGET_K '(' NAME ')'
324 { lang_add_target($3); }
325 | SEARCH_DIR '(' filename ')'
326 { ldfile_add_library_path($3); }
327 | OUTPUT '(' filename ')'
328 { lang_add_output($3); }
329 | OUTPUT_FORMAT '(' NAME ')'
330 { lang_add_output_format($3); }
331 | OUTPUT_ARCH '(' NAME ')'
332 { ldfile_set_output_arch($3); }
333 | FORCE_COMMON_ALLOCATION
334 { command_line.force_common_definition = true ; }
335 | INPUT '(' input_list ')'
336 | MAP '(' filename ')'
337 { lang_add_map($3); }
342 { lang_add_input_file($1,lang_input_file_is_file_enum,
344 | input_list ',' NAME
345 { lang_add_input_file($3,lang_input_file_is_file_enum,
348 { lang_add_input_file($2, lang_input_file_is_file_enum,
353 SECTIONS '{'sec_or_group_p1 '}'
357 sec_or_group_p1 section
358 | sec_or_group_p1 statement_anywhere
364 { lang_add_entry($3); }
370 { lang_add_wild($1, current_file); }
371 | file_NAME_list opt_comma NAME
372 { lang_add_wild($3, current_file); }
378 lang_add_wild((char *)NULL, $1);
382 current_file = (char *)NULL;
390 '(' file_NAME_list ')'
393 current_file = (char *)NULL;
395 '(' file_NAME_list ')'
399 statement assignment end
400 | statement CREATE_OBJECT_SYMBOLS
402 lang_add_attribute(lang_object_symbols_statement_enum); }
404 | statement input_section_spec
405 | statement length '(' exp_head ')'
407 lang_add_data($2,$4);
410 | statement FILL '(' exp_head ')'
413 (exp_get_value_int($4,
416 lang_first_phase_enum));
433 $$ = exp_get_value_int($2,
436 lang_first_phase_enum);
471 lang_add_assignment(exp_assop($2,$1,$3));
473 | NAME assign_op exp_head
475 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
486 MEMORY '{' memory_spec memory_spec_list '}'
490 memory_spec_list memory_spec
491 | memory_spec_list ',' memory_spec
498 { region = lang_memory_region_lookup($1); }
499 attributes_opt ':' origin_spec opt_comma length_spec
510 exp_get_vma($3, 0L,"origin", lang_first_phase_enum); }
514 { region->length = exp_get_vma($3,
517 lang_first_phase_enum);
524 lang_set_flags(®ion->flags, $2);
531 STARTUP '(' filename ')'
532 { lang_startup($3); }
536 HLL '(' high_level_library_NAME_list ')'
538 { ldemul_hll((char *)NULL); }
541 high_level_library_NAME_list:
542 high_level_library_NAME_list opt_comma filename
550 SYSLIB '(' low_level_library_NAME_list ')'
552 low_level_library_NAME_list:
553 low_level_library_NAME_list opt_comma filename
554 { ldemul_syslib($3); }
558 floating_point_support:
560 { lang_float(true); }
562 { lang_float(false); }
570 { $$ = exp_unop('-', $2); }
573 | NEXT '(' exp ')' %prec UNARY
574 { $$ = exp_unop($1,$3); }
575 | '!' exp %prec UNARY
576 { $$ = exp_unop('!', $2); }
577 | '+' exp %prec UNARY
579 | '~' exp %prec UNARY
580 { $$ = exp_unop('~', $2);}
583 { $$ = exp_binop('*', $1, $3); }
585 { $$ = exp_binop('/', $1, $3); }
587 { $$ = exp_binop('%', $1, $3); }
589 { $$ = exp_binop('+', $1, $3); }
591 { $$ = exp_binop('-' , $1, $3); }
593 { $$ = exp_binop(LSHIFT , $1, $3); }
595 { $$ = exp_binop(RSHIFT , $1, $3); }
597 { $$ = exp_binop(EQ , $1, $3); }
599 { $$ = exp_binop(NE , $1, $3); }
601 { $$ = exp_binop(LE , $1, $3); }
603 { $$ = exp_binop(GE , $1, $3); }
605 { $$ = exp_binop('<' , $1, $3); }
607 { $$ = exp_binop('>' , $1, $3); }
609 { $$ = exp_binop('&' , $1, $3); }
611 { $$ = exp_binop('^' , $1, $3); }
613 { $$ = exp_binop('|' , $1, $3); }
614 | exp '?' exp ':' exp
615 { $$ = exp_trinop('?' , $1, $3, $5); }
617 { $$ = exp_binop(ANDAND , $1, $3); }
619 { $$ = exp_binop(OROR , $1, $3); }
620 | DEFINED '(' NAME ')'
621 { $$ = exp_nameop(DEFINED, $3); }
623 { $$ = exp_intop($1); }
625 { $$ = exp_nameop(SIZEOF_HEADERS,0); }
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*"; }