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