25cc0f377d7e762e0910c68198bc620e9f7be12f
[platform/upstream/binutils.git] / ld / ldgram.y
1 /* A YACC grammer to parse a superset of the AT&T linker scripting languaue.
2    Copyright (C) 1991 Free Software Foundation, Inc.
3    Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
4
5 This file is part of GNU ld.
6
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
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
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.
16
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
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21 %{
22 /*
23
24  */
25
26 #define DONTDECLARE_MALLOC
27
28 #include "bfd.h"
29 #include "sysdep.h"
30 #include "ld.h"    
31 #include "ldexp.h"
32 #include "ldver.h"
33 #include "ldlang.h"
34 #include "ldemul.h"
35 #include "ldfile.h"
36 #include "ldmisc.h"
37 #include "mri.h"
38
39 #define YYDEBUG 1
40
41 boolean option_v;
42 extern unsigned int lineno;
43 extern boolean trace_files;
44 extern boolean write_map;
45 extern boolean option_longmap;
46 extern int g_switch_value;
47 boolean hex_mode;
48 static int typebits;
49 strip_symbols_type strip_symbols=STRIP_NONE;
50 discard_locals_type discard_locals=DISCARD_NONE;
51
52
53 lang_memory_region_type *region;
54
55
56 lang_memory_region_type *lang_memory_region_lookup();
57 lang_output_section_statement_type *lang_output_section_statement_lookup();
58 etree_type *lang_atin();
59 #ifdef __STDC__
60
61 void lang_add_data(int type, union etree_union *exp);
62 void lang_enter_output_section_statement(char *output_section_statement_name, etree_type *address_exp, int flags, bfd_vma block_value,etree_type*,etree_type*, etree_type*);
63
64 #else
65
66 void lang_add_data();
67 void lang_enter_output_section_statement();
68
69 #endif /* __STDC__ */
70
71 extern args_type command_line;
72 char *current_file;
73 boolean ldgram_want_filename = true;
74 boolean had_script = false;
75 boolean force_make_executable = false;
76
77 boolean ldgram_in_script = false;
78 boolean ldgram_had_equals = false;
79 /* LOCALS */
80
81
82 #define ERROR_NAME_MAX 20
83 static char *error_names[ERROR_NAME_MAX];
84 static int error_index;
85 #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
86 #define POP_ERROR()   error_index--;
87 %}
88 %union {
89   bfd_vma integer;
90   int voidval;
91   char *name;
92   int token;
93   union etree_union *etree;
94   struct sec *section;
95   struct lang_output_section_statement_struct *output_section_statement;
96   union  lang_statement_union **statement_ptr;
97   int lineno;
98   struct {
99     FILE *file;
100     char *name;
101     unsigned int lineno;
102   } state;
103
104   
105 }
106
107 %type <etree> exp  opt_exp_with_type  mustbe_exp opt_at
108 %type <integer> fill_opt
109 %type <name> memspec_opt
110 %token <integer> INT  
111 %token <name> NAME
112 %type  <integer> length
113
114 %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ  '=' LSHIFTEQ RSHIFTEQ   ANDEQ OREQ 
115 %right <token> '?' ':'
116 %left <token> OROR
117 %left <token>  ANDAND
118 %left <token> '|'
119 %left <token>  '^'
120 %left  <token> '&'
121 %left <token>  EQ NE
122 %left  <token> '<' '>' LE GE
123 %left  <token> LSHIFT RSHIFT
124
125 %left  <token> '+' '-'
126 %left  <token> '*' '/' '%'
127
128 /*%token <token> '+' '-' '*' '/' '%'*/
129 %right UNARY
130 %token END 
131 %left <token> '('
132 %token <token> ALIGN_K BLOCK LONG SHORT BYTE
133 %token SECTIONS  
134 %token '{' '}'
135 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
136 %token SIZEOF_HEADERS
137 %token INCLUDE
138 %token MEMORY  DEFSYMEND
139 %token NOLOAD DSECT COPY INFO OVERLAY
140 %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY 
141 %token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S OPTION_sort_common
142 %token OPTION_EB OPTION_EL OPTION_G OPTION_Gval
143 %token OPTION_format  OPTION_F OPTION_u OPTION_Bstatic OPTION_N
144 %token <integer> SIZEOF NEXT ADDR 
145 %token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X OPTION_defsym
146 %token OPTION_v OPTION_V OPTION_m OPTION_memul OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT  NOFLOAT 
147 %token OPTION_Map
148 %token OPTION_n OPTION_r OPTION_o OPTION_b  OPTION_R OPTION_relax
149 %token <name> OPTION_l OPTION_L OPTION_T OPTION_Aarch OPTION_Tfile  OPTION_Texp
150 %token <name> OPTION_y
151 %token OPTION_Ur 
152 %token ORIGIN FILL OPTION_g
153 %token LENGTH    CREATE_OBJECT_SYMBOLS INPUT OUTPUT  CONSTRUCTORS
154 %token OPTION_RETAIN_SYMBOLS_FILE ALIGNMOD AT
155
156 %type <token> assign_op 
157
158 %type <name>  filename
159
160
161 %token CHIP LIST SECT ABSOLUTE  LOAD NEWLINE ENDWORD ORDER NAMEWORD
162 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE
163
164 %{
165 ld_config_type config;
166 %}
167
168 %%
169
170 file:   command_line  { lang_final(); };
171
172
173 filename:  NAME;
174
175
176 command_line:
177                 command_line command_line_option
178         |
179         ;
180
181 command_line_option:
182                 OPTION_Bstatic { }
183         |       OPTION_v
184                         {       
185                         ldversion(0);
186                         option_v = true;
187                         }
188         |       OPTION_V
189                         {       
190                         ldversion(1);
191                         option_v = true;
192                         }
193         |       OPTION_t {
194                         trace_files = true;
195                         }
196         |     OPTION_Map  NAME
197                 {
198                 write_map = true;
199                 config.map_filename = $2;
200                 }
201         |       OPTION_m NAME
202                 {
203                   /* Ignore.  */
204                 }
205         |       OPTION_memul
206                 {
207                   /* Ignore.  */
208                 }
209         |       OPTION_M 
210                 {
211                   config.map_filename = "-";
212                 }
213         |       OPTION_n {
214                         config.magic_demand_paged = false;
215                         }
216         |       OPTION_N {
217                         config.text_read_only = false;
218                         config.magic_demand_paged = false;
219                         }
220         |       OPTION_s {
221                         strip_symbols = STRIP_ALL;
222                         }
223         |       OPTION_S {
224                         strip_symbols = STRIP_DEBUGGER;
225                         }
226         |       OPTION_u NAME {
227                         ldlang_add_undef($2);
228                 }
229             
230         |       OPTION_r {
231                         config.relocateable_output = true;
232                         config.build_constructors = false;
233                         config.magic_demand_paged = false;
234                         config.text_read_only = false;
235                         }
236         |       OPTION_Ur {
237                         config.relocateable_output = true;
238                         config.build_constructors = true;
239                         config.magic_demand_paged = false;
240                         config.text_read_only = false;
241                       }             
242         |       OPTION_o filename
243                         {
244                         lang_add_output($2); 
245                         }
246         |       OPTION_e NAME
247                         { lang_add_entry($2); 
248                         }
249         |       OPTION_X {
250                         discard_locals = DISCARD_L;
251                 }
252         |       OPTION_x {
253                         discard_locals = DISCARD_ALL;
254                 }
255
256         |       OPTION_noinhibit_exec
257                         {
258                         force_make_executable = true;
259                         }
260         |      OPTION_sort_common {
261         config.sort_common = true;
262       }
263         |      OPTION_d {
264                           command_line.force_common_definition = true;
265                         }
266
267         |      OPTION_relax {
268                           command_line.relax = true;
269                         }
270         |      OPTION_dc
271                          {
272                           command_line.force_common_definition = true;
273                         }
274         |       OPTION_g
275                         {
276                         /* Ignored */
277                         }
278         |       OPTION_dp
279                          {
280                           command_line.force_common_definition = true;
281                         }
282         |       OPTION_format NAME
283                    {
284                           lang_add_target($2);
285                    }
286         |       OPTION_Texp 
287                 { ldlex_expression();
288                         hex_mode  = 16; 
289                 } 
290                 INT
291                 {  ldlex_popstate();
292                         lang_section_start($1,exp_intop($3));
293                         hex_mode = 0; 
294                 }
295         |       OPTION_y
296                         {
297                         add_ysym($1);
298                         }
299         |       OPTION_Aarch 
300                 { 
301                         ldfile_add_arch($1); 
302                 }
303         |        OPTION_b NAME
304                         {
305                         lang_add_target($2);
306                         }
307         |       OPTION_L
308                         {
309                         ldfile_add_library_path($1);
310                         }
311         |       OPTION_F
312                 {
313                 /* Ignore */
314                 }
315         |       OPTION_c filename 
316                         { ldfile_open_command_file($2); } mri_script_file  END {  ldlex_command();}
317
318         |       OPTION_Tfile 
319                         { ldfile_open_command_file($1); } script_file
320                         END {  ldlex_command();}
321
322         |       OPTION_T filename 
323                         { ldfile_open_command_file($2); } script_file
324                 END {  ldlex_command();}
325
326         |       OPTION_l
327                         {
328                           lang_add_input_file($1,
329                                          lang_input_file_is_l_enum,
330                                          (char *)NULL);
331                         }
332         |       OPTION_R filename
333                         {
334                         lang_add_input_file($2,
335                                 lang_input_file_is_symbols_only_enum,
336                                 (char *)NULL);
337                         }
338
339         |       OPTION_defsym  { ldlex_defsym(); }
340                 NAME     '=' exp  DEFSYMEND { ldlex_popstate();
341                         lang_add_assignment(exp_assop($4,$3,$5));
342                         }
343         |       OPTION_RETAIN_SYMBOLS_FILE filename
344                 { lang_add_keepsyms_file ($2); }
345         |       OPTION_EB
346                 {
347                   /* FIXME: This is currently ignored.  It means
348                      ``produce a big-endian object file''.  It could
349                      be used to select an output format.  */
350                 }
351         |       OPTION_EL
352                 {
353                   /* FIXME: This is currently ignored.  It means
354                      ``produce a little-endian object file''.  It could
355                      be used to select an output format.  */
356                 }
357         |       OPTION_G NAME
358                 {
359                   g_switch_value = atoi ($2);
360                 }
361         |       OPTION_Gval
362                 {
363                   g_switch_value = yylval.integer;
364                 }
365         |       NAME
366                 {
367                   if (*$1 == '-')
368                     einfo("%P%F: illegal option -- %s\n", $1);
369                   else
370                     lang_add_input_file($1,lang_input_file_is_file_enum,
371                                         (char *)NULL);
372                 }
373         | '{' script_file '}'  
374         ;
375
376
377 /* SYNTAX WITHIN AN MRI SCRIPT FILE */  
378 mri_script_file:
379                 {       ldlex_mri_script();
380                         PUSH_ERROR("MRI style script");
381                 }
382              mri_script_lines
383                 {       ldlex_popstate(); 
384                         POP_ERROR();
385                 }
386         ;
387
388 mri_script_lines:
389                 mri_script_lines mri_script_command NEWLINE
390           |
391         ;
392
393 mri_script_command:
394                 CHIP  exp 
395         |       CHIP  exp ',' exp
396         |       NAME    {
397                         einfo("%P%F: unrecognised keyword in MRI style script '%s'\n",$1);
398                         }
399         |       LIST    {
400                         write_map = true;
401                         config.map_filename = "-";
402                         }
403         |       ORDER ordernamelist
404         |       ENDWORD 
405         |       PUBLIC NAME '=' exp 
406                         { mri_public($2, $4); }
407         |       PUBLIC NAME ',' exp 
408                         { mri_public($2, $4); }
409         |       PUBLIC NAME  exp 
410                         { mri_public($2, $3); }
411         |       FORMAT NAME
412                         { mri_format($2); }
413         |       SECT NAME ',' exp 
414                         { mri_output_section($2, $4);}
415         |       SECT NAME  exp
416                         { mri_output_section($2, $3);}
417         |       SECT NAME '=' exp
418                         { mri_output_section($2, $4);}
419         |       ALIGN_K NAME '=' exp
420                         { mri_align($2,$4); }
421         |       ALIGNMOD NAME '=' exp
422                         { mri_alignmod($2,$4); }
423         |       ABSOLUTE mri_abs_name_list
424         |       LOAD     mri_load_name_list
425         |       NAMEWORD NAME 
426                         { mri_name($2); }   
427         |       ALIAS NAME ',' NAME
428                         { mri_alias($2,$4,0);}
429         |       ALIAS NAME ',' INT
430                         { mri_alias($2,0,$4);}
431         |       BASE     exp
432                         { mri_base($2); }
433         |       TRUNCATE INT
434                 {  mri_truncate($2); }
435         |
436         ;
437
438 ordernamelist:
439               ordernamelist ',' NAME         { mri_order($3); }
440         |     ordernamelist  NAME         { mri_order($2); }
441         |
442         ;
443
444 mri_load_name_list:
445                 NAME
446                         { mri_load($1); }
447         |       mri_load_name_list ',' NAME { mri_load($3); }
448         ;
449
450 mri_abs_name_list:
451                 NAME
452                         { mri_only_load($1); }
453         |       mri_abs_name_list ','  NAME
454                         { mri_only_load($3); }
455         ;
456
457 script_file:
458         {
459          ldlex_both();
460         }
461        ifile_list
462         {
463         ldlex_popstate();
464         }
465         ;
466
467
468 ifile_list:
469        ifile_list ifile_p1
470         |
471         ;
472
473
474
475 ifile_p1:
476                 memory
477         |       sections
478         |       startup
479         |       high_level_library
480         |       low_level_library
481         |       floating_point_support
482         |       statement_anywhere
483         |        ';'
484         |       TARGET_K '(' NAME ')'
485                 { lang_add_target($3); }
486         |       SEARCH_DIR '(' filename ')'
487                 { ldfile_add_library_path($3); }
488         |       OUTPUT '(' filename ')'
489                 { lang_add_output($3); }
490         | OUTPUT_FORMAT '(' NAME ')'
491                   { lang_add_output_format($3); }
492         | OUTPUT_ARCH '(' NAME ')'
493                   { ldfile_set_output_arch($3); }
494         |       FORCE_COMMON_ALLOCATION
495                 { command_line.force_common_definition = true ; }
496         |       INPUT '(' input_list ')'
497         |       MAP '(' filename ')'
498                 { lang_add_map($3); }
499         |       INCLUDE filename 
500                 { ldfile_open_command_file($2); } ifile_list END
501         ;
502
503 input_list:
504                 NAME
505                 { lang_add_input_file($1,lang_input_file_is_file_enum,
506                                  (char *)NULL); }
507         |       input_list ',' NAME
508                 { lang_add_input_file($3,lang_input_file_is_file_enum,
509                                  (char *)NULL); }
510         |       input_list NAME
511                 { lang_add_input_file($2,
512 lang_input_file_is_file_enum,
513                                  (char *)NULL); }
514         ;
515
516 sections:
517                 SECTIONS '{' sec_or_group_p1 '}'
518         ;
519
520 sec_or_group_p1:
521                 sec_or_group_p1 section
522         |       sec_or_group_p1 statement_anywhere
523         |
524         ;
525
526 statement_anywhere:
527                 ENTRY '(' NAME ')'
528                 { lang_add_entry($3); }
529         |       assignment end
530         ;
531
532 file_NAME_list:
533                 NAME
534                         { lang_add_wild($1, current_file); }
535         |       file_NAME_list opt_comma NAME
536                         { lang_add_wild($3, current_file); }
537         ;
538
539 input_section_spec:
540                 NAME
541                 {
542                 lang_add_wild((char *)NULL, $1);
543                 }
544         |       '['
545                         {
546                         current_file = (char *)NULL;
547                         }
548                         file_NAME_list
549                 ']'
550         |       NAME
551                         {
552                         current_file =$1;
553                         }
554                 '(' file_NAME_list ')'
555         |       '*'
556                         {
557                         current_file = (char *)NULL;
558                         }
559                 '(' file_NAME_list ')'
560         ;
561
562 statement:
563                 assignment end
564         |       CREATE_OBJECT_SYMBOLS
565                 {
566                 lang_add_attribute(lang_object_symbols_statement_enum); 
567                 }
568         |       ';'
569         |       CONSTRUCTORS
570                 {
571                 
572                   lang_add_attribute(lang_constructors_statement_enum); 
573                 }
574         | input_section_spec
575         | length '(' exp ')'
576                         {
577                         lang_add_data($1,$3);
578                         }
579   
580         | FILL '(' exp ')'
581                         {
582                           lang_add_fill
583                             (exp_get_value_int($3,
584                                                0,
585                                                "fill value",
586                                                lang_first_phase_enum));
587                         }
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                 LONG
602                         { $$ = $1; }
603         |       SHORT
604                         { $$ = $1; }
605         |       BYTE
606                         { $$ = $1; }
607         ;
608
609 fill_opt:
610           '=' mustbe_exp
611                 {
612                   $$ =   exp_get_value_int($2,
613                                            0,
614                                            "fill value",
615                                            lang_first_phase_enum);
616                 }
617         |       { $$ = 0; }
618         ;
619
620                 
621
622 assign_op:
623                 PLUSEQ
624                         { $$ = '+'; }
625         |       MINUSEQ
626                         { $$ = '-'; }
627         |       MULTEQ
628                         { $$ = '*'; }
629         |       DIVEQ
630                         { $$ = '/'; }
631         |       LSHIFTEQ
632                         { $$ = LSHIFT; }
633         |       RSHIFTEQ
634                         { $$ = RSHIFT; }
635         |       ANDEQ
636                         { $$ = '&'; }
637         |       OREQ
638                         { $$ = '|'; }
639
640         ;
641
642 end:    ';' | ','
643         ;
644
645
646 assignment:
647                 NAME '=' mustbe_exp
648                 {
649                   lang_add_assignment(exp_assop($2,$1,$3));
650                 }
651         |       NAME assign_op mustbe_exp
652                 {
653                 
654 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
655                 }
656                 
657         ;
658
659
660 opt_comma:
661                 ','     |       ;
662
663
664 memory:
665                 MEMORY '{' memory_spec memory_spec_list '}'
666         ;
667
668 memory_spec_list:
669                 memory_spec_list memory_spec
670         |       memory_spec_list ',' memory_spec
671         |
672         ;
673
674
675 memory_spec:            NAME
676                         { region = lang_memory_region_lookup($1); }
677                 attributes_opt ':'
678                 origin_spec opt_comma length_spec
679
680         ; origin_spec:
681         ORIGIN '=' mustbe_exp
682                 { region->current =
683                  region->origin =
684                  exp_get_vma($3, 0L,"origin", lang_first_phase_enum);
685 }
686         ; length_spec:
687              LENGTH '=' mustbe_exp
688                { region->length = exp_get_vma($3,
689                                                ~((bfd_vma)0),
690                                                "length",
691                                                lang_first_phase_enum);
692                 }
693         
694
695 attributes_opt:
696                   '(' NAME ')'
697                         {
698                         lang_set_flags(&region->flags, $2);
699                         }
700         |
701   
702         ;
703
704 startup:
705         STARTUP '(' filename ')'
706                 { lang_startup($3); }
707         ;
708
709 high_level_library:
710                 HLL '(' high_level_library_NAME_list ')'
711         |       HLL '(' ')'
712                         { ldemul_hll((char *)NULL); }
713         ;
714
715 high_level_library_NAME_list:
716                 high_level_library_NAME_list opt_comma filename
717                         { ldemul_hll($3); }
718         |       filename
719                         { ldemul_hll($1); }
720
721         ;
722
723 low_level_library:
724         SYSLIB '(' low_level_library_NAME_list ')'
725         ; low_level_library_NAME_list:
726                 low_level_library_NAME_list opt_comma filename
727                         { ldemul_syslib($3); }
728         |
729         ;
730
731 floating_point_support:
732                 FLOAT
733                         { lang_float(true); }
734         |       NOFLOAT
735                         { lang_float(false); }
736         ;
737                 
738
739 mustbe_exp:              { ldlex_expression(); }
740                 exp
741                          { ldlex_popstate(); $$=$2;}
742         ;
743
744 exp     :
745                 '-' exp %prec UNARY
746                         { $$ = exp_unop('-', $2); }
747         |       '(' exp ')'
748                         { $$ = $2; }
749         |       NEXT '(' exp ')' %prec UNARY
750                         { $$ = exp_unop($1,$3); }
751         |       '!' exp %prec UNARY
752                         { $$ = exp_unop('!', $2); }
753         |       '+' exp %prec UNARY
754                         { $$ = $2; }
755         |       '~' exp %prec UNARY
756                         { $$ = exp_unop('~', $2);}
757
758         |       exp '*' exp
759                         { $$ = exp_binop('*', $1, $3); }
760         |       exp '/' exp
761                         { $$ = exp_binop('/', $1, $3); }
762         |       exp '%' exp
763                         { $$ = exp_binop('%', $1, $3); }
764         |       exp '+' exp
765                         { $$ = exp_binop('+', $1, $3); }
766         |       exp '-' exp
767                         { $$ = exp_binop('-' , $1, $3); }
768         |       exp LSHIFT exp
769                         { $$ = exp_binop(LSHIFT , $1, $3); }
770         |       exp RSHIFT exp
771                         { $$ = exp_binop(RSHIFT , $1, $3); }
772         |       exp EQ exp
773                         { $$ = exp_binop(EQ , $1, $3); }
774         |       exp NE exp
775                         { $$ = exp_binop(NE , $1, $3); }
776         |       exp LE exp
777                         { $$ = exp_binop(LE , $1, $3); }
778         |       exp GE exp
779                         { $$ = exp_binop(GE , $1, $3); }
780         |       exp '<' exp
781                         { $$ = exp_binop('<' , $1, $3); }
782         |       exp '>' exp
783                         { $$ = exp_binop('>' , $1, $3); }
784         |       exp '&' exp
785                         { $$ = exp_binop('&' , $1, $3); }
786         |       exp '^' exp
787                         { $$ = exp_binop('^' , $1, $3); }
788         |       exp '|' exp
789                         { $$ = exp_binop('|' , $1, $3); }
790         |       exp '?' exp ':' exp
791                         { $$ = exp_trinop('?' , $1, $3, $5); }
792         |       exp ANDAND exp
793                         { $$ = exp_binop(ANDAND , $1, $3); }
794         |       exp OROR exp
795                         { $$ = exp_binop(OROR , $1, $3); }
796         |       DEFINED '(' NAME ')'
797                         { $$ = exp_nameop(DEFINED, $3); }
798         |       INT
799                         { $$ = exp_intop($1); }
800         |       SIZEOF_HEADERS
801                         { $$ = exp_nameop(SIZEOF_HEADERS,0); }
802
803         |       SIZEOF '(' NAME ')'
804                         { $$ = exp_nameop(SIZEOF,$3); }
805         |       ADDR '(' NAME ')'
806                         { $$ = exp_nameop(ADDR,$3); }
807         |       ABSOLUTE '(' exp ')'
808                         { $$ = exp_unop(ABSOLUTE, $3); }
809         |       ALIGN_K '(' exp ')'
810                         { $$ = exp_unop(ALIGN_K,$3); }
811         |       NAME
812                         { $$ = exp_nameop(NAME,$1); }
813         ;
814
815
816 opt_at:
817                 AT '(' exp ')' { $$ = $3; }
818         |       { $$ = 0; }
819         ;
820
821 section:        NAME            { ldlex_expression(); }
822                 opt_exp_with_type 
823                 opt_at          { ldlex_popstate(); }
824                 '{'
825                         {
826                         lang_enter_output_section_statement($1,$3,typebits,0,0,0,$4);
827                         }
828                 statement_list_opt      
829                 '}' {ldlex_expression();} fill_opt memspec_opt
830                 {
831                   ldlex_popstate();
832                   lang_leave_output_section_statement($11, $12);
833                 }
834 opt_comma
835
836         ;
837
838 type:
839            NOLOAD  { typebits = SEC_NEVER_LOAD; }
840         |  DSECT   { typebits = 0; }
841         |  COPY    { typebits = 0; }
842         |  INFO    { typebits = 0; }
843         |  OVERLAY { typebits = 0; }
844         | { typebits = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; }
845         ;
846
847
848 opt_exp_with_type:
849                 exp ':'                 { $$ = $1; typebits =0;}
850         |       exp '(' type ')' ':'    { $$ = $1; }
851         |       ':'                     { $$= (etree_type *)NULL; typebits = 0; }
852         |       '(' type ')' ':'        { $$= (etree_type *)NULL;  }
853         ;
854
855 memspec_opt:
856                 '>' NAME
857                 { $$ = $2; }
858         |       { $$ = "*default*"; }
859         ;
860 %%
861 void
862 yyerror(arg) 
863 char *arg;
864
865   if (error_index> 0  && error_index < ERROR_NAME_MAX)
866      einfo("%P%F: %S syntax error in %s\n",error_names[error_index-1]);
867   else
868      einfo("%P%F: %S syntax error\n");
869 }