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