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