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