* ldfile.c (ldfile_open_command): Don't try .ld extension.
[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                  { einfo("%P%F illegal option -- %s\n", $2);  }
367         |       NAME
368                 { lang_add_input_file($1,lang_input_file_is_file_enum,
369                                  (char *)NULL); }
370         | '{' script_file '}'  
371         ;
372
373
374 /* SYNTAX WITHIN AN MRI SCRIPT FILE */  
375 mri_script_file:
376                 {       ldlex_mri_script();
377                         PUSH_ERROR("MRI style script");
378                 }
379              mri_script_lines
380                 {       ldlex_popstate(); 
381                         POP_ERROR();
382                 }
383         ;
384
385 mri_script_lines:
386                 mri_script_lines mri_script_command NEWLINE
387           |
388         ;
389
390 mri_script_command:
391                 CHIP  exp 
392         |       CHIP  exp ',' exp
393         |       NAME    {
394                         einfo("%P%F: unrecognised keyword in MRI style script '%s'\n",$1);
395                         }
396         |       LIST    {
397                         write_map = true;
398                         config.map_filename = "-";
399                         }
400         |       ORDER ordernamelist
401         |       ENDWORD 
402         |       PUBLIC NAME '=' exp 
403                         { mri_public($2, $4); }
404         |       PUBLIC NAME ',' exp 
405                         { mri_public($2, $4); }
406         |       PUBLIC NAME  exp 
407                         { mri_public($2, $3); }
408         |       FORMAT NAME
409                         { mri_format($2); }
410         |       SECT NAME ',' exp 
411                         { mri_output_section($2, $4);}
412         |       SECT NAME  exp
413                         { mri_output_section($2, $3);}
414         |       SECT NAME '=' exp
415                         { mri_output_section($2, $4);}
416         |       ALIGN_K NAME '=' exp
417                         { mri_align($2,$4); }
418         |       ALIGNMOD NAME '=' exp
419                         { mri_alignmod($2,$4); }
420         |       ABSOLUTE mri_abs_name_list
421         |       LOAD     mri_load_name_list
422         |       NAMEWORD NAME 
423                         { mri_name($2); }   
424         |       ALIAS NAME ',' NAME
425                         { mri_alias($2,$4,0);}
426         |       ALIAS NAME ',' INT
427                         { mri_alias($2,0,$4);}
428         |       BASE     exp
429                         { mri_base($2); }
430         |       TRUNCATE INT
431                 {  mri_truncate($2); }
432         |
433         ;
434
435 ordernamelist:
436               ordernamelist ',' NAME         { mri_order($3); }
437         |     ordernamelist  NAME         { mri_order($2); }
438         |
439         ;
440
441 mri_load_name_list:
442                 NAME
443                         { mri_load($1); }
444         |       mri_load_name_list ',' NAME { mri_load($3); }
445         ;
446
447 mri_abs_name_list:
448                 NAME
449                         { mri_only_load($1); }
450         |       mri_abs_name_list ','  NAME
451                         { mri_only_load($3); }
452         ;
453
454 script_file:
455         {
456          ldlex_both();
457         }
458        ifile_list
459         {
460         ldlex_popstate();
461         }
462         ;
463
464
465 ifile_list:
466        ifile_list ifile_p1
467         |
468         ;
469
470
471
472 ifile_p1:
473                 memory
474         |       sections
475         |       startup
476         |       high_level_library
477         |       low_level_library
478         |       floating_point_support
479         |       statement_anywhere
480         |        ';'
481         |       TARGET_K '(' NAME ')'
482                 { lang_add_target($3); }
483         |       SEARCH_DIR '(' filename ')'
484                 { ldfile_add_library_path($3); }
485         |       OUTPUT '(' filename ')'
486                 { lang_add_output($3); }
487         | OUTPUT_FORMAT '(' NAME ')'
488                   { lang_add_output_format($3); }
489         | OUTPUT_ARCH '(' NAME ')'
490                   { ldfile_set_output_arch($3); }
491         |       FORCE_COMMON_ALLOCATION
492                 { command_line.force_common_definition = true ; }
493         |       INPUT '(' input_list ')'
494         |       MAP '(' filename ')'
495                 { lang_add_map($3); }
496         |       INCLUDE filename 
497                 { ldfile_open_command_file($2); } ifile_list END
498         ;
499
500 input_list:
501                 NAME
502                 { lang_add_input_file($1,lang_input_file_is_file_enum,
503                                  (char *)NULL); }
504         |       input_list ',' NAME
505                 { lang_add_input_file($3,lang_input_file_is_file_enum,
506                                  (char *)NULL); }
507         |       input_list NAME
508                 { lang_add_input_file($2,
509 lang_input_file_is_file_enum,
510                                  (char *)NULL); }
511         ;
512
513 sections:
514                 SECTIONS '{' sec_or_group_p1 '}'
515         ;
516
517 sec_or_group_p1:
518                 sec_or_group_p1 section
519         |       sec_or_group_p1 statement_anywhere
520         |
521         ;
522
523 statement_anywhere:
524                 ENTRY '(' NAME ')'
525                 { lang_add_entry($3); }
526         |       assignment end
527         ;
528
529 file_NAME_list:
530                 NAME
531                         { lang_add_wild($1, current_file); }
532         |       file_NAME_list opt_comma NAME
533                         { lang_add_wild($3, current_file); }
534         ;
535
536 input_section_spec:
537                 NAME
538                 {
539                 lang_add_wild((char *)NULL, $1);
540                 }
541         |       '['
542                         {
543                         current_file = (char *)NULL;
544                         }
545                         file_NAME_list
546                 ']'
547         |       NAME
548                         {
549                         current_file =$1;
550                         }
551                 '(' file_NAME_list ')'
552         |       '*'
553                         {
554                         current_file = (char *)NULL;
555                         }
556                 '(' file_NAME_list ')'
557         ;
558
559 statement:
560                 assignment end
561         |       CREATE_OBJECT_SYMBOLS
562                 {
563                 lang_add_attribute(lang_object_symbols_statement_enum); 
564                 }
565         |       ';'
566         |       CONSTRUCTORS
567                 {
568                 
569                   lang_add_attribute(lang_constructors_statement_enum); 
570                 }
571         | input_section_spec
572         | length '(' exp ')'
573                         {
574                         lang_add_data($1,$3);
575                         }
576   
577         | FILL '(' exp ')'
578                         {
579                           lang_add_fill
580                             (exp_get_value_int($3,
581                                                0,
582                                                "fill value",
583                                                lang_first_phase_enum));
584                         }
585         ;
586
587 statement_list:
588                 statement_list statement
589         |       statement
590         ;
591   
592 statement_list_opt:
593                 /* empty */
594         |       statement_list
595         ;
596
597 length:
598                 LONG
599                         { $$ = $1; }
600         |       SHORT
601                         { $$ = $1; }
602         |       BYTE
603                         { $$ = $1; }
604         ;
605
606 fill_opt:
607           '=' mustbe_exp
608                 {
609                   $$ =   exp_get_value_int($2,
610                                            0,
611                                            "fill value",
612                                            lang_first_phase_enum);
613                 }
614         |       { $$ = 0; }
615         ;
616
617                 
618
619 assign_op:
620                 PLUSEQ
621                         { $$ = '+'; }
622         |       MINUSEQ
623                         { $$ = '-'; }
624         |       MULTEQ
625                         { $$ = '*'; }
626         |       DIVEQ
627                         { $$ = '/'; }
628         |       LSHIFTEQ
629                         { $$ = LSHIFT; }
630         |       RSHIFTEQ
631                         { $$ = RSHIFT; }
632         |       ANDEQ
633                         { $$ = '&'; }
634         |       OREQ
635                         { $$ = '|'; }
636
637         ;
638
639 end:    ';' | ','
640         ;
641
642
643 assignment:
644                 NAME '=' mustbe_exp
645                 {
646                   lang_add_assignment(exp_assop($2,$1,$3));
647                 }
648         |       NAME assign_op mustbe_exp
649                 {
650                 
651 lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
652                 }
653                 
654         ;
655
656
657 opt_comma:
658                 ','     |       ;
659
660
661 memory:
662                 MEMORY '{' memory_spec memory_spec_list '}'
663         ;
664
665 memory_spec_list:
666                 memory_spec_list memory_spec
667         |       memory_spec_list ',' memory_spec
668         |
669         ;
670
671
672 memory_spec:            NAME
673                         { region = lang_memory_region_lookup($1); }
674                 attributes_opt ':'
675                 origin_spec opt_comma length_spec
676
677         ; origin_spec:
678         ORIGIN '=' mustbe_exp
679                 { region->current =
680                  region->origin =
681                  exp_get_vma($3, 0L,"origin", lang_first_phase_enum);
682 }
683         ; length_spec:
684              LENGTH '=' mustbe_exp
685                { region->length = exp_get_vma($3,
686                                                ~((bfd_vma)0),
687                                                "length",
688                                                lang_first_phase_enum);
689                 }
690         
691
692 attributes_opt:
693                   '(' NAME ')'
694                         {
695                         lang_set_flags(&region->flags, $2);
696                         }
697         |
698   
699         ;
700
701 startup:
702         STARTUP '(' filename ')'
703                 { lang_startup($3); }
704         ;
705
706 high_level_library:
707                 HLL '(' high_level_library_NAME_list ')'
708         |       HLL '(' ')'
709                         { ldemul_hll((char *)NULL); }
710         ;
711
712 high_level_library_NAME_list:
713                 high_level_library_NAME_list opt_comma filename
714                         { ldemul_hll($3); }
715         |       filename
716                         { ldemul_hll($1); }
717
718         ;
719
720 low_level_library:
721         SYSLIB '(' low_level_library_NAME_list ')'
722         ; low_level_library_NAME_list:
723                 low_level_library_NAME_list opt_comma filename
724                         { ldemul_syslib($3); }
725         |
726         ;
727
728 floating_point_support:
729                 FLOAT
730                         { lang_float(true); }
731         |       NOFLOAT
732                         { lang_float(false); }
733         ;
734                 
735
736 mustbe_exp:              { ldlex_expression(); }
737                 exp
738                          { ldlex_popstate(); $$=$2;}
739         ;
740
741 exp     :
742                 '-' exp %prec UNARY
743                         { $$ = exp_unop('-', $2); }
744         |       '(' exp ')'
745                         { $$ = $2; }
746         |       NEXT '(' exp ')' %prec UNARY
747                         { $$ = exp_unop($1,$3); }
748         |       '!' exp %prec UNARY
749                         { $$ = exp_unop('!', $2); }
750         |       '+' exp %prec UNARY
751                         { $$ = $2; }
752         |       '~' exp %prec UNARY
753                         { $$ = exp_unop('~', $2);}
754
755         |       exp '*' exp
756                         { $$ = exp_binop('*', $1, $3); }
757         |       exp '/' exp
758                         { $$ = exp_binop('/', $1, $3); }
759         |       exp '%' exp
760                         { $$ = exp_binop('%', $1, $3); }
761         |       exp '+' exp
762                         { $$ = exp_binop('+', $1, $3); }
763         |       exp '-' exp
764                         { $$ = exp_binop('-' , $1, $3); }
765         |       exp LSHIFT exp
766                         { $$ = exp_binop(LSHIFT , $1, $3); }
767         |       exp RSHIFT exp
768                         { $$ = exp_binop(RSHIFT , $1, $3); }
769         |       exp EQ exp
770                         { $$ = exp_binop(EQ , $1, $3); }
771         |       exp NE exp
772                         { $$ = exp_binop(NE , $1, $3); }
773         |       exp LE exp
774                         { $$ = exp_binop(LE , $1, $3); }
775         |       exp GE exp
776                         { $$ = exp_binop(GE , $1, $3); }
777         |       exp '<' exp
778                         { $$ = exp_binop('<' , $1, $3); }
779         |       exp '>' exp
780                         { $$ = exp_binop('>' , $1, $3); }
781         |       exp '&' exp
782                         { $$ = exp_binop('&' , $1, $3); }
783         |       exp '^' exp
784                         { $$ = exp_binop('^' , $1, $3); }
785         |       exp '|' exp
786                         { $$ = exp_binop('|' , $1, $3); }
787         |       exp '?' exp ':' exp
788                         { $$ = exp_trinop('?' , $1, $3, $5); }
789         |       exp ANDAND exp
790                         { $$ = exp_binop(ANDAND , $1, $3); }
791         |       exp OROR exp
792                         { $$ = exp_binop(OROR , $1, $3); }
793         |       DEFINED '(' NAME ')'
794                         { $$ = exp_nameop(DEFINED, $3); }
795         |       INT
796                         { $$ = exp_intop($1); }
797         |       SIZEOF_HEADERS
798                         { $$ = exp_nameop(SIZEOF_HEADERS,0); }
799
800         |       SIZEOF '(' NAME ')'
801                         { $$ = exp_nameop(SIZEOF,$3); }
802         |       ADDR '(' NAME ')'
803                         { $$ = exp_nameop(ADDR,$3); }
804         |       ABSOLUTE '(' exp ')'
805                         { $$ = exp_unop(ABSOLUTE, $3); }
806         |       ALIGN_K '(' exp ')'
807                         { $$ = exp_unop(ALIGN_K,$3); }
808         |       NAME
809                         { $$ = exp_nameop(NAME,$1); }
810         ;
811
812
813 opt_at:
814                 AT '(' exp ')' { $$ = $3; }
815         |       { $$ = 0; }
816         ;
817
818 section:        NAME            { ldlex_expression(); }
819                 opt_exp_with_type 
820                 opt_at          { ldlex_popstate(); }
821                 '{'
822                         {
823                         lang_enter_output_section_statement($1,$3,typebits,0,0,0,$4);
824                         }
825                 statement_list_opt      
826                 '}' {ldlex_expression();} fill_opt memspec_opt
827                 {
828                   ldlex_popstate();
829                   lang_leave_output_section_statement($11, $12);
830                 }
831 opt_comma
832
833         ;
834
835 type:
836            NOLOAD  { typebits = SEC_NEVER_LOAD; }
837         |  DSECT   { typebits = 0; }
838         |  COPY    { typebits = 0; }
839         |  INFO    { typebits = 0; }
840         |  OVERLAY { typebits = 0; }
841         | { typebits = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; }
842         ;
843
844
845 opt_exp_with_type:
846                 exp ':'                 { $$ = $1; typebits =0;}
847         |       exp '(' type ')' ':'    { $$ = $1; }
848         |       ':'                     { $$= (etree_type *)NULL; typebits = 0; }
849         |       '(' type ')' ':'        { $$= (etree_type *)NULL;  }
850         ;
851
852 memspec_opt:
853                 '>' NAME
854                 { $$ = $2; }
855         |       { $$ = "*default*"; }
856         ;
857 %%
858 void
859 yyerror(arg) 
860 char *arg;
861
862   if (error_index> 0  && error_index < ERROR_NAME_MAX)
863      einfo("%P%F: %S syntax error in %s\n",error_names[error_index-1]);
864   else
865      einfo("%P%F: %S syntax error\n");
866 }