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, 98, 99, 2000
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
48 static enum section_type sectype
;
50 lang_memory_region_type
*region
;
52 struct wildcard_spec current_file
;
53 boolean ldgram_want_filename
= true
;
54 boolean had_script
= false
;
55 boolean force_make_executable
= false
;
57 boolean ldgram_in_script
= false
;
58 boolean ldgram_had_equals
= false
;
59 boolean ldgram_had_keep
= false
;
60 char *ldgram_vers_current_lang
= NULL
;
62 #define ERROR_NAME_MAX 20
63 static char *error_names
[ERROR_NAME_MAX
];
64 static int error_index
;
65 #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
66 #define POP_ERROR() error_index--;
72 struct wildcard_spec wildcard
;
73 struct name_list
*name_list
;
75 union etree_union
*etree
;
80 union etree_union
*at
;
81 union etree_union
*flags
;
83 struct lang_nocrossref
*nocrossref
;
84 struct lang_output_section_phdr_list
*section_phdr
;
85 struct bfd_elf_version_deps
*deflist
;
86 struct bfd_elf_version_expr
*versyms
;
87 struct bfd_elf_version_tree
*versnode
;
90 %type
<etree
> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val
91 %type
<etree
> opt_exp_without_type
92 %type
<integer
> fill_opt
93 %type
<name_list
> exclude_name_list
94 %type
<name
> memspec_opt casesymlist
95 %type
<name
> memspec_at_opt
96 %type
<cname
> wildcard_name
97 %type
<wildcard
> wildcard_spec
99 %token
<name
> NAME LNAME
100 %type
<integer
> length
101 %type
<phdr
> phdr_qualifiers
102 %type
<nocrossref
> nocrossref_list
103 %type
<section_phdr
> phdr_opt
104 %type
<integer
> opt_nocrossrefs
106 %right
<token
> PLUSEQ MINUSEQ MULTEQ DIVEQ
'=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
107 %right
<token
> '?' ':'
114 %left
<token
> '<' '>' LE GE
115 %left
<token
> LSHIFT RSHIFT
117 %left
<token
> '+' '-'
118 %left
<token
> '*' '/' '%'
123 %token
<token
> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
124 %token SECTIONS PHDRS SORT
126 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
127 %token SIZEOF_HEADERS
129 %token MEMORY DEFSYMEND
130 %token NOLOAD DSECT COPY INFO OVERLAY
131 %token NAME LNAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
132 %token
<integer
> NEXT
133 %token SIZEOF ADDR LOADADDR MAX_K MIN_K
134 %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS
136 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
137 %token ALIGNMOD AT PROVIDE
138 %type
<token
> assign_op atype attributes_opt
139 %type
<name
> filename
140 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
141 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
142 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
143 %token
<name
> VERS_TAG VERS_IDENTIFIER
144 %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
147 %type
<versyms
> vers_defns
148 %type
<versnode
> vers_tag
149 %type
<deflist
> verdep
154 INPUT_SCRIPT script_file
155 | INPUT_MRI_SCRIPT mri_script_file
156 | INPUT_VERSION_SCRIPT version_script_file
157 | INPUT_DEFSYM defsym_expr
169 lang_add_assignment
(exp_assop
($3,$2,$4));
172 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
176 PUSH_ERROR
(_
("MRI style script"));
187 mri_script_lines mri_script_command NEWLINE
195 einfo
(_
("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1);
198 config.map_filename
= "-";
200 | ORDER ordernamelist
202 | PUBLIC NAME
'=' exp
203 { mri_public
($2, $4); }
204 | PUBLIC NAME
',' exp
205 { mri_public
($2, $4); }
207 { mri_public
($2, $3); }
211 { mri_output_section
($2, $4);}
213 { mri_output_section
($2, $3);}
215 { mri_output_section
($2, $4);}
216 | ALIGN_K NAME
'=' exp
217 { mri_align
($2,$4); }
218 | ALIGN_K NAME
',' exp
219 { mri_align
($2,$4); }
220 | ALIGNMOD NAME
'=' exp
221 { mri_alignmod
($2,$4); }
222 | ALIGNMOD NAME
',' exp
223 { mri_alignmod
($2,$4); }
224 | ABSOLUTE mri_abs_name_list
225 | LOAD mri_load_name_list
228 | ALIAS NAME
',' NAME
229 { mri_alias
($2,$4,0);}
231 { mri_alias
($2,0,(int) $4);}
235 { mri_truncate
((unsigned int) $2); }
237 | EXTERN extern_name_list
239 { ldfile_open_command_file
($2); } mri_script_lines END
241 { lang_add_entry
($2, false
); }
246 ordernamelist
',' NAME
{ mri_order
($3); }
247 | ordernamelist NAME
{ mri_order
($2); }
254 | mri_load_name_list
',' NAME
{ mri_load
($3); }
259 { mri_only_load
($1); }
260 | mri_abs_name_list
',' NAME
261 { mri_only_load
($3); }
265 /* empty */ { $$
= NULL
; }
267 | casesymlist
',' NAME
272 { ldlang_add_undef
($1); }
273 | extern_name_list NAME
274 { ldlang_add_undef
($2); }
275 | extern_name_list
',' NAME
276 { ldlang_add_undef
($3); }
304 | floating_point_support
308 | TARGET_K
'(' NAME
')'
309 { lang_add_target
($3); }
310 | SEARCH_DIR
'(' filename
')'
311 { ldfile_add_library_path
($3, false
); }
312 | OUTPUT
'(' filename
')'
313 { lang_add_output
($3, 1); }
314 | OUTPUT_FORMAT
'(' NAME
')'
315 { lang_add_output_format
($3, (char *) NULL
,
317 | OUTPUT_FORMAT
'(' NAME
',' NAME
',' NAME
')'
318 { lang_add_output_format
($3, $5, $7, 1); }
319 | OUTPUT_ARCH
'(' NAME
')'
320 { ldfile_set_output_arch
($3); }
321 | FORCE_COMMON_ALLOCATION
322 { command_line.force_common_definition
= true
; }
323 | INPUT
'(' input_list
')'
325 { lang_enter_group
(); }
327 { lang_leave_group
(); }
328 | MAP
'(' filename
')'
329 { lang_add_map
($3); }
331 { ldfile_open_command_file
($2); } ifile_list END
332 | NOCROSSREFS
'(' nocrossref_list
')'
334 lang_add_nocrossref
($3);
336 | EXTERN
'(' extern_name_list
')'
341 { lang_add_input_file
($1,lang_input_file_is_search_file_enum
,
343 | input_list
',' NAME
344 { lang_add_input_file
($3,lang_input_file_is_search_file_enum
,
347 { lang_add_input_file
($2,lang_input_file_is_search_file_enum
,
350 { lang_add_input_file
($1,lang_input_file_is_l_enum
,
352 | input_list
',' LNAME
353 { lang_add_input_file
($3,lang_input_file_is_l_enum
,
356 { lang_add_input_file
($2,lang_input_file_is_l_enum
,
361 SECTIONS
'{' sec_or_group_p1
'}'
365 sec_or_group_p1 section
366 | sec_or_group_p1 statement_anywhere
372 { lang_add_entry
($3, false
); }
376 /* The '*' and '?' cases are there because the lexer returns them as
377 separate tokens rather than as NAME. */
398 $$.exclude_name_list
= NULL
;
400 | EXCLUDE_FILE
'(' exclude_name_list
')' wildcard_name
404 $$.exclude_name_list
= $3;
406 | SORT
'(' wildcard_name
')'
410 $$.exclude_name_list
= NULL
;
412 | SORT
'(' EXCLUDE_FILE
'(' exclude_name_list
')' wildcard_name
')'
416 $$.exclude_name_list
= $5;
423 exclude_name_list wildcard_name
425 struct name_list
*tmp
;
426 tmp
= (struct name_list
*) xmalloc
(sizeof
*tmp
);
434 struct name_list
*tmp
;
435 tmp
= (struct name_list
*) xmalloc
(sizeof
*tmp
);
445 lang_add_wild
($1.name
, $1.sorted
,
448 ldgram_had_keep
, $1.exclude_name_list
);
450 | file_NAME_list opt_comma wildcard_spec
452 lang_add_wild
($3.name
, $3.sorted
,
455 ldgram_had_keep
, $3.exclude_name_list
);
459 input_section_spec_no_keep:
462 lang_add_wild
(NULL
, false
, $1, false
,
463 ldgram_had_keep
, NULL
);
467 current_file.name
= NULL
;
468 current_file.sorted
= false
;
474 /* '*' matches any file name. */
475 if
(strcmp
(current_file.name
, "*") == 0)
476 current_file.name
= NULL
;
478 '(' file_NAME_list
')'
482 input_section_spec_no_keep
484 { ldgram_had_keep
= true
; }
485 input_section_spec_no_keep
')'
486 { ldgram_had_keep
= false
; }
491 | CREATE_OBJECT_SYMBOLS
493 lang_add_attribute
(lang_object_symbols_statement_enum
);
499 lang_add_attribute
(lang_constructors_statement_enum
);
501 | SORT
'(' CONSTRUCTORS
')'
503 constructors_sorted
= true
;
504 lang_add_attribute
(lang_constructors_statement_enum
);
507 | length
'(' mustbe_exp
')'
509 lang_add_data
((int) $1,$3);
512 | FILL
'(' mustbe_exp
')'
515 (exp_get_value_int
($3,
518 lang_first_phase_enum
));
523 statement_list statement
548 $$
= exp_get_value_int
($2,
551 lang_first_phase_enum
);
585 lang_add_assignment
(exp_assop
($2, $1, $3));
587 | NAME assign_op mustbe_exp
589 lang_add_assignment
(exp_assop
('=', $1,
595 | PROVIDE
'(' NAME
'=' mustbe_exp
')'
597 lang_add_assignment
(exp_provide
($3, $5));
607 MEMORY
'{' memory_spec memory_spec_list
'}'
611 memory_spec_list memory_spec
612 | memory_spec_list
',' memory_spec
618 { region
= lang_memory_region_lookup
($1); }
620 origin_spec opt_comma length_spec
625 ORIGIN
'=' mustbe_exp
628 exp_get_vma
($3, 0L,"origin", lang_first_phase_enum
);
633 LENGTH
'=' mustbe_exp
634 { region
->length
= exp_get_vma
($3,
637 lang_first_phase_enum
);
643 { /* dummy action to avoid bison 1.25 error message */ }
644 |
'(' attributes_list
')'
649 | attributes_list attributes_string
654 { lang_set_flags
(region
, $1, 0); }
656 { lang_set_flags
(region
, $2, 1); }
660 STARTUP
'(' filename
')'
661 { lang_startup
($3); }
665 HLL
'(' high_level_library_NAME_list
')'
667 { ldemul_hll
((char *)NULL
); }
670 high_level_library_NAME_list:
671 high_level_library_NAME_list opt_comma filename
679 SYSLIB
'(' low_level_library_NAME_list
')'
680 ; low_level_library_NAME_list
:
681 low_level_library_NAME_list opt_comma filename
682 { ldemul_syslib
($3); }
686 floating_point_support:
688 { lang_float
(true
); }
690 { lang_float
(false
); }
698 | NAME nocrossref_list
700 struct lang_nocrossref
*n
;
702 n
= (struct lang_nocrossref
*) xmalloc
(sizeof
*n
);
707 | NAME
',' nocrossref_list
709 struct lang_nocrossref
*n
;
711 n
= (struct lang_nocrossref
*) xmalloc
(sizeof
*n
);
718 mustbe_exp: { ldlex_expression
(); }
720 { ldlex_popstate
(); $$
=$2;}
725 { $$
= exp_unop
('-', $2); }
728 | NEXT
'(' exp
')' %prec UNARY
729 { $$
= exp_unop
((int) $1,$3); }
730 |
'!' exp %prec UNARY
731 { $$
= exp_unop
('!', $2); }
732 |
'+' exp %prec UNARY
734 |
'~' exp %prec UNARY
735 { $$
= exp_unop
('~', $2);}
738 { $$
= exp_binop
('*', $1, $3); }
740 { $$
= exp_binop
('/', $1, $3); }
742 { $$
= exp_binop
('%', $1, $3); }
744 { $$
= exp_binop
('+', $1, $3); }
746 { $$
= exp_binop
('-' , $1, $3); }
748 { $$
= exp_binop
(LSHIFT
, $1, $3); }
750 { $$
= exp_binop
(RSHIFT
, $1, $3); }
752 { $$
= exp_binop
(EQ
, $1, $3); }
754 { $$
= exp_binop
(NE
, $1, $3); }
756 { $$
= exp_binop
(LE
, $1, $3); }
758 { $$
= exp_binop
(GE
, $1, $3); }
760 { $$
= exp_binop
('<' , $1, $3); }
762 { $$
= exp_binop
('>' , $1, $3); }
764 { $$
= exp_binop
('&' , $1, $3); }
766 { $$
= exp_binop
('^' , $1, $3); }
768 { $$
= exp_binop
('|' , $1, $3); }
769 | exp
'?' exp
':' exp
770 { $$
= exp_trinop
('?' , $1, $3, $5); }
772 { $$
= exp_binop
(ANDAND
, $1, $3); }
774 { $$
= exp_binop
(OROR
, $1, $3); }
775 | DEFINED
'(' NAME
')'
776 { $$
= exp_nameop
(DEFINED
, $3); }
778 { $$
= exp_intop
($1); }
780 { $$
= exp_nameop
(SIZEOF_HEADERS
,0); }
782 | SIZEOF
'(' NAME
')'
783 { $$
= exp_nameop
(SIZEOF
,$3); }
785 { $$
= exp_nameop
(ADDR
,$3); }
786 | LOADADDR
'(' NAME
')'
787 { $$
= exp_nameop
(LOADADDR
,$3); }
788 | ABSOLUTE
'(' exp
')'
789 { $$
= exp_unop
(ABSOLUTE
, $3); }
790 | ALIGN_K
'(' exp
')'
791 { $$
= exp_unop
(ALIGN_K
,$3); }
793 { $$
= exp_unop
(ALIGN_K
,$3); }
795 { $$
= exp_nameop
(NAME
,$1); }
796 | MAX_K
'(' exp
',' exp
')'
797 { $$
= exp_binop
(MAX_K
, $3, $5 ); }
798 | MIN_K
'(' exp
',' exp
')'
799 { $$
= exp_binop
(MIN_K
, $3, $5 ); }
800 | ASSERT_K
'(' exp
',' NAME
')'
801 { $$
= exp_assert
($3, $5); }
806 AT
'>' NAME
{ $$
= $3; }
807 |
{ $$
= "*default*"; }
811 AT
'(' exp
')' { $$
= $3; }
815 section: NAME
{ ldlex_expression
(); }
817 opt_at
{ ldlex_popstate
(); ldlex_script
(); }
820 lang_enter_output_section_statement
($1, $3,
825 '}' { ldlex_popstate
(); ldlex_expression
(); }
826 memspec_opt memspec_at_opt phdr_opt fill_opt
829 lang_leave_output_section_statement
($14, $11, $13, $12);
833 { ldlex_expression
(); }
834 opt_exp_without_type opt_nocrossrefs opt_at
835 { ldlex_popstate
(); ldlex_script
(); }
838 lang_enter_overlay
($3, $5, (int) $4);
842 { ldlex_popstate
(); ldlex_expression
(); }
843 memspec_opt memspec_at_opt phdr_opt fill_opt
846 lang_leave_overlay
($15, $12, $14, $13);
849 |
/* The GROUP case is just enough to support the gcc
850 svr3.ifile script. It is not intended to be full
851 support. I'm not even sure what GROUP is supposed
853 GROUP
{ ldlex_expression
(); }
857 lang_add_assignment
(exp_assop
('=', ".", $3));
859 '{' sec_or_group_p1
'}'
863 NOLOAD
{ sectype
= noload_section
; }
864 | DSECT
{ sectype
= dsect_section
; }
865 | COPY
{ sectype
= copy_section
; }
866 | INFO
{ sectype
= info_section
; }
867 | OVERLAY
{ sectype
= overlay_section
; }
872 |
/* EMPTY */ { sectype
= normal_section
; }
873 |
'(' ')' { sectype
= normal_section
; }
877 exp atype
':' { $$
= $1; }
878 | atype
':' { $$
= (etree_type
*)NULL
; }
879 |
/* The BIND cases are to support the gcc svr3.ifile
880 script. They aren't intended to implement full
881 support for the BIND keyword. I'm not even sure
882 what BIND is supposed to mean. */
883 BIND
'(' exp
')' atype
':' { $$
= $3; }
884 | BIND
'(' exp
')' BLOCK
'(' exp
')' atype
':'
888 opt_exp_without_type:
890 |
':' { $$
= (etree_type
*) NULL
; }
903 |
{ $$
= "*default*"; }
913 struct lang_output_section_phdr_list
*n
;
915 n
= ((struct lang_output_section_phdr_list
*)
916 xmalloc
(sizeof
*n
));
930 lang_enter_overlay_section
($2);
932 '{' statement_list_opt
'}'
933 { ldlex_popstate
(); ldlex_expression
(); }
937 lang_leave_overlay_section
($9, $8);
943 PHDRS
'{' phdr_list
'}'
952 NAME
{ ldlex_expression
(); }
953 phdr_type phdr_qualifiers
{ ldlex_popstate
(); }
956 lang_new_phdr
($1, $3, $4.filehdr
, $4.phdrs
, $4.at
,
966 if
($1->type.node_class
== etree_name
967 && $1->type.node_code
== NAME
)
971 static const char * const phdr_types
[] =
973 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
974 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
980 i
< sizeof phdr_types
/ sizeof phdr_types
[0];
982 if
(strcmp
(s
, phdr_types
[i
]) == 0)
994 memset
(&$$
, 0, sizeof
(struct phdr_info
));
996 | NAME phdr_val phdr_qualifiers
999 if
(strcmp
($1, "FILEHDR") == 0 && $2 == NULL
)
1001 else if
(strcmp
($1, "PHDRS") == 0 && $2 == NULL
)
1003 else if
(strcmp
($1, "FLAGS") == 0 && $2 != NULL
)
1006 einfo
(_
("%X%P:%S: PHDRS syntax error at `%s'\n"), $1);
1008 | AT
'(' exp
')' phdr_qualifiers
1026 /* This syntax is used within an external version script file. */
1028 version_script_file:
1030 ldlex_version_file
();
1031 PUSH_ERROR
(_
("VERSION script"));
1040 /* This is used within a normal linker script file. */
1044 ldlex_version_script
();
1046 VERSIONK
'{' vers_nodes
'}'
1054 | vers_nodes vers_node
1058 VERS_TAG
'{' vers_tag
'}' ';'
1060 lang_register_vers_node
($1, $3, NULL
);
1062 | VERS_TAG
'{' vers_tag
'}' verdep
';'
1064 lang_register_vers_node
($1, $3, $5);
1071 $$
= lang_add_vers_depend
(NULL
, $1);
1075 $$
= lang_add_vers_depend
($1, $2);
1082 $$
= lang_new_vers_node
(NULL
, NULL
);
1086 $$
= lang_new_vers_node
($1, NULL
);
1088 | GLOBAL
':' vers_defns
';'
1090 $$
= lang_new_vers_node
($3, NULL
);
1092 | LOCAL
':' vers_defns
';'
1094 $$
= lang_new_vers_node
(NULL
, $3);
1096 | GLOBAL
':' vers_defns
';' LOCAL
':' vers_defns
';'
1098 $$
= lang_new_vers_node
($3, $7);
1105 $$
= lang_new_vers_regex
(NULL
, $1, ldgram_vers_current_lang
);
1107 | vers_defns
';' VERS_IDENTIFIER
1109 $$
= lang_new_vers_regex
($1, $3, ldgram_vers_current_lang
);
1113 $
<name
>$
= ldgram_vers_current_lang
;
1114 ldgram_vers_current_lang
= $2;
1119 ldgram_vers_current_lang
= $
<name
>4;
1128 if
(ldfile_assumed_script
)
1129 einfo
(_
("%P:%s: file format not recognized; treating as linker script\n"),
1130 ldfile_input_filename
);
1131 if
(error_index
> 0 && error_index
< ERROR_NAME_MAX
)
1132 einfo
("%P%F:%S: %s in %s\n", arg
, error_names
[error_index
-1]);
1134 einfo
("%P%F:%S: %s\n", arg
);