2 /* Copyright (C) 1991 Free Software Foundation, Inc.
4 This file is part of GLD, the Gnu Linker.
6 GLD is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GLD is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GLD; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 * Revision 1.1 1991/03/21 21:28:41 gumby
27 * Revision 1.2 1991/03/16 22:27:24 rich
30 * Revision 1.1 1991/03/13 00:48:21 chrisb
33 * Revision 1.6 1991/03/10 09:31:26 rich
35 * Makefile config.h ld-emul.c ld-emul.h ld-gld.c ld-gld960.c
36 * ld-lnk960.c ld.h lddigest.c ldexp.c ldexp.h ldfile.c ldfile.h
37 * ldgram.y ldinfo.h ldlang.c ldlang.h ldlex.h ldlex.l ldmain.c
38 * ldmain.h ldmisc.c ldmisc.h ldsym.c ldsym.h ldversion.c
39 * ldversion.h ldwarn.h ldwrite.c ldwrite.h y.tab.h
41 * As of this round of changes, ld now builds on all hosts of (Intel960)
42 * interest and copy passes my copy test on big endian hosts again.
44 * Revision 1.5 1991/03/09 03:25:48 sac
45 * Can now parse the -Ur flag
47 * Revision 1.4 1991/03/06 02:26:01 sac
48 * Added support for constructor sections.
49 * Remove parsing ambiguity.
52 * Revision 1.3 1991/02/22 17:15:13 sac
53 * Added RCS keywords and copyrights
58 This is a YACC grammer intended to parse a superset of the AT&T
59 linker scripting languaue.
62 Written by Steve Chamberlain steve@cygnus.com
74 #include "ldversion.h"
84 extern unsigned int lineno;
85 extern boolean trace_files;
86 extern boolean write_map;
93 lang_memory_region_type *region;
96 lang_memory_region_type *lang_memory_region_lookup();
97 lang_output_section_statement_type *lang_output_section_statement_lookup();
101 void lang_add_data(int type, union etree_union *exp);
102 void lang_enter_output_section_statement(char *output_section_statement_name, etree_type *address_exp, bfd_vma block_value);
106 void lang_add_data();
107 void lang_enter_output_section_statement();
109 #endif /* __STDC__ */
111 extern args_type command_line;
113 boolean ldgram_want_filename = true;
114 boolean had_script = false;
115 boolean force_make_executable = false;
116 boolean ldgram_mustbe_filename = false;
117 boolean ldgram_mustbe_symbolname = false;
118 boolean ldgram_has_inputfile = false;
131 union etree_union *etree;
133 struct lang_output_section_statement_struct *output_section_statement;
134 union lang_statement_union **statement_ptr;
145 %type <etree> exp opt_exp exp_head
146 %type <integer> fill_opt opt_block
147 %type <name> memspec_opt
148 %token <integer> INT CHAR
150 %type <integer> length
152 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
153 %right <token> '?' ':'
160 %left <token> '<' '>' LE GE
161 %left <token> LSHIFT RSHIFT
162 %left <token> '+' '-'
163 %left <token> '*' '/' '%'
166 %token <token> ALIGN_K BLOCK LONG SHORT BYTE
169 %token ALIGNMENT SIZEOF_HEADERS
170 %token NEXT SIZEOF ADDR
172 %token DSECT NOLOAD COPY INFO OVERLAY
173 %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
174 %token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S OPTION_format
175 %token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X
176 %token OPTION_v OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT NOFLOAT OPTION_defsym
177 %token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_A
178 %token <name> OPTION_l OPTION_L OPTION_T OPTION_Aarch OPTION_Tfile OPTION_Texp
180 %token ORIGIN FILL OPTION_g
181 %token LENGTH BIND SUBSECTION_ALIGN CREATE_OBJECT_SYMBOLS INPUT OUTPUT
182 %type <token> assign_op SIZEOF NEXT ADDR
183 %type <etree> assignment
184 %type <name> filename
187 ld_config_type config;
194 file: command_line { lang_final(); };
199 ldgram_mustbe_filename =true;
203 ldgram_mustbe_filename = false;
208 command_line command_line_option
225 config.magic_demand_paged = false;
226 config.make_executable = false;
229 strip_symbols = STRIP_ALL;
232 strip_symbols = STRIP_DEBUGGER;
236 config.relocateable_output = true;
237 config.build_constructors = false;
238 config.magic_demand_paged = false;
241 config.relocateable_output = true;
242 config.build_constructors = true;
243 config.magic_demand_paged = false;
250 { lang_add_entry($2);
253 discard_locals = DISCARD_L;
256 discard_locals = DISCARD_ALL;
259 | OPTION_noinhibit_exec
261 force_make_executable = true;
264 command_line.force_common_definition = true;
268 command_line.force_common_definition = true;
276 command_line.force_common_definition = true;
283 | OPTION_Texp { hex_mode =true; }
285 { lang_section_start($1, $3);
289 { ldfile_add_arch($1); }
296 ldfile_add_library_path($1);
301 { ldfile_open_command_file($2); }
303 { ldfile_open_command_file($1); }
306 { ldfile_open_command_file($2); }
310 lang_add_input_file($1,
311 lang_input_file_is_l_enum,
316 lang_add_input_file($2,
317 lang_input_file_is_symbols_only_enum,
320 | OPTION_defsym assignment_with_nospaces
327 lang_add_wild((char *)NULL, $1);
331 current_file = (char *)NULL;
339 '(' file_NAME_list ')'
342 current_file = (char *)NULL;
344 '(' file_NAME_list ')'
351 { lang_add_wild($1, current_file); }
352 | file_NAME_list opt_comma NAME
353 { lang_add_wild($3, current_file); }
364 | floating_point_support
366 | TARGET_K '(' NAME ')'
367 { lang_add_target($3); }
368 | SEARCH_DIR '(' filename ')'
369 { ldfile_add_library_path($3); }
370 | OUTPUT '(' filename ')'
371 { lang_add_output($3); }
372 | INPUT '(' input_list ')'
373 | MAP '(' filename ')'
374 { lang_add_map($3); }
379 { lang_add_input_file($1,lang_input_file_is_file_enum,
381 | input_list ',' NAME
382 { lang_add_input_file($3,lang_input_file_is_file_enum,
385 { lang_add_input_file($2, lang_input_file_is_file_enum,
390 SECTIONS '{'sec_or_group_p1 '}'
394 sec_or_group_p1 section
395 | sec_or_group_p1 statement_anywhere
401 { lang_add_entry($3); }
406 statement assignment end
407 | statement CREATE_OBJECT_SYMBOLS
408 { lang_add_attribute(lang_object_symbols_statement_enum); }
409 | statement input_section_spec
410 | statement length '(' exp_head ')'
412 lang_add_data($2,$4);
415 | statement FILL '(' exp_head ')'
418 (exp_get_value_int($4,
421 lang_first_phase_enum));
438 $$ = exp_get_value_int($2,
441 lang_first_phase_enum);
471 assignment_with_nospaces:
472 { ldgram_want_filename = false; }
474 { ldgram_want_filename = true; }
481 lang_add_assignment(exp_assop($2,$1,$3));
483 | NAME assign_op exp_head
485 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
496 MEMORY '{' memory_spec memory_spec_list '}'
500 memory_spec_list memory_spec
501 | memory_spec_list ',' memory_spec
508 { region = lang_memory_region_lookup($1); }
509 attributes_opt ':' origin_spec opt_comma length_spec
520 exp_get_vma($3, 0L,"origin", lang_first_phase_enum); }
524 { region->length = exp_get_vma($3,
527 lang_first_phase_enum);
534 lang_set_flags(®ion->flags, $2);
541 STARTUP '(' filename ')'
542 { lang_startup($3); }
546 HLL '(' high_level_library_NAME_list ')'
548 { ldemul_hll((char *)NULL); }
551 high_level_library_NAME_list:
552 high_level_library_NAME_list opt_comma filename
560 SYSLIB '(' low_level_library_NAME_list ')'
562 low_level_library_NAME_list:
563 low_level_library_NAME_list opt_comma filename
564 { ldemul_syslib($3); }
568 floating_point_support:
570 { lang_float(true); }
572 { lang_float(false); }
580 { $$ = exp_unop('-', $2); }
583 | NEXT '(' exp ')' %prec UNARY
584 { $$ = exp_unop($1,$3); }
585 | '!' exp %prec UNARY
586 { $$ = exp_unop('!', $2); }
587 | '+' exp %prec UNARY
589 | '~' exp %prec UNARY
590 { $$ = exp_unop('~', $2);}
593 { $$ = exp_binop('*', $1, $3); }
595 { $$ = exp_binop('/', $1, $3); }
597 { $$ = exp_binop('%', $1, $3); }
599 { $$ = exp_binop('+', $1, $3); }
601 { $$ = exp_binop('-' , $1, $3); }
603 { $$ = exp_binop(LSHIFT , $1, $3); }
605 { $$ = exp_binop(RSHIFT , $1, $3); }
607 { $$ = exp_binop(EQ , $1, $3); }
609 { $$ = exp_binop(NE , $1, $3); }
611 { $$ = exp_binop(LE , $1, $3); }
613 { $$ = exp_binop(GE , $1, $3); }
615 { $$ = exp_binop('<' , $1, $3); }
617 { $$ = exp_binop('>' , $1, $3); }
619 { $$ = exp_binop('&' , $1, $3); }
621 { $$ = exp_binop('^' , $1, $3); }
623 { $$ = exp_binop('|' , $1, $3); }
624 | exp '?' exp ':' exp
625 { $$ = exp_trinop('?' , $1, $3, $5); }
627 { $$ = exp_binop(ANDAND , $1, $3); }
629 { $$ = exp_binop(OROR , $1, $3); }
630 | DEFINED '(' NAME ')'
631 { $$ = exp_nameop(DEFINED, $3); }
633 { $$ = exp_intop($1); }
635 | SIZEOF '(' NAME ')'
636 { $$ = exp_nameop($1,$3); }
638 { $$ = exp_nameop($1,$3); }
639 | ALIGN_K '(' exp ')'
640 { $$ = exp_unop($1,$3); }
642 { $$ = exp_nameop(NAME,$1); }
648 section: NAME opt_exp opt_block ':' opt_things'{'
650 lang_enter_output_section_statement($1,$2,$3);
652 statement '}' fill_opt memspec_opt
654 lang_leave_output_section_statement($10, $11);
666 { ldgram_mustbe_symbolname = true; }
668 { ldgram_mustbe_symbolname = false;
675 | { $$= (etree_type *)NULL; }
679 BLOCK '(' exp_head ')'
680 { $$ = exp_get_value_int($3,
683 lang_first_phase_enum);
691 | { $$ = "*default*"; }