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
41 extern unsigned int lineno;
42 extern boolean trace_file_tries;
43 extern boolean trace_files;
44 extern boolean write_map;
45 extern int g_switch_value;
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();
57 etree_type *lang_atin();
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,etree_type*,etree_type*, etree_type*);
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_with_type mustbe_exp opt_at
107 %type <integer> fill_opt
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
137 %token MEMORY DEFSYMEND
138 %token NOLOAD DSECT COPY INFO OVERLAY
139 %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
140 %token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S OPTION_sort_common
141 %token OPTION_EB OPTION_EL OPTION_G OPTION_Gval OPTION_help
142 %token OPTION_format OPTION_oformat OPTION_F OPTION_u OPTION_Bstatic OPTION_N
143 %token <integer> SIZEOF NEXT ADDR
144 %token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X OPTION_defsym
145 %token OPTION_v OPTION_V OPTION_m OPTION_memul OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT NOFLOAT
146 %token OPTION_L OPTION_Map
147 %token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_R OPTION_relax OPTION_version
148 %token <name> OPTION_l OPTION_Lfile OPTION_T OPTION_Aarch OPTION_Tfile
149 %token <name> OPTION_Texp OPTION_y
151 %token ORIGIN FILL OPTION_g
152 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT OUTPUT CONSTRUCTORS
153 %token OPTION_RETAIN_SYMBOLS_FILE ALIGNMOD AT
155 %type <token> assign_op
157 %type <name> filename
160 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD
161 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE
164 ld_config_type config;
169 file: command_line { lang_final(); };
176 command_line command_line_option
194 trace_file_tries = true;
207 config.map_filename = $2;
219 config.map_filename = "-";
222 config.magic_demand_paged = false;
225 config.text_read_only = false;
226 config.magic_demand_paged = false;
229 strip_symbols = STRIP_ALL;
232 strip_symbols = STRIP_DEBUGGER;
235 ldlang_add_undef($2);
239 config.relocateable_output = true;
240 config.build_constructors = false;
241 config.magic_demand_paged = false;
242 config.text_read_only = false;
245 config.relocateable_output = true;
246 config.build_constructors = true;
247 config.magic_demand_paged = false;
248 config.text_read_only = false;
255 { lang_add_entry($2);
258 discard_locals = DISCARD_L;
261 discard_locals = DISCARD_ALL;
264 | OPTION_noinhibit_exec
266 force_make_executable = true;
270 config.sort_common = true;
273 command_line.force_common_definition = true;
277 command_line.relax = true;
281 command_line.force_common_definition = true;
289 command_line.force_common_definition = true;
295 | OPTION_oformat NAME
297 lang_add_output_format($2, 0);
300 { ldlex_expression();
305 lang_section_start($1,exp_intop($3));
322 ldfile_add_library_path($2);
326 ldfile_add_library_path($1);
333 {ldfile_open_command_file($2); }
334 mri_script_file END { ldlex_command();}
337 { ldfile_open_command_file($1); } script_file
338 END { ldlex_command();}
341 { ldfile_open_command_file($2); } script_file
342 END { ldlex_command();}
346 lang_add_input_file($1,
347 lang_input_file_is_l_enum,
352 lang_add_input_file($2,
353 lang_input_file_is_symbols_only_enum,
357 | OPTION_defsym { ldlex_defsym(); }
358 NAME '=' exp DEFSYMEND { ldlex_popstate();
359 lang_add_assignment(exp_assop($4,$3,$5));
361 | OPTION_RETAIN_SYMBOLS_FILE filename
362 { lang_add_keepsyms_file ($2); }
365 /* FIXME: This is currently ignored. It means
366 ``produce a big-endian object file''. It could
367 be used to select an output format. */
371 /* FIXME: This is currently ignored. It means
372 ``produce a little-endian object file''. It could
373 be used to select an output format. */
377 g_switch_value = atoi ($2);
381 g_switch_value = yylval.integer;
386 einfo("%P%F: illegal option -- %s\n", $1);
388 lang_add_input_file($1,lang_input_file_is_file_enum,
394 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
396 { ldlex_mri_script();
397 PUSH_ERROR("MRI style script");
406 mri_script_lines mri_script_command NEWLINE
414 einfo("%P%F: unrecognised keyword in MRI style script '%s'\n",$1);
418 config.map_filename = "-";
420 | ORDER ordernamelist
422 | PUBLIC NAME '=' exp
423 { mri_public($2, $4); }
424 | PUBLIC NAME ',' exp
425 { mri_public($2, $4); }
427 { mri_public($2, $3); }
431 { mri_output_section($2, $4);}
433 { mri_output_section($2, $3);}
435 { mri_output_section($2, $4);}
436 | ALIGN_K NAME '=' exp
437 { mri_align($2,$4); }
438 | ALIGNMOD NAME '=' exp
439 { mri_alignmod($2,$4); }
440 | ABSOLUTE mri_abs_name_list
441 | LOAD mri_load_name_list
444 | ALIAS NAME ',' NAME
445 { mri_alias($2,$4,0);}
447 { mri_alias($2,0,$4);}
451 { mri_truncate($2); }
456 ordernamelist ',' NAME { mri_order($3); }
457 | ordernamelist NAME { mri_order($2); }
464 | mri_load_name_list ',' NAME { mri_load($3); }
469 { mri_only_load($1); }
470 | mri_abs_name_list ',' NAME
471 { mri_only_load($3); }
498 | floating_point_support
501 | TARGET_K '(' NAME ')'
502 { lang_add_target($3); }
503 | SEARCH_DIR '(' filename ')'
504 { ldfile_add_library_path($3); }
505 | OUTPUT '(' filename ')'
506 { lang_add_output($3); }
507 | OUTPUT_FORMAT '(' NAME ')'
508 { lang_add_output_format($3, 1); }
509 | OUTPUT_ARCH '(' NAME ')'
510 { ldfile_set_output_arch($3); }
511 | FORCE_COMMON_ALLOCATION
512 { command_line.force_common_definition = true ; }
513 | INPUT '(' input_list ')'
514 | MAP '(' filename ')'
515 { lang_add_map($3); }
517 { ldfile_open_command_file($2); } ifile_list END
522 { lang_add_input_file($1,lang_input_file_is_file_enum,
524 | input_list ',' NAME
525 { lang_add_input_file($3,lang_input_file_is_file_enum,
528 { lang_add_input_file($2,
529 lang_input_file_is_file_enum,
534 SECTIONS '{' sec_or_group_p1 '}'
538 sec_or_group_p1 section
539 | sec_or_group_p1 statement_anywhere
545 { lang_add_entry($3); }
551 { lang_add_wild($1, current_file); }
552 | file_NAME_list opt_comma NAME
553 { lang_add_wild($3, current_file); }
559 lang_add_wild((char *)NULL, $1);
563 current_file = (char *)NULL;
571 '(' file_NAME_list ')'
574 current_file = (char *)NULL;
576 '(' file_NAME_list ')'
581 | CREATE_OBJECT_SYMBOLS
583 lang_add_attribute(lang_object_symbols_statement_enum);
589 lang_add_attribute(lang_constructors_statement_enum);
594 lang_add_data($1,$3);
600 (exp_get_value_int($3,
603 lang_first_phase_enum));
608 statement_list statement
629 $$ = exp_get_value_int($2,
632 lang_first_phase_enum);
666 lang_add_assignment(exp_assop($2,$1,$3));
668 | NAME assign_op mustbe_exp
671 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
682 MEMORY '{' memory_spec memory_spec_list '}'
686 memory_spec_list memory_spec
687 | memory_spec_list ',' memory_spec
693 { region = lang_memory_region_lookup($1); }
695 origin_spec opt_comma length_spec
698 ORIGIN '=' mustbe_exp
701 exp_get_vma($3, 0L,"origin", lang_first_phase_enum);
704 LENGTH '=' mustbe_exp
705 { region->length = exp_get_vma($3,
708 lang_first_phase_enum);
715 lang_set_flags(®ion->flags, $2);
722 STARTUP '(' filename ')'
723 { lang_startup($3); }
727 HLL '(' high_level_library_NAME_list ')'
729 { ldemul_hll((char *)NULL); }
732 high_level_library_NAME_list:
733 high_level_library_NAME_list opt_comma filename
741 SYSLIB '(' low_level_library_NAME_list ')'
742 ; low_level_library_NAME_list:
743 low_level_library_NAME_list opt_comma filename
744 { ldemul_syslib($3); }
748 floating_point_support:
750 { lang_float(true); }
752 { lang_float(false); }
756 mustbe_exp: { ldlex_expression(); }
758 { ldlex_popstate(); $$=$2;}
763 { $$ = exp_unop('-', $2); }
766 | NEXT '(' exp ')' %prec UNARY
767 { $$ = exp_unop($1,$3); }
768 | '!' exp %prec UNARY
769 { $$ = exp_unop('!', $2); }
770 | '+' exp %prec UNARY
772 | '~' exp %prec UNARY
773 { $$ = exp_unop('~', $2);}
776 { $$ = exp_binop('*', $1, $3); }
778 { $$ = exp_binop('/', $1, $3); }
780 { $$ = exp_binop('%', $1, $3); }
782 { $$ = exp_binop('+', $1, $3); }
784 { $$ = exp_binop('-' , $1, $3); }
786 { $$ = exp_binop(LSHIFT , $1, $3); }
788 { $$ = exp_binop(RSHIFT , $1, $3); }
790 { $$ = exp_binop(EQ , $1, $3); }
792 { $$ = exp_binop(NE , $1, $3); }
794 { $$ = exp_binop(LE , $1, $3); }
796 { $$ = exp_binop(GE , $1, $3); }
798 { $$ = exp_binop('<' , $1, $3); }
800 { $$ = exp_binop('>' , $1, $3); }
802 { $$ = exp_binop('&' , $1, $3); }
804 { $$ = exp_binop('^' , $1, $3); }
806 { $$ = exp_binop('|' , $1, $3); }
807 | exp '?' exp ':' exp
808 { $$ = exp_trinop('?' , $1, $3, $5); }
810 { $$ = exp_binop(ANDAND , $1, $3); }
812 { $$ = exp_binop(OROR , $1, $3); }
813 | DEFINED '(' NAME ')'
814 { $$ = exp_nameop(DEFINED, $3); }
816 { $$ = exp_intop($1); }
818 { $$ = exp_nameop(SIZEOF_HEADERS,0); }
820 | SIZEOF '(' NAME ')'
821 { $$ = exp_nameop(SIZEOF,$3); }
823 { $$ = exp_nameop(ADDR,$3); }
824 | ABSOLUTE '(' exp ')'
825 { $$ = exp_unop(ABSOLUTE, $3); }
826 | ALIGN_K '(' exp ')'
827 { $$ = exp_unop(ALIGN_K,$3); }
829 { $$ = exp_nameop(NAME,$1); }
834 AT '(' exp ')' { $$ = $3; }
838 section: NAME { ldlex_expression(); }
840 opt_at { ldlex_popstate(); }
843 lang_enter_output_section_statement($1,$3,typebits,0,0,0,$4);
846 '}' {ldlex_expression();} fill_opt memspec_opt
849 lang_leave_output_section_statement($11, $12);
856 NOLOAD { typebits = SEC_NEVER_LOAD; }
857 | DSECT { typebits = 0; }
858 | COPY { typebits = 0; }
859 | INFO { typebits = 0; }
860 | OVERLAY { typebits = 0; }
861 | { typebits = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; }
866 exp ':' { $$ = $1; typebits =0;}
867 | exp '(' type ')' ':' { $$ = $1; }
868 | ':' { $$= (etree_type *)NULL; typebits = 0; }
869 | '(' type ')' ':' { $$= (etree_type *)NULL; }
875 | { $$ = "*default*"; }
882 if (error_index> 0 && error_index < ERROR_NAME_MAX)
883 einfo("%P%F: %S syntax error in %s\n",error_names[error_index-1]);
885 einfo("%P%F: %S syntax error\n");