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_has_inputfile = false;
64 boolean ldgram_in_expression = false;
66 boolean ldgram_in_defsym = 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
117 %token NEXT SIZEOF ADDR
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
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
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
167 config.magic_demand_paged = false;
168 config.make_executable = false;
171 strip_symbols = STRIP_ALL;
174 strip_symbols = STRIP_DEBUGGER;
178 config.relocateable_output = true;
179 config.build_constructors = false;
180 config.magic_demand_paged = false;
183 config.relocateable_output = true;
184 config.build_constructors = true;
185 config.magic_demand_paged = false;
192 { lang_add_entry($2);
195 discard_locals = DISCARD_L;
198 discard_locals = DISCARD_ALL;
201 | OPTION_noinhibit_exec
203 force_make_executable = true;
206 command_line.force_common_definition = true;
210 command_line.force_common_definition = true;
218 command_line.force_common_definition = true;
228 { lang_section_start($1, $3);
232 { ldfile_add_arch($1); }
239 ldfile_add_library_path($1);
249 { ldfile_open_command_file($2); }
251 { ldfile_open_command_file($1); }
254 { ldfile_open_command_file($2); }
258 lang_add_input_file($1,
259 lang_input_file_is_l_enum,
264 lang_add_input_file($2,
265 lang_input_file_is_symbols_only_enum,
270 ldgram_in_defsym = true;
276 ldgram_in_defsym = false;
285 lang_add_wild((char *)NULL, $1);
289 current_file = (char *)NULL;
297 '(' file_NAME_list ')'
300 current_file = (char *)NULL;
302 '(' file_NAME_list ')'
309 { lang_add_wild($1, current_file); }
310 | file_NAME_list opt_comma NAME
311 { lang_add_wild($3, current_file); }
322 | floating_point_support
324 | TARGET_K '(' NAME ')'
325 { lang_add_target($3); }
326 | SEARCH_DIR '(' filename ')'
327 { ldfile_add_library_path($3); }
328 | OUTPUT '(' filename ')'
329 { lang_add_output($3); }
330 | INPUT '(' input_list ')'
331 | MAP '(' filename ')'
332 { lang_add_map($3); }
337 { lang_add_input_file($1,lang_input_file_is_file_enum,
339 | input_list ',' NAME
340 { lang_add_input_file($3,lang_input_file_is_file_enum,
343 { lang_add_input_file($2, lang_input_file_is_file_enum,
348 SECTIONS '{'sec_or_group_p1 '}'
352 sec_or_group_p1 section
353 | sec_or_group_p1 statement_anywhere
359 { lang_add_entry($3); }
364 statement assignment end
365 | statement CREATE_OBJECT_SYMBOLS
366 { lang_add_attribute(lang_object_symbols_statement_enum); }
367 | statement input_section_spec
368 | statement length '(' exp_head ')'
370 lang_add_data($2,$4);
373 | statement FILL '(' exp_head ')'
376 (exp_get_value_int($4,
379 lang_first_phase_enum));
396 $$ = exp_get_value_int($2,
399 lang_first_phase_enum);
434 lang_add_assignment(exp_assop($2,$1,$3));
436 | NAME assign_op exp_head
438 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
449 MEMORY '{' memory_spec memory_spec_list '}'
453 memory_spec_list memory_spec
454 | memory_spec_list ',' memory_spec
461 { region = lang_memory_region_lookup($1); }
462 attributes_opt ':' origin_spec opt_comma length_spec
473 exp_get_vma($3, 0L,"origin", lang_first_phase_enum); }
477 { region->length = exp_get_vma($3,
480 lang_first_phase_enum);
487 lang_set_flags(®ion->flags, $2);
494 STARTUP '(' filename ')'
495 { lang_startup($3); }
499 HLL '(' high_level_library_NAME_list ')'
501 { ldemul_hll((char *)NULL); }
504 high_level_library_NAME_list:
505 high_level_library_NAME_list opt_comma filename
513 SYSLIB '(' low_level_library_NAME_list ')'
515 low_level_library_NAME_list:
516 low_level_library_NAME_list opt_comma filename
517 { ldemul_syslib($3); }
521 floating_point_support:
523 { lang_float(true); }
525 { lang_float(false); }
533 { $$ = exp_unop('-', $2); }
536 | NEXT '(' exp ')' %prec UNARY
537 { $$ = exp_unop($1,$3); }
538 | '!' exp %prec UNARY
539 { $$ = exp_unop('!', $2); }
540 | '+' exp %prec UNARY
542 | '~' exp %prec UNARY
543 { $$ = exp_unop('~', $2);}
546 { $$ = exp_binop('*', $1, $3); }
548 { $$ = exp_binop('/', $1, $3); }
550 { $$ = exp_binop('%', $1, $3); }
552 { $$ = exp_binop('+', $1, $3); }
554 { $$ = exp_binop('-' , $1, $3); }
556 { $$ = exp_binop(LSHIFT , $1, $3); }
558 { $$ = exp_binop(RSHIFT , $1, $3); }
560 { $$ = exp_binop(EQ , $1, $3); }
562 { $$ = exp_binop(NE , $1, $3); }
564 { $$ = exp_binop(LE , $1, $3); }
566 { $$ = exp_binop(GE , $1, $3); }
568 { $$ = exp_binop('<' , $1, $3); }
570 { $$ = exp_binop('>' , $1, $3); }
572 { $$ = exp_binop('&' , $1, $3); }
574 { $$ = exp_binop('^' , $1, $3); }
576 { $$ = exp_binop('|' , $1, $3); }
577 | exp '?' exp ':' exp
578 { $$ = exp_trinop('?' , $1, $3, $5); }
580 { $$ = exp_binop(ANDAND , $1, $3); }
582 { $$ = exp_binop(OROR , $1, $3); }
583 | DEFINED '(' NAME ')'
584 { $$ = exp_nameop(DEFINED, $3); }
586 { $$ = exp_intop($1); }
588 | SIZEOF '(' NAME ')'
589 { $$ = exp_nameop($1,$3); }
591 { $$ = exp_nameop($1,$3); }
592 | ALIGN_K '(' exp ')'
593 { $$ = exp_unop($1,$3); }
595 { $$ = exp_nameop(NAME,$1); }
601 section: NAME opt_exp opt_block ':' opt_things'{'
603 lang_enter_output_section_statement($1,$2,$3);
605 statement '}' fill_opt memspec_opt
607 lang_leave_output_section_statement($10, $11);
620 ldgram_in_expression = true;
624 ldgram_in_expression = false;
632 | { $$= (etree_type *)NULL; }
636 BLOCK '(' exp_head ')'
637 { $$ = exp_get_value_int($3,
640 lang_first_phase_enum);
648 | { $$ = "*default*"; }