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
44 lang_memory_region_type *region;
48 boolean ldgram_want_filename = true;
49 boolean had_script = false;
50 boolean force_make_executable = false;
52 boolean ldgram_in_script = false;
53 boolean ldgram_had_equals = false;
56 #define ERROR_NAME_MAX 20
57 static char *error_names[ERROR_NAME_MAX];
58 static int error_index;
59 #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
60 #define POP_ERROR() error_index--;
66 union etree_union *etree;
69 %type <etree> exp opt_exp_with_type mustbe_exp opt_at
70 %type <integer> fill_opt
71 %type <name> memspec_opt
74 %type <integer> length
76 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
77 %right <token> '?' ':'
84 %left <token> '<' '>' LE GE
85 %left <token> LSHIFT RSHIFT
88 %left <token> '*' '/' '%'
93 %token <token> ALIGN_K BLOCK QUAD LONG SHORT BYTE
96 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
99 %token MEMORY DEFSYMEND
100 %token NOLOAD DSECT COPY INFO OVERLAY
101 %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
102 %token <integer> SIZEOF NEXT ADDR
103 %token STARTUP HLL SYSLIB FLOAT NOFLOAT
105 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT OUTPUT CONSTRUCTORS
107 %type <token> assign_op
108 %type <name> filename
109 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD
110 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
111 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM
116 INPUT_SCRIPT script_file
117 | INPUT_MRI_SCRIPT mri_script_file
118 | INPUT_DEFSYM defsym_expr
130 lang_add_assignment(exp_assop($3,$2,$4));
133 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
135 { ldlex_mri_script();
136 PUSH_ERROR("MRI style script");
145 mri_script_lines mri_script_command NEWLINE
153 einfo("%P%F: unrecognised keyword in MRI style script '%s'\n",$1);
156 config.map_filename = "-";
158 | ORDER ordernamelist
160 | PUBLIC NAME '=' exp
161 { mri_public($2, $4); }
162 | PUBLIC NAME ',' exp
163 { mri_public($2, $4); }
165 { mri_public($2, $3); }
169 { mri_output_section($2, $4);}
171 { mri_output_section($2, $3);}
173 { mri_output_section($2, $4);}
174 | ALIGN_K NAME '=' exp
175 { mri_align($2,$4); }
176 | ALIGNMOD NAME '=' exp
177 { mri_alignmod($2,$4); }
178 | ABSOLUTE mri_abs_name_list
179 | LOAD mri_load_name_list
182 | ALIAS NAME ',' NAME
183 { mri_alias($2,$4,0);}
185 { mri_alias($2,0,(int) $4);}
189 { mri_truncate((unsigned int) $2); }
194 ordernamelist ',' NAME { mri_order($3); }
195 | ordernamelist NAME { mri_order($2); }
202 | mri_load_name_list ',' NAME { mri_load($3); }
207 { mri_only_load($1); }
208 | mri_abs_name_list ',' NAME
209 { mri_only_load($3); }
236 | floating_point_support
239 | TARGET_K '(' NAME ')'
240 { lang_add_target($3); }
241 | SEARCH_DIR '(' filename ')'
242 { ldfile_add_library_path ($3, false); }
243 | OUTPUT '(' filename ')'
244 { lang_add_output($3, 1); }
245 | OUTPUT_FORMAT '(' NAME ')'
246 { lang_add_output_format($3, 1); }
247 | OUTPUT_ARCH '(' NAME ')'
248 { ldfile_set_output_arch($3); }
249 | FORCE_COMMON_ALLOCATION
250 { command_line.force_common_definition = true ; }
251 | INPUT '(' input_list ')'
252 | MAP '(' filename ')'
253 { lang_add_map($3); }
255 { ldfile_open_command_file($2); } ifile_list END
260 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
262 | input_list ',' NAME
263 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
266 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
271 SECTIONS '{' sec_or_group_p1 '}'
275 sec_or_group_p1 section
276 | sec_or_group_p1 statement_anywhere
282 { lang_add_entry ($3, 0); }
288 { lang_add_wild($1, current_file); }
289 | file_NAME_list opt_comma NAME
290 { lang_add_wild($3, current_file); }
296 lang_add_wild((char *)NULL, $1);
300 current_file = (char *)NULL;
308 '(' file_NAME_list ')'
311 current_file = (char *)NULL;
313 '(' file_NAME_list ')'
318 | CREATE_OBJECT_SYMBOLS
320 lang_add_attribute(lang_object_symbols_statement_enum);
326 lang_add_attribute(lang_constructors_statement_enum);
331 lang_add_data((int) $1,$3);
337 (exp_get_value_int($3,
340 lang_first_phase_enum));
345 statement_list statement
368 $$ = exp_get_value_int($2,
371 lang_first_phase_enum);
405 lang_add_assignment(exp_assop($2,$1,$3));
407 | NAME assign_op mustbe_exp
410 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
421 MEMORY '{' memory_spec memory_spec_list '}'
425 memory_spec_list memory_spec
426 | memory_spec_list ',' memory_spec
432 { region = lang_memory_region_lookup($1); }
434 origin_spec opt_comma length_spec
437 ORIGIN '=' mustbe_exp
440 exp_get_vma($3, 0L,"origin", lang_first_phase_enum);
443 LENGTH '=' mustbe_exp
444 { region->length = exp_get_vma($3,
447 lang_first_phase_enum);
454 lang_set_flags(®ion->flags, $2);
461 STARTUP '(' filename ')'
462 { lang_startup($3); }
466 HLL '(' high_level_library_NAME_list ')'
468 { ldemul_hll((char *)NULL); }
471 high_level_library_NAME_list:
472 high_level_library_NAME_list opt_comma filename
480 SYSLIB '(' low_level_library_NAME_list ')'
481 ; low_level_library_NAME_list:
482 low_level_library_NAME_list opt_comma filename
483 { ldemul_syslib($3); }
487 floating_point_support:
489 { lang_float(true); }
491 { lang_float(false); }
495 mustbe_exp: { ldlex_expression(); }
497 { ldlex_popstate(); $$=$2;}
502 { $$ = exp_unop('-', $2); }
505 | NEXT '(' exp ')' %prec UNARY
506 { $$ = exp_unop((int) $1,$3); }
507 | '!' exp %prec UNARY
508 { $$ = exp_unop('!', $2); }
509 | '+' exp %prec UNARY
511 | '~' exp %prec UNARY
512 { $$ = exp_unop('~', $2);}
515 { $$ = exp_binop('*', $1, $3); }
517 { $$ = exp_binop('/', $1, $3); }
519 { $$ = exp_binop('%', $1, $3); }
521 { $$ = exp_binop('+', $1, $3); }
523 { $$ = exp_binop('-' , $1, $3); }
525 { $$ = exp_binop(LSHIFT , $1, $3); }
527 { $$ = exp_binop(RSHIFT , $1, $3); }
529 { $$ = exp_binop(EQ , $1, $3); }
531 { $$ = exp_binop(NE , $1, $3); }
533 { $$ = exp_binop(LE , $1, $3); }
535 { $$ = exp_binop(GE , $1, $3); }
537 { $$ = exp_binop('<' , $1, $3); }
539 { $$ = exp_binop('>' , $1, $3); }
541 { $$ = exp_binop('&' , $1, $3); }
543 { $$ = exp_binop('^' , $1, $3); }
545 { $$ = exp_binop('|' , $1, $3); }
546 | exp '?' exp ':' exp
547 { $$ = exp_trinop('?' , $1, $3, $5); }
549 { $$ = exp_binop(ANDAND , $1, $3); }
551 { $$ = exp_binop(OROR , $1, $3); }
552 | DEFINED '(' NAME ')'
553 { $$ = exp_nameop(DEFINED, $3); }
555 { $$ = exp_intop($1); }
557 { $$ = exp_nameop(SIZEOF_HEADERS,0); }
559 | SIZEOF '(' NAME ')'
560 { $$ = exp_nameop(SIZEOF,$3); }
562 { $$ = exp_nameop(ADDR,$3); }
563 | ABSOLUTE '(' exp ')'
564 { $$ = exp_unop(ABSOLUTE, $3); }
565 | ALIGN_K '(' exp ')'
566 { $$ = exp_unop(ALIGN_K,$3); }
568 { $$ = exp_nameop(NAME,$1); }
573 AT '(' exp ')' { $$ = $3; }
577 section: NAME { ldlex_expression(); }
579 opt_at { ldlex_popstate(); }
582 lang_enter_output_section_statement($1,$3,typebits,0,0,0,$4);
585 '}' {ldlex_expression();} memspec_opt fill_opt
588 lang_leave_output_section_statement($12, $11);
595 NOLOAD { typebits = SEC_NEVER_LOAD; }
596 | DSECT { typebits = 0; }
597 | COPY { typebits = 0; }
598 | INFO { typebits = 0; }
599 | OVERLAY { typebits = 0; }
600 | { typebits = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; }
605 exp ':' { $$ = $1; typebits =0;}
606 | exp '(' type ')' ':' { $$ = $1; }
607 | ':' { $$= (etree_type *)NULL; typebits = 0; }
608 | '(' type ')' ':' { $$= (etree_type *)NULL; }
614 | { $$ = "*default*"; }
621 if (error_index > 0 && error_index < ERROR_NAME_MAX)
622 einfo("%P%F: %S %s in %s\n", arg, error_names[error_index-1]);
624 einfo("%P%F: %S %s\n", arg);