OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [gold/] [yyscript.y] - Blame information for rev 287

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 khays
/* yyscript.y -- linker script grammar for gold.  */
2
 
3
/* Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4
   Written by Ian Lance Taylor .
5
 
6
   This file is part of gold.
7
 
8
   This program is free software; you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation; either version 3 of the License, or
11
   (at your option) any later version.
12
 
13
   This program is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
   GNU General Public License for more details.
17
 
18
   You should have received a copy of the GNU General Public License
19
   along with this program; if not, write to the Free Software
20
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21
   MA 02110-1301, USA.  */
22
 
23
/* This is a bison grammar to parse a subset of the original GNU ld
24
   linker script language.  */
25
 
26
%{
27
 
28
#include "config.h"
29
 
30
#include 
31
#include 
32
#include 
33
#include 
34
 
35
#include "script-c.h"
36
 
37
%}
38
 
39
/* We need to use a pure parser because we might be multi-threaded.
40
   We pass some arguments through the parser to the lexer.  */
41
 
42
%pure-parser
43
 
44
%parse-param {void* closure}
45
%lex-param {void* closure}
46
 
47
/* Since we require bison anyhow, we take advantage of it.  */
48
 
49
%error-verbose
50
 
51
/* The values associated with tokens.  */
52
 
53
%union {
54
  /* A string.  */
55
  struct Parser_string string;
56
  /* A number.  */
57
  uint64_t integer;
58
  /* An expression.  */
59
  Expression_ptr expr;
60
  /* An output section header.  */
61
  struct Parser_output_section_header output_section_header;
62
  /* An output section trailer.  */
63
  struct Parser_output_section_trailer output_section_trailer;
64
  /* A section constraint.  */
65
  enum Section_constraint constraint;
66
  /* A complete input section specification.  */
67
  struct Input_section_spec input_section_spec;
68
  /* A list of wildcard specifications, with exclusions.  */
69
  struct Wildcard_sections wildcard_sections;
70
  /* A single wildcard specification.  */
71
  struct Wildcard_section wildcard_section;
72
  /* A list of strings.  */
73
  String_list_ptr string_list;
74
  /* Information for a program header.  */
75
  struct Phdr_info phdr_info;
76
  /* Used for version scripts and within VERSION {}.  */
77
  struct Version_dependency_list* deplist;
78
  struct Version_expression_list* versyms;
79
  struct Version_tree* versnode;
80
  enum Script_section_type section_type;
81
}
82
 
83
/* Operators, including a precedence table for expressions.  */
84
 
85
%right PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
86
%right '?' ':'
87
%left OROR
88
%left ANDAND
89
%left '|'
90
%left '^'
91
%left '&'
92
%left EQ NE
93
%left '<' '>' LE GE
94
%left LSHIFT RSHIFT
95
%left '+' '-'
96
%left '*' '/' '%'
97
 
98
/* A fake operator used to indicate unary operator precedence.  */
99
%right UNARY
100
 
101
/* Constants.  */
102
 
103
%token  STRING
104
%token  QUOTED_STRING
105
%token  INTEGER
106
 
107
/* Keywords.  This list is taken from ldgram.y and ldlex.l in the old
108
   GNU linker, with the keywords which only appear in MRI mode
109
   removed.  Not all these keywords are actually used in this grammar.
110
   In most cases the keyword is recognized as the token name in upper
111
   case.  The comments indicate where this is not the case.  */
112
 
113
%token ABSOLUTE
114
%token ADDR
115
%token ALIGN_K          /* ALIGN */
116
%token ALIGNOF
117
%token ASSERT_K         /* ASSERT */
118
%token AS_NEEDED
119
%token AT
120
%token BIND
121
%token BLOCK
122
%token BYTE
123
%token CONSTANT
124
%token CONSTRUCTORS
125
%token COPY
126
%token CREATE_OBJECT_SYMBOLS
127
%token DATA_SEGMENT_ALIGN
128
%token DATA_SEGMENT_END
129
%token DATA_SEGMENT_RELRO_END
130
%token DEFINED
131
%token DSECT
132
%token ENTRY
133
%token EXCLUDE_FILE
134
%token EXTERN
135
%token FILL
136
%token FLOAT
137
%token FORCE_COMMON_ALLOCATION
138
%token GLOBAL           /* global */
139
%token GROUP
140
%token HLL
141
%token INCLUDE
142
%token INHIBIT_COMMON_ALLOCATION
143
%token INFO
144
%token INPUT
145
%token KEEP
146
%token LEN
147
%token LENGTH           /* LENGTH, l, len */
148
%token LOADADDR
149
%token LOCAL            /* local */
150
%token LONG
151
%token MAP
152
%token MAX_K            /* MAX */
153
%token MEMORY
154
%token MIN_K            /* MIN */
155
%token NEXT
156
%token NOCROSSREFS
157
%token NOFLOAT
158
%token NOLOAD
159
%token ONLY_IF_RO
160
%token ONLY_IF_RW
161
%token ORG
162
%token ORIGIN           /* ORIGIN, o, org */
163
%token OUTPUT
164
%token OUTPUT_ARCH
165
%token OUTPUT_FORMAT
166
%token OVERLAY
167
%token PHDRS
168
%token PROVIDE
169
%token PROVIDE_HIDDEN
170
%token QUAD
171
%token SEARCH_DIR
172
%token SECTIONS
173
%token SEGMENT_START
174
%token SHORT
175
%token SIZEOF
176
%token SIZEOF_HEADERS   /* SIZEOF_HEADERS, sizeof_headers */
177
%token SORT_BY_ALIGNMENT
178
%token SORT_BY_NAME
179
%token SPECIAL
180
%token SQUAD
181
%token STARTUP
182
%token SUBALIGN
183
%token SYSLIB
184
%token TARGET_K         /* TARGET */
185
%token TRUNCATE
186
%token VERSIONK         /* VERSION */
187
 
188
/* Keywords, part 2.  These are keywords that are unique to gold,
189
   and not present in the old GNU linker.  As before, unless the
190
   comments say otherwise, the keyword is recognized as the token
191
   name in upper case. */
192
 
193
%token OPTION
194
 
195
/* Special tokens used to tell the grammar what type of tokens we are
196
   parsing.  The token stream always begins with one of these tokens.
197
   We do this because version scripts can appear embedded within
198
   linker scripts, and because --defsym uses the expression
199
   parser.  */
200
%token PARSING_LINKER_SCRIPT
201
%token PARSING_VERSION_SCRIPT
202
%token PARSING_DEFSYM
203
%token PARSING_DYNAMIC_LIST
204
 
205
/* Non-terminal types, where needed.  */
206
 
207
%type  parse_exp exp
208
%type  opt_at opt_align opt_subalign opt_fill
209
%type  section_header opt_address_and_section_type
210
%type  section_type
211
%type  section_trailer
212
%type  opt_constraint
213
%type  opt_phdr
214
%type  data_length
215
%type  input_section_no_keep
216
%type  wildcard_sections
217
%type  wildcard_file wildcard_section
218
%type  exclude_names
219
%type  wildcard_name
220
%type  phdr_type memory_attr
221
%type  phdr_info
222
%type  vers_defns
223
%type  vers_tag
224
%type  verdep
225
%type  string
226
 
227
%%
228
 
229
/* Read the special token to see what to read next.  */
230
top:
231
          PARSING_LINKER_SCRIPT linker_script
232
        | PARSING_VERSION_SCRIPT version_script
233
        | PARSING_DEFSYM defsym_expr
234
        | PARSING_DYNAMIC_LIST dynamic_list_expr
235
        ;
236
 
237
/* A file contains a list of commands.  */
238
linker_script:
239
          linker_script file_cmd
240
        | /* empty */
241
        ;
242
 
243
/* A command which may appear at top level of a linker script.  */
244
file_cmd:
245
          EXTERN '(' extern_name_list ')'
246
        | FORCE_COMMON_ALLOCATION
247
            { script_set_common_allocation(closure, 1); }
248
        | GROUP
249
            { script_start_group(closure); }
250
          '(' input_list ')'
251
            { script_end_group(closure); }
252
        | INHIBIT_COMMON_ALLOCATION
253
            { script_set_common_allocation(closure, 0); }
254
        | INPUT '(' input_list ')'
255
        | MEMORY '{' memory_defs '}'
256
        | OPTION '(' string ')'
257
            { script_parse_option(closure, $3.value, $3.length); }
258
        | OUTPUT_FORMAT '(' string ')'
259
            {
260
              if (!script_check_output_format(closure, $3.value, $3.length,
261
                                              NULL, 0, NULL, 0))
262
                YYABORT;
263
            }
264
        | OUTPUT_FORMAT '(' string ',' string ',' string ')'
265
            {
266
              if (!script_check_output_format(closure, $3.value, $3.length,
267
                                              $5.value, $5.length,
268
                                              $7.value, $7.length))
269
                YYABORT;
270
            }
271
        | PHDRS '{' phdrs_defs '}'
272
        | SEARCH_DIR '(' string ')'
273
            { script_add_search_dir(closure, $3.value, $3.length); }
274
        | SECTIONS '{'
275
            { script_start_sections(closure); }
276
          sections_block '}'
277
            { script_finish_sections(closure); }
278
        | TARGET_K '(' string ')'
279
            { script_set_target(closure, $3.value, $3.length); }
280
        | VERSIONK '{'
281
            { script_push_lex_into_version_mode(closure); }
282
          version_script '}'
283
            { script_pop_lex_mode(closure); }
284
        | file_or_sections_cmd
285
        | ignore_cmd
286
        | ';'
287
        ;
288
 
289
/* Top level commands which we ignore.  The GNU linker uses these to
290
   select the output format, but we don't offer a choice.  Ignoring
291
   these is more-or-less OK since most scripts simply explicitly
292
   choose the default.  */
293
ignore_cmd:
294
          OUTPUT_ARCH '(' string ')'
295
        ;
296
 
297
/* A list of external undefined symbols.  We put the lexer into
298
   expression mode so that commas separate names; this is what the GNU
299
   linker does.  */
300
 
301
extern_name_list:
302
            { script_push_lex_into_expression_mode(closure); }
303
          extern_name_list_body
304
            { script_pop_lex_mode(closure); }
305
        ;
306
 
307
extern_name_list_body:
308
          string
309
            { script_add_extern(closure, $1.value, $1.length); }
310
        | extern_name_list_body string
311
            { script_add_extern(closure, $2.value, $2.length); }
312
        | extern_name_list_body ',' string
313
            { script_add_extern(closure, $3.value, $3.length); }
314
        ;
315
 
316
/* A list of input file names.  */
317
input_list:
318
          input_list_element
319
        | input_list opt_comma input_list_element
320
        ;
321
 
322
/* An input file name.  */
323
input_list_element:
324
          string
325
            { script_add_file(closure, $1.value, $1.length); }
326
        | '-' STRING
327
            { script_add_library(closure, $2.value, $2.length); }
328
        | AS_NEEDED
329
            { script_start_as_needed(closure); }
330
          '(' input_list ')'
331
            { script_end_as_needed(closure); }
332
        ;
333
 
334
/* Commands in a SECTIONS block.  */
335
sections_block:
336
          sections_block section_block_cmd
337
        | /* empty */
338
        ;
339
 
340
/* A command which may appear within a SECTIONS block.  */
341
section_block_cmd:
342
          file_or_sections_cmd
343
        | string section_header
344
            { script_start_output_section(closure, $1.value, $1.length, &$2); }
345
          '{' section_cmds '}' section_trailer
346
            { script_finish_output_section(closure, &$7); }
347
        ;
348
 
349
/* The header of an output section in a SECTIONS block--everything
350
   after the name.  */
351
section_header:
352
            { script_push_lex_into_expression_mode(closure); }
353
          opt_address_and_section_type opt_at opt_align opt_subalign
354
            { script_pop_lex_mode(closure); }
355
          opt_constraint
356
            {
357
              $$.address = $2.address;
358
              $$.section_type = $2.section_type;
359
              $$.load_address = $3;
360
              $$.align = $4;
361
              $$.subalign = $5;
362
              $$.constraint = $7;
363
            }
364
        ;
365
 
366
/* The optional address followed by the optional section type.  This
367
   is a separate nonterminal to avoid a shift/reduce conflict on
368
   '(' in section_header.  */
369
 
370
opt_address_and_section_type:
371
        ':'
372
            {
373
              $$.address = NULL;
374
              $$.section_type = SCRIPT_SECTION_TYPE_NONE;
375
            }
376
        | '(' ')' ':'
377
            {
378
              $$.address = NULL;
379
              $$.section_type = SCRIPT_SECTION_TYPE_NONE;
380
            }
381
        | exp ':'
382
            {
383
              $$.address = $1;
384
              $$.section_type = SCRIPT_SECTION_TYPE_NONE;
385
            }
386
        | exp '(' ')' ':'
387
            {
388
              $$.address = $1;
389
              $$.section_type = SCRIPT_SECTION_TYPE_NONE;
390
            }
391
        | '(' section_type ')' ':'
392
            {
393
              $$.address = NULL;
394
              $$.section_type = $2;
395
            }
396
        | exp '(' section_type ')' ':'
397
            {
398
              $$.address = $1;
399
              $$.section_type = $3;
400
            }
401
        ;
402
 
403
/* We only support NOLOAD.  */
404
section_type:
405
        NOLOAD
406
            { $$ = SCRIPT_SECTION_TYPE_NOLOAD; }
407
        | DSECT
408
            {
409
              yyerror(closure, "DSECT section type is unsupported");
410
              $$ = SCRIPT_SECTION_TYPE_DSECT;
411
            }
412
        | COPY
413
            {
414
              yyerror(closure, "COPY section type is unsupported");
415
              $$ = SCRIPT_SECTION_TYPE_COPY;
416
            }
417
        | INFO
418
            {
419
              yyerror(closure, "INFO section type is unsupported");
420
              $$ = SCRIPT_SECTION_TYPE_INFO;
421
            }
422
        | OVERLAY
423
            {
424
              yyerror(closure, "OVERLAY section type is unsupported");
425
              $$ = SCRIPT_SECTION_TYPE_OVERLAY;
426
            }
427
        ;
428
 
429
/* The address at which an output section should be loaded.  */
430
opt_at:
431
          /* empty */
432
            { $$ = NULL; }
433
        | AT '(' exp ')'
434
            { $$ = $3; }
435
        ;
436
 
437
/* The alignment of an output section.  */
438
opt_align:
439
          /* empty */
440
            { $$ = NULL; }
441
        | ALIGN_K '(' exp ')'
442
            { $$ = $3; }
443
        ;
444
 
445
/* The input section alignment within an output section.  */
446
opt_subalign:
447
          /* empty */
448
            { $$ = NULL; }
449
        | SUBALIGN '(' exp ')'
450
            { $$ = $3; }
451
        ;
452
 
453
/* A section constraint.  */
454
opt_constraint:
455
          /* empty */
456
            { $$ = CONSTRAINT_NONE; }
457
        | ONLY_IF_RO
458
            { $$ = CONSTRAINT_ONLY_IF_RO; }
459
        | ONLY_IF_RW
460
            { $$ = CONSTRAINT_ONLY_IF_RW; }
461
        | SPECIAL
462
            { $$ = CONSTRAINT_SPECIAL; }
463
        ;
464
 
465
/* The trailer of an output section in a SECTIONS block.  */
466
section_trailer:
467
          opt_memspec opt_at_memspec opt_phdr opt_fill opt_comma
468
            {
469
              $$.fill = $4;
470
              $$.phdrs = $3;
471
            }
472
        ;
473
 
474
/* A memory specification for an output section.  */
475
opt_memspec:
476
          '>' string
477
            { script_set_section_region(closure, $2.value, $2.length, 1); }
478
        | /* empty */
479
        ;
480
 
481
/* A memory specification for where to load an output section.  */
482
opt_at_memspec:
483
          AT '>' string
484
            { script_set_section_region(closure, $3.value, $3.length, 0); }
485
        | /* empty */
486
        ;
487
 
488
/* The program segment an output section should go into.  */
489
opt_phdr:
490
          opt_phdr ':' string
491
            { $$ = script_string_list_push_back($1, $3.value, $3.length); }
492
        | /* empty */
493
            { $$ = NULL; }
494
        ;
495
 
496
/* The value to use to fill an output section.  FIXME: This does not
497
   handle a string of arbitrary length.  */
498
opt_fill:
499
          '=' parse_exp
500
            { $$ = $2; }
501
        | /* empty */
502
            { $$ = NULL; }
503
        ;
504
 
505
/* Commands which may appear within the description of an output
506
   section in a SECTIONS block.  */
507
section_cmds:
508
          /* empty */
509
        | section_cmds section_cmd
510
        ;
511
 
512
/* A command which may appear within the description of an output
513
   section in a SECTIONS block.  */
514
section_cmd:
515
          assignment end
516
        | input_section_spec
517
        | data_length '(' parse_exp ')'
518
            { script_add_data(closure, $1, $3); }
519
        | ASSERT_K '(' parse_exp ',' string ')'
520
            { script_add_assertion(closure, $3, $5.value, $5.length); }
521
        | FILL '(' parse_exp ')'
522
            { script_add_fill(closure, $3); }
523
        | CONSTRUCTORS
524
            {
525
              /* The GNU linker uses CONSTRUCTORS for the a.out object
526
                 file format.  It does nothing when using ELF.  Since
527
                 some ELF linker scripts use it although it does
528
                 nothing, we accept it and ignore it.  */
529
            }
530
        | SORT_BY_NAME '(' CONSTRUCTORS ')'
531 163 khays
        | INCLUDE string
532
            { script_include_directive(closure, $2.value, $2.length); }
533 27 khays
        | ';'
534
        ;
535
 
536
/* The length of data which may appear within the description of an
537
   output section in a SECTIONS block.  */
538
data_length:
539
          QUAD
540
            { $$ = QUAD; }
541
        | SQUAD
542
            { $$ = SQUAD; }
543
        | LONG
544
            { $$ = LONG; }
545
        | SHORT
546
            { $$ = SHORT; }
547
        | BYTE
548
            { $$ = BYTE; }
549
        ;
550
 
551
/* An input section specification.  This may appear within the
552
   description of an output section in a SECTIONS block.  */
553
input_section_spec:
554
          input_section_no_keep
555
            { script_add_input_section(closure, &$1, 0); }
556
        | KEEP '(' input_section_no_keep ')'
557
            { script_add_input_section(closure, &$3, 1); }
558
        ;
559
 
560
/* An input section specification within a KEEP clause.  */
561
input_section_no_keep:
562
          string
563
            {
564
              $$.file.name = $1;
565
              $$.file.sort = SORT_WILDCARD_NONE;
566
              $$.input_sections.sections = NULL;
567
              $$.input_sections.exclude = NULL;
568
            }
569
        | wildcard_file '(' wildcard_sections ')'
570
            {
571
              $$.file = $1;
572
              $$.input_sections = $3;
573
            }
574
        ;
575
 
576
/* A wildcard file specification.  */
577
wildcard_file:
578
          wildcard_name
579
            {
580
              $$.name = $1;
581
              $$.sort = SORT_WILDCARD_NONE;
582
            }
583
        | SORT_BY_NAME '(' wildcard_name ')'
584
            {
585
              $$.name = $3;
586
              $$.sort = SORT_WILDCARD_BY_NAME;
587
            }
588
        ;
589
 
590
/* A list of wild card section specifications.  */
591
wildcard_sections:
592
          wildcard_sections opt_comma wildcard_section
593
            {
594
              $$.sections = script_string_sort_list_add($1.sections, &$3);
595
              $$.exclude = $1.exclude;
596
            }
597
        | wildcard_section
598
            {
599
              $$.sections = script_new_string_sort_list(&$1);
600
              $$.exclude = NULL;
601
            }
602
        | wildcard_sections opt_comma EXCLUDE_FILE '(' exclude_names ')'
603
            {
604
              $$.sections = $1.sections;
605
              $$.exclude = script_string_list_append($1.exclude, $5);
606
            }
607
        | EXCLUDE_FILE '(' exclude_names ')'
608
            {
609
              $$.sections = NULL;
610
              $$.exclude = $3;
611
            }
612
        ;
613
 
614
/* A single wild card specification.  */
615
wildcard_section:
616
          wildcard_name
617
            {
618
              $$.name = $1;
619
              $$.sort = SORT_WILDCARD_NONE;
620
            }
621
        | SORT_BY_NAME '(' wildcard_section ')'
622
            {
623
              $$.name = $3.name;
624
              switch ($3.sort)
625
                {
626
                case SORT_WILDCARD_NONE:
627
                  $$.sort = SORT_WILDCARD_BY_NAME;
628
                  break;
629
                case SORT_WILDCARD_BY_NAME:
630
                case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
631
                  break;
632
                case SORT_WILDCARD_BY_ALIGNMENT:
633
                case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
634
                  $$.sort = SORT_WILDCARD_BY_NAME_BY_ALIGNMENT;
635
                  break;
636
                default:
637
                  abort();
638
                }
639
            }
640
        | SORT_BY_ALIGNMENT '(' wildcard_section ')'
641
            {
642
              $$.name = $3.name;
643
              switch ($3.sort)
644
                {
645
                case SORT_WILDCARD_NONE:
646
                  $$.sort = SORT_WILDCARD_BY_ALIGNMENT;
647
                  break;
648
                case SORT_WILDCARD_BY_ALIGNMENT:
649
                case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
650
                  break;
651
                case SORT_WILDCARD_BY_NAME:
652
                case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
653
                  $$.sort = SORT_WILDCARD_BY_ALIGNMENT_BY_NAME;
654
                  break;
655
                default:
656
                  abort();
657
                }
658
            }
659
        ;
660
 
661
/* A list of file names to exclude.  */
662
exclude_names:
663
          exclude_names opt_comma wildcard_name
664
            { $$ = script_string_list_push_back($1, $3.value, $3.length); }
665
        | wildcard_name
666
            { $$ = script_new_string_list($1.value, $1.length); }
667
        ;
668
 
669
/* A single wildcard name.  We recognize '*' and '?' specially since
670
   they are expression tokens.  */
671
wildcard_name:
672
          string
673
            { $$ = $1; }
674
        | '*'
675
            {
676
              $$.value = "*";
677
              $$.length = 1;
678
            }
679
        | '?'
680
            {
681
              $$.value = "?";
682
              $$.length = 1;
683
            }
684
        ;
685
 
686
/* A command which may appear at the top level of a linker script, or
687
   within a SECTIONS block.  */
688
file_or_sections_cmd:
689
          ENTRY '(' string ')'
690
            { script_set_entry(closure, $3.value, $3.length); }
691
        | assignment end
692
        | ASSERT_K '(' parse_exp ',' string ')'
693
            { script_add_assertion(closure, $3, $5.value, $5.length); }
694 163 khays
        | INCLUDE string
695
            { script_include_directive(closure, $2.value, $2.length); }
696 27 khays
        ;
697
 
698
/* A list of MEMORY definitions.  */
699
memory_defs:
700
          memory_defs opt_comma memory_def
701
        | /* empty */
702
        ;
703
 
704
/* A single MEMORY definition.  */
705
memory_def:
706
          string memory_attr ':' memory_origin '=' parse_exp opt_comma memory_length '=' parse_exp
707
          { script_add_memory(closure, $1.value, $1.length, $2, $6, $10); }
708
        |
709
          /* LD supports an INCLUDE directive here, currently GOLD does not.  */
710
          INCLUDE string
711
          { script_include_directive(closure, $2.value, $2.length); }
712
        |
713
        ;
714
 
715
/* The (optional) attributes of a MEMORY region.  */
716
memory_attr:
717
          '(' string ')'
718
          { $$ = script_parse_memory_attr(closure, $2.value, $2.length, 0); }
719
        | /* Inverted attributes. */
720
          '(' '!' string ')'
721
          { $$ = script_parse_memory_attr(closure, $3.value, $3.length, 1); }
722
        | /* empty */
723
            { $$ = 0; }
724
        ;
725
 
726
memory_origin:
727
          ORIGIN
728
        |
729
          ORG
730
        |
731
          'o'
732
        ;
733
 
734
memory_length:
735
          LENGTH
736
        |
737
          LEN
738
        |
739
          'l'
740
        ;
741
 
742
/* A list of program header definitions.  */
743
phdrs_defs:
744
          phdrs_defs phdr_def
745
        | /* empty */
746
        ;
747
 
748
/* A program header definition.  */
749
phdr_def:
750
          string phdr_type phdr_info ';'
751
            { script_add_phdr(closure, $1.value, $1.length, $2, &$3); }
752
        ;
753
 
754
/* A program header type.  The GNU linker accepts a general expression
755
   here, but that would be a pain because we would have to dig into
756
   the expression structure.  It's unlikely that anybody uses anything
757
   other than a string or a number here, so that is all we expect.  */
758
phdr_type:
759
          string
760
            { $$ = script_phdr_string_to_type(closure, $1.value, $1.length); }
761
        | INTEGER
762
            { $$ = $1; }
763
        ;
764
 
765
/* Additional information for a program header.  */
766
phdr_info:
767
          /* empty */
768
            { memset(&$$, 0, sizeof(struct Phdr_info)); }
769
        | string phdr_info
770
            {
771
              $$ = $2;
772
              if ($1.length == 7 && strncmp($1.value, "FILEHDR", 7) == 0)
773
                $$.includes_filehdr = 1;
774
              else
775
                yyerror(closure, "PHDRS syntax error");
776
            }
777
        | PHDRS phdr_info
778
            {
779
              $$ = $2;
780
              $$.includes_phdrs = 1;
781
            }
782
        | string '(' INTEGER ')' phdr_info
783
            {
784
              $$ = $5;
785
              if ($1.length == 5 && strncmp($1.value, "FLAGS", 5) == 0)
786
                {
787
                  $$.is_flags_valid = 1;
788
                  $$.flags = $3;
789
                }
790
              else
791
                yyerror(closure, "PHDRS syntax error");
792
            }
793
        | AT '(' parse_exp ')' phdr_info
794
            {
795
              $$ = $5;
796
              $$.load_address = $3;
797
            }
798
        ;
799
 
800
/* Set a symbol to a value.  */
801
assignment:
802
          string '=' parse_exp
803
            { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
804
        | string PLUSEQ parse_exp
805
            {
806
              Expression_ptr s = script_exp_string($1.value, $1.length);
807
              Expression_ptr e = script_exp_binary_add(s, $3);
808
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
809
            }
810
        | string MINUSEQ parse_exp
811
            {
812
              Expression_ptr s = script_exp_string($1.value, $1.length);
813
              Expression_ptr e = script_exp_binary_sub(s, $3);
814
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
815
            }
816
        | string MULTEQ parse_exp
817
            {
818
              Expression_ptr s = script_exp_string($1.value, $1.length);
819
              Expression_ptr e = script_exp_binary_mult(s, $3);
820
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
821
            }
822
        | string DIVEQ parse_exp
823
            {
824
              Expression_ptr s = script_exp_string($1.value, $1.length);
825
              Expression_ptr e = script_exp_binary_div(s, $3);
826
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
827
            }
828
        | string LSHIFTEQ parse_exp
829
            {
830
              Expression_ptr s = script_exp_string($1.value, $1.length);
831
              Expression_ptr e = script_exp_binary_lshift(s, $3);
832
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
833
            }
834
        | string RSHIFTEQ parse_exp
835
            {
836
              Expression_ptr s = script_exp_string($1.value, $1.length);
837
              Expression_ptr e = script_exp_binary_rshift(s, $3);
838
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
839
            }
840
        | string ANDEQ parse_exp
841
            {
842
              Expression_ptr s = script_exp_string($1.value, $1.length);
843
              Expression_ptr e = script_exp_binary_bitwise_and(s, $3);
844
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
845
            }
846
        | string OREQ parse_exp
847
            {
848
              Expression_ptr s = script_exp_string($1.value, $1.length);
849
              Expression_ptr e = script_exp_binary_bitwise_or(s, $3);
850
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
851
            }
852
        | PROVIDE '(' string '=' parse_exp ')'
853
            { script_set_symbol(closure, $3.value, $3.length, $5, 1, 0); }
854
        | PROVIDE_HIDDEN '(' string '=' parse_exp ')'
855
            { script_set_symbol(closure, $3.value, $3.length, $5, 1, 1); }
856
        ;
857
 
858
/* Parse an expression, putting the lexer into the right mode.  */
859
parse_exp:
860
            { script_push_lex_into_expression_mode(closure); }
861
          exp
862
            {
863
              script_pop_lex_mode(closure);
864
              $$ = $2;
865
            }
866
        ;
867
 
868
/* An expression.  */
869
exp:
870
          '(' exp ')'
871
            { $$ = $2; }
872
        | '-' exp %prec UNARY
873
            { $$ = script_exp_unary_minus($2); }
874
        | '!' exp %prec UNARY
875
            { $$ = script_exp_unary_logical_not($2); }
876
        | '~' exp %prec UNARY
877
            { $$ = script_exp_unary_bitwise_not($2); }
878
        | '+' exp %prec UNARY
879
            { $$ = $2; }
880
        | exp '*' exp
881
            { $$ = script_exp_binary_mult($1, $3); }
882
        | exp '/' exp
883
            { $$ = script_exp_binary_div($1, $3); }
884
        | exp '%' exp
885
            { $$ = script_exp_binary_mod($1, $3); }
886
        | exp '+' exp
887
            { $$ = script_exp_binary_add($1, $3); }
888
        | exp '-' exp
889
            { $$ = script_exp_binary_sub($1, $3); }
890
        | exp LSHIFT exp
891
            { $$ = script_exp_binary_lshift($1, $3); }
892
        | exp RSHIFT exp
893
            { $$ = script_exp_binary_rshift($1, $3); }
894
        | exp EQ exp
895
            { $$ = script_exp_binary_eq($1, $3); }
896
        | exp NE exp
897
            { $$ = script_exp_binary_ne($1, $3); }
898
        | exp LE exp
899
            { $$ = script_exp_binary_le($1, $3); }
900
        | exp GE exp
901
            { $$ = script_exp_binary_ge($1, $3); }
902
        | exp '<' exp
903
            { $$ = script_exp_binary_lt($1, $3); }
904
        | exp '>' exp
905
            { $$ = script_exp_binary_gt($1, $3); }
906
        | exp '&' exp
907
            { $$ = script_exp_binary_bitwise_and($1, $3); }
908
        | exp '^' exp
909
            { $$ = script_exp_binary_bitwise_xor($1, $3); }
910
        | exp '|' exp
911
            { $$ = script_exp_binary_bitwise_or($1, $3); }
912
        | exp ANDAND exp
913
            { $$ = script_exp_binary_logical_and($1, $3); }
914
        | exp OROR exp
915
            { $$ = script_exp_binary_logical_or($1, $3); }
916
        | exp '?' exp ':' exp
917
            { $$ = script_exp_trinary_cond($1, $3, $5); }
918
        | INTEGER
919
            { $$ = script_exp_integer($1); }
920
        | string
921
            { $$ = script_symbol(closure, $1.value, $1.length); }
922
        | MAX_K '(' exp ',' exp ')'
923
            { $$ = script_exp_function_max($3, $5); }
924
        | MIN_K '(' exp ',' exp ')'
925
            { $$ = script_exp_function_min($3, $5); }
926
        | DEFINED '(' string ')'
927
            { $$ = script_exp_function_defined($3.value, $3.length); }
928
        | SIZEOF_HEADERS
929
            { $$ = script_exp_function_sizeof_headers(); }
930
        | ALIGNOF '(' string ')'
931
            { $$ = script_exp_function_alignof($3.value, $3.length); }
932
        | SIZEOF '(' string ')'
933
            { $$ = script_exp_function_sizeof($3.value, $3.length); }
934
        | ADDR '(' string ')'
935
            { $$ = script_exp_function_addr($3.value, $3.length); }
936
        | LOADADDR '(' string ')'
937
            { $$ = script_exp_function_loadaddr($3.value, $3.length); }
938
        | ORIGIN '(' string ')'
939
            { $$ = script_exp_function_origin(closure, $3.value, $3.length); }
940
        | LENGTH '(' string ')'
941
            { $$ = script_exp_function_length(closure, $3.value, $3.length); }
942
        | CONSTANT '(' string ')'
943
            { $$ = script_exp_function_constant($3.value, $3.length); }
944
        | ABSOLUTE '(' exp ')'
945
            { $$ = script_exp_function_absolute($3); }
946
        | ALIGN_K '(' exp ')'
947
            { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
948
        | ALIGN_K '(' exp ',' exp ')'
949
            { $$ = script_exp_function_align($3, $5); }
950
        | BLOCK '(' exp ')'
951
            { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
952
        | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
953
            {
954
              script_data_segment_align(closure);
955
              $$ = script_exp_function_data_segment_align($3, $5);
956
            }
957
        | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
958
            {
959
              script_data_segment_relro_end(closure);
960
              $$ = script_exp_function_data_segment_relro_end($3, $5);
961
            }
962
        | DATA_SEGMENT_END '(' exp ')'
963
            { $$ = script_exp_function_data_segment_end($3); }
964
        | SEGMENT_START '(' string ',' exp ')'
965
            {
966
              $$ = script_exp_function_segment_start($3.value, $3.length, $5);
967
              /* We need to take note of any SEGMENT_START expressions
968
                 because they change the behaviour of -Ttext, -Tdata and
969
                 -Tbss options.  */
970
              script_saw_segment_start_expression(closure);
971
            }
972
        | ASSERT_K '(' exp ',' string ')'
973
            { $$ = script_exp_function_assert($3, $5.value, $5.length); }
974
        ;
975
 
976
/* Handle the --defsym option.  */
977
defsym_expr:
978
          string '=' parse_exp
979
            { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
980
        ;
981
 
982
/* Handle the --dynamic-list option.  A dynamic list has the format
983
   { sym1; sym2; extern "C++" { namespace::sym3 }; };
984
   We store the symbol we see in the "local" list; that is where
985
   Command_line::in_dynamic_list() will look to do its check.
986
   TODO(csilvers): More than one of these brace-lists can appear, and
987
   should just be merged and treated as a single list.  */
988
dynamic_list_expr: dynamic_list_nodes ;
989
 
990
dynamic_list_nodes:
991
          dynamic_list_node
992
        | dynamic_list_nodes dynamic_list_node
993
        ;
994
 
995
dynamic_list_node:
996
          '{' vers_defns ';' '}' ';'
997
            { script_new_vers_node (closure, NULL, $2); }
998
        ;
999
 
1000
/* A version script.  */
1001
version_script:
1002
          vers_nodes
1003
        ;
1004
 
1005
vers_nodes:
1006
          vers_node
1007
        | vers_nodes vers_node
1008
        ;
1009
 
1010
vers_node:
1011
          '{' vers_tag '}' ';'
1012
            {
1013
              script_register_vers_node (closure, NULL, 0, $2, NULL);
1014
            }
1015
        | string '{' vers_tag '}' ';'
1016
            {
1017
              script_register_vers_node (closure, $1.value, $1.length, $3,
1018
                                         NULL);
1019
            }
1020
        | string '{' vers_tag '}' verdep ';'
1021
            {
1022
              script_register_vers_node (closure, $1.value, $1.length, $3, $5);
1023
            }
1024
        ;
1025
 
1026
verdep:
1027
          string
1028
            {
1029
              $$ = script_add_vers_depend (closure, NULL, $1.value, $1.length);
1030
            }
1031
        | verdep string
1032
            {
1033
              $$ = script_add_vers_depend (closure, $1, $2.value, $2.length);
1034
            }
1035
        ;
1036
 
1037
vers_tag:
1038
          /* empty */
1039
            { $$ = script_new_vers_node (closure, NULL, NULL); }
1040
        | vers_defns ';'
1041
            { $$ = script_new_vers_node (closure, $1, NULL); }
1042
        | GLOBAL ':' vers_defns ';'
1043
            { $$ = script_new_vers_node (closure, $3, NULL); }
1044
        | LOCAL ':' vers_defns ';'
1045
            { $$ = script_new_vers_node (closure, NULL, $3); }
1046
        | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
1047
            { $$ = script_new_vers_node (closure, $3, $7); }
1048
        ;
1049
 
1050
/* Here is one of the rare places we care about the distinction
1051
   between STRING and QUOTED_STRING.  For QUOTED_STRING, we do exact
1052
   matching on the pattern, so we pass in true for the exact_match
1053
   parameter.  For STRING, we do glob matching and pass in false.  */
1054
vers_defns:
1055
          STRING
1056
            {
1057
              $$ = script_new_vers_pattern (closure, NULL, $1.value,
1058
                                            $1.length, 0);
1059
            }
1060
        | QUOTED_STRING
1061
            {
1062
              $$ = script_new_vers_pattern (closure, NULL, $1.value,
1063
                                            $1.length, 1);
1064
            }
1065
        | vers_defns ';' STRING
1066
            {
1067
              $$ = script_new_vers_pattern (closure, $1, $3.value,
1068
                                            $3.length, 0);
1069
            }
1070
        | vers_defns ';' QUOTED_STRING
1071
            {
1072
              $$ = script_new_vers_pattern (closure, $1, $3.value,
1073
                                            $3.length, 1);
1074
            }
1075
        | /* Push string on the language stack. */
1076
          EXTERN string '{'
1077
            { version_script_push_lang (closure, $2.value, $2.length); }
1078
          vers_defns opt_semicolon '}'
1079
            {
1080
              $$ = $5;
1081
              version_script_pop_lang(closure);
1082
            }
1083
        | /* Push string on the language stack.  This is more complicated
1084
             than the other cases because we need to merge the linked-list
1085
             state from the pre-EXTERN defns and the post-EXTERN defns.  */
1086
          vers_defns ';' EXTERN string '{'
1087
            { version_script_push_lang (closure, $4.value, $4.length); }
1088
          vers_defns opt_semicolon '}'
1089
            {
1090
              $$ = script_merge_expressions ($1, $7);
1091
              version_script_pop_lang(closure);
1092
            }
1093
        | EXTERN  // "extern" as a symbol name
1094
            {
1095
              $$ = script_new_vers_pattern (closure, NULL, "extern",
1096
                                            sizeof("extern") - 1, 1);
1097
            }
1098
        | vers_defns ';' EXTERN
1099
            {
1100
              $$ = script_new_vers_pattern (closure, $1, "extern",
1101
                                            sizeof("extern") - 1, 1);
1102
            }
1103
        ;
1104
 
1105
/* A string can be either a STRING or a QUOTED_STRING.  Almost all the
1106
   time we don't care, and we use this rule.  */
1107
string:
1108
          STRING
1109
            { $$ = $1; }
1110
        | QUOTED_STRING
1111
            { $$ = $1; }
1112
        ;
1113
 
1114
/* Some statements require a terminator, which may be a semicolon or a
1115
   comma.  */
1116
end:
1117
          ';'
1118
        | ','
1119
        ;
1120
 
1121
/* An optional semicolon.  */
1122
opt_semicolon:
1123
          ';'
1124
        |  /* empty */
1125
        ;
1126
 
1127
/* An optional comma.  */
1128
opt_comma:
1129
          ','
1130
        | /* empty */
1131
        ;
1132
 
1133
%%

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.