]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/ldgram.y
Update the NetBSD system call table to match NetBSD-current.
[thirdparty/binutils-gdb.git] / ld / ldgram.y
CommitLineData
8e5a525c 1/* A YACC grammar to parse a superset of the AT&T linker scripting language.
250d07de 2 Copyright (C) 1991-2021 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"
1ff6de03 32#include "ctf-api.h"
d038301c 33#include "ld.h"
252b5132
RH
34#include "ldexp.h"
35#include "ldver.h"
36#include "ldlang.h"
252b5132 37#include "ldfile.h"
b71e2778 38#include "ldemul.h"
252b5132
RH
39#include "ldmisc.h"
40#include "ldmain.h"
41#include "mri.h"
42#include "ldctor.h"
43#include "ldlex.h"
44
45#ifndef YYDEBUG
46#define YYDEBUG 1
47#endif
48
49static enum section_type sectype;
279e75dc 50static lang_memory_region_type *region;
252b5132 51
f38a2680 52static bool ldgram_had_keep = false;
2b94abd4 53static char *ldgram_vers_current_lang = NULL;
252b5132
RH
54
55#define ERROR_NAME_MAX 20
56static char *error_names[ERROR_NAME_MAX];
57static int error_index;
58#define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
59#define POP_ERROR() error_index--;
60%}
61%union {
62 bfd_vma integer;
2c382fb6
AM
63 struct big_int
64 {
65 bfd_vma integer;
66 char *str;
67 } bigint;
68 fill_type *fill;
252b5132
RH
69 char *name;
70 const char *cname;
71 struct wildcard_spec wildcard;
b6bf44ba 72 struct wildcard_list *wildcard_list;
18625d54 73 struct name_list *name_list;
ae17ab41
CM
74 struct flag_info_list *flag_info_list;
75 struct flag_info *flag_info;
252b5132
RH
76 int token;
77 union etree_union *etree;
78 struct phdr_info
79 {
f38a2680
AM
80 bool filehdr;
81 bool phdrs;
252b5132
RH
82 union etree_union *at;
83 union etree_union *flags;
84 } phdr;
85 struct lang_nocrossref *nocrossref;
86 struct lang_output_section_phdr_list *section_phdr;
87 struct bfd_elf_version_deps *deflist;
88 struct bfd_elf_version_expr *versyms;
89 struct bfd_elf_version_tree *versnode;
90}
91
92%type <etree> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val
bbf115d3 93%type <etree> opt_exp_without_type opt_subalign opt_align
2c382fb6 94%type <fill> fill_opt fill_exp
18625d54 95%type <name_list> exclude_name_list
2b94abd4 96%type <wildcard_list> section_name_list
ae17ab41
CM
97%type <flag_info_list> sect_flag_list
98%type <flag_info> sect_flags
252b5132 99%type <name> memspec_opt casesymlist
562d3460 100%type <name> memspec_at_opt
252b5132 101%type <cname> wildcard_name
2b94abd4 102%type <wildcard> section_name_spec filename_spec wildcard_maybe_exclude
d038301c 103%token <bigint> INT
252b5132
RH
104%token <name> NAME LNAME
105%type <integer> length
106%type <phdr> phdr_qualifiers
107%type <nocrossref> nocrossref_list
108%type <section_phdr> phdr_opt
109%type <integer> opt_nocrossrefs
110
d038301c 111%right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
252b5132
RH
112%right <token> '?' ':'
113%left <token> OROR
114%left <token> ANDAND
115%left <token> '|'
116%left <token> '^'
117%left <token> '&'
118%left <token> EQ NE
119%left <token> '<' '>' LE GE
120%left <token> LSHIFT RSHIFT
121
122%left <token> '+' '-'
123%left <token> '*' '/' '%'
124
125%right UNARY
d038301c 126%token END
252b5132
RH
127%left <token> '('
128%token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
53d25da6
AM
129%token SECTIONS PHDRS INSERT_K AFTER BEFORE
130%token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
eda680f8 131%token SORT_BY_NAME SORT_BY_ALIGNMENT SORT_NONE
02ecc8e9 132%token SORT_BY_INIT_PRIORITY
252b5132
RH
133%token '{' '}'
134%token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
7bdf4127 135%token INHIBIT_COMMON_ALLOCATION FORCE_GROUP_ALLOCATION
ba916c8a 136%token SEGMENT_START
252b5132 137%token INCLUDE
ed9ef263 138%token MEMORY
4a93e180 139%token REGION_ALIAS
01554a74 140%token LD_FEATURE
252b5132 141%token NOLOAD DSECT COPY INFO OVERLAY
6b86da53 142%token READONLY
ed9ef263 143%token DEFINED TARGET_K SEARCH_DIR MAP ENTRY
252b5132 144%token <integer> NEXT
5d41b3ef 145%token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K
cdf96953 146%token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS NOCROSSREFS_TO
252b5132
RH
147%token ORIGIN FILL
148%token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
eb8476a6 149%token ALIGNMOD AT SUBALIGN HIDDEN PROVIDE PROVIDE_HIDDEN AS_NEEDED
1eec346e 150%type <token> assign_op atype attributes_opt sect_constraint opt_align_with_input
252b5132
RH
151%type <name> filename
152%token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
2e53f7d6 153%token LOG2CEIL FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
252b5132
RH
154%token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
155%token <name> VERS_TAG VERS_IDENTIFIER
156%token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
1eec346e 157%token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL INPUT_SECTION_FLAGS ALIGN_WITH_INPUT
252b5132 158%token EXCLUDE_FILE
24718e3b 159%token CONSTANT
252b5132
RH
160%type <versyms> vers_defns
161%type <versnode> vers_tag
162%type <deflist> verdep
55255dae 163%token INPUT_DYNAMIC_LIST
252b5132
RH
164
165%%
166
d038301c 167file:
252b5132
RH
168 INPUT_SCRIPT script_file
169 | INPUT_MRI_SCRIPT mri_script_file
170 | INPUT_VERSION_SCRIPT version_script_file
55255dae 171 | INPUT_DYNAMIC_LIST dynamic_list_file
252b5132
RH
172 | INPUT_DEFSYM defsym_expr
173 ;
174
175
176filename: NAME;
177
178
179defsym_expr:
fb6c220e
AM
180 { ldlex_expression(); }
181 assignment
182 { ldlex_popstate(); }
944cd72c 183 ;
252b5132 184
d038301c 185/* SYNTAX WITHIN AN MRI SCRIPT FILE */
252b5132
RH
186mri_script_file:
187 {
188 ldlex_mri_script ();
189 PUSH_ERROR (_("MRI style script"));
190 }
191 mri_script_lines
192 {
193 ldlex_popstate ();
194 mri_draw_tree ();
195 POP_ERROR ();
196 }
197 ;
198
199mri_script_lines:
200 mri_script_lines mri_script_command NEWLINE
6c19b93b 201 |
252b5132
RH
202 ;
203
204mri_script_command:
d038301c 205 CHIP exp
252b5132 206 | CHIP exp ',' exp
6c19b93b 207 | NAME {
df5f2391 208 einfo(_("%F%P: unrecognised keyword in MRI style script '%s'\n"),$1);
252b5132 209 }
6c19b93b 210 | LIST {
252b5132
RH
211 config.map_filename = "-";
212 }
6c19b93b
AM
213 | ORDER ordernamelist
214 | ENDWORD
215 | PUBLIC NAME '=' exp
216 { mri_public($2, $4); }
217 | PUBLIC NAME ',' exp
218 { mri_public($2, $4); }
219 | PUBLIC NAME exp
220 { mri_public($2, $3); }
221 | FORMAT NAME
252b5132
RH
222 { mri_format($2); }
223 | SECT NAME ',' exp
224 { mri_output_section($2, $4);}
225 | SECT NAME exp
226 { mri_output_section($2, $3);}
227 | SECT NAME '=' exp
228 { mri_output_section($2, $4);}
229 | ALIGN_K NAME '=' exp
230 { mri_align($2,$4); }
231 | ALIGN_K NAME ',' exp
232 { mri_align($2,$4); }
233 | ALIGNMOD NAME '=' exp
234 { mri_alignmod($2,$4); }
235 | ALIGNMOD NAME ',' exp
236 { mri_alignmod($2,$4); }
237 | ABSOLUTE mri_abs_name_list
238 | LOAD mri_load_name_list
6c19b93b 239 | NAMEWORD NAME
d038301c 240 { mri_name($2); }
252b5132
RH
241 | ALIAS NAME ',' NAME
242 { mri_alias($2,$4,0);}
243 | ALIAS NAME ',' INT
2c382fb6 244 { mri_alias ($2, 0, (int) $4.integer); }
6c19b93b 245 | BASE exp
252b5132 246 { mri_base($2); }
2c382fb6
AM
247 | TRUNCATE INT
248 { mri_truncate ((unsigned int) $2.integer); }
252b5132
RH
249 | CASE casesymlist
250 | EXTERN extern_name_list
251 | INCLUDE filename
b47c4208
AM
252 { ldlex_script (); ldfile_open_command_file($2); }
253 mri_script_lines END
254 { ldlex_popstate (); }
252b5132 255 | START NAME
f38a2680 256 { lang_add_entry ($2, false); }
6c19b93b 257 |
252b5132
RH
258 ;
259
260ordernamelist:
6c19b93b
AM
261 ordernamelist ',' NAME { mri_order($3); }
262 | ordernamelist NAME { mri_order($2); }
263 |
252b5132
RH
264 ;
265
266mri_load_name_list:
267 NAME
268 { mri_load($1); }
269 | mri_load_name_list ',' NAME { mri_load($3); }
270 ;
271
272mri_abs_name_list:
6c19b93b
AM
273 NAME
274 { mri_only_load($1); }
252b5132 275 | mri_abs_name_list ',' NAME
6c19b93b 276 { mri_only_load($3); }
252b5132
RH
277 ;
278
279casesymlist:
280 /* empty */ { $$ = NULL; }
281 | NAME
282 | casesymlist ',' NAME
283 ;
284
8545d1a9 285/* Parsed as expressions so that commas separate entries */
252b5132 286extern_name_list:
8545d1a9
NS
287 { ldlex_expression (); }
288 extern_name_list_body
289 { ldlex_popstate (); }
290
291extern_name_list_body:
252b5132 292 NAME
f38a2680 293 { ldlang_add_undef ($1, false); }
8545d1a9 294 | extern_name_list_body NAME
f38a2680 295 { ldlang_add_undef ($2, false); }
8545d1a9 296 | extern_name_list_body ',' NAME
f38a2680 297 { ldlang_add_undef ($3, false); }
252b5132
RH
298 ;
299
300script_file:
8545d1a9
NS
301 { ldlex_both(); }
302 ifile_list
303 { ldlex_popstate(); }
6c19b93b 304 ;
252b5132 305
252b5132 306ifile_list:
8545d1a9 307 ifile_list ifile_p1
6c19b93b 308 |
252b5132
RH
309 ;
310
311
252b5132
RH
312ifile_p1:
313 memory
314 | sections
315 | phdrs
316 | startup
317 | high_level_library
318 | low_level_library
319 | floating_point_support
320 | statement_anywhere
321 | version
6c19b93b 322 | ';'
252b5132
RH
323 | TARGET_K '(' NAME ')'
324 { lang_add_target($3); }
325 | SEARCH_DIR '(' filename ')'
f38a2680 326 { ldfile_add_library_path ($3, false); }
252b5132
RH
327 | OUTPUT '(' filename ')'
328 { lang_add_output($3, 1); }
6c19b93b 329 | OUTPUT_FORMAT '(' NAME ')'
252b5132
RH
330 { lang_add_output_format ($3, (char *) NULL,
331 (char *) NULL, 1); }
332 | OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')'
333 { lang_add_output_format ($3, $5, $7, 1); }
6c19b93b 334 | OUTPUT_ARCH '(' NAME ')'
5e2f1575 335 { ldfile_set_output_arch ($3, bfd_arch_unknown); }
252b5132 336 | FORCE_COMMON_ALLOCATION
f38a2680 337 { command_line.force_common_definition = true ; }
7bdf4127 338 | FORCE_GROUP_ALLOCATION
f38a2680 339 { command_line.force_group_allocation = true ; }
4818e05f 340 | INHIBIT_COMMON_ALLOCATION
f38a2680 341 { link_info.inhibit_common_definition = true ; }
252b5132
RH
342 | INPUT '(' input_list ')'
343 | GROUP
344 { lang_enter_group (); }
345 '(' input_list ')'
346 { lang_leave_group (); }
6c19b93b 347 | MAP '(' filename ')'
252b5132 348 { lang_add_map($3); }
d038301c 349 | INCLUDE filename
b47c4208
AM
350 { ldlex_script (); ldfile_open_command_file($2); }
351 ifile_list END
352 { ldlex_popstate (); }
252b5132
RH
353 | NOCROSSREFS '(' nocrossref_list ')'
354 {
355 lang_add_nocrossref ($3);
356 }
cdf96953
MF
357 | NOCROSSREFS_TO '(' nocrossref_list ')'
358 {
359 lang_add_nocrossref_to ($3);
360 }
252b5132 361 | EXTERN '(' extern_name_list ')'
53d25da6
AM
362 | INSERT_K AFTER NAME
363 { lang_add_insert ($3, 0); }
364 | INSERT_K BEFORE NAME
365 { lang_add_insert ($3, 1); }
4a93e180
NC
366 | REGION_ALIAS '(' NAME ',' NAME ')'
367 { lang_memory_region_alias ($3, $5); }
01554a74
AM
368 | LD_FEATURE '(' NAME ')'
369 { lang_ld_feature ($3); }
252b5132
RH
370 ;
371
372input_list:
eeed9cc7
HPN
373 { ldlex_inputlist(); }
374 input_list1
375 { ldlex_popstate(); }
376
377input_list1:
252b5132
RH
378 NAME
379 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
380 (char *)NULL); }
eeed9cc7 381 | input_list1 ',' NAME
252b5132
RH
382 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
383 (char *)NULL); }
eeed9cc7 384 | input_list1 NAME
252b5132
RH
385 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
386 (char *)NULL); }
387 | LNAME
388 { lang_add_input_file($1,lang_input_file_is_l_enum,
389 (char *)NULL); }
eeed9cc7 390 | input_list1 ',' LNAME
252b5132
RH
391 { lang_add_input_file($3,lang_input_file_is_l_enum,
392 (char *)NULL); }
eeed9cc7 393 | input_list1 LNAME
252b5132
RH
394 { lang_add_input_file($2,lang_input_file_is_l_enum,
395 (char *)NULL); }
b717d30e 396 | AS_NEEDED '('
66be1055 397 { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
f38a2680 398 input_flags.add_DT_NEEDED_for_regular = true; }
eeed9cc7 399 input_list1 ')'
66be1055 400 { input_flags.add_DT_NEEDED_for_regular = $<integer>3; }
eeed9cc7 401 | input_list1 ',' AS_NEEDED '('
66be1055 402 { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
f38a2680 403 input_flags.add_DT_NEEDED_for_regular = true; }
eeed9cc7 404 input_list1 ')'
66be1055 405 { input_flags.add_DT_NEEDED_for_regular = $<integer>5; }
eeed9cc7 406 | input_list1 AS_NEEDED '('
66be1055 407 { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
f38a2680 408 input_flags.add_DT_NEEDED_for_regular = true; }
eeed9cc7 409 input_list1 ')'
66be1055 410 { input_flags.add_DT_NEEDED_for_regular = $<integer>4; }
252b5132
RH
411 ;
412
413sections:
414 SECTIONS '{' sec_or_group_p1 '}'
415 ;
416
417sec_or_group_p1:
418 sec_or_group_p1 section
419 | sec_or_group_p1 statement_anywhere
420 |
421 ;
422
423statement_anywhere:
424 ENTRY '(' NAME ')'
f38a2680 425 { lang_add_entry ($3, false); }
252b5132 426 | assignment end
b6ca8815
NS
427 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')'
428 { ldlex_popstate ();
429 lang_add_assignment (exp_assert ($4, $6)); }
252b5132
RH
430 ;
431
432/* The '*' and '?' cases are there because the lexer returns them as
433 separate tokens rather than as NAME. */
434wildcard_name:
435 NAME
436 {
437 $$ = $1;
438 }
439 | '*'
440 {
441 $$ = "*";
442 }
443 | '?'
444 {
445 $$ = "?";
446 }
447 ;
448
2b94abd4 449wildcard_maybe_exclude:
252b5132
RH
450 wildcard_name
451 {
452 $$.name = $1;
bcaa7b3e 453 $$.sorted = none;
18625d54 454 $$.exclude_name_list = NULL;
ae17ab41 455 $$.section_flag_list = NULL;
252b5132 456 }
6c19b93b 457 | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
252b5132
RH
458 {
459 $$.name = $5;
bcaa7b3e 460 $$.sorted = none;
18625d54 461 $$.exclude_name_list = $3;
ae17ab41 462 $$.section_flag_list = NULL;
252b5132 463 }
2b94abd4
AB
464 ;
465
466filename_spec:
467 wildcard_maybe_exclude
468 | SORT_BY_NAME '(' wildcard_maybe_exclude ')'
252b5132 469 {
2b94abd4 470 $$ = $3;
bcaa7b3e 471 $$.sorted = by_name;
252b5132 472 }
2b94abd4
AB
473 | SORT_NONE '(' wildcard_maybe_exclude ')'
474 {
475 $$ = $3;
476 $$.sorted = by_none;
477 }
478 ;
479
480section_name_spec:
481 wildcard_maybe_exclude
482 | SORT_BY_NAME '(' wildcard_maybe_exclude ')'
bcaa7b3e 483 {
2b94abd4
AB
484 $$ = $3;
485 $$.sorted = by_name;
486 }
487 | SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')'
488 {
489 $$ = $3;
bcaa7b3e 490 $$.sorted = by_alignment;
bcaa7b3e 491 }
2b94abd4 492 | SORT_NONE '(' wildcard_maybe_exclude ')'
eda680f8 493 {
2b94abd4 494 $$ = $3;
eda680f8 495 $$.sorted = by_none;
eda680f8 496 }
2b94abd4 497 | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')'
bcaa7b3e 498 {
2b94abd4 499 $$ = $5;
bcaa7b3e 500 $$.sorted = by_name_alignment;
bcaa7b3e 501 }
2b94abd4 502 | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')'
bcaa7b3e 503 {
2b94abd4 504 $$ = $5;
bcaa7b3e 505 $$.sorted = by_name;
bcaa7b3e 506 }
2b94abd4 507 | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')'
bcaa7b3e 508 {
2b94abd4 509 $$ = $5;
bcaa7b3e 510 $$.sorted = by_alignment_name;
bcaa7b3e 511 }
2b94abd4 512 | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')'
bcaa7b3e 513 {
2b94abd4 514 $$ = $5;
bcaa7b3e 515 $$.sorted = by_alignment;
252b5132 516 }
2b94abd4 517 | SORT_BY_INIT_PRIORITY '(' wildcard_maybe_exclude ')'
02ecc8e9 518 {
2b94abd4 519 $$ = $3;
02ecc8e9 520 $$.sorted = by_init_priority;
ae17ab41
CM
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 }
f38a2680 538 n->valid = false;
ae17ab41
CM
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 }
f38a2680 556 n->valid = false;
ae17ab41
CM
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;
f38a2680 568 n->flags_initialized = false;
ae17ab41
CM
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
2b94abd4
AB
595section_name_list:
596 section_name_list opt_comma section_name_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 604 |
2b94abd4 605 section_name_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 }
6c19b93b 634 | '[' section_name_list ']'
252b5132 635 {
b6bf44ba 636 lang_add_wild (NULL, $2, ldgram_had_keep);
252b5132 637 }
6c19b93b 638 | sect_flags '[' section_name_list ']'
ae17ab41
CM
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 }
2b94abd4 647 | filename_spec '(' section_name_list ')'
252b5132 648 {
b6bf44ba 649 lang_add_wild (&$1, $3, ldgram_had_keep);
252b5132 650 }
2b94abd4 651 | sect_flags filename_spec '(' section_name_list ')'
ae17ab41
CM
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 '('
f38a2680 661 { ldgram_had_keep = true; }
252b5132 662 input_section_spec_no_keep ')'
f38a2680 663 { ldgram_had_keep = false; }
252b5132
RH
664 ;
665
666statement:
6c19b93b 667 assignment end
252b5132
RH
668 | CREATE_OBJECT_SYMBOLS
669 {
6c19b93b
AM
670 lang_add_attribute(lang_object_symbols_statement_enum);
671 }
672 | ';'
673 | CONSTRUCTORS
252b5132 674 {
d038301c
RM
675
676 lang_add_attribute(lang_constructors_statement_enum);
252b5132 677 }
bcaa7b3e 678 | SORT_BY_NAME '(' CONSTRUCTORS ')'
252b5132 679 {
f38a2680 680 constructors_sorted = true;
252b5132
RH
681 lang_add_attribute (lang_constructors_statement_enum);
682 }
683 | input_section_spec
6c19b93b
AM
684 | length '(' mustbe_exp ')'
685 {
686 lang_add_data ((int) $1, $3);
687 }
d038301c 688
2c382fb6 689 | FILL '(' fill_exp ')'
6c19b93b
AM
690 {
691 lang_add_fill ($3);
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
6c19b93b 704 | statement
252b5132 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; }
6c19b93b 719 | SHORT
252b5132
RH
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; }
6c19b93b 735 | { $$ = (fill_type *) 0; }
2c382fb6 736 ;
252b5132
RH
737
738assign_op:
739 PLUSEQ
740 { $$ = '+'; }
741 | MINUSEQ
742 { $$ = '-'; }
6c19b93b 743 | MULTEQ
252b5132 744 { $$ = '*'; }
6c19b93b 745 | DIVEQ
252b5132 746 { $$ = '/'; }
6c19b93b 747 | LSHIFTEQ
252b5132 748 { $$ = LSHIFT; }
6c19b93b 749 | RSHIFTEQ
252b5132 750 { $$ = RSHIFT; }
6c19b93b 751 | ANDEQ
252b5132 752 { $$ = '&'; }
6c19b93b 753 | OREQ
252b5132
RH
754 { $$ = '|'; }
755
756 ;
757
758end: ';' | ','
759 ;
760
761
762assignment:
763 NAME '=' mustbe_exp
764 {
f38a2680 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),
f38a2680 773 $3), false));
eb8476a6
MR
774 }
775 | HIDDEN '(' NAME '=' mustbe_exp ')'
776 {
f38a2680 777 lang_add_assignment (exp_assign ($3, $5, true));
252b5132
RH
778 }
779 | PROVIDE '(' NAME '=' mustbe_exp ')'
780 {
f38a2680 781 lang_add_assignment (exp_provide ($3, $5, false));
7af8e998
L
782 }
783 | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
784 {
f38a2680 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
6c19b93b 806memory_spec: NAME
f38a2680 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 821 }
252b5132
RH
822 ;
823
824length_spec:
6c19b93b 825 LENGTH '=' mustbe_exp
e9ee469a 826 {
cc9ad334 827 region->length_exp = $3;
252b5132 828 }
aa8804e4 829 ;
252b5132
RH
830
831attributes_opt:
aa8804e4
ILT
832 /* empty */
833 { /* dummy action to avoid bison 1.25 error message */ }
834 | '(' attributes_list ')'
835 ;
836
837attributes_list:
838 attributes_string
839 | attributes_list attributes_string
840 ;
841
842attributes_string:
843 NAME
844 { lang_set_flags (region, $1, 0); }
845 | '!' NAME
846 { lang_set_flags (region, $2, 1); }
252b5132
RH
847 ;
848
849startup:
850 STARTUP '(' filename ')'
851 { lang_startup($3); }
852 ;
853
854high_level_library:
855 HLL '(' high_level_library_NAME_list ')'
856 | HLL '(' ')'
857 { ldemul_hll((char *)NULL); }
858 ;
859
860high_level_library_NAME_list:
861 high_level_library_NAME_list opt_comma filename
862 { ldemul_hll($3); }
863 | filename
864 { ldemul_hll($1); }
252b5132
RH
865 ;
866
867low_level_library:
868 SYSLIB '(' low_level_library_NAME_list ')'
a5f92c67
AM
869 ;
870
871low_level_library_NAME_list:
252b5132
RH
872 low_level_library_NAME_list opt_comma filename
873 { ldemul_syslib($3); }
874 |
875 ;
876
877floating_point_support:
878 FLOAT
f38a2680 879 { lang_float(true); }
252b5132 880 | NOFLOAT
f38a2680 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); }
6c19b93b 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); }
6c19b93b 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); }
6c19b93b
AM
995 | SEGMENT_START '(' NAME ',' exp ')'
996 { /* The operands to the expression node are
ba916c8a
MM
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 1023memspec_at_opt:
6c19b93b
AM
1024 AT '>' NAME { $$ = $3; }
1025 | { $$ = 0; }
1026 ;
562d3460 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
6c19b93b 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
6c19b93b 1069 '}' { ldlex_popstate (); ldlex_expression (); }
562d3460 1070 memspec_opt memspec_at_opt phdr_opt fill_opt
252b5132 1071 {
40726f16
AM
1072 if (yychar == NAME)
1073 {
1074 yyclearin;
1075 ldlex_backup ();
1076 }
252b5132 1077 ldlex_popstate ();
1eec346e 1078 lang_leave_output_section_statement ($18, $15, $17, $16);
252b5132
RH
1079 }
1080 opt_comma
1081 | OVERLAY
1082 { ldlex_expression (); }
7e7d5768 1083 opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
252b5132 1084 { ldlex_popstate (); ldlex_script (); }
d038301c 1085 '{'
252b5132 1086 {
7e7d5768 1087 lang_enter_overlay ($3, $6);
252b5132
RH
1088 }
1089 overlay_section
1090 '}'
1091 { ldlex_popstate (); ldlex_expression (); }
562d3460 1092 memspec_opt memspec_at_opt phdr_opt fill_opt
252b5132 1093 {
40726f16
AM
1094 if (yychar == NAME)
1095 {
1096 yyclearin;
1097 ldlex_backup ();
1098 }
252b5132 1099 ldlex_popstate ();
9f88b410 1100 lang_leave_overlay ($5, (int) $4,
7e7d5768 1101 $16, $13, $15, $14);
252b5132
RH
1102 }
1103 opt_comma
1104 | /* The GROUP case is just enough to support the gcc
1105 svr3.ifile script. It is not intended to be full
1106 support. I'm not even sure what GROUP is supposed
1107 to mean. */
1108 GROUP { ldlex_expression (); }
1109 opt_exp_with_type
1110 {
1111 ldlex_popstate ();
f38a2680 1112 lang_add_assignment (exp_assign (".", $3, false));
252b5132
RH
1113 }
1114 '{' sec_or_group_p1 '}'
4006703d
NS
1115 | INCLUDE filename
1116 { ldlex_script (); ldfile_open_command_file($2); }
1117 sec_or_group_p1 END
1118 { ldlex_popstate (); }
252b5132
RH
1119 ;
1120
1121type:
1122 NOLOAD { sectype = noload_section; }
02a38f92
AM
1123 | DSECT { sectype = noalloc_section; }
1124 | COPY { sectype = noalloc_section; }
1125 | INFO { sectype = noalloc_section; }
1126 | OVERLAY { sectype = noalloc_section; }
6b86da53 1127 | READONLY { sectype = readonly_section; }
252b5132
RH
1128 ;
1129
1130atype:
6c19b93b
AM
1131 '(' type ')'
1132 | /* EMPTY */ { sectype = normal_section; }
1133 | '(' ')' { sectype = normal_section; }
252b5132
RH
1134 ;
1135
1136opt_exp_with_type:
1137 exp atype ':' { $$ = $1; }
1138 | atype ':' { $$ = (etree_type *)NULL; }
1139 | /* The BIND cases are to support the gcc svr3.ifile
1140 script. They aren't intended to implement full
1141 support for the BIND keyword. I'm not even sure
1142 what BIND is supposed to mean. */
1143 BIND '(' exp ')' atype ':' { $$ = $3; }
1144 | BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
1145 { $$ = $3; }
1146 ;
1147
1148opt_exp_without_type:
1149 exp ':' { $$ = $1; }
1150 | ':' { $$ = (etree_type *) NULL; }
1151 ;
1152
1153opt_nocrossrefs:
1154 /* empty */
1155 { $$ = 0; }
1156 | NOCROSSREFS
1157 { $$ = 1; }
1158 ;
1159
1160memspec_opt:
1161 '>' NAME
1162 { $$ = $2; }
a747ee4d 1163 | { $$ = DEFAULT_MEMORY_REGION; }
252b5132
RH
1164 ;
1165
1166phdr_opt:
1167 /* empty */
1168 {
1169 $$ = NULL;
1170 }
1171 | phdr_opt ':' NAME
1172 {
1173 struct lang_output_section_phdr_list *n;
1174
1175 n = ((struct lang_output_section_phdr_list *)
1176 xmalloc (sizeof *n));
1177 n->name = $3;
f38a2680 1178 n->used = false;
252b5132
RH
1179 n->next = $1;
1180 $$ = n;
1181 }
1182 ;
1183
1184overlay_section:
1185 /* empty */
1186 | overlay_section
1187 NAME
1188 {
1189 ldlex_script ();
1190 lang_enter_overlay_section ($2);
1191 }
1192 '{' statement_list_opt '}'
1193 { ldlex_popstate (); ldlex_expression (); }
1194 phdr_opt fill_opt
1195 {
1196 ldlex_popstate ();
1197 lang_leave_overlay_section ($9, $8);
1198 }
1199 opt_comma
1200 ;
1201
1202phdrs:
1203 PHDRS '{' phdr_list '}'
1204 ;
1205
1206phdr_list:
1207 /* empty */
1208 | phdr_list phdr
1209 ;
1210
1211phdr:
1212 NAME { ldlex_expression (); }
1213 phdr_type phdr_qualifiers { ldlex_popstate (); }
1214 ';'
1215 {
1216 lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1217 $4.flags);
1218 }
1219 ;
1220
1221phdr_type:
1222 exp
1223 {
1224 $$ = $1;
1225
1226 if ($1->type.node_class == etree_name
1227 && $1->type.node_code == NAME)
1228 {
1229 const char *s;
1230 unsigned int i;
1231 static const char * const phdr_types[] =
1232 {
1233 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1234 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
d038301c 1235 "PT_PHDR", "PT_TLS"
252b5132
RH
1236 };
1237
1238 s = $1->name.name;
1239 for (i = 0;
1240 i < sizeof phdr_types / sizeof phdr_types[0];
1241 i++)
1242 if (strcmp (s, phdr_types[i]) == 0)
1243 {
1244 $$ = exp_intop (i);
1245 break;
1246 }
d038301c
RM
1247 if (i == sizeof phdr_types / sizeof phdr_types[0])
1248 {
1249 if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1250 $$ = exp_intop (0x6474e550);
9ee5e499
JJ
1251 else if (strcmp (s, "PT_GNU_STACK") == 0)
1252 $$ = exp_intop (0x6474e551);
d038301c
RM
1253 else
1254 {
1255 einfo (_("\
c1c8c1ef 1256%X%P:%pS: unknown phdr type `%s' (try integer literal)\n"),
dab69f68 1257 NULL, s);
d038301c
RM
1258 $$ = exp_intop (0);
1259 }
1260 }
252b5132
RH
1261 }
1262 }
1263 ;
1264
1265phdr_qualifiers:
1266 /* empty */
1267 {
1268 memset (&$$, 0, sizeof (struct phdr_info));
1269 }
1270 | NAME phdr_val phdr_qualifiers
1271 {
1272 $$ = $3;
1273 if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
f38a2680 1274 $$.filehdr = true;
252b5132 1275 else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
f38a2680 1276 $$.phdrs = true;
252b5132
RH
1277 else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1278 $$.flags = $2;
1279 else
c1c8c1ef 1280 einfo (_("%X%P:%pS: PHDRS syntax error at `%s'\n"),
dab69f68 1281 NULL, $1);
252b5132
RH
1282 }
1283 | AT '(' exp ')' phdr_qualifiers
1284 {
1285 $$ = $5;
1286 $$.at = $3;
1287 }
1288 ;
1289
1290phdr_val:
1291 /* empty */
1292 {
1293 $$ = NULL;
1294 }
1295 | '(' exp ')'
1296 {
1297 $$ = $2;
1298 }
1299 ;
1300
55255dae
L
1301dynamic_list_file:
1302 {
1303 ldlex_version_file ();
1304 PUSH_ERROR (_("dynamic list"));
1305 }
1306 dynamic_list_nodes
1307 {
1308 ldlex_popstate ();
1309 POP_ERROR ();
1310 }
1311 ;
1312
1313dynamic_list_nodes:
1314 dynamic_list_node
1315 | dynamic_list_nodes dynamic_list_node
1316 ;
1317
1318dynamic_list_node:
1319 '{' dynamic_list_tag '}' ';'
1320 ;
1321
1322dynamic_list_tag:
1323 vers_defns ';'
1324 {
37a141bf 1325 lang_append_dynamic_list (current_dynamic_list_p, $1);
55255dae
L
1326 }
1327 ;
1328
252b5132
RH
1329/* This syntax is used within an external version script file. */
1330
1331version_script_file:
1332 {
1333 ldlex_version_file ();
1334 PUSH_ERROR (_("VERSION script"));
1335 }
1336 vers_nodes
1337 {
1338 ldlex_popstate ();
1339 POP_ERROR ();
1340 }
1341 ;
1342
1343/* This is used within a normal linker script file. */
1344
1345version:
1346 {
1347 ldlex_version_script ();
1348 }
1349 VERSIONK '{' vers_nodes '}'
1350 {
1351 ldlex_popstate ();
1352 }
1353 ;
1354
1355vers_nodes:
1356 vers_node
1357 | vers_nodes vers_node
1358 ;
1359
1360vers_node:
6b9b879a
JJ
1361 '{' vers_tag '}' ';'
1362 {
1363 lang_register_vers_node (NULL, $2, NULL);
1364 }
1365 | VERS_TAG '{' vers_tag '}' ';'
252b5132
RH
1366 {
1367 lang_register_vers_node ($1, $3, NULL);
1368 }
1369 | VERS_TAG '{' vers_tag '}' verdep ';'
1370 {
1371 lang_register_vers_node ($1, $3, $5);
1372 }
1373 ;
1374
1375verdep:
1376 VERS_TAG
1377 {
1378 $$ = lang_add_vers_depend (NULL, $1);
1379 }
1380 | verdep VERS_TAG
1381 {
1382 $$ = lang_add_vers_depend ($1, $2);
1383 }
1384 ;
1385
1386vers_tag:
1387 /* empty */
1388 {
1389 $$ = lang_new_vers_node (NULL, NULL);
1390 }
1391 | vers_defns ';'
1392 {
1393 $$ = lang_new_vers_node ($1, NULL);
1394 }
1395 | GLOBAL ':' vers_defns ';'
1396 {
1397 $$ = lang_new_vers_node ($3, NULL);
1398 }
1399 | LOCAL ':' vers_defns ';'
1400 {
1401 $$ = lang_new_vers_node (NULL, $3);
1402 }
1403 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1404 {
1405 $$ = lang_new_vers_node ($3, $7);
1406 }
1407 ;
1408
1409vers_defns:
1410 VERS_IDENTIFIER
1411 {
f38a2680 1412 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, false);
86043bbb 1413 }
6c19b93b 1414 | NAME
86043bbb 1415 {
f38a2680 1416 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, true);
252b5132
RH
1417 }
1418 | vers_defns ';' VERS_IDENTIFIER
1419 {
f38a2680 1420 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, false);
86043bbb
MM
1421 }
1422 | vers_defns ';' NAME
1423 {
f38a2680 1424 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, true);
252b5132 1425 }
8e23b15d
AM
1426 | vers_defns ';' EXTERN NAME '{'
1427 {
1428 $<name>$ = ldgram_vers_current_lang;
1429 ldgram_vers_current_lang = $4;
1430 }
1431 vers_defns opt_semicolon '}'
1432 {
96f8ade5
JJ
1433 struct bfd_elf_version_expr *pat;
1434 for (pat = $7; pat->next != NULL; pat = pat->next);
1435 pat->next = $1;
8e23b15d
AM
1436 $$ = $7;
1437 ldgram_vers_current_lang = $<name>6;
1438 }
252b5132
RH
1439 | EXTERN NAME '{'
1440 {
1441 $<name>$ = ldgram_vers_current_lang;
1442 ldgram_vers_current_lang = $2;
1443 }
8e23b15d 1444 vers_defns opt_semicolon '}'
252b5132 1445 {
e06cae36 1446 $$ = $5;
252b5132
RH
1447 ldgram_vers_current_lang = $<name>4;
1448 }
96f8ade5
JJ
1449 | GLOBAL
1450 {
f38a2680 1451 $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, false);
96f8ade5
JJ
1452 }
1453 | vers_defns ';' GLOBAL
1454 {
f38a2680 1455 $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, false);
96f8ade5
JJ
1456 }
1457 | LOCAL
1458 {
f38a2680 1459 $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, false);
96f8ade5
JJ
1460 }
1461 | vers_defns ';' LOCAL
1462 {
f38a2680 1463 $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, false);
96f8ade5
JJ
1464 }
1465 | EXTERN
1466 {
f38a2680 1467 $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, false);
96f8ade5
JJ
1468 }
1469 | vers_defns ';' EXTERN
1470 {
f38a2680 1471 $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, false);
96f8ade5 1472 }
252b5132
RH
1473 ;
1474
8e23b15d
AM
1475opt_semicolon:
1476 /* empty */
1477 | ';'
1478 ;
1479
252b5132
RH
1480%%
1481void
d038301c 1482yyerror(arg)
252b5132 1483 const char *arg;
d038301c 1484{
252b5132
RH
1485 if (ldfile_assumed_script)
1486 einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
dab69f68 1487 ldlex_filename ());
252b5132 1488 if (error_index > 0 && error_index < ERROR_NAME_MAX)
df5f2391 1489 einfo ("%F%P:%pS: %s in %s\n", NULL, arg, error_names[error_index - 1]);
252b5132 1490 else
df5f2391 1491 einfo ("%F%P:%pS: %s\n", NULL, arg);
252b5132 1492}