1 /* A YACC grammer to parse a superset of the AT&T linker scripting languaue.
2 Copyright (C) 1991 Free Software Foundation, Inc.
3 Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
5 This file is part of GNU ld.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #define DONTDECLARE_MALLOC
42 extern unsigned int lineno;
43 extern boolean trace_files;
44 extern boolean write_map;
45 extern boolean option_longmap;
48 strip_symbols_type strip_symbols=STRIP_NONE;
49 discard_locals_type discard_locals=DISCARD_NONE;
52 lang_memory_region_type *region;
55 lang_memory_region_type *lang_memory_region_lookup();
56 lang_output_section_statement_type *lang_output_section_statement_lookup();
60 void lang_add_data(int type, union etree_union *exp);
61 void lang_enter_output_section_statement(char *output_section_statement_name, etree_type *address_exp, int flags, bfd_vma block_value);
66 void lang_enter_output_section_statement();
70 extern args_type command_line;
72 boolean ldgram_want_filename = true;
73 boolean had_script = false;
74 boolean force_make_executable = false;
76 boolean ldgram_in_script = false;
77 boolean ldgram_had_equals = false;
81 #define ERROR_NAME_MAX 20
82 static char *error_names[ERROR_NAME_MAX];
83 static int error_index;
84 #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
85 #define POP_ERROR() error_index--;
92 union etree_union *etree;
94 struct lang_output_section_statement_struct *output_section_statement;
95 union lang_statement_union **statement_ptr;
106 %type <etree> exp opt_exp mustbe_exp
107 %type <integer> fill_opt opt_block opt_type
108 %type <name> memspec_opt
111 %type <integer> length
113 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
114 %right <token> '?' ':'
121 %left <token> '<' '>' LE GE
122 %left <token> LSHIFT RSHIFT
124 %left <token> '+' '-'
125 %left <token> '*' '/' '%'
127 /*%token <token> '+' '-' '*' '/' '%'*/
131 %token <token> ALIGN_K BLOCK LONG SHORT BYTE
134 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
135 %token SIZEOF_HEADERS
136 %token MEMORY DEFSYMEND
137 %token NOLOAD DSECT COPY INFO OVERLAY
138 %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
139 %token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S OPTION_sort_common
140 %token OPTION_format OPTION_F OPTION_u OPTION_Bstatic OPTION_N
141 %token <integer> SIZEOF NEXT ADDR
142 %token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X OPTION_defsym
143 %token OPTION_v OPTION_V OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT NOFLOAT
145 %token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_R OPTION_relax
146 %token <name> OPTION_l OPTION_L OPTION_T OPTION_Aarch OPTION_Tfile OPTION_Texp
148 %token ORIGIN FILL OPTION_g
149 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT OUTPUT CONSTRUCTORS
150 %type <token> assign_op
152 %type <name> filename
155 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD
156 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS
159 ld_config_type config;
164 file: command_line { lang_final(); };
171 command_line command_line_option
193 config.map_filename = $2;
196 config.map_filename = "-";
200 config.magic_demand_paged = false;
203 config.text_read_only = false;
204 config.magic_demand_paged = false;
207 strip_symbols = STRIP_ALL;
210 strip_symbols = STRIP_DEBUGGER;
213 ldlang_add_undef($2);
217 config.relocateable_output = true;
218 config.build_constructors = false;
219 config.magic_demand_paged = false;
220 config.text_read_only = false;
223 config.relocateable_output = true;
224 config.build_constructors = true;
225 config.magic_demand_paged = false;
226 config.text_read_only = false;
233 { lang_add_entry($2);
236 discard_locals = DISCARD_L;
239 discard_locals = DISCARD_ALL;
242 | OPTION_noinhibit_exec
244 force_make_executable = true;
246 | OPTION_sort_common {
247 config.sort_common = true;
250 command_line.force_common_definition = true;
254 command_line.relax = true;
258 command_line.force_common_definition = true;
266 command_line.force_common_definition = true;
273 { ldlex_expression();
278 lang_section_start($1,exp_intop($3));
292 ldfile_add_library_path($1);
299 { lang_add_input_file($1,lang_input_file_is_file_enum,
302 { ldfile_open_command_file($2); } mri_script_file END { ldlex_command()};
305 { ldfile_open_command_file($1); } script_file
306 END { ldlex_command();}
309 { ldfile_open_command_file($2); } script_file
310 END { ldlex_command();}
314 lang_add_input_file($1,
315 lang_input_file_is_l_enum,
320 lang_add_input_file($2,
321 lang_input_file_is_symbols_only_enum,
325 | OPTION_defsym { ldlex_defsym(); }
326 NAME '=' exp DEFSYMEND { ldlex_popstate();
327 lang_add_assignment(exp_assop($4,$3,$5));
330 { info("%P%F Unrecognised option -%s\n", $2); }
332 | '{' script_file '}'
336 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
338 { ldlex_mri_script();
339 PUSH_ERROR("MRI style script");
348 mri_script_lines mri_script_command NEWLINE
356 einfo("%P%F: unrecognised keyword in MRI style script '%s'\n",$1);
360 config.map_filename = "-";
362 | ORDER ordernamelist
364 | PUBLIC NAME '=' exp
365 { mri_public($2, $4); }
366 | PUBLIC NAME ',' exp
367 { mri_public($2, $4); }
369 { mri_public($2, $3); }
373 { mri_output_section($2, $4);}
375 { mri_output_section($2, $3);}
377 { mri_output_section($2, $4);}
378 | ABSOLUTE mri_abs_name_list
379 | LOAD mri_load_name_list
382 | ALIAS NAME ',' NAME
383 { mri_alias($2,$4,0);}
385 { mri_alias($2,0,$4);}
392 ordernamelist ',' NAME { mri_order($3); }
393 | ordernamelist NAME { mri_order($2); }
400 | mri_load_name_list ',' NAME { mri_load($3); }
405 { mri_only_load($1); }
406 | mri_abs_name_list ',' NAME
407 { mri_only_load($3); }
434 | floating_point_support
437 | TARGET_K '(' NAME ')'
438 { lang_add_target($3); }
439 | SEARCH_DIR '(' filename ')'
440 { ldfile_add_library_path($3); }
441 | OUTPUT '(' filename ')'
442 { lang_add_output($3); }
443 | OUTPUT_FORMAT '(' NAME ')'
444 { lang_add_output_format($3); }
445 | OUTPUT_ARCH '(' NAME ')'
446 { ldfile_set_output_arch($3); }
447 | FORCE_COMMON_ALLOCATION
448 { command_line.force_common_definition = true ; }
449 | INPUT '(' input_list ')'
450 | MAP '(' filename ')'
451 { lang_add_map($3); }
456 { lang_add_input_file($1,lang_input_file_is_file_enum,
458 | input_list ',' NAME
459 { lang_add_input_file($3,lang_input_file_is_file_enum,
462 { lang_add_input_file($2,
463 lang_input_file_is_file_enum,
468 SECTIONS '{' sec_or_group_p1 '}'
472 sec_or_group_p1 section
473 | sec_or_group_p1 statement_anywhere
479 { lang_add_entry($3); }
485 { lang_add_wild($1, current_file); }
486 | file_NAME_list opt_comma NAME
487 { lang_add_wild($3, current_file); }
493 lang_add_wild((char *)NULL, $1);
497 current_file = (char *)NULL;
505 '(' file_NAME_list ')'
508 current_file = (char *)NULL;
510 '(' file_NAME_list ')'
514 statement assignment end
515 | statement CREATE_OBJECT_SYMBOLS
518 lang_add_attribute(lang_object_symbols_statement_enum); }
520 | statement CONSTRUCTORS
523 lang_add_attribute(lang_constructors_statement_enum); }
525 | statement input_section_spec
526 | statement length '(' exp ')'
528 lang_add_data($2,$4);
531 | statement FILL '(' exp ')'
534 (exp_get_value_int($4,
538 lang_first_phase_enum));
555 $$ = exp_get_value_int($2,
558 lang_first_phase_enum);
592 lang_add_assignment(exp_assop($2,$1,$3));
594 | NAME assign_op mustbe_exp
597 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
608 MEMORY '{' memory_spec memory_spec_list '}'
612 memory_spec_list memory_spec
613 | memory_spec_list ',' memory_spec
619 { region = lang_memory_region_lookup($1); }
621 origin_spec opt_comma length_spec
624 ORIGIN '=' mustbe_exp
627 exp_get_vma($3, 0L,"origin", lang_first_phase_enum);
630 LENGTH '=' mustbe_exp
631 { region->length = exp_get_vma($3,
634 lang_first_phase_enum);
641 lang_set_flags(®ion->flags, $2);
648 STARTUP '(' filename ')'
649 { lang_startup($3); }
653 HLL '(' high_level_library_NAME_list ')'
655 { ldemul_hll((char *)NULL); }
658 high_level_library_NAME_list:
659 high_level_library_NAME_list opt_comma filename
667 SYSLIB '(' low_level_library_NAME_list ')'
668 ; low_level_library_NAME_list:
669 low_level_library_NAME_list opt_comma filename
670 { ldemul_syslib($3); }
674 floating_point_support:
676 { lang_float(true); }
678 { lang_float(false); }
682 mustbe_exp: { ldlex_expression(); }
684 { ldlex_popstate(); $$=$2;}
689 { $$ = exp_unop('-', $2); }
692 | NEXT '(' exp ')' %prec UNARY
693 { $$ = exp_unop($1,$3); }
694 | '!' exp %prec UNARY
695 { $$ = exp_unop('!', $2); }
696 | '+' exp %prec UNARY
698 | '~' exp %prec UNARY
699 { $$ = exp_unop('~', $2);}
702 { $$ = exp_binop('*', $1, $3); }
704 { $$ = exp_binop('/', $1, $3); }
706 { $$ = exp_binop('%', $1, $3); }
708 { $$ = exp_binop('+', $1, $3); }
710 { $$ = exp_binop('-' , $1, $3); }
712 { $$ = exp_binop(LSHIFT , $1, $3); }
714 { $$ = exp_binop(RSHIFT , $1, $3); }
716 { $$ = exp_binop(EQ , $1, $3); }
718 { $$ = exp_binop(NE , $1, $3); }
720 { $$ = exp_binop(LE , $1, $3); }
722 { $$ = exp_binop(GE , $1, $3); }
724 { $$ = exp_binop('<' , $1, $3); }
726 { $$ = exp_binop('>' , $1, $3); }
728 { $$ = exp_binop('&' , $1, $3); }
730 { $$ = exp_binop('^' , $1, $3); }
732 { $$ = exp_binop('|' , $1, $3); }
733 | exp '?' exp ':' exp
734 { $$ = exp_trinop('?' , $1, $3, $5); }
736 { $$ = exp_binop(ANDAND , $1, $3); }
738 { $$ = exp_binop(OROR , $1, $3); }
739 | DEFINED '(' NAME ')'
740 { $$ = exp_nameop(DEFINED, $3); }
742 { $$ = exp_intop($1); }
744 { $$ = exp_nameop(SIZEOF_HEADERS,0); }
746 | SIZEOF '(' NAME ')'
747 { $$ = exp_nameop(SIZEOF,$3); }
749 { $$ = exp_nameop(ADDR,$3); }
750 | ALIGN_K '(' exp ')'
751 { $$ = exp_unop(ALIGN_K,$3); }
753 { $$ = exp_nameop(NAME,$1); }
759 section: NAME { ldlex_expression(); }
760 opt_exp { ldlex_popstate(); }
761 opt_type opt_block ':' opt_things'{'
763 lang_enter_output_section_statement($1,$3,$5,$6);
765 statement '}' {ldlex_expression();} fill_opt memspec_opt
768 lang_leave_output_section_statement($14, $15);
775 '(' NOLOAD ')' { $$ = SEC_NO_FLAGS; }
776 | '(' DSECT ')' { $$ = 0; }
777 | '(' COPY ')' { $$ = 0; }
778 | '(' INFO ')' { $$ = 0; }
779 | '(' OVERLAY ')' { $$ = 0; }
780 | { $$ = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; }
791 | { $$= (etree_type *)NULL; }
796 { $$ = exp_get_value_int($3,
799 lang_first_phase_enum);
807 | { $$ = "*default*"; }
814 if (error_index> 0 && error_index < ERROR_NAME_MAX)
815 einfo("%P%F: %S syntax error in %s\n",error_names[error_index-1]);
817 einfo("%P%F: %S syntax error\n");