1 /* A YACC grammer to parse a superset of the AT&T linker scripting languaue.
2 Copyright (C) 1991, 1993 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
46 static char *dirlist_ptr;
48 lang_memory_region_type *region;
52 boolean ldgram_want_filename = true;
53 boolean had_script = false;
54 boolean force_make_executable = false;
56 boolean ldgram_in_script = false;
57 boolean ldgram_had_equals = false;
60 #define ERROR_NAME_MAX 20
61 static char *error_names[ERROR_NAME_MAX];
62 static int error_index;
63 #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
64 #define POP_ERROR() error_index--;
71 union etree_union *etree;
73 struct lang_output_section_statement_struct *output_section_statement;
74 union lang_statement_union **statement_ptr;
85 %type <etree> exp opt_exp_with_type mustbe_exp opt_at
86 %type <integer> fill_opt
87 %type <name> memspec_opt
90 %type <integer> length
92 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
93 %right <token> '?' ':'
100 %left <token> '<' '>' LE GE
101 %left <token> LSHIFT RSHIFT
103 %left <token> '+' '-'
104 %left <token> '*' '/' '%'
106 /*%token <token> '+' '-' '*' '/' '%'*/
110 %token <token> ALIGN_K BLOCK LONG SHORT BYTE
113 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
114 %token SIZEOF_HEADERS
116 %token MEMORY DEFSYMEND
117 %token NOLOAD DSECT COPY INFO OVERLAY
118 %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
119 %token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S OPTION_sort_common OPTION_warn_common
120 %token OPTION_EB OPTION_EL OPTION_G OPTION_Gval OPTION_help
121 %token OPTION_format OPTION_oformat OPTION_F OPTION_u OPTION_Bstatic OPTION_N
122 %token <integer> SIZEOF NEXT ADDR
123 %token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X OPTION_defsym
124 %token OPTION_v OPTION_V OPTION_m OPTION_memul OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT NOFLOAT
125 %token OPTION_L OPTION_Map
126 %token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_R OPTION_relax OPTION_version
127 %token <name> OPTION_l OPTION_Lfile OPTION_T OPTION_Aarch OPTION_Tfile
128 %token <name> OPTION_Texp OPTION_y
130 %token ORIGIN FILL OPTION_g
131 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT OUTPUT CONSTRUCTORS
132 %token OPTION_RETAIN_SYMBOLS_FILE ALIGNMOD AT
133 %token OPTION_Qy OPTION_Y OPTION_dn OPTION_call_shared OPTION_non_shared
134 %token OPTION_Oval OPTION_stats OPTION_no_keep_memory
135 %token <name> OPTION_YP
137 %type <token> assign_op
139 %type <name> filename
142 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD
143 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
154 command_line command_line_option
172 trace_file_tries = true;
185 config.map_filename = $2;
197 config.map_filename = "-";
200 config.magic_demand_paged = false;
203 config.text_read_only = false;
204 config.magic_demand_paged = false;
207 link_info.strip = strip_all;
210 link_info.strip = strip_debugger;
215 | OPTION_no_keep_memory {
216 link_info.keep_memory = false;
219 ldlang_add_undef($2);
222 link_info.relocateable = true;
223 config.build_constructors = false;
224 config.magic_demand_paged = false;
225 config.text_read_only = false;
228 link_info.relocateable = true;
229 config.build_constructors = true;
230 config.magic_demand_paged = false;
231 config.text_read_only = false;
235 lang_add_output($2, 0);
238 { lang_add_entry($2);
241 link_info.discard = discard_l;
244 link_info.discard = discard_all;
247 | OPTION_noinhibit_exec
249 force_make_executable = true;
253 config.sort_common = true;
257 config.warn_common = true;
260 command_line.force_common_definition = true;
264 command_line.relax = true;
268 command_line.force_common_definition = true;
276 command_line.force_common_definition = true;
282 | OPTION_oformat NAME
284 lang_add_output_format($2, 0);
287 { ldlex_expression();
292 lang_section_start($1,exp_intop($3));
309 ldfile_add_library_path($2);
313 ldfile_add_library_path($1);
320 {ldfile_open_command_file($2); }
321 mri_script_file END { ldlex_command();}
324 { ldfile_open_command_file($1); } script_file
325 END { ldlex_command();}
328 { ldfile_open_command_file($2); } script_file
329 END { ldlex_command();}
333 lang_add_input_file($1,
334 lang_input_file_is_l_enum,
339 lang_add_input_file($2,
340 lang_input_file_is_symbols_only_enum,
344 | OPTION_defsym { ldlex_defsym(); }
345 NAME '=' exp DEFSYMEND { ldlex_popstate();
346 lang_add_assignment(exp_assop($4,$3,$5));
348 | OPTION_RETAIN_SYMBOLS_FILE filename
349 { add_keepsyms_file ($2); }
352 /* FIXME: This is currently ignored. It means
353 ``produce a big-endian object file''. It could
354 be used to select an output format. */
358 /* FIXME: This is currently ignored. It means
359 ``produce a little-endian object file''. It could
360 be used to select an output format. */
364 g_switch_value = atoi ($2);
368 g_switch_value = yylval.integer;
378 goto set_default_dirlist;
382 if (strncmp ($2, "P,", 2))
383 einfo ("%P%F: unknown -Y option -- %s\n", $2);
391 p = strchr (dirlist_ptr, ':');
395 ldfile_add_library_path (dirlist_ptr);
403 | '{' script_file '}' { /* This parses compiled-in scripts. */ }
407 einfo("%P%F: illegal option -- %s\n", $1);
409 lang_add_input_file($1,lang_input_file_is_file_enum,
415 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
417 { ldlex_mri_script();
418 PUSH_ERROR("MRI style script");
427 mri_script_lines mri_script_command NEWLINE
435 einfo("%P%F: unrecognised keyword in MRI style script '%s'\n",$1);
439 config.map_filename = "-";
441 | ORDER ordernamelist
443 | PUBLIC NAME '=' exp
444 { mri_public($2, $4); }
445 | PUBLIC NAME ',' exp
446 { mri_public($2, $4); }
448 { mri_public($2, $3); }
452 { mri_output_section($2, $4);}
454 { mri_output_section($2, $3);}
456 { mri_output_section($2, $4);}
457 | ALIGN_K NAME '=' exp
458 { mri_align($2,$4); }
459 | ALIGNMOD NAME '=' exp
460 { mri_alignmod($2,$4); }
461 | ABSOLUTE mri_abs_name_list
462 | LOAD mri_load_name_list
465 | ALIAS NAME ',' NAME
466 { mri_alias($2,$4,0);}
468 { mri_alias($2,0,(int) $4);}
472 { mri_truncate((unsigned int) $2); }
477 ordernamelist ',' NAME { mri_order($3); }
478 | ordernamelist NAME { mri_order($2); }
485 | mri_load_name_list ',' NAME { mri_load($3); }
490 { mri_only_load($1); }
491 | mri_abs_name_list ',' NAME
492 { mri_only_load($3); }
519 | floating_point_support
522 | TARGET_K '(' NAME ')'
523 { lang_add_target($3); }
524 | SEARCH_DIR '(' filename ')'
525 { ldfile_add_library_path($3); }
526 | OUTPUT '(' filename ')'
527 { lang_add_output($3, 1); }
528 | OUTPUT_FORMAT '(' NAME ')'
529 { lang_add_output_format($3, 1); }
530 | OUTPUT_ARCH '(' NAME ')'
531 { ldfile_set_output_arch($3); }
532 | FORCE_COMMON_ALLOCATION
533 { command_line.force_common_definition = true ; }
534 | INPUT '(' input_list ')'
535 | MAP '(' filename ')'
536 { lang_add_map($3); }
538 { ldfile_open_command_file($2); } ifile_list END
543 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
545 | input_list ',' NAME
546 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
549 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
554 SECTIONS '{' sec_or_group_p1 '}'
558 sec_or_group_p1 section
559 | sec_or_group_p1 statement_anywhere
565 { lang_add_entry($3); }
571 { lang_add_wild($1, current_file); }
572 | file_NAME_list opt_comma NAME
573 { lang_add_wild($3, current_file); }
579 lang_add_wild((char *)NULL, $1);
583 current_file = (char *)NULL;
591 '(' file_NAME_list ')'
594 current_file = (char *)NULL;
596 '(' file_NAME_list ')'
601 | CREATE_OBJECT_SYMBOLS
603 lang_add_attribute(lang_object_symbols_statement_enum);
609 lang_add_attribute(lang_constructors_statement_enum);
614 lang_add_data((int) $1,$3);
620 (exp_get_value_int($3,
623 lang_first_phase_enum));
628 statement_list statement
649 $$ = exp_get_value_int($2,
652 lang_first_phase_enum);
686 lang_add_assignment(exp_assop($2,$1,$3));
688 | NAME assign_op mustbe_exp
691 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
702 MEMORY '{' memory_spec memory_spec_list '}'
706 memory_spec_list memory_spec
707 | memory_spec_list ',' memory_spec
713 { region = lang_memory_region_lookup($1); }
715 origin_spec opt_comma length_spec
718 ORIGIN '=' mustbe_exp
721 exp_get_vma($3, 0L,"origin", lang_first_phase_enum);
724 LENGTH '=' mustbe_exp
725 { region->length = exp_get_vma($3,
728 lang_first_phase_enum);
735 lang_set_flags(®ion->flags, $2);
742 STARTUP '(' filename ')'
743 { lang_startup($3); }
747 HLL '(' high_level_library_NAME_list ')'
749 { ldemul_hll((char *)NULL); }
752 high_level_library_NAME_list:
753 high_level_library_NAME_list opt_comma filename
761 SYSLIB '(' low_level_library_NAME_list ')'
762 ; low_level_library_NAME_list:
763 low_level_library_NAME_list opt_comma filename
764 { ldemul_syslib($3); }
768 floating_point_support:
770 { lang_float(true); }
772 { lang_float(false); }
776 mustbe_exp: { ldlex_expression(); }
778 { ldlex_popstate(); $$=$2;}
783 { $$ = exp_unop('-', $2); }
786 | NEXT '(' exp ')' %prec UNARY
787 { $$ = exp_unop((int) $1,$3); }
788 | '!' exp %prec UNARY
789 { $$ = exp_unop('!', $2); }
790 | '+' exp %prec UNARY
792 | '~' exp %prec UNARY
793 { $$ = exp_unop('~', $2);}
796 { $$ = exp_binop('*', $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(LSHIFT , $1, $3); }
808 { $$ = exp_binop(RSHIFT , $1, $3); }
810 { $$ = exp_binop(EQ , $1, $3); }
812 { $$ = exp_binop(NE , $1, $3); }
814 { $$ = exp_binop(LE , $1, $3); }
816 { $$ = exp_binop(GE , $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('|' , $1, $3); }
827 | exp '?' exp ':' exp
828 { $$ = exp_trinop('?' , $1, $3, $5); }
830 { $$ = exp_binop(ANDAND , $1, $3); }
832 { $$ = exp_binop(OROR , $1, $3); }
833 | DEFINED '(' NAME ')'
834 { $$ = exp_nameop(DEFINED, $3); }
836 { $$ = exp_intop($1); }
838 { $$ = exp_nameop(SIZEOF_HEADERS,0); }
840 | SIZEOF '(' NAME ')'
841 { $$ = exp_nameop(SIZEOF,$3); }
843 { $$ = exp_nameop(ADDR,$3); }
844 | ABSOLUTE '(' exp ')'
845 { $$ = exp_unop(ABSOLUTE, $3); }
846 | ALIGN_K '(' exp ')'
847 { $$ = exp_unop(ALIGN_K,$3); }
849 { $$ = exp_nameop(NAME,$1); }
854 AT '(' exp ')' { $$ = $3; }
858 section: NAME { ldlex_expression(); }
860 opt_at { ldlex_popstate(); }
863 lang_enter_output_section_statement($1,$3,typebits,0,0,0,$4);
866 '}' {ldlex_expression();} fill_opt memspec_opt
869 lang_leave_output_section_statement($11, $12);
876 NOLOAD { typebits = SEC_NEVER_LOAD; }
877 | DSECT { typebits = 0; }
878 | COPY { typebits = 0; }
879 | INFO { typebits = 0; }
880 | OVERLAY { typebits = 0; }
881 | { typebits = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; }
886 exp ':' { $$ = $1; typebits =0;}
887 | exp '(' type ')' ':' { $$ = $1; }
888 | ':' { $$= (etree_type *)NULL; typebits = 0; }
889 | '(' type ')' ':' { $$= (etree_type *)NULL; }
895 | { $$ = "*default*"; }
902 if (error_index> 0 && error_index < ERROR_NAME_MAX)
903 einfo("%P%F: %S syntax error in %s\n",error_names[error_index-1]);
905 einfo("%P%F: %S syntax error\n");