1 /* A YACC grammer to parse a superset of the AT&T linker scripting languaue.
2 Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
4 Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
6 This file is part of GNU ld.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #define DONTDECLARE_MALLOC
47 static enum section_type sectype
;
49 lang_memory_region_type
*region
;
51 struct wildcard_spec current_file
;
52 boolean ldgram_want_filename
= true
;
53 boolean had_script
= false
;
54 boolean force_make_executable
= false
;
56 boolean ldgram_in_script
= false
;
57 boolean ldgram_had_equals
= false
;
58 boolean ldgram_had_keep
= false
;
60 #define ERROR_NAME_MAX 20
61 static char *error_names
[ERROR_NAME_MAX
];
62 static int error_index
;
63 #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
64 #define POP_ERROR() error_index--;
70 struct wildcard_spec wildcard
;
72 union etree_union
*etree
;
77 union etree_union
*at
;
78 union etree_union
*flags
;
80 struct lang_nocrossref
*nocrossref
;
81 struct lang_output_section_phdr_list
*section_phdr
;
82 struct bfd_elf_version_deps
*deflist
;
83 struct bfd_elf_version_expr
*versyms
;
84 struct bfd_elf_version_tree
*versnode
;
87 %type
<etree
> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val
88 %type
<etree
> opt_exp_without_type
89 %type
<integer
> fill_opt
90 %type
<name
> memspec_opt casesymlist
91 %type
<cname
> wildcard_name
92 %type
<wildcard
> wildcard_spec
94 %token
<name
> NAME LNAME
95 %type
<integer
> length
96 %type
<phdr
> phdr_qualifiers
97 %type
<nocrossref
> nocrossref_list
98 %type
<section_phdr
> phdr_opt
99 %type
<integer
> opt_nocrossrefs
101 %right
<token
> PLUSEQ MINUSEQ MULTEQ DIVEQ
'=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
102 %right
<token
> '?' ':'
109 %left
<token
> '<' '>' LE GE
110 %left
<token
> LSHIFT RSHIFT
112 %left
<token
> '+' '-'
113 %left
<token
> '*' '/' '%'
118 %token
<token
> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
119 %token SECTIONS PHDRS SORT
121 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
122 %token SIZEOF_HEADERS
124 %token MEMORY DEFSYMEND
125 %token NOLOAD DSECT COPY INFO OVERLAY
126 %token NAME LNAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
127 %token
<integer
> NEXT
128 %token SIZEOF ADDR LOADADDR MAX_K MIN_K
129 %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS
131 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
132 %token ALIGNMOD AT PROVIDE
133 %type
<token
> assign_op atype
134 %type
<name
> filename
135 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD
136 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
137 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
138 %token
<name
> VERS_TAG VERS_IDENTIFIER
139 %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
141 %type
<versyms
> vers_defns
142 %type
<versnode
> vers_tag
143 %type
<deflist
> verdep
148 INPUT_SCRIPT script_file
149 | INPUT_MRI_SCRIPT mri_script_file
150 | INPUT_VERSION_SCRIPT version_script_file
151 | INPUT_DEFSYM defsym_expr
163 lang_add_assignment
(exp_assop
($3,$2,$4));
166 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
170 PUSH_ERROR
(_
("MRI style script"));
181 mri_script_lines mri_script_command NEWLINE
189 einfo
(_
("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1);
192 config.map_filename
= "-";
194 | ORDER ordernamelist
196 | PUBLIC NAME
'=' exp
197 { mri_public
($2, $4); }
198 | PUBLIC NAME
',' exp
199 { mri_public
($2, $4); }
201 { mri_public
($2, $3); }
205 { mri_output_section
($2, $4);}
207 { mri_output_section
($2, $3);}
209 { mri_output_section
($2, $4);}
210 | ALIGN_K NAME
'=' exp
211 { mri_align
($2,$4); }
212 | ALIGN_K NAME
',' exp
213 { mri_align
($2,$4); }
214 | ALIGNMOD NAME
'=' exp
215 { mri_alignmod
($2,$4); }
216 | ALIGNMOD NAME
',' exp
217 { mri_alignmod
($2,$4); }
218 | ABSOLUTE mri_abs_name_list
219 | LOAD mri_load_name_list
222 | ALIAS NAME
',' NAME
223 { mri_alias
($2,$4,0);}
225 { mri_alias
($2,0,(int) $4);}
229 { mri_truncate
((unsigned int) $2); }
231 | EXTERN extern_name_list
233 { ldfile_open_command_file
($2); } mri_script_lines END
235 { lang_add_entry
($2, false
); }
240 ordernamelist
',' NAME
{ mri_order
($3); }
241 | ordernamelist NAME
{ mri_order
($2); }
248 | mri_load_name_list
',' NAME
{ mri_load
($3); }
253 { mri_only_load
($1); }
254 | mri_abs_name_list
',' NAME
255 { mri_only_load
($3); }
259 /* empty */ { $$
= NULL
; }
261 | casesymlist
',' NAME
266 { ldlang_add_undef
($1); }
267 | extern_name_list NAME
268 { ldlang_add_undef
($2); }
269 | extern_name_list
',' NAME
270 { ldlang_add_undef
($3); }
298 | floating_point_support
302 | TARGET_K
'(' NAME
')'
303 { lang_add_target
($3); }
304 | SEARCH_DIR
'(' filename
')'
305 { ldfile_add_library_path
($3, false
); }
306 | OUTPUT
'(' filename
')'
307 { lang_add_output
($3, 1); }
308 | OUTPUT_FORMAT
'(' NAME
')'
309 { lang_add_output_format
($3, (char *) NULL
,
311 | OUTPUT_FORMAT
'(' NAME
',' NAME
',' NAME
')'
312 { lang_add_output_format
($3, $5, $7, 1); }
313 | OUTPUT_ARCH
'(' NAME
')'
314 { ldfile_set_output_arch
($3); }
315 | FORCE_COMMON_ALLOCATION
316 { command_line.force_common_definition
= true
; }
317 | INPUT
'(' input_list
')'
319 { lang_enter_group
(); }
321 { lang_leave_group
(); }
322 | MAP
'(' filename
')'
323 { lang_add_map
($3); }
325 { ldfile_open_command_file
($2); } ifile_list END
326 | NOCROSSREFS
'(' nocrossref_list
')'
328 lang_add_nocrossref
($3);
330 | EXTERN
'(' extern_name_list
')'
335 { lang_add_input_file
($1,lang_input_file_is_search_file_enum
,
337 | input_list
',' NAME
338 { lang_add_input_file
($3,lang_input_file_is_search_file_enum
,
341 { lang_add_input_file
($2,lang_input_file_is_search_file_enum
,
344 { lang_add_input_file
($1,lang_input_file_is_l_enum
,
346 | input_list
',' LNAME
347 { lang_add_input_file
($3,lang_input_file_is_l_enum
,
350 { lang_add_input_file
($2,lang_input_file_is_l_enum
,
355 SECTIONS
'{' sec_or_group_p1
'}'
359 sec_or_group_p1 section
360 | sec_or_group_p1 statement_anywhere
366 { lang_add_entry
($3, false
); }
370 /* The '*' and '?' cases are there because the lexer returns them as
371 separate tokens rather than as NAME. */
393 | SORT
'(' wildcard_name
')'
403 lang_add_wild
($1.name
, $1.sorted
,
408 | file_NAME_list opt_comma wildcard_spec
410 lang_add_wild
($3.name
, $3.sorted
,
417 input_section_spec_no_keep:
420 lang_add_wild
(NULL
, false
, $1, false
,
425 current_file.name
= NULL
;
426 current_file.sorted
= false
;
432 /* '*' matches any file name. */
433 if
(strcmp
(current_file.name
, "*") == 0)
434 current_file.name
= NULL
;
436 '(' file_NAME_list
')'
440 input_section_spec_no_keep
442 { ldgram_had_keep
= true
; }
443 input_section_spec_no_keep
')'
444 { ldgram_had_keep
= false
; }
449 | CREATE_OBJECT_SYMBOLS
451 lang_add_attribute
(lang_object_symbols_statement_enum
);
457 lang_add_attribute
(lang_constructors_statement_enum
);
460 | length
'(' mustbe_exp
')'
462 lang_add_data
((int) $1,$3);
465 | FILL
'(' mustbe_exp
')'
468 (exp_get_value_int
($3,
471 lang_first_phase_enum
));
476 statement_list statement
501 $$
= exp_get_value_int
($2,
504 lang_first_phase_enum
);
538 lang_add_assignment
(exp_assop
($2, $1, $3));
540 | NAME assign_op mustbe_exp
542 lang_add_assignment
(exp_assop
('=', $1,
548 | PROVIDE
'(' NAME
'=' mustbe_exp
')'
550 lang_add_assignment
(exp_provide
($3, $5));
560 MEMORY
'{' memory_spec memory_spec_list
'}'
564 memory_spec_list memory_spec
565 | memory_spec_list
',' memory_spec
571 { region
= lang_memory_region_lookup
($1); }
573 origin_spec opt_comma length_spec
576 ORIGIN
'=' mustbe_exp
579 exp_get_vma
($3, 0L,"origin", lang_first_phase_enum
);
584 LENGTH
'=' mustbe_exp
585 { region
->length
= exp_get_vma
($3,
588 lang_first_phase_enum
);
595 lang_set_flags
(region
, $2);
602 STARTUP
'(' filename
')'
603 { lang_startup
($3); }
607 HLL
'(' high_level_library_NAME_list
')'
609 { ldemul_hll
((char *)NULL
); }
612 high_level_library_NAME_list:
613 high_level_library_NAME_list opt_comma filename
621 SYSLIB
'(' low_level_library_NAME_list
')'
622 ; low_level_library_NAME_list
:
623 low_level_library_NAME_list opt_comma filename
624 { ldemul_syslib
($3); }
628 floating_point_support:
630 { lang_float
(true
); }
632 { lang_float
(false
); }
640 | NAME nocrossref_list
642 struct lang_nocrossref
*n
;
644 n
= (struct lang_nocrossref
*) xmalloc
(sizeof
*n
);
649 | NAME
',' nocrossref_list
651 struct lang_nocrossref
*n
;
653 n
= (struct lang_nocrossref
*) xmalloc
(sizeof
*n
);
660 mustbe_exp: { ldlex_expression
(); }
662 { ldlex_popstate
(); $$
=$2;}
667 { $$
= exp_unop
('-', $2); }
670 | NEXT
'(' exp
')' %prec UNARY
671 { $$
= exp_unop
((int) $1,$3); }
672 |
'!' exp %prec UNARY
673 { $$
= exp_unop
('!', $2); }
674 |
'+' exp %prec UNARY
676 |
'~' exp %prec UNARY
677 { $$
= exp_unop
('~', $2);}
680 { $$
= exp_binop
('*', $1, $3); }
682 { $$
= exp_binop
('/', $1, $3); }
684 { $$
= exp_binop
('%', $1, $3); }
686 { $$
= exp_binop
('+', $1, $3); }
688 { $$
= exp_binop
('-' , $1, $3); }
690 { $$
= exp_binop
(LSHIFT
, $1, $3); }
692 { $$
= exp_binop
(RSHIFT
, $1, $3); }
694 { $$
= exp_binop
(EQ
, $1, $3); }
696 { $$
= exp_binop
(NE
, $1, $3); }
698 { $$
= exp_binop
(LE
, $1, $3); }
700 { $$
= exp_binop
(GE
, $1, $3); }
702 { $$
= exp_binop
('<' , $1, $3); }
704 { $$
= exp_binop
('>' , $1, $3); }
706 { $$
= exp_binop
('&' , $1, $3); }
708 { $$
= exp_binop
('^' , $1, $3); }
710 { $$
= exp_binop
('|' , $1, $3); }
711 | exp
'?' exp
':' exp
712 { $$
= exp_trinop
('?' , $1, $3, $5); }
714 { $$
= exp_binop
(ANDAND
, $1, $3); }
716 { $$
= exp_binop
(OROR
, $1, $3); }
717 | DEFINED
'(' NAME
')'
718 { $$
= exp_nameop
(DEFINED
, $3); }
720 { $$
= exp_intop
($1); }
722 { $$
= exp_nameop
(SIZEOF_HEADERS
,0); }
724 | SIZEOF
'(' NAME
')'
725 { $$
= exp_nameop
(SIZEOF
,$3); }
727 { $$
= exp_nameop
(ADDR
,$3); }
728 | LOADADDR
'(' NAME
')'
729 { $$
= exp_nameop
(LOADADDR
,$3); }
730 | ABSOLUTE
'(' exp
')'
731 { $$
= exp_unop
(ABSOLUTE
, $3); }
732 | ALIGN_K
'(' exp
')'
733 { $$
= exp_unop
(ALIGN_K
,$3); }
735 { $$
= exp_unop
(ALIGN_K
,$3); }
737 { $$
= exp_nameop
(NAME
,$1); }
738 | MAX_K
'(' exp
',' exp
')'
739 { $$
= exp_binop
(MAX_K
, $3, $5 ); }
740 | MIN_K
'(' exp
',' exp
')'
741 { $$
= exp_binop
(MIN_K
, $3, $5 ); }
746 AT
'(' exp
')' { $$
= $3; }
750 section: NAME
{ ldlex_expression
(); }
752 opt_at
{ ldlex_popstate
(); ldlex_script
(); }
755 lang_enter_output_section_statement
($1, $3,
760 '}' { ldlex_popstate
(); ldlex_expression
(); }
761 memspec_opt phdr_opt fill_opt
764 lang_leave_output_section_statement
($13, $11, $12);
768 { ldlex_expression
(); }
769 opt_exp_without_type opt_nocrossrefs opt_at
770 { ldlex_popstate
(); ldlex_script
(); }
773 lang_enter_overlay
($3, $5, (int) $4);
777 { ldlex_popstate
(); ldlex_expression
(); }
778 memspec_opt phdr_opt fill_opt
781 lang_leave_overlay
($14, $12, $13);
784 |
/* The GROUP case is just enough to support the gcc
785 svr3.ifile script. It is not intended to be full
786 support. I'm not even sure what GROUP is supposed
788 GROUP
{ ldlex_expression
(); }
792 lang_add_assignment
(exp_assop
('=', ".", $3));
794 '{' sec_or_group_p1
'}'
798 NOLOAD
{ sectype
= noload_section
; }
799 | DSECT
{ sectype
= dsect_section
; }
800 | COPY
{ sectype
= copy_section
; }
801 | INFO
{ sectype
= info_section
; }
802 | OVERLAY
{ sectype
= overlay_section
; }
807 |
/* EMPTY */ { sectype
= normal_section
; }
808 |
'(' ')' { sectype
= normal_section
; }
812 exp atype
':' { $$
= $1; }
813 | atype
':' { $$
= (etree_type
*)NULL
; }
814 |
/* The BIND cases are to support the gcc svr3.ifile
815 script. They aren't intended to implement full
816 support for the BIND keyword. I'm not even sure
817 what BIND is supposed to mean. */
818 BIND
'(' exp
')' atype
':' { $$
= $3; }
819 | BIND
'(' exp
')' BLOCK
'(' exp
')' atype
':'
823 opt_exp_without_type:
825 |
':' { $$
= (etree_type
*) NULL
; }
838 |
{ $$
= "*default*"; }
848 struct lang_output_section_phdr_list
*n
;
850 n
= ((struct lang_output_section_phdr_list
*)
851 xmalloc
(sizeof
*n
));
865 lang_enter_overlay_section
($2);
867 '{' statement_list_opt
'}'
868 { ldlex_popstate
(); ldlex_expression
(); }
872 lang_leave_overlay_section
($9, $8);
878 PHDRS
'{' phdr_list
'}'
887 NAME
{ ldlex_expression
(); }
888 phdr_type phdr_qualifiers
{ ldlex_popstate
(); }
891 lang_new_phdr
($1, $3, $4.filehdr
, $4.phdrs
, $4.at
,
901 if
($1->type.node_class
== etree_name
902 && $1->type.node_code
== NAME
)
906 static const char * const phdr_types
[] =
908 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
909 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
915 i
< sizeof phdr_types
/ sizeof phdr_types
[0];
917 if
(strcmp
(s
, phdr_types
[i
]) == 0)
929 memset
(&$$
, 0, sizeof
(struct phdr_info
));
931 | NAME phdr_val phdr_qualifiers
934 if
(strcmp
($1, "FILEHDR") == 0 && $2 == NULL
)
936 else if
(strcmp
($1, "PHDRS") == 0 && $2 == NULL
)
938 else if
(strcmp
($1, "FLAGS") == 0 && $2 != NULL
)
941 einfo
(_
("%X%P:%S: PHDRS syntax error at `%s'\n"), $1);
943 | AT
'(' exp
')' phdr_qualifiers
961 /* This syntax is used within an external version script file. */
965 ldlex_version_file
();
966 PUSH_ERROR
(_
("VERSION script"));
975 /* This is used within a normal linker script file. */
979 ldlex_version_script
();
981 VERSIONK
'{' vers_nodes
'}'
989 | vers_nodes vers_node
993 VERS_TAG
'{' vers_tag
'}' ';'
995 lang_register_vers_node
($1, $3, NULL
);
997 | VERS_TAG
'{' vers_tag
'}' verdep
';'
999 lang_register_vers_node
($1, $3, $5);
1006 $$
= lang_add_vers_depend
(NULL
, $1);
1010 $$
= lang_add_vers_depend
($1, $2);
1017 $$
= lang_new_vers_node
(NULL
, NULL
);
1021 $$
= lang_new_vers_node
($1, NULL
);
1023 | GLOBAL
':' vers_defns
';'
1025 $$
= lang_new_vers_node
($3, NULL
);
1027 | LOCAL
':' vers_defns
';'
1029 $$
= lang_new_vers_node
(NULL
, $3);
1031 | GLOBAL
':' vers_defns
';' LOCAL
':' vers_defns
';'
1033 $$
= lang_new_vers_node
($3, $7);
1040 $$
= lang_new_vers_regex
(NULL
, $1);
1042 | vers_defns
';' VERS_IDENTIFIER
1044 $$
= lang_new_vers_regex
($1, $3);
1053 if
(ldfile_assumed_script
)
1054 einfo
(_
("%P:%s: file format not recognized; treating as linker script\n"),
1055 ldfile_input_filename
);
1056 if
(error_index
> 0 && error_index
< ERROR_NAME_MAX
)
1057 einfo
("%P%F:%S: %s in %s\n", arg
, error_names
[error_index
-1]);
1059 einfo
("%P%F:%S: %s\n", arg
);