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--;
70 union etree_union *etree;
73 %type <etree> exp opt_exp_with_type mustbe_exp opt_at
74 %type <integer> fill_opt
75 %type <name> memspec_opt
78 %type <integer> length
80 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
81 %right <token> '?' ':'
88 %left <token> '<' '>' LE GE
89 %left <token> LSHIFT RSHIFT
92 %left <token> '*' '/' '%'
97 %token <token> ALIGN_K BLOCK QUAD LONG SHORT BYTE
100 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
101 %token SIZEOF_HEADERS
103 %token MEMORY DEFSYMEND
104 %token NOLOAD DSECT COPY INFO OVERLAY
105 %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
106 %token <integer> SIZEOF NEXT ADDR
107 %token STARTUP HLL SYSLIB FLOAT NOFLOAT
109 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT OUTPUT CONSTRUCTORS
111 %type <token> assign_op
112 %type <name> filename
113 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD
114 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
115 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM
120 INPUT_SCRIPT script_file
121 | INPUT_MRI_SCRIPT mri_script_file
122 | INPUT_DEFSYM defsym_expr
134 lang_add_assignment(exp_assop($3,$2,$4));
137 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
139 { ldlex_mri_script();
140 PUSH_ERROR("MRI style script");
149 mri_script_lines mri_script_command NEWLINE
157 einfo("%P%F: unrecognised keyword in MRI style script '%s'\n",$1);
161 config.map_filename = "-";
163 | ORDER ordernamelist
165 | PUBLIC NAME '=' exp
166 { mri_public($2, $4); }
167 | PUBLIC NAME ',' exp
168 { mri_public($2, $4); }
170 { mri_public($2, $3); }
174 { mri_output_section($2, $4);}
176 { mri_output_section($2, $3);}
178 { mri_output_section($2, $4);}
179 | ALIGN_K NAME '=' exp
180 { mri_align($2,$4); }
181 | ALIGNMOD NAME '=' exp
182 { mri_alignmod($2,$4); }
183 | ABSOLUTE mri_abs_name_list
184 | LOAD mri_load_name_list
187 | ALIAS NAME ',' NAME
188 { mri_alias($2,$4,0);}
190 { mri_alias($2,0,(int) $4);}
194 { mri_truncate((unsigned int) $2); }
199 ordernamelist ',' NAME { mri_order($3); }
200 | ordernamelist NAME { mri_order($2); }
207 | mri_load_name_list ',' NAME { mri_load($3); }
212 { mri_only_load($1); }
213 | mri_abs_name_list ',' NAME
214 { mri_only_load($3); }
241 | floating_point_support
244 | TARGET_K '(' NAME ')'
245 { lang_add_target($3); }
246 | SEARCH_DIR '(' filename ')'
247 { ldfile_add_library_path($3); }
248 | OUTPUT '(' filename ')'
249 { lang_add_output($3, 1); }
250 | OUTPUT_FORMAT '(' NAME ')'
251 { lang_add_output_format($3, 1); }
252 | OUTPUT_ARCH '(' NAME ')'
253 { ldfile_set_output_arch($3); }
254 | FORCE_COMMON_ALLOCATION
255 { command_line.force_common_definition = true ; }
256 | INPUT '(' input_list ')'
257 | MAP '(' filename ')'
258 { lang_add_map($3); }
260 { ldfile_open_command_file($2); } ifile_list END
265 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
267 | input_list ',' NAME
268 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
271 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
276 SECTIONS '{' sec_or_group_p1 '}'
280 sec_or_group_p1 section
281 | sec_or_group_p1 statement_anywhere
287 { lang_add_entry($3); }
293 { lang_add_wild($1, current_file); }
294 | file_NAME_list opt_comma NAME
295 { lang_add_wild($3, current_file); }
301 lang_add_wild((char *)NULL, $1);
305 current_file = (char *)NULL;
313 '(' file_NAME_list ')'
316 current_file = (char *)NULL;
318 '(' file_NAME_list ')'
323 | CREATE_OBJECT_SYMBOLS
325 lang_add_attribute(lang_object_symbols_statement_enum);
331 lang_add_attribute(lang_constructors_statement_enum);
336 lang_add_data((int) $1,$3);
342 (exp_get_value_int($3,
345 lang_first_phase_enum));
350 statement_list statement
373 $$ = exp_get_value_int($2,
376 lang_first_phase_enum);
410 lang_add_assignment(exp_assop($2,$1,$3));
412 | NAME assign_op mustbe_exp
415 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
426 MEMORY '{' memory_spec memory_spec_list '}'
430 memory_spec_list memory_spec
431 | memory_spec_list ',' memory_spec
437 { region = lang_memory_region_lookup($1); }
439 origin_spec opt_comma length_spec
442 ORIGIN '=' mustbe_exp
445 exp_get_vma($3, 0L,"origin", lang_first_phase_enum);
448 LENGTH '=' mustbe_exp
449 { region->length = exp_get_vma($3,
452 lang_first_phase_enum);
459 lang_set_flags(®ion->flags, $2);
466 STARTUP '(' filename ')'
467 { lang_startup($3); }
471 HLL '(' high_level_library_NAME_list ')'
473 { ldemul_hll((char *)NULL); }
476 high_level_library_NAME_list:
477 high_level_library_NAME_list opt_comma filename
485 SYSLIB '(' low_level_library_NAME_list ')'
486 ; low_level_library_NAME_list:
487 low_level_library_NAME_list opt_comma filename
488 { ldemul_syslib($3); }
492 floating_point_support:
494 { lang_float(true); }
496 { lang_float(false); }
500 mustbe_exp: { ldlex_expression(); }
502 { ldlex_popstate(); $$=$2;}
507 { $$ = exp_unop('-', $2); }
510 | NEXT '(' exp ')' %prec UNARY
511 { $$ = exp_unop((int) $1,$3); }
512 | '!' exp %prec UNARY
513 { $$ = exp_unop('!', $2); }
514 | '+' exp %prec UNARY
516 | '~' exp %prec UNARY
517 { $$ = exp_unop('~', $2);}
520 { $$ = exp_binop('*', $1, $3); }
522 { $$ = exp_binop('/', $1, $3); }
524 { $$ = exp_binop('%', $1, $3); }
526 { $$ = exp_binop('+', $1, $3); }
528 { $$ = exp_binop('-' , $1, $3); }
530 { $$ = exp_binop(LSHIFT , $1, $3); }
532 { $$ = exp_binop(RSHIFT , $1, $3); }
534 { $$ = exp_binop(EQ , $1, $3); }
536 { $$ = exp_binop(NE , $1, $3); }
538 { $$ = exp_binop(LE , $1, $3); }
540 { $$ = exp_binop(GE , $1, $3); }
542 { $$ = exp_binop('<' , $1, $3); }
544 { $$ = exp_binop('>' , $1, $3); }
546 { $$ = exp_binop('&' , $1, $3); }
548 { $$ = exp_binop('^' , $1, $3); }
550 { $$ = exp_binop('|' , $1, $3); }
551 | exp '?' exp ':' exp
552 { $$ = exp_trinop('?' , $1, $3, $5); }
554 { $$ = exp_binop(ANDAND , $1, $3); }
556 { $$ = exp_binop(OROR , $1, $3); }
557 | DEFINED '(' NAME ')'
558 { $$ = exp_nameop(DEFINED, $3); }
560 { $$ = exp_intop($1); }
562 { $$ = exp_nameop(SIZEOF_HEADERS,0); }
564 | SIZEOF '(' NAME ')'
565 { $$ = exp_nameop(SIZEOF,$3); }
567 { $$ = exp_nameop(ADDR,$3); }
568 | ABSOLUTE '(' exp ')'
569 { $$ = exp_unop(ABSOLUTE, $3); }
570 | ALIGN_K '(' exp ')'
571 { $$ = exp_unop(ALIGN_K,$3); }
573 { $$ = exp_nameop(NAME,$1); }
578 AT '(' exp ')' { $$ = $3; }
582 section: NAME { ldlex_expression(); }
584 opt_at { ldlex_popstate(); }
587 lang_enter_output_section_statement($1,$3,typebits,0,0,0,$4);
590 '}' {ldlex_expression();} fill_opt memspec_opt
593 lang_leave_output_section_statement($11, $12);
600 NOLOAD { typebits = SEC_NEVER_LOAD; }
601 | DSECT { typebits = 0; }
602 | COPY { typebits = 0; }
603 | INFO { typebits = 0; }
604 | OVERLAY { typebits = 0; }
605 | { typebits = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; }
610 exp ':' { $$ = $1; typebits =0;}
611 | exp '(' type ')' ':' { $$ = $1; }
612 | ':' { $$= (etree_type *)NULL; typebits = 0; }
613 | '(' type ')' ':' { $$= (etree_type *)NULL; }
619 | { $$ = "*default*"; }
626 if (error_index > 0 && error_index < ERROR_NAME_MAX)
627 einfo("%P%F: %S %s in %s\n", arg, error_names[error_index-1]);
629 einfo("%P%F: %S %s\n", arg);