1*56bb7041Schristos /* A YACC grammar to parse a superset of the AT&T linker scripting language.
2*56bb7041Schristos Copyright (C) 1991-2020 Free Software Foundation, Inc.
3*56bb7041Schristos Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
4*56bb7041Schristos
5*56bb7041Schristos This file is part of the GNU Binutils.
6*56bb7041Schristos
7*56bb7041Schristos This program is free software; you can redistribute it and/or modify
8*56bb7041Schristos it under the terms of the GNU General Public License as published by
9*56bb7041Schristos the Free Software Foundation; either version 3 of the License, or
10*56bb7041Schristos (at your option) any later version.
11*56bb7041Schristos
12*56bb7041Schristos This program is distributed in the hope that it will be useful,
13*56bb7041Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
14*56bb7041Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*56bb7041Schristos GNU General Public License for more details.
16*56bb7041Schristos
17*56bb7041Schristos You should have received a copy of the GNU General Public License
18*56bb7041Schristos along with this program; if not, write to the Free Software
19*56bb7041Schristos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20*56bb7041Schristos MA 02110-1301, USA. */
21*56bb7041Schristos
22*56bb7041Schristos %{
23*56bb7041Schristos /*
24*56bb7041Schristos
25*56bb7041Schristos */
26*56bb7041Schristos
27*56bb7041Schristos #define DONTDECLARE_MALLOC
28*56bb7041Schristos
29*56bb7041Schristos #include "sysdep.h"
30*56bb7041Schristos #include "bfd.h"
31*56bb7041Schristos #include "bfdlink.h"
32*56bb7041Schristos #include "ctf-api.h"
33*56bb7041Schristos #include "ld.h"
34*56bb7041Schristos #include "ldexp.h"
35*56bb7041Schristos #include "ldver.h"
36*56bb7041Schristos #include "ldlang.h"
37*56bb7041Schristos #include "ldfile.h"
38*56bb7041Schristos #include "ldemul.h"
39*56bb7041Schristos #include "ldmisc.h"
40*56bb7041Schristos #include "ldmain.h"
41*56bb7041Schristos #include "mri.h"
42*56bb7041Schristos #include "ldctor.h"
43*56bb7041Schristos #include "ldlex.h"
44*56bb7041Schristos
45*56bb7041Schristos #ifndef YYDEBUG
46*56bb7041Schristos #define YYDEBUG 1
47*56bb7041Schristos #endif
48*56bb7041Schristos
49*56bb7041Schristos static enum section_type sectype;
50*56bb7041Schristos static lang_memory_region_type *region;
51*56bb7041Schristos
52*56bb7041Schristos static bfd_boolean ldgram_had_keep = FALSE;
53*56bb7041Schristos static char *ldgram_vers_current_lang = NULL;
54*56bb7041Schristos
55*56bb7041Schristos #define ERROR_NAME_MAX 20
56*56bb7041Schristos static char *error_names[ERROR_NAME_MAX];
57*56bb7041Schristos static int error_index;
58*56bb7041Schristos #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
59*56bb7041Schristos #define POP_ERROR() error_index--;
60*56bb7041Schristos %}
61*56bb7041Schristos %union {
62*56bb7041Schristos bfd_vma integer;
63*56bb7041Schristos struct big_int
64*56bb7041Schristos {
65*56bb7041Schristos bfd_vma integer;
66*56bb7041Schristos char *str;
67*56bb7041Schristos } bigint;
68*56bb7041Schristos fill_type *fill;
69*56bb7041Schristos char *name;
70*56bb7041Schristos const char *cname;
71*56bb7041Schristos struct wildcard_spec wildcard;
72*56bb7041Schristos struct wildcard_list *wildcard_list;
73*56bb7041Schristos struct name_list *name_list;
74*56bb7041Schristos struct flag_info_list *flag_info_list;
75*56bb7041Schristos struct flag_info *flag_info;
76*56bb7041Schristos int token;
77*56bb7041Schristos union etree_union *etree;
78*56bb7041Schristos struct phdr_info
79*56bb7041Schristos {
80*56bb7041Schristos bfd_boolean filehdr;
81*56bb7041Schristos bfd_boolean phdrs;
82*56bb7041Schristos union etree_union *at;
83*56bb7041Schristos union etree_union *flags;
84*56bb7041Schristos } phdr;
85*56bb7041Schristos struct lang_nocrossref *nocrossref;
86*56bb7041Schristos struct lang_output_section_phdr_list *section_phdr;
87*56bb7041Schristos struct bfd_elf_version_deps *deflist;
88*56bb7041Schristos struct bfd_elf_version_expr *versyms;
89*56bb7041Schristos struct bfd_elf_version_tree *versnode;
90*56bb7041Schristos }
91*56bb7041Schristos
92*56bb7041Schristos %type <etree> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val
93*56bb7041Schristos %type <etree> opt_exp_without_type opt_subalign opt_align
94*56bb7041Schristos %type <fill> fill_opt fill_exp
95*56bb7041Schristos %type <name_list> exclude_name_list
96*56bb7041Schristos %type <wildcard_list> section_name_list
97*56bb7041Schristos %type <flag_info_list> sect_flag_list
98*56bb7041Schristos %type <flag_info> sect_flags
99*56bb7041Schristos %type <name> memspec_opt casesymlist
100*56bb7041Schristos %type <name> memspec_at_opt
101*56bb7041Schristos %type <cname> wildcard_name
102*56bb7041Schristos %type <wildcard> section_name_spec filename_spec wildcard_maybe_exclude
103*56bb7041Schristos %token <bigint> INT
104*56bb7041Schristos %token <name> NAME LNAME
105*56bb7041Schristos %type <integer> length
106*56bb7041Schristos %type <phdr> phdr_qualifiers
107*56bb7041Schristos %type <nocrossref> nocrossref_list
108*56bb7041Schristos %type <section_phdr> phdr_opt
109*56bb7041Schristos %type <integer> opt_nocrossrefs
110*56bb7041Schristos
111*56bb7041Schristos %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
112*56bb7041Schristos %right <token> '?' ':'
113*56bb7041Schristos %left <token> OROR
114*56bb7041Schristos %left <token> ANDAND
115*56bb7041Schristos %left <token> '|'
116*56bb7041Schristos %left <token> '^'
117*56bb7041Schristos %left <token> '&'
118*56bb7041Schristos %left <token> EQ NE
119*56bb7041Schristos %left <token> '<' '>' LE GE
120*56bb7041Schristos %left <token> LSHIFT RSHIFT
121*56bb7041Schristos
122*56bb7041Schristos %left <token> '+' '-'
123*56bb7041Schristos %left <token> '*' '/' '%'
124*56bb7041Schristos
125*56bb7041Schristos %right UNARY
126*56bb7041Schristos %token END
127*56bb7041Schristos %left <token> '('
128*56bb7041Schristos %token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
129*56bb7041Schristos %token SECTIONS PHDRS INSERT_K AFTER BEFORE
130*56bb7041Schristos %token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
131*56bb7041Schristos %token SORT_BY_NAME SORT_BY_ALIGNMENT SORT_NONE
132*56bb7041Schristos %token SORT_BY_INIT_PRIORITY
133*56bb7041Schristos %token '{' '}'
134*56bb7041Schristos %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
135*56bb7041Schristos %token INHIBIT_COMMON_ALLOCATION FORCE_GROUP_ALLOCATION
136*56bb7041Schristos %token SEGMENT_START
137*56bb7041Schristos %token INCLUDE
138*56bb7041Schristos %token MEMORY
139*56bb7041Schristos %token REGION_ALIAS
140*56bb7041Schristos %token LD_FEATURE
141*56bb7041Schristos %token NOLOAD DSECT COPY INFO OVERLAY
142*56bb7041Schristos %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY
143*56bb7041Schristos %token <integer> NEXT
144*56bb7041Schristos %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K
145*56bb7041Schristos %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS NOCROSSREFS_TO
146*56bb7041Schristos %token ORIGIN FILL
147*56bb7041Schristos %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
148*56bb7041Schristos %token ALIGNMOD AT SUBALIGN HIDDEN PROVIDE PROVIDE_HIDDEN AS_NEEDED
149*56bb7041Schristos %type <token> assign_op atype attributes_opt sect_constraint opt_align_with_input
150*56bb7041Schristos %type <name> filename
151*56bb7041Schristos %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
152*56bb7041Schristos %token LOG2CEIL FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
153*56bb7041Schristos %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
154*56bb7041Schristos %token <name> VERS_TAG VERS_IDENTIFIER
155*56bb7041Schristos %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
156*56bb7041Schristos %token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL INPUT_SECTION_FLAGS ALIGN_WITH_INPUT
157*56bb7041Schristos %token EXCLUDE_FILE
158*56bb7041Schristos %token CONSTANT
159*56bb7041Schristos %type <versyms> vers_defns
160*56bb7041Schristos %type <versnode> vers_tag
161*56bb7041Schristos %type <deflist> verdep
162*56bb7041Schristos %token INPUT_DYNAMIC_LIST
163*56bb7041Schristos
164*56bb7041Schristos %%
165*56bb7041Schristos
166*56bb7041Schristos file:
167*56bb7041Schristos INPUT_SCRIPT script_file
168*56bb7041Schristos | INPUT_MRI_SCRIPT mri_script_file
169*56bb7041Schristos | INPUT_VERSION_SCRIPT version_script_file
170*56bb7041Schristos | INPUT_DYNAMIC_LIST dynamic_list_file
171*56bb7041Schristos | INPUT_DEFSYM defsym_expr
172*56bb7041Schristos ;
173*56bb7041Schristos
174*56bb7041Schristos
175*56bb7041Schristos filename: NAME;
176*56bb7041Schristos
177*56bb7041Schristos
178*56bb7041Schristos defsym_expr:
179*56bb7041Schristos { ldlex_defsym(); }
180*56bb7041Schristos NAME '=' exp
181*56bb7041Schristos {
182*56bb7041Schristos ldlex_popstate();
183*56bb7041Schristos lang_add_assignment (exp_defsym ($2, $4));
184*56bb7041Schristos }
185*56bb7041Schristos ;
186*56bb7041Schristos
187*56bb7041Schristos /* SYNTAX WITHIN AN MRI SCRIPT FILE */
188*56bb7041Schristos mri_script_file:
189*56bb7041Schristos {
190*56bb7041Schristos ldlex_mri_script ();
191*56bb7041Schristos PUSH_ERROR (_("MRI style script"));
192*56bb7041Schristos }
193*56bb7041Schristos mri_script_lines
194*56bb7041Schristos {
195*56bb7041Schristos ldlex_popstate ();
196*56bb7041Schristos mri_draw_tree ();
197*56bb7041Schristos POP_ERROR ();
198*56bb7041Schristos }
199*56bb7041Schristos ;
200*56bb7041Schristos
201*56bb7041Schristos mri_script_lines:
202*56bb7041Schristos mri_script_lines mri_script_command NEWLINE
203*56bb7041Schristos |
204*56bb7041Schristos ;
205*56bb7041Schristos
206*56bb7041Schristos mri_script_command:
207*56bb7041Schristos CHIP exp
208*56bb7041Schristos | CHIP exp ',' exp
209*56bb7041Schristos | NAME {
210*56bb7041Schristos einfo(_("%F%P: unrecognised keyword in MRI style script '%s'\n"),$1);
211*56bb7041Schristos }
212*56bb7041Schristos | LIST {
213*56bb7041Schristos config.map_filename = "-";
214*56bb7041Schristos }
215*56bb7041Schristos | ORDER ordernamelist
216*56bb7041Schristos | ENDWORD
217*56bb7041Schristos | PUBLIC NAME '=' exp
218*56bb7041Schristos { mri_public($2, $4); }
219*56bb7041Schristos | PUBLIC NAME ',' exp
220*56bb7041Schristos { mri_public($2, $4); }
221*56bb7041Schristos | PUBLIC NAME exp
222*56bb7041Schristos { mri_public($2, $3); }
223*56bb7041Schristos | FORMAT NAME
224*56bb7041Schristos { mri_format($2); }
225*56bb7041Schristos | SECT NAME ',' exp
226*56bb7041Schristos { mri_output_section($2, $4);}
227*56bb7041Schristos | SECT NAME exp
228*56bb7041Schristos { mri_output_section($2, $3);}
229*56bb7041Schristos | SECT NAME '=' exp
230*56bb7041Schristos { mri_output_section($2, $4);}
231*56bb7041Schristos | ALIGN_K NAME '=' exp
232*56bb7041Schristos { mri_align($2,$4); }
233*56bb7041Schristos | ALIGN_K NAME ',' exp
234*56bb7041Schristos { mri_align($2,$4); }
235*56bb7041Schristos | ALIGNMOD NAME '=' exp
236*56bb7041Schristos { mri_alignmod($2,$4); }
237*56bb7041Schristos | ALIGNMOD NAME ',' exp
238*56bb7041Schristos { mri_alignmod($2,$4); }
239*56bb7041Schristos | ABSOLUTE mri_abs_name_list
240*56bb7041Schristos | LOAD mri_load_name_list
241*56bb7041Schristos | NAMEWORD NAME
242*56bb7041Schristos { mri_name($2); }
243*56bb7041Schristos | ALIAS NAME ',' NAME
244*56bb7041Schristos { mri_alias($2,$4,0);}
245*56bb7041Schristos | ALIAS NAME ',' INT
246*56bb7041Schristos { mri_alias ($2, 0, (int) $4.integer); }
247*56bb7041Schristos | BASE exp
248*56bb7041Schristos { mri_base($2); }
249*56bb7041Schristos | TRUNCATE INT
250*56bb7041Schristos { mri_truncate ((unsigned int) $2.integer); }
251*56bb7041Schristos | CASE casesymlist
252*56bb7041Schristos | EXTERN extern_name_list
253*56bb7041Schristos | INCLUDE filename
254*56bb7041Schristos { ldlex_script (); ldfile_open_command_file($2); }
255*56bb7041Schristos mri_script_lines END
256*56bb7041Schristos { ldlex_popstate (); }
257*56bb7041Schristos | START NAME
258*56bb7041Schristos { lang_add_entry ($2, FALSE); }
259*56bb7041Schristos |
260*56bb7041Schristos ;
261*56bb7041Schristos
262*56bb7041Schristos ordernamelist:
263*56bb7041Schristos ordernamelist ',' NAME { mri_order($3); }
264*56bb7041Schristos | ordernamelist NAME { mri_order($2); }
265*56bb7041Schristos |
266*56bb7041Schristos ;
267*56bb7041Schristos
268*56bb7041Schristos mri_load_name_list:
269*56bb7041Schristos NAME
270*56bb7041Schristos { mri_load($1); }
271*56bb7041Schristos | mri_load_name_list ',' NAME { mri_load($3); }
272*56bb7041Schristos ;
273*56bb7041Schristos
274*56bb7041Schristos mri_abs_name_list:
275*56bb7041Schristos NAME
276*56bb7041Schristos { mri_only_load($1); }
277*56bb7041Schristos | mri_abs_name_list ',' NAME
278*56bb7041Schristos { mri_only_load($3); }
279*56bb7041Schristos ;
280*56bb7041Schristos
281*56bb7041Schristos casesymlist:
282*56bb7041Schristos /* empty */ { $$ = NULL; }
283*56bb7041Schristos | NAME
284*56bb7041Schristos | casesymlist ',' NAME
285*56bb7041Schristos ;
286*56bb7041Schristos
287*56bb7041Schristos /* Parsed as expressions so that commas separate entries */
288*56bb7041Schristos extern_name_list:
289*56bb7041Schristos { ldlex_expression (); }
290*56bb7041Schristos extern_name_list_body
291*56bb7041Schristos { ldlex_popstate (); }
292*56bb7041Schristos
293*56bb7041Schristos extern_name_list_body:
294*56bb7041Schristos NAME
295*56bb7041Schristos { ldlang_add_undef ($1, FALSE); }
296*56bb7041Schristos | extern_name_list_body NAME
297*56bb7041Schristos { ldlang_add_undef ($2, FALSE); }
298*56bb7041Schristos | extern_name_list_body ',' NAME
299*56bb7041Schristos { ldlang_add_undef ($3, FALSE); }
300*56bb7041Schristos ;
301*56bb7041Schristos
302*56bb7041Schristos script_file:
303*56bb7041Schristos { ldlex_both(); }
304*56bb7041Schristos ifile_list
305*56bb7041Schristos { ldlex_popstate(); }
306*56bb7041Schristos ;
307*56bb7041Schristos
308*56bb7041Schristos ifile_list:
309*56bb7041Schristos ifile_list ifile_p1
310*56bb7041Schristos |
311*56bb7041Schristos ;
312*56bb7041Schristos
313*56bb7041Schristos
314*56bb7041Schristos ifile_p1:
315*56bb7041Schristos memory
316*56bb7041Schristos | sections
317*56bb7041Schristos | phdrs
318*56bb7041Schristos | startup
319*56bb7041Schristos | high_level_library
320*56bb7041Schristos | low_level_library
321*56bb7041Schristos | floating_point_support
322*56bb7041Schristos | statement_anywhere
323*56bb7041Schristos | version
324*56bb7041Schristos | ';'
325*56bb7041Schristos | TARGET_K '(' NAME ')'
326*56bb7041Schristos { lang_add_target($3); }
327*56bb7041Schristos | SEARCH_DIR '(' filename ')'
328*56bb7041Schristos { ldfile_add_library_path ($3, FALSE); }
329*56bb7041Schristos | OUTPUT '(' filename ')'
330*56bb7041Schristos { lang_add_output($3, 1); }
331*56bb7041Schristos | OUTPUT_FORMAT '(' NAME ')'
332*56bb7041Schristos { lang_add_output_format ($3, (char *) NULL,
333*56bb7041Schristos (char *) NULL, 1); }
334*56bb7041Schristos | OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')'
335*56bb7041Schristos { lang_add_output_format ($3, $5, $7, 1); }
336*56bb7041Schristos | OUTPUT_ARCH '(' NAME ')'
337*56bb7041Schristos { ldfile_set_output_arch ($3, bfd_arch_unknown); }
338*56bb7041Schristos | FORCE_COMMON_ALLOCATION
339*56bb7041Schristos { command_line.force_common_definition = TRUE ; }
340*56bb7041Schristos | FORCE_GROUP_ALLOCATION
341*56bb7041Schristos { command_line.force_group_allocation = TRUE ; }
342*56bb7041Schristos | INHIBIT_COMMON_ALLOCATION
343*56bb7041Schristos { link_info.inhibit_common_definition = TRUE ; }
344*56bb7041Schristos | INPUT '(' input_list ')'
345*56bb7041Schristos | GROUP
346*56bb7041Schristos { lang_enter_group (); }
347*56bb7041Schristos '(' input_list ')'
348*56bb7041Schristos { lang_leave_group (); }
349*56bb7041Schristos | MAP '(' filename ')'
350*56bb7041Schristos { lang_add_map($3); }
351*56bb7041Schristos | INCLUDE filename
352*56bb7041Schristos { ldlex_script (); ldfile_open_command_file($2); }
353*56bb7041Schristos ifile_list END
354*56bb7041Schristos { ldlex_popstate (); }
355*56bb7041Schristos | NOCROSSREFS '(' nocrossref_list ')'
356*56bb7041Schristos {
357*56bb7041Schristos lang_add_nocrossref ($3);
358*56bb7041Schristos }
359*56bb7041Schristos | NOCROSSREFS_TO '(' nocrossref_list ')'
360*56bb7041Schristos {
361*56bb7041Schristos lang_add_nocrossref_to ($3);
362*56bb7041Schristos }
363*56bb7041Schristos | EXTERN '(' extern_name_list ')'
364*56bb7041Schristos | INSERT_K AFTER NAME
365*56bb7041Schristos { lang_add_insert ($3, 0); }
366*56bb7041Schristos | INSERT_K BEFORE NAME
367*56bb7041Schristos { lang_add_insert ($3, 1); }
368*56bb7041Schristos | REGION_ALIAS '(' NAME ',' NAME ')'
369*56bb7041Schristos { lang_memory_region_alias ($3, $5); }
370*56bb7041Schristos | LD_FEATURE '(' NAME ')'
371*56bb7041Schristos { lang_ld_feature ($3); }
372*56bb7041Schristos ;
373*56bb7041Schristos
374*56bb7041Schristos input_list:
375*56bb7041Schristos { ldlex_inputlist(); }
376*56bb7041Schristos input_list1
377*56bb7041Schristos { ldlex_popstate(); }
378*56bb7041Schristos
379*56bb7041Schristos input_list1:
380*56bb7041Schristos NAME
381*56bb7041Schristos { lang_add_input_file($1,lang_input_file_is_search_file_enum,
382*56bb7041Schristos (char *)NULL); }
383*56bb7041Schristos | input_list1 ',' NAME
384*56bb7041Schristos { lang_add_input_file($3,lang_input_file_is_search_file_enum,
385*56bb7041Schristos (char *)NULL); }
386*56bb7041Schristos | input_list1 NAME
387*56bb7041Schristos { lang_add_input_file($2,lang_input_file_is_search_file_enum,
388*56bb7041Schristos (char *)NULL); }
389*56bb7041Schristos | LNAME
390*56bb7041Schristos { lang_add_input_file($1,lang_input_file_is_l_enum,
391*56bb7041Schristos (char *)NULL); }
392*56bb7041Schristos | input_list1 ',' LNAME
393*56bb7041Schristos { lang_add_input_file($3,lang_input_file_is_l_enum,
394*56bb7041Schristos (char *)NULL); }
395*56bb7041Schristos | input_list1 LNAME
396*56bb7041Schristos { lang_add_input_file($2,lang_input_file_is_l_enum,
397*56bb7041Schristos (char *)NULL); }
398*56bb7041Schristos | AS_NEEDED '('
399*56bb7041Schristos { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
400*56bb7041Schristos input_flags.add_DT_NEEDED_for_regular = TRUE; }
401*56bb7041Schristos input_list1 ')'
402*56bb7041Schristos { input_flags.add_DT_NEEDED_for_regular = $<integer>3; }
403*56bb7041Schristos | input_list1 ',' AS_NEEDED '('
404*56bb7041Schristos { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
405*56bb7041Schristos input_flags.add_DT_NEEDED_for_regular = TRUE; }
406*56bb7041Schristos input_list1 ')'
407*56bb7041Schristos { input_flags.add_DT_NEEDED_for_regular = $<integer>5; }
408*56bb7041Schristos | input_list1 AS_NEEDED '('
409*56bb7041Schristos { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
410*56bb7041Schristos input_flags.add_DT_NEEDED_for_regular = TRUE; }
411*56bb7041Schristos input_list1 ')'
412*56bb7041Schristos { input_flags.add_DT_NEEDED_for_regular = $<integer>4; }
413*56bb7041Schristos ;
414*56bb7041Schristos
415*56bb7041Schristos sections:
416*56bb7041Schristos SECTIONS '{' sec_or_group_p1 '}'
417*56bb7041Schristos ;
418*56bb7041Schristos
419*56bb7041Schristos sec_or_group_p1:
420*56bb7041Schristos sec_or_group_p1 section
421*56bb7041Schristos | sec_or_group_p1 statement_anywhere
422*56bb7041Schristos |
423*56bb7041Schristos ;
424*56bb7041Schristos
425*56bb7041Schristos statement_anywhere:
426*56bb7041Schristos ENTRY '(' NAME ')'
427*56bb7041Schristos { lang_add_entry ($3, FALSE); }
428*56bb7041Schristos | assignment end
429*56bb7041Schristos | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')'
430*56bb7041Schristos { ldlex_popstate ();
431*56bb7041Schristos lang_add_assignment (exp_assert ($4, $6)); }
432*56bb7041Schristos ;
433*56bb7041Schristos
434*56bb7041Schristos /* The '*' and '?' cases are there because the lexer returns them as
435*56bb7041Schristos separate tokens rather than as NAME. */
436*56bb7041Schristos wildcard_name:
437*56bb7041Schristos NAME
438*56bb7041Schristos {
439*56bb7041Schristos $$ = $1;
440*56bb7041Schristos }
441*56bb7041Schristos | '*'
442*56bb7041Schristos {
443*56bb7041Schristos $$ = "*";
444*56bb7041Schristos }
445*56bb7041Schristos | '?'
446*56bb7041Schristos {
447*56bb7041Schristos $$ = "?";
448*56bb7041Schristos }
449*56bb7041Schristos ;
450*56bb7041Schristos
451*56bb7041Schristos wildcard_maybe_exclude:
452*56bb7041Schristos wildcard_name
453*56bb7041Schristos {
454*56bb7041Schristos $$.name = $1;
455*56bb7041Schristos $$.sorted = none;
456*56bb7041Schristos $$.exclude_name_list = NULL;
457*56bb7041Schristos $$.section_flag_list = NULL;
458*56bb7041Schristos }
459*56bb7041Schristos | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
460*56bb7041Schristos {
461*56bb7041Schristos $$.name = $5;
462*56bb7041Schristos $$.sorted = none;
463*56bb7041Schristos $$.exclude_name_list = $3;
464*56bb7041Schristos $$.section_flag_list = NULL;
465*56bb7041Schristos }
466*56bb7041Schristos ;
467*56bb7041Schristos
468*56bb7041Schristos filename_spec:
469*56bb7041Schristos wildcard_maybe_exclude
470*56bb7041Schristos | SORT_BY_NAME '(' wildcard_maybe_exclude ')'
471*56bb7041Schristos {
472*56bb7041Schristos $$ = $3;
473*56bb7041Schristos $$.sorted = by_name;
474*56bb7041Schristos }
475*56bb7041Schristos | SORT_NONE '(' wildcard_maybe_exclude ')'
476*56bb7041Schristos {
477*56bb7041Schristos $$ = $3;
478*56bb7041Schristos $$.sorted = by_none;
479*56bb7041Schristos }
480*56bb7041Schristos ;
481*56bb7041Schristos
482*56bb7041Schristos section_name_spec:
483*56bb7041Schristos wildcard_maybe_exclude
484*56bb7041Schristos | SORT_BY_NAME '(' wildcard_maybe_exclude ')'
485*56bb7041Schristos {
486*56bb7041Schristos $$ = $3;
487*56bb7041Schristos $$.sorted = by_name;
488*56bb7041Schristos }
489*56bb7041Schristos | SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')'
490*56bb7041Schristos {
491*56bb7041Schristos $$ = $3;
492*56bb7041Schristos $$.sorted = by_alignment;
493*56bb7041Schristos }
494*56bb7041Schristos | SORT_NONE '(' wildcard_maybe_exclude ')'
495*56bb7041Schristos {
496*56bb7041Schristos $$ = $3;
497*56bb7041Schristos $$.sorted = by_none;
498*56bb7041Schristos }
499*56bb7041Schristos | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')'
500*56bb7041Schristos {
501*56bb7041Schristos $$ = $5;
502*56bb7041Schristos $$.sorted = by_name_alignment;
503*56bb7041Schristos }
504*56bb7041Schristos | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')'
505*56bb7041Schristos {
506*56bb7041Schristos $$ = $5;
507*56bb7041Schristos $$.sorted = by_name;
508*56bb7041Schristos }
509*56bb7041Schristos | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')'
510*56bb7041Schristos {
511*56bb7041Schristos $$ = $5;
512*56bb7041Schristos $$.sorted = by_alignment_name;
513*56bb7041Schristos }
514*56bb7041Schristos | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')'
515*56bb7041Schristos {
516*56bb7041Schristos $$ = $5;
517*56bb7041Schristos $$.sorted = by_alignment;
518*56bb7041Schristos }
519*56bb7041Schristos | SORT_BY_INIT_PRIORITY '(' wildcard_maybe_exclude ')'
520*56bb7041Schristos {
521*56bb7041Schristos $$ = $3;
522*56bb7041Schristos $$.sorted = by_init_priority;
523*56bb7041Schristos }
524*56bb7041Schristos ;
525*56bb7041Schristos
526*56bb7041Schristos sect_flag_list: NAME
527*56bb7041Schristos {
528*56bb7041Schristos struct flag_info_list *n;
529*56bb7041Schristos n = ((struct flag_info_list *) xmalloc (sizeof *n));
530*56bb7041Schristos if ($1[0] == '!')
531*56bb7041Schristos {
532*56bb7041Schristos n->with = without_flags;
533*56bb7041Schristos n->name = &$1[1];
534*56bb7041Schristos }
535*56bb7041Schristos else
536*56bb7041Schristos {
537*56bb7041Schristos n->with = with_flags;
538*56bb7041Schristos n->name = $1;
539*56bb7041Schristos }
540*56bb7041Schristos n->valid = FALSE;
541*56bb7041Schristos n->next = NULL;
542*56bb7041Schristos $$ = n;
543*56bb7041Schristos }
544*56bb7041Schristos | sect_flag_list '&' NAME
545*56bb7041Schristos {
546*56bb7041Schristos struct flag_info_list *n;
547*56bb7041Schristos n = ((struct flag_info_list *) xmalloc (sizeof *n));
548*56bb7041Schristos if ($3[0] == '!')
549*56bb7041Schristos {
550*56bb7041Schristos n->with = without_flags;
551*56bb7041Schristos n->name = &$3[1];
552*56bb7041Schristos }
553*56bb7041Schristos else
554*56bb7041Schristos {
555*56bb7041Schristos n->with = with_flags;
556*56bb7041Schristos n->name = $3;
557*56bb7041Schristos }
558*56bb7041Schristos n->valid = FALSE;
559*56bb7041Schristos n->next = $1;
560*56bb7041Schristos $$ = n;
561*56bb7041Schristos }
562*56bb7041Schristos ;
563*56bb7041Schristos
564*56bb7041Schristos sect_flags:
565*56bb7041Schristos INPUT_SECTION_FLAGS '(' sect_flag_list ')'
566*56bb7041Schristos {
567*56bb7041Schristos struct flag_info *n;
568*56bb7041Schristos n = ((struct flag_info *) xmalloc (sizeof *n));
569*56bb7041Schristos n->flag_list = $3;
570*56bb7041Schristos n->flags_initialized = FALSE;
571*56bb7041Schristos n->not_with_flags = 0;
572*56bb7041Schristos n->only_with_flags = 0;
573*56bb7041Schristos $$ = n;
574*56bb7041Schristos }
575*56bb7041Schristos ;
576*56bb7041Schristos
577*56bb7041Schristos exclude_name_list:
578*56bb7041Schristos exclude_name_list wildcard_name
579*56bb7041Schristos {
580*56bb7041Schristos struct name_list *tmp;
581*56bb7041Schristos tmp = (struct name_list *) xmalloc (sizeof *tmp);
582*56bb7041Schristos tmp->name = $2;
583*56bb7041Schristos tmp->next = $1;
584*56bb7041Schristos $$ = tmp;
585*56bb7041Schristos }
586*56bb7041Schristos |
587*56bb7041Schristos wildcard_name
588*56bb7041Schristos {
589*56bb7041Schristos struct name_list *tmp;
590*56bb7041Schristos tmp = (struct name_list *) xmalloc (sizeof *tmp);
591*56bb7041Schristos tmp->name = $1;
592*56bb7041Schristos tmp->next = NULL;
593*56bb7041Schristos $$ = tmp;
594*56bb7041Schristos }
595*56bb7041Schristos ;
596*56bb7041Schristos
597*56bb7041Schristos section_name_list:
598*56bb7041Schristos section_name_list opt_comma section_name_spec
599*56bb7041Schristos {
600*56bb7041Schristos struct wildcard_list *tmp;
601*56bb7041Schristos tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
602*56bb7041Schristos tmp->next = $1;
603*56bb7041Schristos tmp->spec = $3;
604*56bb7041Schristos $$ = tmp;
605*56bb7041Schristos }
606*56bb7041Schristos |
607*56bb7041Schristos section_name_spec
608*56bb7041Schristos {
609*56bb7041Schristos struct wildcard_list *tmp;
610*56bb7041Schristos tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
611*56bb7041Schristos tmp->next = NULL;
612*56bb7041Schristos tmp->spec = $1;
613*56bb7041Schristos $$ = tmp;
614*56bb7041Schristos }
615*56bb7041Schristos ;
616*56bb7041Schristos
617*56bb7041Schristos input_section_spec_no_keep:
618*56bb7041Schristos NAME
619*56bb7041Schristos {
620*56bb7041Schristos struct wildcard_spec tmp;
621*56bb7041Schristos tmp.name = $1;
622*56bb7041Schristos tmp.exclude_name_list = NULL;
623*56bb7041Schristos tmp.sorted = none;
624*56bb7041Schristos tmp.section_flag_list = NULL;
625*56bb7041Schristos lang_add_wild (&tmp, NULL, ldgram_had_keep);
626*56bb7041Schristos }
627*56bb7041Schristos | sect_flags NAME
628*56bb7041Schristos {
629*56bb7041Schristos struct wildcard_spec tmp;
630*56bb7041Schristos tmp.name = $2;
631*56bb7041Schristos tmp.exclude_name_list = NULL;
632*56bb7041Schristos tmp.sorted = none;
633*56bb7041Schristos tmp.section_flag_list = $1;
634*56bb7041Schristos lang_add_wild (&tmp, NULL, ldgram_had_keep);
635*56bb7041Schristos }
636*56bb7041Schristos | '[' section_name_list ']'
637*56bb7041Schristos {
638*56bb7041Schristos lang_add_wild (NULL, $2, ldgram_had_keep);
639*56bb7041Schristos }
640*56bb7041Schristos | sect_flags '[' section_name_list ']'
641*56bb7041Schristos {
642*56bb7041Schristos struct wildcard_spec tmp;
643*56bb7041Schristos tmp.name = NULL;
644*56bb7041Schristos tmp.exclude_name_list = NULL;
645*56bb7041Schristos tmp.sorted = none;
646*56bb7041Schristos tmp.section_flag_list = $1;
647*56bb7041Schristos lang_add_wild (&tmp, $3, ldgram_had_keep);
648*56bb7041Schristos }
649*56bb7041Schristos | filename_spec '(' section_name_list ')'
650*56bb7041Schristos {
651*56bb7041Schristos lang_add_wild (&$1, $3, ldgram_had_keep);
652*56bb7041Schristos }
653*56bb7041Schristos | sect_flags filename_spec '(' section_name_list ')'
654*56bb7041Schristos {
655*56bb7041Schristos $2.section_flag_list = $1;
656*56bb7041Schristos lang_add_wild (&$2, $4, ldgram_had_keep);
657*56bb7041Schristos }
658*56bb7041Schristos ;
659*56bb7041Schristos
660*56bb7041Schristos input_section_spec:
661*56bb7041Schristos input_section_spec_no_keep
662*56bb7041Schristos | KEEP '('
663*56bb7041Schristos { ldgram_had_keep = TRUE; }
664*56bb7041Schristos input_section_spec_no_keep ')'
665*56bb7041Schristos { ldgram_had_keep = FALSE; }
666*56bb7041Schristos ;
667*56bb7041Schristos
668*56bb7041Schristos statement:
669*56bb7041Schristos assignment end
670*56bb7041Schristos | CREATE_OBJECT_SYMBOLS
671*56bb7041Schristos {
672*56bb7041Schristos lang_add_attribute(lang_object_symbols_statement_enum);
673*56bb7041Schristos }
674*56bb7041Schristos | ';'
675*56bb7041Schristos | CONSTRUCTORS
676*56bb7041Schristos {
677*56bb7041Schristos
678*56bb7041Schristos lang_add_attribute(lang_constructors_statement_enum);
679*56bb7041Schristos }
680*56bb7041Schristos | SORT_BY_NAME '(' CONSTRUCTORS ')'
681*56bb7041Schristos {
682*56bb7041Schristos constructors_sorted = TRUE;
683*56bb7041Schristos lang_add_attribute (lang_constructors_statement_enum);
684*56bb7041Schristos }
685*56bb7041Schristos | input_section_spec
686*56bb7041Schristos | length '(' mustbe_exp ')'
687*56bb7041Schristos {
688*56bb7041Schristos lang_add_data ((int) $1, $3);
689*56bb7041Schristos }
690*56bb7041Schristos
691*56bb7041Schristos | FILL '(' fill_exp ')'
692*56bb7041Schristos {
693*56bb7041Schristos lang_add_fill ($3);
694*56bb7041Schristos }
695*56bb7041Schristos | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')' end
696*56bb7041Schristos { ldlex_popstate ();
697*56bb7041Schristos lang_add_assignment (exp_assert ($4, $6)); }
698*56bb7041Schristos | INCLUDE filename
699*56bb7041Schristos { ldlex_script (); ldfile_open_command_file($2); }
700*56bb7041Schristos statement_list_opt END
701*56bb7041Schristos { ldlex_popstate (); }
702*56bb7041Schristos ;
703*56bb7041Schristos
704*56bb7041Schristos statement_list:
705*56bb7041Schristos statement_list statement
706*56bb7041Schristos | statement
707*56bb7041Schristos ;
708*56bb7041Schristos
709*56bb7041Schristos statement_list_opt:
710*56bb7041Schristos /* empty */
711*56bb7041Schristos | statement_list
712*56bb7041Schristos ;
713*56bb7041Schristos
714*56bb7041Schristos length:
715*56bb7041Schristos QUAD
716*56bb7041Schristos { $$ = $1; }
717*56bb7041Schristos | SQUAD
718*56bb7041Schristos { $$ = $1; }
719*56bb7041Schristos | LONG
720*56bb7041Schristos { $$ = $1; }
721*56bb7041Schristos | SHORT
722*56bb7041Schristos { $$ = $1; }
723*56bb7041Schristos | BYTE
724*56bb7041Schristos { $$ = $1; }
725*56bb7041Schristos ;
726*56bb7041Schristos
727*56bb7041Schristos fill_exp:
728*56bb7041Schristos mustbe_exp
729*56bb7041Schristos {
730*56bb7041Schristos $$ = exp_get_fill ($1, 0, "fill value");
731*56bb7041Schristos }
732*56bb7041Schristos ;
733*56bb7041Schristos
734*56bb7041Schristos fill_opt:
735*56bb7041Schristos '=' fill_exp
736*56bb7041Schristos { $$ = $2; }
737*56bb7041Schristos | { $$ = (fill_type *) 0; }
738*56bb7041Schristos ;
739*56bb7041Schristos
740*56bb7041Schristos assign_op:
741*56bb7041Schristos PLUSEQ
742*56bb7041Schristos { $$ = '+'; }
743*56bb7041Schristos | MINUSEQ
744*56bb7041Schristos { $$ = '-'; }
745*56bb7041Schristos | MULTEQ
746*56bb7041Schristos { $$ = '*'; }
747*56bb7041Schristos | DIVEQ
748*56bb7041Schristos { $$ = '/'; }
749*56bb7041Schristos | LSHIFTEQ
750*56bb7041Schristos { $$ = LSHIFT; }
751*56bb7041Schristos | RSHIFTEQ
752*56bb7041Schristos { $$ = RSHIFT; }
753*56bb7041Schristos | ANDEQ
754*56bb7041Schristos { $$ = '&'; }
755*56bb7041Schristos | OREQ
756*56bb7041Schristos { $$ = '|'; }
757*56bb7041Schristos
758*56bb7041Schristos ;
759*56bb7041Schristos
760*56bb7041Schristos end: ';' | ','
761*56bb7041Schristos ;
762*56bb7041Schristos
763*56bb7041Schristos
764*56bb7041Schristos assignment:
765*56bb7041Schristos NAME '=' mustbe_exp
766*56bb7041Schristos {
767*56bb7041Schristos lang_add_assignment (exp_assign ($1, $3, FALSE));
768*56bb7041Schristos }
769*56bb7041Schristos | NAME assign_op mustbe_exp
770*56bb7041Schristos {
771*56bb7041Schristos lang_add_assignment (exp_assign ($1,
772*56bb7041Schristos exp_binop ($2,
773*56bb7041Schristos exp_nameop (NAME,
774*56bb7041Schristos $1),
775*56bb7041Schristos $3), FALSE));
776*56bb7041Schristos }
777*56bb7041Schristos | HIDDEN '(' NAME '=' mustbe_exp ')'
778*56bb7041Schristos {
779*56bb7041Schristos lang_add_assignment (exp_assign ($3, $5, TRUE));
780*56bb7041Schristos }
781*56bb7041Schristos | PROVIDE '(' NAME '=' mustbe_exp ')'
782*56bb7041Schristos {
783*56bb7041Schristos lang_add_assignment (exp_provide ($3, $5, FALSE));
784*56bb7041Schristos }
785*56bb7041Schristos | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
786*56bb7041Schristos {
787*56bb7041Schristos lang_add_assignment (exp_provide ($3, $5, TRUE));
788*56bb7041Schristos }
789*56bb7041Schristos ;
790*56bb7041Schristos
791*56bb7041Schristos
792*56bb7041Schristos opt_comma:
793*56bb7041Schristos ',' | ;
794*56bb7041Schristos
795*56bb7041Schristos
796*56bb7041Schristos memory:
797*56bb7041Schristos MEMORY '{' memory_spec_list_opt '}'
798*56bb7041Schristos ;
799*56bb7041Schristos
800*56bb7041Schristos memory_spec_list_opt: memory_spec_list | ;
801*56bb7041Schristos
802*56bb7041Schristos memory_spec_list:
803*56bb7041Schristos memory_spec_list opt_comma memory_spec
804*56bb7041Schristos | memory_spec
805*56bb7041Schristos ;
806*56bb7041Schristos
807*56bb7041Schristos
808*56bb7041Schristos memory_spec: NAME
809*56bb7041Schristos { region = lang_memory_region_lookup ($1, TRUE); }
810*56bb7041Schristos attributes_opt ':'
811*56bb7041Schristos origin_spec opt_comma length_spec
812*56bb7041Schristos {}
813*56bb7041Schristos | INCLUDE filename
814*56bb7041Schristos { ldlex_script (); ldfile_open_command_file($2); }
815*56bb7041Schristos memory_spec_list_opt END
816*56bb7041Schristos { ldlex_popstate (); }
817*56bb7041Schristos ;
818*56bb7041Schristos
819*56bb7041Schristos origin_spec:
820*56bb7041Schristos ORIGIN '=' mustbe_exp
821*56bb7041Schristos {
822*56bb7041Schristos region->origin_exp = $3;
823*56bb7041Schristos }
824*56bb7041Schristos ;
825*56bb7041Schristos
826*56bb7041Schristos length_spec:
827*56bb7041Schristos LENGTH '=' mustbe_exp
828*56bb7041Schristos {
829*56bb7041Schristos region->length_exp = $3;
830*56bb7041Schristos }
831*56bb7041Schristos ;
832*56bb7041Schristos
833*56bb7041Schristos attributes_opt:
834*56bb7041Schristos /* empty */
835*56bb7041Schristos { /* dummy action to avoid bison 1.25 error message */ }
836*56bb7041Schristos | '(' attributes_list ')'
837*56bb7041Schristos ;
838*56bb7041Schristos
839*56bb7041Schristos attributes_list:
840*56bb7041Schristos attributes_string
841*56bb7041Schristos | attributes_list attributes_string
842*56bb7041Schristos ;
843*56bb7041Schristos
844*56bb7041Schristos attributes_string:
845*56bb7041Schristos NAME
846*56bb7041Schristos { lang_set_flags (region, $1, 0); }
847*56bb7041Schristos | '!' NAME
848*56bb7041Schristos { lang_set_flags (region, $2, 1); }
849*56bb7041Schristos ;
850*56bb7041Schristos
851*56bb7041Schristos startup:
852*56bb7041Schristos STARTUP '(' filename ')'
853*56bb7041Schristos { lang_startup($3); }
854*56bb7041Schristos ;
855*56bb7041Schristos
856*56bb7041Schristos high_level_library:
857*56bb7041Schristos HLL '(' high_level_library_NAME_list ')'
858*56bb7041Schristos | HLL '(' ')'
859*56bb7041Schristos { ldemul_hll((char *)NULL); }
860*56bb7041Schristos ;
861*56bb7041Schristos
862*56bb7041Schristos high_level_library_NAME_list:
863*56bb7041Schristos high_level_library_NAME_list opt_comma filename
864*56bb7041Schristos { ldemul_hll($3); }
865*56bb7041Schristos | filename
866*56bb7041Schristos { ldemul_hll($1); }
867*56bb7041Schristos
868*56bb7041Schristos ;
869*56bb7041Schristos
870*56bb7041Schristos low_level_library:
871*56bb7041Schristos SYSLIB '(' low_level_library_NAME_list ')'
872*56bb7041Schristos ; low_level_library_NAME_list:
873*56bb7041Schristos low_level_library_NAME_list opt_comma filename
874*56bb7041Schristos { ldemul_syslib($3); }
875*56bb7041Schristos |
876*56bb7041Schristos ;
877*56bb7041Schristos
878*56bb7041Schristos floating_point_support:
879*56bb7041Schristos FLOAT
880*56bb7041Schristos { lang_float(TRUE); }
881*56bb7041Schristos | NOFLOAT
882*56bb7041Schristos { lang_float(FALSE); }
883*56bb7041Schristos ;
884*56bb7041Schristos
885*56bb7041Schristos nocrossref_list:
886*56bb7041Schristos /* empty */
887*56bb7041Schristos {
888*56bb7041Schristos $$ = NULL;
889*56bb7041Schristos }
890*56bb7041Schristos | NAME nocrossref_list
891*56bb7041Schristos {
892*56bb7041Schristos struct lang_nocrossref *n;
893*56bb7041Schristos
894*56bb7041Schristos n = (struct lang_nocrossref *) xmalloc (sizeof *n);
895*56bb7041Schristos n->name = $1;
896*56bb7041Schristos n->next = $2;
897*56bb7041Schristos $$ = n;
898*56bb7041Schristos }
899*56bb7041Schristos | NAME ',' nocrossref_list
900*56bb7041Schristos {
901*56bb7041Schristos struct lang_nocrossref *n;
902*56bb7041Schristos
903*56bb7041Schristos n = (struct lang_nocrossref *) xmalloc (sizeof *n);
904*56bb7041Schristos n->name = $1;
905*56bb7041Schristos n->next = $3;
906*56bb7041Schristos $$ = n;
907*56bb7041Schristos }
908*56bb7041Schristos ;
909*56bb7041Schristos
910*56bb7041Schristos mustbe_exp: { ldlex_expression (); }
911*56bb7041Schristos exp
912*56bb7041Schristos { ldlex_popstate (); $$=$2;}
913*56bb7041Schristos ;
914*56bb7041Schristos
915*56bb7041Schristos exp :
916*56bb7041Schristos '-' exp %prec UNARY
917*56bb7041Schristos { $$ = exp_unop ('-', $2); }
918*56bb7041Schristos | '(' exp ')'
919*56bb7041Schristos { $$ = $2; }
920*56bb7041Schristos | NEXT '(' exp ')' %prec UNARY
921*56bb7041Schristos { $$ = exp_unop ((int) $1,$3); }
922*56bb7041Schristos | '!' exp %prec UNARY
923*56bb7041Schristos { $$ = exp_unop ('!', $2); }
924*56bb7041Schristos | '+' exp %prec UNARY
925*56bb7041Schristos { $$ = $2; }
926*56bb7041Schristos | '~' exp %prec UNARY
927*56bb7041Schristos { $$ = exp_unop ('~', $2);}
928*56bb7041Schristos
929*56bb7041Schristos | exp '*' exp
930*56bb7041Schristos { $$ = exp_binop ('*', $1, $3); }
931*56bb7041Schristos | exp '/' exp
932*56bb7041Schristos { $$ = exp_binop ('/', $1, $3); }
933*56bb7041Schristos | exp '%' exp
934*56bb7041Schristos { $$ = exp_binop ('%', $1, $3); }
935*56bb7041Schristos | exp '+' exp
936*56bb7041Schristos { $$ = exp_binop ('+', $1, $3); }
937*56bb7041Schristos | exp '-' exp
938*56bb7041Schristos { $$ = exp_binop ('-' , $1, $3); }
939*56bb7041Schristos | exp LSHIFT exp
940*56bb7041Schristos { $$ = exp_binop (LSHIFT , $1, $3); }
941*56bb7041Schristos | exp RSHIFT exp
942*56bb7041Schristos { $$ = exp_binop (RSHIFT , $1, $3); }
943*56bb7041Schristos | exp EQ exp
944*56bb7041Schristos { $$ = exp_binop (EQ , $1, $3); }
945*56bb7041Schristos | exp NE exp
946*56bb7041Schristos { $$ = exp_binop (NE , $1, $3); }
947*56bb7041Schristos | exp LE exp
948*56bb7041Schristos { $$ = exp_binop (LE , $1, $3); }
949*56bb7041Schristos | exp GE exp
950*56bb7041Schristos { $$ = exp_binop (GE , $1, $3); }
951*56bb7041Schristos | exp '<' exp
952*56bb7041Schristos { $$ = exp_binop ('<' , $1, $3); }
953*56bb7041Schristos | exp '>' exp
954*56bb7041Schristos { $$ = exp_binop ('>' , $1, $3); }
955*56bb7041Schristos | exp '&' exp
956*56bb7041Schristos { $$ = exp_binop ('&' , $1, $3); }
957*56bb7041Schristos | exp '^' exp
958*56bb7041Schristos { $$ = exp_binop ('^' , $1, $3); }
959*56bb7041Schristos | exp '|' exp
960*56bb7041Schristos { $$ = exp_binop ('|' , $1, $3); }
961*56bb7041Schristos | exp '?' exp ':' exp
962*56bb7041Schristos { $$ = exp_trinop ('?' , $1, $3, $5); }
963*56bb7041Schristos | exp ANDAND exp
964*56bb7041Schristos { $$ = exp_binop (ANDAND , $1, $3); }
965*56bb7041Schristos | exp OROR exp
966*56bb7041Schristos { $$ = exp_binop (OROR , $1, $3); }
967*56bb7041Schristos | DEFINED '(' NAME ')'
968*56bb7041Schristos { $$ = exp_nameop (DEFINED, $3); }
969*56bb7041Schristos | INT
970*56bb7041Schristos { $$ = exp_bigintop ($1.integer, $1.str); }
971*56bb7041Schristos | SIZEOF_HEADERS
972*56bb7041Schristos { $$ = exp_nameop (SIZEOF_HEADERS,0); }
973*56bb7041Schristos
974*56bb7041Schristos | ALIGNOF '(' NAME ')'
975*56bb7041Schristos { $$ = exp_nameop (ALIGNOF,$3); }
976*56bb7041Schristos | SIZEOF '(' NAME ')'
977*56bb7041Schristos { $$ = exp_nameop (SIZEOF,$3); }
978*56bb7041Schristos | ADDR '(' NAME ')'
979*56bb7041Schristos { $$ = exp_nameop (ADDR,$3); }
980*56bb7041Schristos | LOADADDR '(' NAME ')'
981*56bb7041Schristos { $$ = exp_nameop (LOADADDR,$3); }
982*56bb7041Schristos | CONSTANT '(' NAME ')'
983*56bb7041Schristos { $$ = exp_nameop (CONSTANT,$3); }
984*56bb7041Schristos | ABSOLUTE '(' exp ')'
985*56bb7041Schristos { $$ = exp_unop (ABSOLUTE, $3); }
986*56bb7041Schristos | ALIGN_K '(' exp ')'
987*56bb7041Schristos { $$ = exp_unop (ALIGN_K,$3); }
988*56bb7041Schristos | ALIGN_K '(' exp ',' exp ')'
989*56bb7041Schristos { $$ = exp_binop (ALIGN_K,$3,$5); }
990*56bb7041Schristos | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
991*56bb7041Schristos { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
992*56bb7041Schristos | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
993*56bb7041Schristos { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
994*56bb7041Schristos | DATA_SEGMENT_END '(' exp ')'
995*56bb7041Schristos { $$ = exp_unop (DATA_SEGMENT_END, $3); }
996*56bb7041Schristos | SEGMENT_START '(' NAME ',' exp ')'
997*56bb7041Schristos { /* The operands to the expression node are
998*56bb7041Schristos placed in the opposite order from the way
999*56bb7041Schristos in which they appear in the script as
1000*56bb7041Schristos that allows us to reuse more code in
1001*56bb7041Schristos fold_binary. */
1002*56bb7041Schristos $$ = exp_binop (SEGMENT_START,
1003*56bb7041Schristos $5,
1004*56bb7041Schristos exp_nameop (NAME, $3)); }
1005*56bb7041Schristos | BLOCK '(' exp ')'
1006*56bb7041Schristos { $$ = exp_unop (ALIGN_K,$3); }
1007*56bb7041Schristos | NAME
1008*56bb7041Schristos { $$ = exp_nameop (NAME,$1); }
1009*56bb7041Schristos | MAX_K '(' exp ',' exp ')'
1010*56bb7041Schristos { $$ = exp_binop (MAX_K, $3, $5 ); }
1011*56bb7041Schristos | MIN_K '(' exp ',' exp ')'
1012*56bb7041Schristos { $$ = exp_binop (MIN_K, $3, $5 ); }
1013*56bb7041Schristos | ASSERT_K '(' exp ',' NAME ')'
1014*56bb7041Schristos { $$ = exp_assert ($3, $5); }
1015*56bb7041Schristos | ORIGIN '(' NAME ')'
1016*56bb7041Schristos { $$ = exp_nameop (ORIGIN, $3); }
1017*56bb7041Schristos | LENGTH '(' NAME ')'
1018*56bb7041Schristos { $$ = exp_nameop (LENGTH, $3); }
1019*56bb7041Schristos | LOG2CEIL '(' exp ')'
1020*56bb7041Schristos { $$ = exp_unop (LOG2CEIL, $3); }
1021*56bb7041Schristos ;
1022*56bb7041Schristos
1023*56bb7041Schristos
1024*56bb7041Schristos memspec_at_opt:
1025*56bb7041Schristos AT '>' NAME { $$ = $3; }
1026*56bb7041Schristos | { $$ = 0; }
1027*56bb7041Schristos ;
1028*56bb7041Schristos
1029*56bb7041Schristos opt_at:
1030*56bb7041Schristos AT '(' exp ')' { $$ = $3; }
1031*56bb7041Schristos | { $$ = 0; }
1032*56bb7041Schristos ;
1033*56bb7041Schristos
1034*56bb7041Schristos opt_align:
1035*56bb7041Schristos ALIGN_K '(' exp ')' { $$ = $3; }
1036*56bb7041Schristos | { $$ = 0; }
1037*56bb7041Schristos ;
1038*56bb7041Schristos
1039*56bb7041Schristos opt_align_with_input:
1040*56bb7041Schristos ALIGN_WITH_INPUT { $$ = ALIGN_WITH_INPUT; }
1041*56bb7041Schristos | { $$ = 0; }
1042*56bb7041Schristos ;
1043*56bb7041Schristos
1044*56bb7041Schristos opt_subalign:
1045*56bb7041Schristos SUBALIGN '(' exp ')' { $$ = $3; }
1046*56bb7041Schristos | { $$ = 0; }
1047*56bb7041Schristos ;
1048*56bb7041Schristos
1049*56bb7041Schristos sect_constraint:
1050*56bb7041Schristos ONLY_IF_RO { $$ = ONLY_IF_RO; }
1051*56bb7041Schristos | ONLY_IF_RW { $$ = ONLY_IF_RW; }
1052*56bb7041Schristos | SPECIAL { $$ = SPECIAL; }
1053*56bb7041Schristos | { $$ = 0; }
1054*56bb7041Schristos ;
1055*56bb7041Schristos
1056*56bb7041Schristos section: NAME { ldlex_expression(); }
1057*56bb7041Schristos opt_exp_with_type
1058*56bb7041Schristos opt_at
1059*56bb7041Schristos opt_align
1060*56bb7041Schristos opt_align_with_input
1061*56bb7041Schristos opt_subalign { ldlex_popstate (); ldlex_script (); }
1062*56bb7041Schristos sect_constraint
1063*56bb7041Schristos '{'
1064*56bb7041Schristos {
1065*56bb7041Schristos lang_enter_output_section_statement($1, $3,
1066*56bb7041Schristos sectype,
1067*56bb7041Schristos $5, $7, $4, $9, $6);
1068*56bb7041Schristos }
1069*56bb7041Schristos statement_list_opt
1070*56bb7041Schristos '}' { ldlex_popstate (); ldlex_expression (); }
1071*56bb7041Schristos memspec_opt memspec_at_opt phdr_opt fill_opt
1072*56bb7041Schristos {
1073*56bb7041Schristos ldlex_popstate ();
1074*56bb7041Schristos lang_leave_output_section_statement ($18, $15, $17, $16);
1075*56bb7041Schristos }
1076*56bb7041Schristos opt_comma
1077*56bb7041Schristos {}
1078*56bb7041Schristos | OVERLAY
1079*56bb7041Schristos { ldlex_expression (); }
1080*56bb7041Schristos opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
1081*56bb7041Schristos { ldlex_popstate (); ldlex_script (); }
1082*56bb7041Schristos '{'
1083*56bb7041Schristos {
1084*56bb7041Schristos lang_enter_overlay ($3, $6);
1085*56bb7041Schristos }
1086*56bb7041Schristos overlay_section
1087*56bb7041Schristos '}'
1088*56bb7041Schristos { ldlex_popstate (); ldlex_expression (); }
1089*56bb7041Schristos memspec_opt memspec_at_opt phdr_opt fill_opt
1090*56bb7041Schristos {
1091*56bb7041Schristos ldlex_popstate ();
1092*56bb7041Schristos lang_leave_overlay ($5, (int) $4,
1093*56bb7041Schristos $16, $13, $15, $14);
1094*56bb7041Schristos }
1095*56bb7041Schristos opt_comma
1096*56bb7041Schristos | /* The GROUP case is just enough to support the gcc
1097*56bb7041Schristos svr3.ifile script. It is not intended to be full
1098*56bb7041Schristos support. I'm not even sure what GROUP is supposed
1099*56bb7041Schristos to mean. */
1100*56bb7041Schristos GROUP { ldlex_expression (); }
1101*56bb7041Schristos opt_exp_with_type
1102*56bb7041Schristos {
1103*56bb7041Schristos ldlex_popstate ();
1104*56bb7041Schristos lang_add_assignment (exp_assign (".", $3, FALSE));
1105*56bb7041Schristos }
1106*56bb7041Schristos '{' sec_or_group_p1 '}'
1107*56bb7041Schristos | INCLUDE filename
1108*56bb7041Schristos { ldlex_script (); ldfile_open_command_file($2); }
1109*56bb7041Schristos sec_or_group_p1 END
1110*56bb7041Schristos { ldlex_popstate (); }
1111*56bb7041Schristos ;
1112*56bb7041Schristos
1113*56bb7041Schristos type:
1114*56bb7041Schristos NOLOAD { sectype = noload_section; }
1115*56bb7041Schristos | DSECT { sectype = noalloc_section; }
1116*56bb7041Schristos | COPY { sectype = noalloc_section; }
1117*56bb7041Schristos | INFO { sectype = noalloc_section; }
1118*56bb7041Schristos | OVERLAY { sectype = noalloc_section; }
1119*56bb7041Schristos ;
1120*56bb7041Schristos
1121*56bb7041Schristos atype:
1122*56bb7041Schristos '(' type ')'
1123*56bb7041Schristos | /* EMPTY */ { sectype = normal_section; }
1124*56bb7041Schristos | '(' ')' { sectype = normal_section; }
1125*56bb7041Schristos ;
1126*56bb7041Schristos
1127*56bb7041Schristos opt_exp_with_type:
1128*56bb7041Schristos exp atype ':' { $$ = $1; }
1129*56bb7041Schristos | atype ':' { $$ = (etree_type *)NULL; }
1130*56bb7041Schristos | /* The BIND cases are to support the gcc svr3.ifile
1131*56bb7041Schristos script. They aren't intended to implement full
1132*56bb7041Schristos support for the BIND keyword. I'm not even sure
1133*56bb7041Schristos what BIND is supposed to mean. */
1134*56bb7041Schristos BIND '(' exp ')' atype ':' { $$ = $3; }
1135*56bb7041Schristos | BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
1136*56bb7041Schristos { $$ = $3; }
1137*56bb7041Schristos ;
1138*56bb7041Schristos
1139*56bb7041Schristos opt_exp_without_type:
1140*56bb7041Schristos exp ':' { $$ = $1; }
1141*56bb7041Schristos | ':' { $$ = (etree_type *) NULL; }
1142*56bb7041Schristos ;
1143*56bb7041Schristos
1144*56bb7041Schristos opt_nocrossrefs:
1145*56bb7041Schristos /* empty */
1146*56bb7041Schristos { $$ = 0; }
1147*56bb7041Schristos | NOCROSSREFS
1148*56bb7041Schristos { $$ = 1; }
1149*56bb7041Schristos ;
1150*56bb7041Schristos
1151*56bb7041Schristos memspec_opt:
1152*56bb7041Schristos '>' NAME
1153*56bb7041Schristos { $$ = $2; }
1154*56bb7041Schristos | { $$ = DEFAULT_MEMORY_REGION; }
1155*56bb7041Schristos ;
1156*56bb7041Schristos
1157*56bb7041Schristos phdr_opt:
1158*56bb7041Schristos /* empty */
1159*56bb7041Schristos {
1160*56bb7041Schristos $$ = NULL;
1161*56bb7041Schristos }
1162*56bb7041Schristos | phdr_opt ':' NAME
1163*56bb7041Schristos {
1164*56bb7041Schristos struct lang_output_section_phdr_list *n;
1165*56bb7041Schristos
1166*56bb7041Schristos n = ((struct lang_output_section_phdr_list *)
1167*56bb7041Schristos xmalloc (sizeof *n));
1168*56bb7041Schristos n->name = $3;
1169*56bb7041Schristos n->used = FALSE;
1170*56bb7041Schristos n->next = $1;
1171*56bb7041Schristos $$ = n;
1172*56bb7041Schristos }
1173*56bb7041Schristos ;
1174*56bb7041Schristos
1175*56bb7041Schristos overlay_section:
1176*56bb7041Schristos /* empty */
1177*56bb7041Schristos | overlay_section
1178*56bb7041Schristos NAME
1179*56bb7041Schristos {
1180*56bb7041Schristos ldlex_script ();
1181*56bb7041Schristos lang_enter_overlay_section ($2);
1182*56bb7041Schristos }
1183*56bb7041Schristos '{' statement_list_opt '}'
1184*56bb7041Schristos { ldlex_popstate (); ldlex_expression (); }
1185*56bb7041Schristos phdr_opt fill_opt
1186*56bb7041Schristos {
1187*56bb7041Schristos ldlex_popstate ();
1188*56bb7041Schristos lang_leave_overlay_section ($9, $8);
1189*56bb7041Schristos }
1190*56bb7041Schristos opt_comma
1191*56bb7041Schristos ;
1192*56bb7041Schristos
1193*56bb7041Schristos phdrs:
1194*56bb7041Schristos PHDRS '{' phdr_list '}'
1195*56bb7041Schristos ;
1196*56bb7041Schristos
1197*56bb7041Schristos phdr_list:
1198*56bb7041Schristos /* empty */
1199*56bb7041Schristos | phdr_list phdr
1200*56bb7041Schristos ;
1201*56bb7041Schristos
1202*56bb7041Schristos phdr:
1203*56bb7041Schristos NAME { ldlex_expression (); }
1204*56bb7041Schristos phdr_type phdr_qualifiers { ldlex_popstate (); }
1205*56bb7041Schristos ';'
1206*56bb7041Schristos {
1207*56bb7041Schristos lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1208*56bb7041Schristos $4.flags);
1209*56bb7041Schristos }
1210*56bb7041Schristos ;
1211*56bb7041Schristos
1212*56bb7041Schristos phdr_type:
1213*56bb7041Schristos exp
1214*56bb7041Schristos {
1215*56bb7041Schristos $$ = $1;
1216*56bb7041Schristos
1217*56bb7041Schristos if ($1->type.node_class == etree_name
1218*56bb7041Schristos && $1->type.node_code == NAME)
1219*56bb7041Schristos {
1220*56bb7041Schristos const char *s;
1221*56bb7041Schristos unsigned int i;
1222*56bb7041Schristos static const char * const phdr_types[] =
1223*56bb7041Schristos {
1224*56bb7041Schristos "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1225*56bb7041Schristos "PT_INTERP", "PT_NOTE", "PT_SHLIB",
1226*56bb7041Schristos "PT_PHDR", "PT_TLS"
1227*56bb7041Schristos };
1228*56bb7041Schristos
1229*56bb7041Schristos s = $1->name.name;
1230*56bb7041Schristos for (i = 0;
1231*56bb7041Schristos i < sizeof phdr_types / sizeof phdr_types[0];
1232*56bb7041Schristos i++)
1233*56bb7041Schristos if (strcmp (s, phdr_types[i]) == 0)
1234*56bb7041Schristos {
1235*56bb7041Schristos $$ = exp_intop (i);
1236*56bb7041Schristos break;
1237*56bb7041Schristos }
1238*56bb7041Schristos if (i == sizeof phdr_types / sizeof phdr_types[0])
1239*56bb7041Schristos {
1240*56bb7041Schristos if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1241*56bb7041Schristos $$ = exp_intop (0x6474e550);
1242*56bb7041Schristos else if (strcmp (s, "PT_GNU_STACK") == 0)
1243*56bb7041Schristos $$ = exp_intop (0x6474e551);
1244*56bb7041Schristos else
1245*56bb7041Schristos {
1246*56bb7041Schristos einfo (_("\
1247*56bb7041Schristos %X%P:%pS: unknown phdr type `%s' (try integer literal)\n"),
1248*56bb7041Schristos NULL, s);
1249*56bb7041Schristos $$ = exp_intop (0);
1250*56bb7041Schristos }
1251*56bb7041Schristos }
1252*56bb7041Schristos }
1253*56bb7041Schristos }
1254*56bb7041Schristos ;
1255*56bb7041Schristos
1256*56bb7041Schristos phdr_qualifiers:
1257*56bb7041Schristos /* empty */
1258*56bb7041Schristos {
1259*56bb7041Schristos memset (&$$, 0, sizeof (struct phdr_info));
1260*56bb7041Schristos }
1261*56bb7041Schristos | NAME phdr_val phdr_qualifiers
1262*56bb7041Schristos {
1263*56bb7041Schristos $$ = $3;
1264*56bb7041Schristos if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
1265*56bb7041Schristos $$.filehdr = TRUE;
1266*56bb7041Schristos else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
1267*56bb7041Schristos $$.phdrs = TRUE;
1268*56bb7041Schristos else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1269*56bb7041Schristos $$.flags = $2;
1270*56bb7041Schristos else
1271*56bb7041Schristos einfo (_("%X%P:%pS: PHDRS syntax error at `%s'\n"),
1272*56bb7041Schristos NULL, $1);
1273*56bb7041Schristos }
1274*56bb7041Schristos | AT '(' exp ')' phdr_qualifiers
1275*56bb7041Schristos {
1276*56bb7041Schristos $$ = $5;
1277*56bb7041Schristos $$.at = $3;
1278*56bb7041Schristos }
1279*56bb7041Schristos ;
1280*56bb7041Schristos
1281*56bb7041Schristos phdr_val:
1282*56bb7041Schristos /* empty */
1283*56bb7041Schristos {
1284*56bb7041Schristos $$ = NULL;
1285*56bb7041Schristos }
1286*56bb7041Schristos | '(' exp ')'
1287*56bb7041Schristos {
1288*56bb7041Schristos $$ = $2;
1289*56bb7041Schristos }
1290*56bb7041Schristos ;
1291*56bb7041Schristos
1292*56bb7041Schristos dynamic_list_file:
1293*56bb7041Schristos {
1294*56bb7041Schristos ldlex_version_file ();
1295*56bb7041Schristos PUSH_ERROR (_("dynamic list"));
1296*56bb7041Schristos }
1297*56bb7041Schristos dynamic_list_nodes
1298*56bb7041Schristos {
1299*56bb7041Schristos ldlex_popstate ();
1300*56bb7041Schristos POP_ERROR ();
1301*56bb7041Schristos }
1302*56bb7041Schristos ;
1303*56bb7041Schristos
1304*56bb7041Schristos dynamic_list_nodes:
1305*56bb7041Schristos dynamic_list_node
1306*56bb7041Schristos | dynamic_list_nodes dynamic_list_node
1307*56bb7041Schristos ;
1308*56bb7041Schristos
1309*56bb7041Schristos dynamic_list_node:
1310*56bb7041Schristos '{' dynamic_list_tag '}' ';'
1311*56bb7041Schristos ;
1312*56bb7041Schristos
1313*56bb7041Schristos dynamic_list_tag:
1314*56bb7041Schristos vers_defns ';'
1315*56bb7041Schristos {
1316*56bb7041Schristos lang_append_dynamic_list (current_dynamic_list_p, $1);
1317*56bb7041Schristos }
1318*56bb7041Schristos ;
1319*56bb7041Schristos
1320*56bb7041Schristos /* This syntax is used within an external version script file. */
1321*56bb7041Schristos
1322*56bb7041Schristos version_script_file:
1323*56bb7041Schristos {
1324*56bb7041Schristos ldlex_version_file ();
1325*56bb7041Schristos PUSH_ERROR (_("VERSION script"));
1326*56bb7041Schristos }
1327*56bb7041Schristos vers_nodes
1328*56bb7041Schristos {
1329*56bb7041Schristos ldlex_popstate ();
1330*56bb7041Schristos POP_ERROR ();
1331*56bb7041Schristos }
1332*56bb7041Schristos ;
1333*56bb7041Schristos
1334*56bb7041Schristos /* This is used within a normal linker script file. */
1335*56bb7041Schristos
1336*56bb7041Schristos version:
1337*56bb7041Schristos {
1338*56bb7041Schristos ldlex_version_script ();
1339*56bb7041Schristos }
1340*56bb7041Schristos VERSIONK '{' vers_nodes '}'
1341*56bb7041Schristos {
1342*56bb7041Schristos ldlex_popstate ();
1343*56bb7041Schristos }
1344*56bb7041Schristos ;
1345*56bb7041Schristos
1346*56bb7041Schristos vers_nodes:
1347*56bb7041Schristos vers_node
1348*56bb7041Schristos | vers_nodes vers_node
1349*56bb7041Schristos ;
1350*56bb7041Schristos
1351*56bb7041Schristos vers_node:
1352*56bb7041Schristos '{' vers_tag '}' ';'
1353*56bb7041Schristos {
1354*56bb7041Schristos lang_register_vers_node (NULL, $2, NULL);
1355*56bb7041Schristos }
1356*56bb7041Schristos | VERS_TAG '{' vers_tag '}' ';'
1357*56bb7041Schristos {
1358*56bb7041Schristos lang_register_vers_node ($1, $3, NULL);
1359*56bb7041Schristos }
1360*56bb7041Schristos | VERS_TAG '{' vers_tag '}' verdep ';'
1361*56bb7041Schristos {
1362*56bb7041Schristos lang_register_vers_node ($1, $3, $5);
1363*56bb7041Schristos }
1364*56bb7041Schristos ;
1365*56bb7041Schristos
1366*56bb7041Schristos verdep:
1367*56bb7041Schristos VERS_TAG
1368*56bb7041Schristos {
1369*56bb7041Schristos $$ = lang_add_vers_depend (NULL, $1);
1370*56bb7041Schristos }
1371*56bb7041Schristos | verdep VERS_TAG
1372*56bb7041Schristos {
1373*56bb7041Schristos $$ = lang_add_vers_depend ($1, $2);
1374*56bb7041Schristos }
1375*56bb7041Schristos ;
1376*56bb7041Schristos
1377*56bb7041Schristos vers_tag:
1378*56bb7041Schristos /* empty */
1379*56bb7041Schristos {
1380*56bb7041Schristos $$ = lang_new_vers_node (NULL, NULL);
1381*56bb7041Schristos }
1382*56bb7041Schristos | vers_defns ';'
1383*56bb7041Schristos {
1384*56bb7041Schristos $$ = lang_new_vers_node ($1, NULL);
1385*56bb7041Schristos }
1386*56bb7041Schristos | GLOBAL ':' vers_defns ';'
1387*56bb7041Schristos {
1388*56bb7041Schristos $$ = lang_new_vers_node ($3, NULL);
1389*56bb7041Schristos }
1390*56bb7041Schristos | LOCAL ':' vers_defns ';'
1391*56bb7041Schristos {
1392*56bb7041Schristos $$ = lang_new_vers_node (NULL, $3);
1393*56bb7041Schristos }
1394*56bb7041Schristos | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1395*56bb7041Schristos {
1396*56bb7041Schristos $$ = lang_new_vers_node ($3, $7);
1397*56bb7041Schristos }
1398*56bb7041Schristos ;
1399*56bb7041Schristos
1400*56bb7041Schristos vers_defns:
1401*56bb7041Schristos VERS_IDENTIFIER
1402*56bb7041Schristos {
1403*56bb7041Schristos $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, FALSE);
1404*56bb7041Schristos }
1405*56bb7041Schristos | NAME
1406*56bb7041Schristos {
1407*56bb7041Schristos $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, TRUE);
1408*56bb7041Schristos }
1409*56bb7041Schristos | vers_defns ';' VERS_IDENTIFIER
1410*56bb7041Schristos {
1411*56bb7041Schristos $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, FALSE);
1412*56bb7041Schristos }
1413*56bb7041Schristos | vers_defns ';' NAME
1414*56bb7041Schristos {
1415*56bb7041Schristos $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, TRUE);
1416*56bb7041Schristos }
1417*56bb7041Schristos | vers_defns ';' EXTERN NAME '{'
1418*56bb7041Schristos {
1419*56bb7041Schristos $<name>$ = ldgram_vers_current_lang;
1420*56bb7041Schristos ldgram_vers_current_lang = $4;
1421*56bb7041Schristos }
1422*56bb7041Schristos vers_defns opt_semicolon '}'
1423*56bb7041Schristos {
1424*56bb7041Schristos struct bfd_elf_version_expr *pat;
1425*56bb7041Schristos for (pat = $7; pat->next != NULL; pat = pat->next);
1426*56bb7041Schristos pat->next = $1;
1427*56bb7041Schristos $$ = $7;
1428*56bb7041Schristos ldgram_vers_current_lang = $<name>6;
1429*56bb7041Schristos }
1430*56bb7041Schristos | EXTERN NAME '{'
1431*56bb7041Schristos {
1432*56bb7041Schristos $<name>$ = ldgram_vers_current_lang;
1433*56bb7041Schristos ldgram_vers_current_lang = $2;
1434*56bb7041Schristos }
1435*56bb7041Schristos vers_defns opt_semicolon '}'
1436*56bb7041Schristos {
1437*56bb7041Schristos $$ = $5;
1438*56bb7041Schristos ldgram_vers_current_lang = $<name>4;
1439*56bb7041Schristos }
1440*56bb7041Schristos | GLOBAL
1441*56bb7041Schristos {
1442*56bb7041Schristos $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, FALSE);
1443*56bb7041Schristos }
1444*56bb7041Schristos | vers_defns ';' GLOBAL
1445*56bb7041Schristos {
1446*56bb7041Schristos $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, FALSE);
1447*56bb7041Schristos }
1448*56bb7041Schristos | LOCAL
1449*56bb7041Schristos {
1450*56bb7041Schristos $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, FALSE);
1451*56bb7041Schristos }
1452*56bb7041Schristos | vers_defns ';' LOCAL
1453*56bb7041Schristos {
1454*56bb7041Schristos $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, FALSE);
1455*56bb7041Schristos }
1456*56bb7041Schristos | EXTERN
1457*56bb7041Schristos {
1458*56bb7041Schristos $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, FALSE);
1459*56bb7041Schristos }
1460*56bb7041Schristos | vers_defns ';' EXTERN
1461*56bb7041Schristos {
1462*56bb7041Schristos $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, FALSE);
1463*56bb7041Schristos }
1464*56bb7041Schristos ;
1465*56bb7041Schristos
1466*56bb7041Schristos opt_semicolon:
1467*56bb7041Schristos /* empty */
1468*56bb7041Schristos | ';'
1469*56bb7041Schristos ;
1470*56bb7041Schristos
1471*56bb7041Schristos %%
1472*56bb7041Schristos void
yyerror(arg)1473*56bb7041Schristos yyerror(arg)
1474*56bb7041Schristos const char *arg;
1475*56bb7041Schristos {
1476*56bb7041Schristos if (ldfile_assumed_script)
1477*56bb7041Schristos einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
1478*56bb7041Schristos ldlex_filename ());
1479*56bb7041Schristos if (error_index > 0 && error_index < ERROR_NAME_MAX)
1480*56bb7041Schristos einfo ("%F%P:%pS: %s in %s\n", NULL, arg, error_names[error_index - 1]);
1481*56bb7041Schristos else
1482*56bb7041Schristos einfo ("%F%P:%pS: %s\n", NULL, arg);
1483*56bb7041Schristos }
1484