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