[gdb/build] Add CXX_DIALECT to CXX
[deliverable/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
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); }
252b5132 425 | assignment end
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:
6c19b93b 666 assignment end
252b5132
RH
667 | CREATE_OBJECT_SYMBOLS
668 {
6c19b93b
AM
669 lang_add_attribute(lang_object_symbols_statement_enum);
670 }
671 | ';'
672 | CONSTRUCTORS
252b5132 673 {
d038301c
RM
674
675 lang_add_attribute(lang_constructors_statement_enum);
252b5132 676 }
bcaa7b3e 677 | SORT_BY_NAME '(' CONSTRUCTORS ')'
252b5132 678 {
f38a2680 679 constructors_sorted = true;
252b5132
RH
680 lang_add_attribute (lang_constructors_statement_enum);
681 }
682 | input_section_spec
6c19b93b
AM
683 | length '(' mustbe_exp ')'
684 {
685 lang_add_data ((int) $1, $3);
686 }
d038301c 687
2c382fb6 688 | FILL '(' fill_exp ')'
6c19b93b
AM
689 {
690 lang_add_fill ($3);
691 }
8545d1a9
NS
692 | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')' end
693 { ldlex_popstate ();
694 lang_add_assignment (exp_assert ($4, $6)); }
4006703d
NS
695 | INCLUDE filename
696 { ldlex_script (); ldfile_open_command_file($2); }
697 statement_list_opt END
698 { ldlex_popstate (); }
252b5132
RH
699 ;
700
701statement_list:
702 statement_list statement
6c19b93b 703 | statement
252b5132 704 ;
d038301c 705
252b5132
RH
706statement_list_opt:
707 /* empty */
708 | statement_list
709 ;
710
711length:
712 QUAD
713 { $$ = $1; }
714 | SQUAD
715 { $$ = $1; }
716 | LONG
717 { $$ = $1; }
6c19b93b 718 | SHORT
252b5132
RH
719 { $$ = $1; }
720 | BYTE
721 { $$ = $1; }
722 ;
723
2c382fb6
AM
724fill_exp:
725 mustbe_exp
252b5132 726 {
e9ee469a 727 $$ = exp_get_fill ($1, 0, "fill value");
252b5132 728 }
252b5132
RH
729 ;
730
2c382fb6
AM
731fill_opt:
732 '=' fill_exp
733 { $$ = $2; }
6c19b93b 734 | { $$ = (fill_type *) 0; }
2c382fb6 735 ;
252b5132
RH
736
737assign_op:
738 PLUSEQ
739 { $$ = '+'; }
740 | MINUSEQ
741 { $$ = '-'; }
6c19b93b 742 | MULTEQ
252b5132 743 { $$ = '*'; }
6c19b93b 744 | DIVEQ
252b5132 745 { $$ = '/'; }
6c19b93b 746 | LSHIFTEQ
252b5132 747 { $$ = LSHIFT; }
6c19b93b 748 | RSHIFTEQ
252b5132 749 { $$ = RSHIFT; }
6c19b93b 750 | ANDEQ
252b5132 751 { $$ = '&'; }
6c19b93b 752 | OREQ
252b5132
RH
753 { $$ = '|'; }
754
755 ;
756
757end: ';' | ','
758 ;
759
760
761assignment:
762 NAME '=' mustbe_exp
763 {
f38a2680 764 lang_add_assignment (exp_assign ($1, $3, false));
252b5132
RH
765 }
766 | NAME assign_op mustbe_exp
767 {
2e57b2af
AM
768 lang_add_assignment (exp_assign ($1,
769 exp_binop ($2,
770 exp_nameop (NAME,
771 $1),
f38a2680 772 $3), false));
eb8476a6
MR
773 }
774 | HIDDEN '(' NAME '=' mustbe_exp ')'
775 {
f38a2680 776 lang_add_assignment (exp_assign ($3, $5, true));
252b5132
RH
777 }
778 | PROVIDE '(' NAME '=' mustbe_exp ')'
779 {
f38a2680 780 lang_add_assignment (exp_provide ($3, $5, false));
7af8e998
L
781 }
782 | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
783 {
f38a2680 784 lang_add_assignment (exp_provide ($3, $5, true));
252b5132
RH
785 }
786 ;
787
788
789opt_comma:
790 ',' | ;
791
792
793memory:
4006703d 794 MEMORY '{' memory_spec_list_opt '}'
252b5132
RH
795 ;
796
4006703d
NS
797memory_spec_list_opt: memory_spec_list | ;
798
252b5132 799memory_spec_list:
4006703d
NS
800 memory_spec_list opt_comma memory_spec
801 | memory_spec
252b5132
RH
802 ;
803
804
6c19b93b 805memory_spec: NAME
f38a2680 806 { region = lang_memory_region_lookup ($1, true); }
252b5132
RH
807 attributes_opt ':'
808 origin_spec opt_comma length_spec
2d801b0f 809 {}
4006703d
NS
810 | INCLUDE filename
811 { ldlex_script (); ldfile_open_command_file($2); }
812 memory_spec_list_opt END
813 { ldlex_popstate (); }
74459f0e
TW
814 ;
815
816origin_spec:
252b5132 817 ORIGIN '=' mustbe_exp
e9ee469a 818 {
cc9ad334 819 region->origin_exp = $3;
e9ee469a 820 }
252b5132
RH
821 ;
822
823length_spec:
6c19b93b 824 LENGTH '=' mustbe_exp
e9ee469a 825 {
cc9ad334 826 region->length_exp = $3;
252b5132 827 }
aa8804e4 828 ;
252b5132
RH
829
830attributes_opt:
aa8804e4
ILT
831 /* empty */
832 { /* dummy action to avoid bison 1.25 error message */ }
833 | '(' attributes_list ')'
834 ;
835
836attributes_list:
837 attributes_string
838 | attributes_list attributes_string
839 ;
840
841attributes_string:
842 NAME
843 { lang_set_flags (region, $1, 0); }
844 | '!' NAME
845 { lang_set_flags (region, $2, 1); }
252b5132
RH
846 ;
847
848startup:
849 STARTUP '(' filename ')'
850 { lang_startup($3); }
851 ;
852
853high_level_library:
854 HLL '(' high_level_library_NAME_list ')'
855 | HLL '(' ')'
856 { ldemul_hll((char *)NULL); }
857 ;
858
859high_level_library_NAME_list:
860 high_level_library_NAME_list opt_comma filename
861 { ldemul_hll($3); }
862 | filename
863 { ldemul_hll($1); }
252b5132
RH
864 ;
865
866low_level_library:
867 SYSLIB '(' low_level_library_NAME_list ')'
a5f92c67
AM
868 ;
869
870low_level_library_NAME_list:
252b5132
RH
871 low_level_library_NAME_list opt_comma filename
872 { ldemul_syslib($3); }
873 |
874 ;
875
876floating_point_support:
877 FLOAT
f38a2680 878 { lang_float(true); }
252b5132 879 | NOFLOAT
f38a2680 880 { lang_float(false); }
252b5132 881 ;
d038301c 882
252b5132
RH
883nocrossref_list:
884 /* empty */
885 {
886 $$ = NULL;
887 }
888 | NAME nocrossref_list
889 {
890 struct lang_nocrossref *n;
891
892 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
893 n->name = $1;
894 n->next = $2;
895 $$ = n;
896 }
897 | NAME ',' nocrossref_list
898 {
899 struct lang_nocrossref *n;
900
901 n = (struct lang_nocrossref *) xmalloc (sizeof *n);
902 n->name = $1;
903 n->next = $3;
904 $$ = n;
905 }
906 ;
907
3ec57632 908mustbe_exp: { ldlex_expression (); }
252b5132 909 exp
3ec57632 910 { ldlex_popstate (); $$=$2;}
252b5132
RH
911 ;
912
913exp :
914 '-' exp %prec UNARY
3ec57632 915 { $$ = exp_unop ('-', $2); }
252b5132
RH
916 | '(' exp ')'
917 { $$ = $2; }
918 | NEXT '(' exp ')' %prec UNARY
3ec57632 919 { $$ = exp_unop ((int) $1,$3); }
252b5132 920 | '!' exp %prec UNARY
3ec57632 921 { $$ = exp_unop ('!', $2); }
252b5132
RH
922 | '+' exp %prec UNARY
923 { $$ = $2; }
924 | '~' exp %prec UNARY
3ec57632 925 { $$ = exp_unop ('~', $2);}
252b5132
RH
926
927 | exp '*' exp
3ec57632 928 { $$ = exp_binop ('*', $1, $3); }
252b5132 929 | exp '/' exp
3ec57632 930 { $$ = exp_binop ('/', $1, $3); }
252b5132 931 | exp '%' exp
3ec57632 932 { $$ = exp_binop ('%', $1, $3); }
252b5132 933 | exp '+' exp
3ec57632 934 { $$ = exp_binop ('+', $1, $3); }
252b5132 935 | exp '-' exp
3ec57632 936 { $$ = exp_binop ('-' , $1, $3); }
252b5132 937 | exp LSHIFT exp
3ec57632 938 { $$ = exp_binop (LSHIFT , $1, $3); }
252b5132 939 | exp RSHIFT exp
3ec57632 940 { $$ = exp_binop (RSHIFT , $1, $3); }
252b5132 941 | exp EQ exp
3ec57632 942 { $$ = exp_binop (EQ , $1, $3); }
252b5132 943 | exp NE exp
3ec57632 944 { $$ = exp_binop (NE , $1, $3); }
252b5132 945 | exp LE exp
3ec57632 946 { $$ = exp_binop (LE , $1, $3); }
6c19b93b 947 | exp GE exp
3ec57632 948 { $$ = exp_binop (GE , $1, $3); }
252b5132 949 | exp '<' exp
3ec57632 950 { $$ = exp_binop ('<' , $1, $3); }
252b5132 951 | exp '>' exp
3ec57632 952 { $$ = exp_binop ('>' , $1, $3); }
252b5132 953 | exp '&' exp
3ec57632 954 { $$ = exp_binop ('&' , $1, $3); }
252b5132 955 | exp '^' exp
3ec57632 956 { $$ = exp_binop ('^' , $1, $3); }
252b5132 957 | exp '|' exp
3ec57632 958 { $$ = exp_binop ('|' , $1, $3); }
252b5132 959 | exp '?' exp ':' exp
3ec57632 960 { $$ = exp_trinop ('?' , $1, $3, $5); }
252b5132 961 | exp ANDAND exp
3ec57632 962 { $$ = exp_binop (ANDAND , $1, $3); }
252b5132 963 | exp OROR exp
3ec57632 964 { $$ = exp_binop (OROR , $1, $3); }
252b5132 965 | DEFINED '(' NAME ')'
3ec57632 966 { $$ = exp_nameop (DEFINED, $3); }
252b5132 967 | INT
2c382fb6 968 { $$ = exp_bigintop ($1.integer, $1.str); }
6c19b93b 969 | SIZEOF_HEADERS
3ec57632 970 { $$ = exp_nameop (SIZEOF_HEADERS,0); }
252b5132 971
5d41b3ef
NS
972 | ALIGNOF '(' NAME ')'
973 { $$ = exp_nameop (ALIGNOF,$3); }
252b5132 974 | SIZEOF '(' NAME ')'
3ec57632 975 { $$ = exp_nameop (SIZEOF,$3); }
252b5132 976 | ADDR '(' NAME ')'
3ec57632 977 { $$ = exp_nameop (ADDR,$3); }
252b5132 978 | LOADADDR '(' NAME ')'
3ec57632 979 { $$ = exp_nameop (LOADADDR,$3); }
24718e3b
L
980 | CONSTANT '(' NAME ')'
981 { $$ = exp_nameop (CONSTANT,$3); }
252b5132 982 | ABSOLUTE '(' exp ')'
3ec57632 983 { $$ = exp_unop (ABSOLUTE, $3); }
252b5132 984 | ALIGN_K '(' exp ')'
3ec57632 985 { $$ = exp_unop (ALIGN_K,$3); }
876f4090 986 | ALIGN_K '(' exp ',' exp ')'
3ec57632 987 { $$ = exp_binop (ALIGN_K,$3,$5); }
2d20f7bf
JJ
988 | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
989 { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
a4f5ad88
JJ
990 | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
991 { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
2d20f7bf 992 | DATA_SEGMENT_END '(' exp ')'
3ec57632 993 { $$ = exp_unop (DATA_SEGMENT_END, $3); }
6c19b93b
AM
994 | SEGMENT_START '(' NAME ',' exp ')'
995 { /* The operands to the expression node are
ba916c8a
MM
996 placed in the opposite order from the way
997 in which they appear in the script as
998 that allows us to reuse more code in
999 fold_binary. */
1000 $$ = exp_binop (SEGMENT_START,
1001 $5,
1002 exp_nameop (NAME, $3)); }
252b5132 1003 | BLOCK '(' exp ')'
3ec57632 1004 { $$ = exp_unop (ALIGN_K,$3); }
252b5132 1005 | NAME
3ec57632 1006 { $$ = exp_nameop (NAME,$1); }
252b5132
RH
1007 | MAX_K '(' exp ',' exp ')'
1008 { $$ = exp_binop (MAX_K, $3, $5 ); }
1009 | MIN_K '(' exp ',' exp ')'
1010 { $$ = exp_binop (MIN_K, $3, $5 ); }
1011 | ASSERT_K '(' exp ',' NAME ')'
1012 { $$ = exp_assert ($3, $5); }
3ec57632
NC
1013 | ORIGIN '(' NAME ')'
1014 { $$ = exp_nameop (ORIGIN, $3); }
1015 | LENGTH '(' NAME ')'
1016 { $$ = exp_nameop (LENGTH, $3); }
2e53f7d6
NC
1017 | LOG2CEIL '(' exp ')'
1018 { $$ = exp_unop (LOG2CEIL, $3); }
252b5132
RH
1019 ;
1020
1021
562d3460 1022memspec_at_opt:
6c19b93b
AM
1023 AT '>' NAME { $$ = $3; }
1024 | { $$ = 0; }
1025 ;
562d3460 1026
252b5132
RH
1027opt_at:
1028 AT '(' exp ')' { $$ = $3; }
1029 | { $$ = 0; }
1030 ;
1031
bbf115d3
L
1032opt_align:
1033 ALIGN_K '(' exp ')' { $$ = $3; }
1034 | { $$ = 0; }
1035 ;
1036
1eec346e
NC
1037opt_align_with_input:
1038 ALIGN_WITH_INPUT { $$ = ALIGN_WITH_INPUT; }
1039 | { $$ = 0; }
1040 ;
1041
7e7d5768
AM
1042opt_subalign:
1043 SUBALIGN '(' exp ')' { $$ = $3; }
1044 | { $$ = 0; }
1045 ;
1046
0841712e
JJ
1047sect_constraint:
1048 ONLY_IF_RO { $$ = ONLY_IF_RO; }
1049 | ONLY_IF_RW { $$ = ONLY_IF_RW; }
0cf7d72c 1050 | SPECIAL { $$ = SPECIAL; }
0841712e
JJ
1051 | { $$ = 0; }
1052 ;
1053
6c19b93b 1054section: NAME { ldlex_expression(); }
d038301c 1055 opt_exp_with_type
7e7d5768 1056 opt_at
bbf115d3 1057 opt_align
1eec346e 1058 opt_align_with_input
7e7d5768 1059 opt_subalign { ldlex_popstate (); ldlex_script (); }
0841712e 1060 sect_constraint
252b5132
RH
1061 '{'
1062 {
1063 lang_enter_output_section_statement($1, $3,
1064 sectype,
1eec346e 1065 $5, $7, $4, $9, $6);
252b5132 1066 }
d038301c 1067 statement_list_opt
6c19b93b 1068 '}' { ldlex_popstate (); ldlex_expression (); }
562d3460 1069 memspec_opt memspec_at_opt phdr_opt fill_opt
252b5132 1070 {
40726f16
AM
1071 if (yychar == NAME)
1072 {
1073 yyclearin;
1074 ldlex_backup ();
1075 }
252b5132 1076 ldlex_popstate ();
1eec346e 1077 lang_leave_output_section_statement ($18, $15, $17, $16);
252b5132
RH
1078 }
1079 opt_comma
1080 | OVERLAY
1081 { ldlex_expression (); }
7e7d5768 1082 opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
252b5132 1083 { ldlex_popstate (); ldlex_script (); }
d038301c 1084 '{'
252b5132 1085 {
7e7d5768 1086 lang_enter_overlay ($3, $6);
252b5132
RH
1087 }
1088 overlay_section
1089 '}'
1090 { ldlex_popstate (); ldlex_expression (); }
562d3460 1091 memspec_opt memspec_at_opt phdr_opt fill_opt
252b5132 1092 {
40726f16
AM
1093 if (yychar == NAME)
1094 {
1095 yyclearin;
1096 ldlex_backup ();
1097 }
252b5132 1098 ldlex_popstate ();
9f88b410 1099 lang_leave_overlay ($5, (int) $4,
7e7d5768 1100 $16, $13, $15, $14);
252b5132
RH
1101 }
1102 opt_comma
1103 | /* The GROUP case is just enough to support the gcc
1104 svr3.ifile script. It is not intended to be full
1105 support. I'm not even sure what GROUP is supposed
1106 to mean. */
1107 GROUP { ldlex_expression (); }
1108 opt_exp_with_type
1109 {
1110 ldlex_popstate ();
f38a2680 1111 lang_add_assignment (exp_assign (".", $3, false));
252b5132
RH
1112 }
1113 '{' sec_or_group_p1 '}'
4006703d
NS
1114 | INCLUDE filename
1115 { ldlex_script (); ldfile_open_command_file($2); }
1116 sec_or_group_p1 END
1117 { ldlex_popstate (); }
252b5132
RH
1118 ;
1119
1120type:
1121 NOLOAD { sectype = noload_section; }
02a38f92
AM
1122 | DSECT { sectype = noalloc_section; }
1123 | COPY { sectype = noalloc_section; }
1124 | INFO { sectype = noalloc_section; }
1125 | OVERLAY { sectype = noalloc_section; }
252b5132
RH
1126 ;
1127
1128atype:
6c19b93b
AM
1129 '(' type ')'
1130 | /* EMPTY */ { sectype = normal_section; }
1131 | '(' ')' { sectype = normal_section; }
252b5132
RH
1132 ;
1133
1134opt_exp_with_type:
1135 exp atype ':' { $$ = $1; }
1136 | atype ':' { $$ = (etree_type *)NULL; }
1137 | /* The BIND cases are to support the gcc svr3.ifile
1138 script. They aren't intended to implement full
1139 support for the BIND keyword. I'm not even sure
1140 what BIND is supposed to mean. */
1141 BIND '(' exp ')' atype ':' { $$ = $3; }
1142 | BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
1143 { $$ = $3; }
1144 ;
1145
1146opt_exp_without_type:
1147 exp ':' { $$ = $1; }
1148 | ':' { $$ = (etree_type *) NULL; }
1149 ;
1150
1151opt_nocrossrefs:
1152 /* empty */
1153 { $$ = 0; }
1154 | NOCROSSREFS
1155 { $$ = 1; }
1156 ;
1157
1158memspec_opt:
1159 '>' NAME
1160 { $$ = $2; }
a747ee4d 1161 | { $$ = DEFAULT_MEMORY_REGION; }
252b5132
RH
1162 ;
1163
1164phdr_opt:
1165 /* empty */
1166 {
1167 $$ = NULL;
1168 }
1169 | phdr_opt ':' NAME
1170 {
1171 struct lang_output_section_phdr_list *n;
1172
1173 n = ((struct lang_output_section_phdr_list *)
1174 xmalloc (sizeof *n));
1175 n->name = $3;
f38a2680 1176 n->used = false;
252b5132
RH
1177 n->next = $1;
1178 $$ = n;
1179 }
1180 ;
1181
1182overlay_section:
1183 /* empty */
1184 | overlay_section
1185 NAME
1186 {
1187 ldlex_script ();
1188 lang_enter_overlay_section ($2);
1189 }
1190 '{' statement_list_opt '}'
1191 { ldlex_popstate (); ldlex_expression (); }
1192 phdr_opt fill_opt
1193 {
1194 ldlex_popstate ();
1195 lang_leave_overlay_section ($9, $8);
1196 }
1197 opt_comma
1198 ;
1199
1200phdrs:
1201 PHDRS '{' phdr_list '}'
1202 ;
1203
1204phdr_list:
1205 /* empty */
1206 | phdr_list phdr
1207 ;
1208
1209phdr:
1210 NAME { ldlex_expression (); }
1211 phdr_type phdr_qualifiers { ldlex_popstate (); }
1212 ';'
1213 {
1214 lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
1215 $4.flags);
1216 }
1217 ;
1218
1219phdr_type:
1220 exp
1221 {
1222 $$ = $1;
1223
1224 if ($1->type.node_class == etree_name
1225 && $1->type.node_code == NAME)
1226 {
1227 const char *s;
1228 unsigned int i;
1229 static const char * const phdr_types[] =
1230 {
1231 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
1232 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
d038301c 1233 "PT_PHDR", "PT_TLS"
252b5132
RH
1234 };
1235
1236 s = $1->name.name;
1237 for (i = 0;
1238 i < sizeof phdr_types / sizeof phdr_types[0];
1239 i++)
1240 if (strcmp (s, phdr_types[i]) == 0)
1241 {
1242 $$ = exp_intop (i);
1243 break;
1244 }
d038301c
RM
1245 if (i == sizeof phdr_types / sizeof phdr_types[0])
1246 {
1247 if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
1248 $$ = exp_intop (0x6474e550);
9ee5e499
JJ
1249 else if (strcmp (s, "PT_GNU_STACK") == 0)
1250 $$ = exp_intop (0x6474e551);
d038301c
RM
1251 else
1252 {
1253 einfo (_("\
c1c8c1ef 1254%X%P:%pS: unknown phdr type `%s' (try integer literal)\n"),
dab69f68 1255 NULL, s);
d038301c
RM
1256 $$ = exp_intop (0);
1257 }
1258 }
252b5132
RH
1259 }
1260 }
1261 ;
1262
1263phdr_qualifiers:
1264 /* empty */
1265 {
1266 memset (&$$, 0, sizeof (struct phdr_info));
1267 }
1268 | NAME phdr_val phdr_qualifiers
1269 {
1270 $$ = $3;
1271 if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
f38a2680 1272 $$.filehdr = true;
252b5132 1273 else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
f38a2680 1274 $$.phdrs = true;
252b5132
RH
1275 else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
1276 $$.flags = $2;
1277 else
c1c8c1ef 1278 einfo (_("%X%P:%pS: PHDRS syntax error at `%s'\n"),
dab69f68 1279 NULL, $1);
252b5132
RH
1280 }
1281 | AT '(' exp ')' phdr_qualifiers
1282 {
1283 $$ = $5;
1284 $$.at = $3;
1285 }
1286 ;
1287
1288phdr_val:
1289 /* empty */
1290 {
1291 $$ = NULL;
1292 }
1293 | '(' exp ')'
1294 {
1295 $$ = $2;
1296 }
1297 ;
1298
55255dae
L
1299dynamic_list_file:
1300 {
1301 ldlex_version_file ();
1302 PUSH_ERROR (_("dynamic list"));
1303 }
1304 dynamic_list_nodes
1305 {
1306 ldlex_popstate ();
1307 POP_ERROR ();
1308 }
1309 ;
1310
1311dynamic_list_nodes:
1312 dynamic_list_node
1313 | dynamic_list_nodes dynamic_list_node
1314 ;
1315
1316dynamic_list_node:
1317 '{' dynamic_list_tag '}' ';'
1318 ;
1319
1320dynamic_list_tag:
1321 vers_defns ';'
1322 {
37a141bf 1323 lang_append_dynamic_list (current_dynamic_list_p, $1);
55255dae
L
1324 }
1325 ;
1326
252b5132
RH
1327/* This syntax is used within an external version script file. */
1328
1329version_script_file:
1330 {
1331 ldlex_version_file ();
1332 PUSH_ERROR (_("VERSION script"));
1333 }
1334 vers_nodes
1335 {
1336 ldlex_popstate ();
1337 POP_ERROR ();
1338 }
1339 ;
1340
1341/* This is used within a normal linker script file. */
1342
1343version:
1344 {
1345 ldlex_version_script ();
1346 }
1347 VERSIONK '{' vers_nodes '}'
1348 {
1349 ldlex_popstate ();
1350 }
1351 ;
1352
1353vers_nodes:
1354 vers_node
1355 | vers_nodes vers_node
1356 ;
1357
1358vers_node:
6b9b879a
JJ
1359 '{' vers_tag '}' ';'
1360 {
1361 lang_register_vers_node (NULL, $2, NULL);
1362 }
1363 | VERS_TAG '{' vers_tag '}' ';'
252b5132
RH
1364 {
1365 lang_register_vers_node ($1, $3, NULL);
1366 }
1367 | VERS_TAG '{' vers_tag '}' verdep ';'
1368 {
1369 lang_register_vers_node ($1, $3, $5);
1370 }
1371 ;
1372
1373verdep:
1374 VERS_TAG
1375 {
1376 $$ = lang_add_vers_depend (NULL, $1);
1377 }
1378 | verdep VERS_TAG
1379 {
1380 $$ = lang_add_vers_depend ($1, $2);
1381 }
1382 ;
1383
1384vers_tag:
1385 /* empty */
1386 {
1387 $$ = lang_new_vers_node (NULL, NULL);
1388 }
1389 | vers_defns ';'
1390 {
1391 $$ = lang_new_vers_node ($1, NULL);
1392 }
1393 | GLOBAL ':' vers_defns ';'
1394 {
1395 $$ = lang_new_vers_node ($3, NULL);
1396 }
1397 | LOCAL ':' vers_defns ';'
1398 {
1399 $$ = lang_new_vers_node (NULL, $3);
1400 }
1401 | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1402 {
1403 $$ = lang_new_vers_node ($3, $7);
1404 }
1405 ;
1406
1407vers_defns:
1408 VERS_IDENTIFIER
1409 {
f38a2680 1410 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, false);
86043bbb 1411 }
6c19b93b 1412 | NAME
86043bbb 1413 {
f38a2680 1414 $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, true);
252b5132
RH
1415 }
1416 | vers_defns ';' VERS_IDENTIFIER
1417 {
f38a2680 1418 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, false);
86043bbb
MM
1419 }
1420 | vers_defns ';' NAME
1421 {
f38a2680 1422 $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, true);
252b5132 1423 }
8e23b15d
AM
1424 | vers_defns ';' EXTERN NAME '{'
1425 {
1426 $<name>$ = ldgram_vers_current_lang;
1427 ldgram_vers_current_lang = $4;
1428 }
1429 vers_defns opt_semicolon '}'
1430 {
96f8ade5
JJ
1431 struct bfd_elf_version_expr *pat;
1432 for (pat = $7; pat->next != NULL; pat = pat->next);
1433 pat->next = $1;
8e23b15d
AM
1434 $$ = $7;
1435 ldgram_vers_current_lang = $<name>6;
1436 }
252b5132
RH
1437 | EXTERN NAME '{'
1438 {
1439 $<name>$ = ldgram_vers_current_lang;
1440 ldgram_vers_current_lang = $2;
1441 }
8e23b15d 1442 vers_defns opt_semicolon '}'
252b5132 1443 {
e06cae36 1444 $$ = $5;
252b5132
RH
1445 ldgram_vers_current_lang = $<name>4;
1446 }
96f8ade5
JJ
1447 | GLOBAL
1448 {
f38a2680 1449 $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, false);
96f8ade5
JJ
1450 }
1451 | vers_defns ';' GLOBAL
1452 {
f38a2680 1453 $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, false);
96f8ade5
JJ
1454 }
1455 | LOCAL
1456 {
f38a2680 1457 $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, false);
96f8ade5
JJ
1458 }
1459 | vers_defns ';' LOCAL
1460 {
f38a2680 1461 $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, false);
96f8ade5
JJ
1462 }
1463 | EXTERN
1464 {
f38a2680 1465 $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, false);
96f8ade5
JJ
1466 }
1467 | vers_defns ';' EXTERN
1468 {
f38a2680 1469 $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, false);
96f8ade5 1470 }
252b5132
RH
1471 ;
1472
8e23b15d
AM
1473opt_semicolon:
1474 /* empty */
1475 | ';'
1476 ;
1477
252b5132
RH
1478%%
1479void
d038301c 1480yyerror(arg)
252b5132 1481 const char *arg;
d038301c 1482{
252b5132
RH
1483 if (ldfile_assumed_script)
1484 einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
dab69f68 1485 ldlex_filename ());
252b5132 1486 if (error_index > 0 && error_index < ERROR_NAME_MAX)
df5f2391 1487 einfo ("%F%P:%pS: %s in %s\n", NULL, arg, error_names[error_index - 1]);
252b5132 1488 else
df5f2391 1489 einfo ("%F%P:%pS: %s\n", NULL, arg);
252b5132 1490}
This page took 1.320706 seconds and 4 git commands to generate.