1 /* A YACC grammer to parse a superset of the AT&T linker scripting languaue.
2 Copyright (C) 1991, 1993 Free Software Foundation, Inc.
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 QUAD 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_y 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_esymbol OPTION_usymbol OPTION_ysymbol
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
168 version_printed = true;
173 version_printed = true;
174 trace_file_tries = true;
179 version_printed = true;
187 config.map_filename = $2;
199 config.map_filename = "-";
202 config.magic_demand_paged = false;
205 config.text_read_only = false;
206 config.magic_demand_paged = false;
209 link_info.strip = strip_all;
212 link_info.strip = strip_debugger;
217 | OPTION_no_keep_memory {
218 link_info.keep_memory = false;
221 ldlang_add_undef($2);
224 ldlang_add_undef($1);
227 link_info.relocateable = true;
228 config.build_constructors = false;
229 config.magic_demand_paged = false;
230 config.text_read_only = false;
233 link_info.relocateable = true;
234 config.build_constructors = true;
235 config.magic_demand_paged = false;
236 config.text_read_only = false;
240 lang_add_output($2, 0);
243 { lang_add_entry($2);
246 { lang_add_entry($1);
249 link_info.discard = discard_l;
252 link_info.discard = discard_all;
255 | OPTION_noinhibit_exec
257 force_make_executable = true;
261 config.sort_common = true;
265 config.warn_common = true;
268 command_line.force_common_definition = true;
272 command_line.relax = true;
276 command_line.force_common_definition = true;
284 command_line.force_common_definition = true;
290 | OPTION_oformat NAME
292 lang_add_output_format($2, 0);
295 { ldlex_expression();
300 lang_section_start($1,exp_intop($3));
321 ldfile_add_library_path($2);
325 ldfile_add_library_path($1);
332 {ldfile_open_command_file($2); }
333 mri_script_file END { ldlex_command();}
336 { ldfile_open_command_file($1); } script_file
337 END { ldlex_command();}
340 { ldfile_open_command_file($2); } script_file
341 END { ldlex_command();}
345 lang_add_input_file($1,
346 lang_input_file_is_l_enum,
351 lang_add_input_file($2,
352 lang_input_file_is_symbols_only_enum,
356 | OPTION_defsym { ldlex_defsym(); }
357 NAME '=' exp DEFSYMEND { ldlex_popstate();
358 lang_add_assignment(exp_assop($4,$3,$5));
360 | OPTION_RETAIN_SYMBOLS_FILE filename
361 { add_keepsyms_file ($2); }
364 /* FIXME: This is currently ignored. It means
365 ``produce a big-endian object file''. It could
366 be used to select an output format. */
370 /* FIXME: This is currently ignored. It means
371 ``produce a little-endian object file''. It could
372 be used to select an output format. */
376 g_switch_value = atoi ($2);
380 g_switch_value = yylval.integer;
390 goto set_default_dirlist;
394 if (strncmp ($2, "P,", 2))
395 einfo ("%P%F: unknown -Y option -- %s\n", $2);
403 p = strchr (dirlist_ptr, ':');
407 ldfile_add_library_path (dirlist_ptr);
415 | '{' script_file '}' { /* This parses compiled-in scripts. */ }
419 einfo("%P%F: illegal option -- %s\n", $1);
421 lang_add_input_file($1,lang_input_file_is_file_enum,
427 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
429 { ldlex_mri_script();
430 PUSH_ERROR("MRI style script");
439 mri_script_lines mri_script_command NEWLINE
447 einfo("%P%F: unrecognised keyword in MRI style script '%s'\n",$1);
451 config.map_filename = "-";
453 | ORDER ordernamelist
455 | PUBLIC NAME '=' exp
456 { mri_public($2, $4); }
457 | PUBLIC NAME ',' exp
458 { mri_public($2, $4); }
460 { mri_public($2, $3); }
464 { mri_output_section($2, $4);}
466 { mri_output_section($2, $3);}
468 { mri_output_section($2, $4);}
469 | ALIGN_K NAME '=' exp
470 { mri_align($2,$4); }
471 | ALIGNMOD NAME '=' exp
472 { mri_alignmod($2,$4); }
473 | ABSOLUTE mri_abs_name_list
474 | LOAD mri_load_name_list
477 | ALIAS NAME ',' NAME
478 { mri_alias($2,$4,0);}
480 { mri_alias($2,0,(int) $4);}
484 { mri_truncate((unsigned int) $2); }
489 ordernamelist ',' NAME { mri_order($3); }
490 | ordernamelist NAME { mri_order($2); }
497 | mri_load_name_list ',' NAME { mri_load($3); }
502 { mri_only_load($1); }
503 | mri_abs_name_list ',' NAME
504 { mri_only_load($3); }
531 | floating_point_support
534 | TARGET_K '(' NAME ')'
535 { lang_add_target($3); }
536 | SEARCH_DIR '(' filename ')'
537 { ldfile_add_library_path($3); }
538 | OUTPUT '(' filename ')'
539 { lang_add_output($3, 1); }
540 | OUTPUT_FORMAT '(' NAME ')'
541 { lang_add_output_format($3, 1); }
542 | OUTPUT_ARCH '(' NAME ')'
543 { ldfile_set_output_arch($3); }
544 | FORCE_COMMON_ALLOCATION
545 { command_line.force_common_definition = true ; }
546 | INPUT '(' input_list ')'
547 | MAP '(' filename ')'
548 { lang_add_map($3); }
550 { ldfile_open_command_file($2); } ifile_list END
555 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
557 | input_list ',' NAME
558 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
561 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
566 SECTIONS '{' sec_or_group_p1 '}'
570 sec_or_group_p1 section
571 | sec_or_group_p1 statement_anywhere
577 { lang_add_entry($3); }
583 { lang_add_wild($1, current_file); }
584 | file_NAME_list opt_comma NAME
585 { lang_add_wild($3, current_file); }
591 lang_add_wild((char *)NULL, $1);
595 current_file = (char *)NULL;
603 '(' file_NAME_list ')'
606 current_file = (char *)NULL;
608 '(' file_NAME_list ')'
613 | CREATE_OBJECT_SYMBOLS
615 lang_add_attribute(lang_object_symbols_statement_enum);
621 lang_add_attribute(lang_constructors_statement_enum);
626 lang_add_data((int) $1,$3);
632 (exp_get_value_int($3,
635 lang_first_phase_enum));
640 statement_list statement
663 $$ = exp_get_value_int($2,
666 lang_first_phase_enum);
700 lang_add_assignment(exp_assop($2,$1,$3));
702 | NAME assign_op mustbe_exp
705 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
716 MEMORY '{' memory_spec memory_spec_list '}'
720 memory_spec_list memory_spec
721 | memory_spec_list ',' memory_spec
727 { region = lang_memory_region_lookup($1); }
729 origin_spec opt_comma length_spec
732 ORIGIN '=' mustbe_exp
735 exp_get_vma($3, 0L,"origin", lang_first_phase_enum);
738 LENGTH '=' mustbe_exp
739 { region->length = exp_get_vma($3,
742 lang_first_phase_enum);
749 lang_set_flags(®ion->flags, $2);
756 STARTUP '(' filename ')'
757 { lang_startup($3); }
761 HLL '(' high_level_library_NAME_list ')'
763 { ldemul_hll((char *)NULL); }
766 high_level_library_NAME_list:
767 high_level_library_NAME_list opt_comma filename
775 SYSLIB '(' low_level_library_NAME_list ')'
776 ; low_level_library_NAME_list:
777 low_level_library_NAME_list opt_comma filename
778 { ldemul_syslib($3); }
782 floating_point_support:
784 { lang_float(true); }
786 { lang_float(false); }
790 mustbe_exp: { ldlex_expression(); }
792 { ldlex_popstate(); $$=$2;}
797 { $$ = exp_unop('-', $2); }
800 | NEXT '(' exp ')' %prec UNARY
801 { $$ = exp_unop((int) $1,$3); }
802 | '!' exp %prec UNARY
803 { $$ = exp_unop('!', $2); }
804 | '+' exp %prec UNARY
806 | '~' exp %prec UNARY
807 { $$ = exp_unop('~', $2);}
810 { $$ = exp_binop('*', $1, $3); }
812 { $$ = exp_binop('/', $1, $3); }
814 { $$ = exp_binop('%', $1, $3); }
816 { $$ = exp_binop('+', $1, $3); }
818 { $$ = exp_binop('-' , $1, $3); }
820 { $$ = exp_binop(LSHIFT , $1, $3); }
822 { $$ = exp_binop(RSHIFT , $1, $3); }
824 { $$ = exp_binop(EQ , $1, $3); }
826 { $$ = exp_binop(NE , $1, $3); }
828 { $$ = exp_binop(LE , $1, $3); }
830 { $$ = exp_binop(GE , $1, $3); }
832 { $$ = exp_binop('<' , $1, $3); }
834 { $$ = exp_binop('>' , $1, $3); }
836 { $$ = exp_binop('&' , $1, $3); }
838 { $$ = exp_binop('^' , $1, $3); }
840 { $$ = exp_binop('|' , $1, $3); }
841 | exp '?' exp ':' exp
842 { $$ = exp_trinop('?' , $1, $3, $5); }
844 { $$ = exp_binop(ANDAND , $1, $3); }
846 { $$ = exp_binop(OROR , $1, $3); }
847 | DEFINED '(' NAME ')'
848 { $$ = exp_nameop(DEFINED, $3); }
850 { $$ = exp_intop($1); }
852 { $$ = exp_nameop(SIZEOF_HEADERS,0); }
854 | SIZEOF '(' NAME ')'
855 { $$ = exp_nameop(SIZEOF,$3); }
857 { $$ = exp_nameop(ADDR,$3); }
858 | ABSOLUTE '(' exp ')'
859 { $$ = exp_unop(ABSOLUTE, $3); }
860 | ALIGN_K '(' exp ')'
861 { $$ = exp_unop(ALIGN_K,$3); }
863 { $$ = exp_nameop(NAME,$1); }
868 AT '(' exp ')' { $$ = $3; }
872 section: NAME { ldlex_expression(); }
874 opt_at { ldlex_popstate(); }
877 lang_enter_output_section_statement($1,$3,typebits,0,0,0,$4);
880 '}' {ldlex_expression();} fill_opt memspec_opt
883 lang_leave_output_section_statement($11, $12);
890 NOLOAD { typebits = SEC_NEVER_LOAD; }
891 | DSECT { typebits = 0; }
892 | COPY { typebits = 0; }
893 | INFO { typebits = 0; }
894 | OVERLAY { typebits = 0; }
895 | { typebits = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; }
900 exp ':' { $$ = $1; typebits =0;}
901 | exp '(' type ')' ':' { $$ = $1; }
902 | ':' { $$= (etree_type *)NULL; typebits = 0; }
903 | '(' type ')' ':' { $$= (etree_type *)NULL; }
909 | { $$ = "*default*"; }
916 if (error_index > 0 && error_index < ERROR_NAME_MAX)
917 einfo("%P%F: %S %s in %s\n", arg, error_names[error_index-1]);
919 einfo("%P%F: %S %s\n", arg);