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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [binutils-2.20.1/] [ld/] [ldgram.y] - Blame information for rev 438

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

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

powered by: WebSVN 2.1.0

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