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
45 strip_symbols_type strip_symbols=STRIP_NONE;
46 discard_locals_type discard_locals=DISCARD_NONE;
48 static char *dirlist_ptr;
50 lang_memory_region_type *region;
54 boolean ldgram_want_filename = true;
55 boolean had_script = false;
56 boolean force_make_executable = false;
58 boolean ldgram_in_script = false;
59 boolean ldgram_had_equals = false;
62 #define ERROR_NAME_MAX 20
63 static char *error_names[ERROR_NAME_MAX];
64 static int error_index;
65 #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
66 #define POP_ERROR() error_index--;
73 union etree_union *etree;
75 struct lang_output_section_statement_struct *output_section_statement;
76 union lang_statement_union **statement_ptr;
87 %type <etree> exp opt_exp_with_type mustbe_exp opt_at
88 %type <integer> fill_opt
89 %type <name> memspec_opt
92 %type <integer> length
94 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
95 %right <token> '?' ':'
102 %left <token> '<' '>' LE GE
103 %left <token> LSHIFT RSHIFT
105 %left <token> '+' '-'
106 %left <token> '*' '/' '%'
108 /*%token <token> '+' '-' '*' '/' '%'*/
112 %token <token> ALIGN_K BLOCK LONG SHORT BYTE
115 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
116 %token SIZEOF_HEADERS
118 %token MEMORY DEFSYMEND
119 %token NOLOAD DSECT COPY INFO OVERLAY
120 %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
121 %token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S OPTION_sort_common OPTION_warn_common
122 %token OPTION_EB OPTION_EL OPTION_G OPTION_Gval OPTION_help
123 %token OPTION_format OPTION_oformat OPTION_F OPTION_u OPTION_Bstatic OPTION_N
124 %token <integer> SIZEOF NEXT ADDR
125 %token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X OPTION_defsym
126 %token OPTION_v OPTION_V OPTION_m OPTION_memul OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT NOFLOAT
127 %token OPTION_L OPTION_Map
128 %token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_R OPTION_relax OPTION_version
129 %token <name> OPTION_l OPTION_Lfile OPTION_T OPTION_Aarch OPTION_Tfile
130 %token <name> OPTION_Texp OPTION_y
132 %token ORIGIN FILL OPTION_g
133 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT OUTPUT CONSTRUCTORS
134 %token OPTION_RETAIN_SYMBOLS_FILE ALIGNMOD AT
135 %token OPTION_Qy OPTION_Y OPTION_dn OPTION_call_shared OPTION_non_shared
137 %token <name> OPTION_YP
139 %type <token> assign_op
141 %type <name> filename
144 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD
145 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE
149 file: command_line { lang_final(); };
156 command_line command_line_option
174 trace_file_tries = 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 strip_symbols = STRIP_ALL;
212 strip_symbols = STRIP_DEBUGGER;
215 ldlang_add_undef($2);
219 config.relocateable_output = true;
220 config.build_constructors = false;
221 config.magic_demand_paged = false;
222 config.text_read_only = false;
225 config.relocateable_output = true;
226 config.build_constructors = true;
227 config.magic_demand_paged = false;
228 config.text_read_only = false;
232 lang_add_output($2, 0);
235 { lang_add_entry($2);
238 discard_locals = DISCARD_L;
241 discard_locals = DISCARD_ALL;
244 | OPTION_noinhibit_exec
246 force_make_executable = true;
250 config.sort_common = true;
254 config.warn_common = true;
257 command_line.force_common_definition = true;
261 command_line.relax = true;
265 command_line.force_common_definition = true;
273 command_line.force_common_definition = true;
279 | OPTION_oformat NAME
281 lang_add_output_format($2, 0);
284 { ldlex_expression();
289 lang_section_start($1,exp_intop($3));
306 ldfile_add_library_path($2);
310 ldfile_add_library_path($1);
317 {ldfile_open_command_file($2); }
318 mri_script_file END { ldlex_command();}
321 { ldfile_open_command_file($1); } script_file
322 END { ldlex_command();}
325 { ldfile_open_command_file($2); } script_file
326 END { ldlex_command();}
330 lang_add_input_file($1,
331 lang_input_file_is_l_enum,
336 lang_add_input_file($2,
337 lang_input_file_is_symbols_only_enum,
341 | OPTION_defsym { ldlex_defsym(); }
342 NAME '=' exp DEFSYMEND { ldlex_popstate();
343 lang_add_assignment(exp_assop($4,$3,$5));
345 | OPTION_RETAIN_SYMBOLS_FILE filename
346 { lang_add_keepsyms_file ($2); }
349 /* FIXME: This is currently ignored. It means
350 ``produce a big-endian object file''. It could
351 be used to select an output format. */
355 /* FIXME: This is currently ignored. It means
356 ``produce a little-endian object file''. It could
357 be used to select an output format. */
361 g_switch_value = atoi ($2);
365 g_switch_value = yylval.integer;
375 goto set_default_dirlist;
379 if (strncmp ($2, "P,", 2))
380 einfo ("%P%F: unknown -Y option -- %s\n", $2);
388 p = strchr (dirlist_ptr, ':');
392 ldfile_add_library_path (dirlist_ptr);
401 | '{' script_file '}' { /* This parses compiled-in scripts. */ }
405 einfo("%P%F: illegal option -- %s\n", $1);
407 lang_add_input_file($1,lang_input_file_is_file_enum,
413 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
415 { ldlex_mri_script();
416 PUSH_ERROR("MRI style script");
425 mri_script_lines mri_script_command NEWLINE
433 einfo("%P%F: unrecognised keyword in MRI style script '%s'\n",$1);
437 config.map_filename = "-";
439 | ORDER ordernamelist
441 | PUBLIC NAME '=' exp
442 { mri_public($2, $4); }
443 | PUBLIC NAME ',' exp
444 { mri_public($2, $4); }
446 { mri_public($2, $3); }
450 { mri_output_section($2, $4);}
452 { mri_output_section($2, $3);}
454 { mri_output_section($2, $4);}
455 | ALIGN_K NAME '=' exp
456 { mri_align($2,$4); }
457 | ALIGNMOD NAME '=' exp
458 { mri_alignmod($2,$4); }
459 | ABSOLUTE mri_abs_name_list
460 | LOAD mri_load_name_list
463 | ALIAS NAME ',' NAME
464 { mri_alias($2,$4,0);}
466 { mri_alias($2,0,$4);}
470 { mri_truncate($2); }
475 ordernamelist ',' NAME { mri_order($3); }
476 | ordernamelist NAME { mri_order($2); }
483 | mri_load_name_list ',' NAME { mri_load($3); }
488 { mri_only_load($1); }
489 | mri_abs_name_list ',' NAME
490 { mri_only_load($3); }
517 | floating_point_support
520 | TARGET_K '(' NAME ')'
521 { lang_add_target($3); }
522 | SEARCH_DIR '(' filename ')'
523 { ldfile_add_library_path($3); }
524 | OUTPUT '(' filename ')'
525 { lang_add_output($3, 1); }
526 | OUTPUT_FORMAT '(' NAME ')'
527 { lang_add_output_format($3, 1); }
528 | OUTPUT_ARCH '(' NAME ')'
529 { ldfile_set_output_arch($3); }
530 | FORCE_COMMON_ALLOCATION
531 { command_line.force_common_definition = true ; }
532 | INPUT '(' input_list ')'
533 | MAP '(' filename ')'
534 { lang_add_map($3); }
536 { ldfile_open_command_file($2); } ifile_list END
541 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
543 | input_list ',' NAME
544 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
547 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
552 SECTIONS '{' sec_or_group_p1 '}'
556 sec_or_group_p1 section
557 | sec_or_group_p1 statement_anywhere
563 { lang_add_entry($3); }
569 { lang_add_wild($1, current_file); }
570 | file_NAME_list opt_comma NAME
571 { lang_add_wild($3, current_file); }
577 lang_add_wild((char *)NULL, $1);
581 current_file = (char *)NULL;
589 '(' file_NAME_list ')'
592 current_file = (char *)NULL;
594 '(' file_NAME_list ')'
599 | CREATE_OBJECT_SYMBOLS
601 lang_add_attribute(lang_object_symbols_statement_enum);
607 lang_add_attribute(lang_constructors_statement_enum);
612 lang_add_data($1,$3);
618 (exp_get_value_int($3,
621 lang_first_phase_enum));
626 statement_list statement
647 $$ = exp_get_value_int($2,
650 lang_first_phase_enum);
684 lang_add_assignment(exp_assop($2,$1,$3));
686 | NAME assign_op mustbe_exp
689 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
700 MEMORY '{' memory_spec memory_spec_list '}'
704 memory_spec_list memory_spec
705 | memory_spec_list ',' memory_spec
711 { region = lang_memory_region_lookup($1); }
713 origin_spec opt_comma length_spec
716 ORIGIN '=' mustbe_exp
719 exp_get_vma($3, 0L,"origin", lang_first_phase_enum);
722 LENGTH '=' mustbe_exp
723 { region->length = exp_get_vma($3,
726 lang_first_phase_enum);
733 lang_set_flags(®ion->flags, $2);
740 STARTUP '(' filename ')'
741 { lang_startup($3); }
745 HLL '(' high_level_library_NAME_list ')'
747 { ldemul_hll((char *)NULL); }
750 high_level_library_NAME_list:
751 high_level_library_NAME_list opt_comma filename
759 SYSLIB '(' low_level_library_NAME_list ')'
760 ; low_level_library_NAME_list:
761 low_level_library_NAME_list opt_comma filename
762 { ldemul_syslib($3); }
766 floating_point_support:
768 { lang_float(true); }
770 { lang_float(false); }
774 mustbe_exp: { ldlex_expression(); }
776 { ldlex_popstate(); $$=$2;}
781 { $$ = exp_unop('-', $2); }
784 | NEXT '(' exp ')' %prec UNARY
785 { $$ = exp_unop($1,$3); }
786 | '!' exp %prec UNARY
787 { $$ = exp_unop('!', $2); }
788 | '+' exp %prec UNARY
790 | '~' exp %prec UNARY
791 { $$ = exp_unop('~', $2);}
794 { $$ = exp_binop('*', $1, $3); }
796 { $$ = exp_binop('/', $1, $3); }
798 { $$ = exp_binop('%', $1, $3); }
800 { $$ = exp_binop('+', $1, $3); }
802 { $$ = exp_binop('-' , $1, $3); }
804 { $$ = exp_binop(LSHIFT , $1, $3); }
806 { $$ = exp_binop(RSHIFT , $1, $3); }
808 { $$ = exp_binop(EQ , $1, $3); }
810 { $$ = exp_binop(NE , $1, $3); }
812 { $$ = exp_binop(LE , $1, $3); }
814 { $$ = exp_binop(GE , $1, $3); }
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); }
825 | exp '?' exp ':' exp
826 { $$ = exp_trinop('?' , $1, $3, $5); }
828 { $$ = exp_binop(ANDAND , $1, $3); }
830 { $$ = exp_binop(OROR , $1, $3); }
831 | DEFINED '(' NAME ')'
832 { $$ = exp_nameop(DEFINED, $3); }
834 { $$ = exp_intop($1); }
836 { $$ = exp_nameop(SIZEOF_HEADERS,0); }
838 | SIZEOF '(' NAME ')'
839 { $$ = exp_nameop(SIZEOF,$3); }
841 { $$ = exp_nameop(ADDR,$3); }
842 | ABSOLUTE '(' exp ')'
843 { $$ = exp_unop(ABSOLUTE, $3); }
844 | ALIGN_K '(' exp ')'
845 { $$ = exp_unop(ALIGN_K,$3); }
847 { $$ = exp_nameop(NAME,$1); }
852 AT '(' exp ')' { $$ = $3; }
856 section: NAME { ldlex_expression(); }
858 opt_at { ldlex_popstate(); }
861 lang_enter_output_section_statement($1,$3,typebits,0,0,0,$4);
864 '}' {ldlex_expression();} fill_opt memspec_opt
867 lang_leave_output_section_statement($11, $12);
874 NOLOAD { typebits = SEC_NEVER_LOAD; }
875 | DSECT { typebits = 0; }
876 | COPY { typebits = 0; }
877 | INFO { typebits = 0; }
878 | OVERLAY { typebits = 0; }
879 | { typebits = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; }
884 exp ':' { $$ = $1; typebits =0;}
885 | exp '(' type ')' ':' { $$ = $1; }
886 | ':' { $$= (etree_type *)NULL; typebits = 0; }
887 | '(' type ')' ':' { $$= (etree_type *)NULL; }
893 | { $$ = "*default*"; }
900 if (error_index> 0 && error_index < ERROR_NAME_MAX)
901 einfo("%P%F: %S syntax error in %s\n",error_names[error_index-1]);
903 einfo("%P%F: %S syntax error\n");