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;
46 extern int g_switch_value;
49 strip_symbols_type strip_symbols=STRIP_NONE;
50 discard_locals_type discard_locals=DISCARD_NONE;
53 lang_memory_region_type *region;
56 lang_memory_region_type *lang_memory_region_lookup();
57 lang_output_section_statement_type *lang_output_section_statement_lookup();
58 etree_type *lang_atin();
61 void lang_add_data(int type, union etree_union *exp);
62 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*);
67 void lang_enter_output_section_statement();
71 extern args_type command_line;
73 boolean ldgram_want_filename = true;
74 boolean had_script = false;
75 boolean force_make_executable = false;
77 boolean ldgram_in_script = false;
78 boolean ldgram_had_equals = false;
82 #define ERROR_NAME_MAX 20
83 static char *error_names[ERROR_NAME_MAX];
84 static int error_index;
85 #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
86 #define POP_ERROR() error_index--;
93 union etree_union *etree;
95 struct lang_output_section_statement_struct *output_section_statement;
96 union lang_statement_union **statement_ptr;
107 %type <etree> exp opt_exp_with_type mustbe_exp opt_at
108 %type <integer> fill_opt
109 %type <name> memspec_opt
112 %type <integer> length
114 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
115 %right <token> '?' ':'
122 %left <token> '<' '>' LE GE
123 %left <token> LSHIFT RSHIFT
125 %left <token> '+' '-'
126 %left <token> '*' '/' '%'
128 /*%token <token> '+' '-' '*' '/' '%'*/
132 %token <token> ALIGN_K BLOCK LONG SHORT BYTE
135 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
136 %token SIZEOF_HEADERS
138 %token MEMORY DEFSYMEND
139 %token NOLOAD DSECT COPY INFO OVERLAY
140 %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
141 %token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S OPTION_sort_common
142 %token OPTION_EB OPTION_EL OPTION_G OPTION_Gval
143 %token OPTION_format OPTION_F OPTION_u OPTION_Bstatic OPTION_N
144 %token <integer> SIZEOF NEXT ADDR
145 %token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X OPTION_defsym
146 %token OPTION_v OPTION_V OPTION_m OPTION_memul OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT NOFLOAT
148 %token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_R OPTION_relax
149 %token <name> OPTION_l OPTION_L OPTION_T OPTION_Aarch OPTION_Tfile OPTION_Texp
150 %token <name> OPTION_y
152 %token ORIGIN FILL OPTION_g
153 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT OUTPUT CONSTRUCTORS
154 %token OPTION_RETAIN_SYMBOLS_FILE ALIGNMOD AT
156 %type <token> assign_op
158 %type <name> filename
161 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD
162 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE
165 ld_config_type config;
170 file: command_line { lang_final(); };
177 command_line command_line_option
199 config.map_filename = $2;
211 config.map_filename = "-";
214 config.magic_demand_paged = false;
217 config.text_read_only = false;
218 config.magic_demand_paged = false;
221 strip_symbols = STRIP_ALL;
224 strip_symbols = STRIP_DEBUGGER;
227 ldlang_add_undef($2);
231 config.relocateable_output = true;
232 config.build_constructors = false;
233 config.magic_demand_paged = false;
234 config.text_read_only = false;
237 config.relocateable_output = true;
238 config.build_constructors = true;
239 config.magic_demand_paged = false;
240 config.text_read_only = false;
247 { lang_add_entry($2);
250 discard_locals = DISCARD_L;
253 discard_locals = DISCARD_ALL;
256 | OPTION_noinhibit_exec
258 force_make_executable = true;
260 | OPTION_sort_common {
261 config.sort_common = true;
264 command_line.force_common_definition = true;
268 command_line.relax = true;
272 command_line.force_common_definition = true;
280 command_line.force_common_definition = true;
287 { ldlex_expression();
292 lang_section_start($1,exp_intop($3));
309 ldfile_add_library_path($1);
316 { ldfile_open_command_file($2); } mri_script_file END { ldlex_command();}
319 { ldfile_open_command_file($1); } script_file
320 END { ldlex_command();}
323 { ldfile_open_command_file($2); } script_file
324 END { ldlex_command();}
328 lang_add_input_file($1,
329 lang_input_file_is_l_enum,
334 lang_add_input_file($2,
335 lang_input_file_is_symbols_only_enum,
339 | OPTION_defsym { ldlex_defsym(); }
340 NAME '=' exp DEFSYMEND { ldlex_popstate();
341 lang_add_assignment(exp_assop($4,$3,$5));
343 | OPTION_RETAIN_SYMBOLS_FILE filename
344 { lang_add_keepsyms_file ($2); }
347 /* FIXME: This is currently ignored. It means
348 ``produce a big-endian object file''. It could
349 be used to select an output format. */
353 /* FIXME: This is currently ignored. It means
354 ``produce a little-endian object file''. It could
355 be used to select an output format. */
359 g_switch_value = atoi ($2);
363 g_switch_value = yylval.integer;
366 { einfo("%P%F illegal option -- %s\n", $2); }
368 { lang_add_input_file($1,lang_input_file_is_file_enum,
370 | '{' script_file '}'
374 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
376 { ldlex_mri_script();
377 PUSH_ERROR("MRI style script");
386 mri_script_lines mri_script_command NEWLINE
394 einfo("%P%F: unrecognised keyword in MRI style script '%s'\n",$1);
398 config.map_filename = "-";
400 | ORDER ordernamelist
402 | PUBLIC NAME '=' exp
403 { mri_public($2, $4); }
404 | PUBLIC NAME ',' exp
405 { mri_public($2, $4); }
407 { mri_public($2, $3); }
411 { mri_output_section($2, $4);}
413 { mri_output_section($2, $3);}
415 { mri_output_section($2, $4);}
416 | ALIGN_K NAME '=' exp
417 { mri_align($2,$4); }
418 | ALIGNMOD NAME '=' exp
419 { mri_alignmod($2,$4); }
420 | ABSOLUTE mri_abs_name_list
421 | LOAD mri_load_name_list
424 | ALIAS NAME ',' NAME
425 { mri_alias($2,$4,0);}
427 { mri_alias($2,0,$4);}
431 { mri_truncate($2); }
436 ordernamelist ',' NAME { mri_order($3); }
437 | ordernamelist NAME { mri_order($2); }
444 | mri_load_name_list ',' NAME { mri_load($3); }
449 { mri_only_load($1); }
450 | mri_abs_name_list ',' NAME
451 { mri_only_load($3); }
478 | floating_point_support
481 | TARGET_K '(' NAME ')'
482 { lang_add_target($3); }
483 | SEARCH_DIR '(' filename ')'
484 { ldfile_add_library_path($3); }
485 | OUTPUT '(' filename ')'
486 { lang_add_output($3); }
487 | OUTPUT_FORMAT '(' NAME ')'
488 { lang_add_output_format($3); }
489 | OUTPUT_ARCH '(' NAME ')'
490 { ldfile_set_output_arch($3); }
491 | FORCE_COMMON_ALLOCATION
492 { command_line.force_common_definition = true ; }
493 | INPUT '(' input_list ')'
494 | MAP '(' filename ')'
495 { lang_add_map($3); }
497 { ldfile_open_command_file($2); } ifile_list END
502 { lang_add_input_file($1,lang_input_file_is_file_enum,
504 | input_list ',' NAME
505 { lang_add_input_file($3,lang_input_file_is_file_enum,
508 { lang_add_input_file($2,
509 lang_input_file_is_file_enum,
514 SECTIONS '{' sec_or_group_p1 '}'
518 sec_or_group_p1 section
519 | sec_or_group_p1 statement_anywhere
525 { lang_add_entry($3); }
531 { lang_add_wild($1, current_file); }
532 | file_NAME_list opt_comma NAME
533 { lang_add_wild($3, current_file); }
539 lang_add_wild((char *)NULL, $1);
543 current_file = (char *)NULL;
551 '(' file_NAME_list ')'
554 current_file = (char *)NULL;
556 '(' file_NAME_list ')'
561 | CREATE_OBJECT_SYMBOLS
563 lang_add_attribute(lang_object_symbols_statement_enum);
569 lang_add_attribute(lang_constructors_statement_enum);
574 lang_add_data($1,$3);
580 (exp_get_value_int($3,
583 lang_first_phase_enum));
588 statement_list statement
609 $$ = exp_get_value_int($2,
612 lang_first_phase_enum);
646 lang_add_assignment(exp_assop($2,$1,$3));
648 | NAME assign_op mustbe_exp
651 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
662 MEMORY '{' memory_spec memory_spec_list '}'
666 memory_spec_list memory_spec
667 | memory_spec_list ',' memory_spec
673 { region = lang_memory_region_lookup($1); }
675 origin_spec opt_comma length_spec
678 ORIGIN '=' mustbe_exp
681 exp_get_vma($3, 0L,"origin", lang_first_phase_enum);
684 LENGTH '=' mustbe_exp
685 { region->length = exp_get_vma($3,
688 lang_first_phase_enum);
695 lang_set_flags(®ion->flags, $2);
702 STARTUP '(' filename ')'
703 { lang_startup($3); }
707 HLL '(' high_level_library_NAME_list ')'
709 { ldemul_hll((char *)NULL); }
712 high_level_library_NAME_list:
713 high_level_library_NAME_list opt_comma filename
721 SYSLIB '(' low_level_library_NAME_list ')'
722 ; low_level_library_NAME_list:
723 low_level_library_NAME_list opt_comma filename
724 { ldemul_syslib($3); }
728 floating_point_support:
730 { lang_float(true); }
732 { lang_float(false); }
736 mustbe_exp: { ldlex_expression(); }
738 { ldlex_popstate(); $$=$2;}
743 { $$ = exp_unop('-', $2); }
746 | NEXT '(' exp ')' %prec UNARY
747 { $$ = exp_unop($1,$3); }
748 | '!' exp %prec UNARY
749 { $$ = exp_unop('!', $2); }
750 | '+' exp %prec UNARY
752 | '~' exp %prec UNARY
753 { $$ = exp_unop('~', $2);}
756 { $$ = exp_binop('*', $1, $3); }
758 { $$ = exp_binop('/', $1, $3); }
760 { $$ = exp_binop('%', $1, $3); }
762 { $$ = exp_binop('+', $1, $3); }
764 { $$ = exp_binop('-' , $1, $3); }
766 { $$ = exp_binop(LSHIFT , $1, $3); }
768 { $$ = exp_binop(RSHIFT , $1, $3); }
770 { $$ = exp_binop(EQ , $1, $3); }
772 { $$ = exp_binop(NE , $1, $3); }
774 { $$ = exp_binop(LE , $1, $3); }
776 { $$ = exp_binop(GE , $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('|' , $1, $3); }
787 | exp '?' exp ':' exp
788 { $$ = exp_trinop('?' , $1, $3, $5); }
790 { $$ = exp_binop(ANDAND , $1, $3); }
792 { $$ = exp_binop(OROR , $1, $3); }
793 | DEFINED '(' NAME ')'
794 { $$ = exp_nameop(DEFINED, $3); }
796 { $$ = exp_intop($1); }
798 { $$ = exp_nameop(SIZEOF_HEADERS,0); }
800 | SIZEOF '(' NAME ')'
801 { $$ = exp_nameop(SIZEOF,$3); }
803 { $$ = exp_nameop(ADDR,$3); }
804 | ABSOLUTE '(' exp ')'
805 { $$ = exp_unop(ABSOLUTE, $3); }
806 | ALIGN_K '(' exp ')'
807 { $$ = exp_unop(ALIGN_K,$3); }
809 { $$ = exp_nameop(NAME,$1); }
814 AT '(' exp ')' { $$ = $3; }
818 section: NAME { ldlex_expression(); }
820 opt_at { ldlex_popstate(); }
823 lang_enter_output_section_statement($1,$3,typebits,0,0,0,$4);
826 '}' {ldlex_expression();} fill_opt memspec_opt
829 lang_leave_output_section_statement($11, $12);
836 NOLOAD { typebits = SEC_NEVER_LOAD; }
837 | DSECT { typebits = 0; }
838 | COPY { typebits = 0; }
839 | INFO { typebits = 0; }
840 | OVERLAY { typebits = 0; }
841 | { typebits = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; }
846 exp ':' { $$ = $1; typebits =0;}
847 | exp '(' type ')' ':' { $$ = $1; }
848 | ':' { $$= (etree_type *)NULL; typebits = 0; }
849 | '(' type ')' ':' { $$= (etree_type *)NULL; }
855 | { $$ = "*default*"; }
862 if (error_index> 0 && error_index < ERROR_NAME_MAX)
863 einfo("%P%F: %S syntax error in %s\n",error_names[error_index-1]);
865 einfo("%P%F: %S syntax error\n");