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