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;
51 static char *dirlist_ptr;
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 OPTION_warn_common
142 %token OPTION_EB OPTION_EL OPTION_G OPTION_Gval OPTION_help
143 %token OPTION_format OPTION_oformat 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
147 %token OPTION_L OPTION_Map
148 %token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_R OPTION_relax OPTION_version
149 %token <name> OPTION_l OPTION_Lfile OPTION_T OPTION_Aarch OPTION_Tfile
150 %token <name> OPTION_Texp 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
155 %token OPTION_Qy OPTION_Y OPTION_dn OPTION_call_shared OPTION_non_shared
156 %token <name> OPTION_YP
158 %type <token> assign_op
160 %type <name> filename
163 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD
164 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE
167 extern ld_config_type config;
172 file: command_line { lang_final(); };
179 command_line command_line_option
197 trace_file_tries = true;
210 config.map_filename = $2;
222 config.map_filename = "-";
225 config.magic_demand_paged = false;
228 config.text_read_only = false;
229 config.magic_demand_paged = false;
232 strip_symbols = STRIP_ALL;
235 strip_symbols = STRIP_DEBUGGER;
238 ldlang_add_undef($2);
242 config.relocateable_output = true;
243 config.build_constructors = false;
244 config.magic_demand_paged = false;
245 config.text_read_only = false;
248 config.relocateable_output = true;
249 config.build_constructors = true;
250 config.magic_demand_paged = false;
251 config.text_read_only = false;
255 lang_add_output($2, 0);
258 { lang_add_entry($2);
261 discard_locals = DISCARD_L;
264 discard_locals = DISCARD_ALL;
267 | OPTION_noinhibit_exec
269 force_make_executable = true;
273 config.sort_common = true;
277 config.warn_common = true;
280 command_line.force_common_definition = true;
284 command_line.relax = true;
288 command_line.force_common_definition = true;
296 command_line.force_common_definition = true;
302 | OPTION_oformat NAME
304 lang_add_output_format($2, 0);
307 { ldlex_expression();
312 lang_section_start($1,exp_intop($3));
329 ldfile_add_library_path($2);
333 ldfile_add_library_path($1);
340 {ldfile_open_command_file($2); }
341 mri_script_file END { ldlex_command();}
344 { ldfile_open_command_file($1); } script_file
345 END { ldlex_command();}
348 { ldfile_open_command_file($2); } script_file
349 END { ldlex_command();}
353 lang_add_input_file($1,
354 lang_input_file_is_l_enum,
359 lang_add_input_file($2,
360 lang_input_file_is_symbols_only_enum,
364 | OPTION_defsym { ldlex_defsym(); }
365 NAME '=' exp DEFSYMEND { ldlex_popstate();
366 lang_add_assignment(exp_assop($4,$3,$5));
368 | OPTION_RETAIN_SYMBOLS_FILE filename
369 { lang_add_keepsyms_file ($2); }
372 /* FIXME: This is currently ignored. It means
373 ``produce a big-endian object file''. It could
374 be used to select an output format. */
378 /* FIXME: This is currently ignored. It means
379 ``produce a little-endian object file''. It could
380 be used to select an output format. */
384 g_switch_value = atoi ($2);
388 g_switch_value = yylval.integer;
397 goto set_default_dirlist;
401 if (strncmp ($2, "P,", 2))
402 einfo ("%P%F: unknown -Y option -- %s\n", $2);
410 p = strchr (dirlist_ptr, ':');
414 ldfile_add_library_path (dirlist_ptr);
423 | '{' script_file '}' { /* This parses compiled-in scripts. */ }
427 einfo("%P%F: illegal option -- %s\n", $1);
429 lang_add_input_file($1,lang_input_file_is_file_enum,
435 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
437 { ldlex_mri_script();
438 PUSH_ERROR("MRI style script");
447 mri_script_lines mri_script_command NEWLINE
455 einfo("%P%F: unrecognised keyword in MRI style script '%s'\n",$1);
459 config.map_filename = "-";
461 | ORDER ordernamelist
463 | PUBLIC NAME '=' exp
464 { mri_public($2, $4); }
465 | PUBLIC NAME ',' exp
466 { mri_public($2, $4); }
468 { mri_public($2, $3); }
472 { mri_output_section($2, $4);}
474 { mri_output_section($2, $3);}
476 { mri_output_section($2, $4);}
477 | ALIGN_K NAME '=' exp
478 { mri_align($2,$4); }
479 | ALIGNMOD NAME '=' exp
480 { mri_alignmod($2,$4); }
481 | ABSOLUTE mri_abs_name_list
482 | LOAD mri_load_name_list
485 | ALIAS NAME ',' NAME
486 { mri_alias($2,$4,0);}
488 { mri_alias($2,0,$4);}
492 { mri_truncate($2); }
497 ordernamelist ',' NAME { mri_order($3); }
498 | ordernamelist NAME { mri_order($2); }
505 | mri_load_name_list ',' NAME { mri_load($3); }
510 { mri_only_load($1); }
511 | mri_abs_name_list ',' NAME
512 { mri_only_load($3); }
539 | floating_point_support
542 | TARGET_K '(' NAME ')'
543 { lang_add_target($3); }
544 | SEARCH_DIR '(' filename ')'
545 { ldfile_add_library_path($3); }
546 | OUTPUT '(' filename ')'
547 { lang_add_output($3, 1); }
548 | OUTPUT_FORMAT '(' NAME ')'
549 { lang_add_output_format($3, 1); }
550 | OUTPUT_ARCH '(' NAME ')'
551 { ldfile_set_output_arch($3); }
552 | FORCE_COMMON_ALLOCATION
553 { command_line.force_common_definition = true ; }
554 | INPUT '(' input_list ')'
555 | MAP '(' filename ')'
556 { lang_add_map($3); }
558 { ldfile_open_command_file($2); } ifile_list END
563 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
565 | input_list ',' NAME
566 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
569 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
574 SECTIONS '{' sec_or_group_p1 '}'
578 sec_or_group_p1 section
579 | sec_or_group_p1 statement_anywhere
585 { lang_add_entry($3); }
591 { lang_add_wild($1, current_file); }
592 | file_NAME_list opt_comma NAME
593 { lang_add_wild($3, current_file); }
599 lang_add_wild((char *)NULL, $1);
603 current_file = (char *)NULL;
611 '(' file_NAME_list ')'
614 current_file = (char *)NULL;
616 '(' file_NAME_list ')'
621 | CREATE_OBJECT_SYMBOLS
623 lang_add_attribute(lang_object_symbols_statement_enum);
629 lang_add_attribute(lang_constructors_statement_enum);
634 lang_add_data($1,$3);
640 (exp_get_value_int($3,
643 lang_first_phase_enum));
648 statement_list statement
669 $$ = exp_get_value_int($2,
672 lang_first_phase_enum);
706 lang_add_assignment(exp_assop($2,$1,$3));
708 | NAME assign_op mustbe_exp
711 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
722 MEMORY '{' memory_spec memory_spec_list '}'
726 memory_spec_list memory_spec
727 | memory_spec_list ',' memory_spec
733 { region = lang_memory_region_lookup($1); }
735 origin_spec opt_comma length_spec
738 ORIGIN '=' mustbe_exp
741 exp_get_vma($3, 0L,"origin", lang_first_phase_enum);
744 LENGTH '=' mustbe_exp
745 { region->length = exp_get_vma($3,
748 lang_first_phase_enum);
755 lang_set_flags(®ion->flags, $2);
762 STARTUP '(' filename ')'
763 { lang_startup($3); }
767 HLL '(' high_level_library_NAME_list ')'
769 { ldemul_hll((char *)NULL); }
772 high_level_library_NAME_list:
773 high_level_library_NAME_list opt_comma filename
781 SYSLIB '(' low_level_library_NAME_list ')'
782 ; low_level_library_NAME_list:
783 low_level_library_NAME_list opt_comma filename
784 { ldemul_syslib($3); }
788 floating_point_support:
790 { lang_float(true); }
792 { lang_float(false); }
796 mustbe_exp: { ldlex_expression(); }
798 { ldlex_popstate(); $$=$2;}
803 { $$ = exp_unop('-', $2); }
806 | NEXT '(' exp ')' %prec UNARY
807 { $$ = exp_unop($1,$3); }
808 | '!' exp %prec UNARY
809 { $$ = exp_unop('!', $2); }
810 | '+' exp %prec UNARY
812 | '~' exp %prec UNARY
813 { $$ = exp_unop('~', $2);}
816 { $$ = exp_binop('*', $1, $3); }
818 { $$ = exp_binop('/', $1, $3); }
820 { $$ = exp_binop('%', $1, $3); }
822 { $$ = exp_binop('+', $1, $3); }
824 { $$ = exp_binop('-' , $1, $3); }
826 { $$ = exp_binop(LSHIFT , $1, $3); }
828 { $$ = exp_binop(RSHIFT , $1, $3); }
830 { $$ = exp_binop(EQ , $1, $3); }
832 { $$ = exp_binop(NE , $1, $3); }
834 { $$ = exp_binop(LE , $1, $3); }
836 { $$ = exp_binop(GE , $1, $3); }
838 { $$ = exp_binop('<' , $1, $3); }
840 { $$ = exp_binop('>' , $1, $3); }
842 { $$ = exp_binop('&' , $1, $3); }
844 { $$ = exp_binop('^' , $1, $3); }
846 { $$ = exp_binop('|' , $1, $3); }
847 | exp '?' exp ':' exp
848 { $$ = exp_trinop('?' , $1, $3, $5); }
850 { $$ = exp_binop(ANDAND , $1, $3); }
852 { $$ = exp_binop(OROR , $1, $3); }
853 | DEFINED '(' NAME ')'
854 { $$ = exp_nameop(DEFINED, $3); }
856 { $$ = exp_intop($1); }
858 { $$ = exp_nameop(SIZEOF_HEADERS,0); }
860 | SIZEOF '(' NAME ')'
861 { $$ = exp_nameop(SIZEOF,$3); }
863 { $$ = exp_nameop(ADDR,$3); }
864 | ABSOLUTE '(' exp ')'
865 { $$ = exp_unop(ABSOLUTE, $3); }
866 | ALIGN_K '(' exp ')'
867 { $$ = exp_unop(ALIGN_K,$3); }
869 { $$ = exp_nameop(NAME,$1); }
874 AT '(' exp ')' { $$ = $3; }
878 section: NAME { ldlex_expression(); }
880 opt_at { ldlex_popstate(); }
883 lang_enter_output_section_statement($1,$3,typebits,0,0,0,$4);
886 '}' {ldlex_expression();} fill_opt memspec_opt
889 lang_leave_output_section_statement($11, $12);
896 NOLOAD { typebits = SEC_NEVER_LOAD; }
897 | DSECT { typebits = 0; }
898 | COPY { typebits = 0; }
899 | INFO { typebits = 0; }
900 | OVERLAY { typebits = 0; }
901 | { typebits = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; }
906 exp ':' { $$ = $1; typebits =0;}
907 | exp '(' type ')' ':' { $$ = $1; }
908 | ':' { $$= (etree_type *)NULL; typebits = 0; }
909 | '(' type ')' ':' { $$= (etree_type *)NULL; }
915 | { $$ = "*default*"; }
922 if (error_index> 0 && error_index < ERROR_NAME_MAX)
923 einfo("%P%F: %S syntax error in %s\n",error_names[error_index-1]);
925 einfo("%P%F: %S syntax error\n");