1 /* A YACC grammar to parse a superset of the AT&T linker scripting language.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001 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 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
;
59 char *ldgram_vers_current_lang
= NULL
;
61 #define ERROR_NAME_MAX 20
62 static char *error_names
[ERROR_NAME_MAX
];
63 static int error_index
;
64 #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
65 #define POP_ERROR() error_index--;
71 struct wildcard_spec wildcard
;
72 struct wildcard_list
*wildcard_list
;
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
<wildcard_list
> file_NAME_list
95 %type
<name
> memspec_opt casesymlist
96 %type
<name
> memspec_at_opt
97 %type
<cname
> wildcard_name
98 %type
<wildcard
> wildcard_spec
100 %token
<name
> NAME LNAME
101 %type
<integer
> length
102 %type
<phdr
> phdr_qualifiers
103 %type
<nocrossref
> nocrossref_list
104 %type
<section_phdr
> phdr_opt
105 %type
<integer
> opt_nocrossrefs
107 %right
<token
> PLUSEQ MINUSEQ MULTEQ DIVEQ
'=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
108 %right
<token
> '?' ':'
115 %left
<token
> '<' '>' LE GE
116 %left
<token
> LSHIFT RSHIFT
118 %left
<token
> '+' '-'
119 %left
<token
> '*' '/' '%'
124 %token
<token
> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
125 %token SECTIONS PHDRS SORT
127 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
128 %token SIZEOF_HEADERS
130 %token MEMORY DEFSYMEND
131 %token NOLOAD DSECT COPY INFO OVERLAY
132 %token NAME LNAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
133 %token
<integer
> NEXT
134 %token SIZEOF ADDR LOADADDR MAX_K MIN_K
135 %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS
137 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
138 %token ALIGNMOD AT PROVIDE
139 %type
<token
> assign_op atype attributes_opt
140 %type
<name
> filename
141 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
142 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
143 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
144 %token
<name
> VERS_TAG VERS_IDENTIFIER
145 %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
148 %type
<versyms
> vers_defns
149 %type
<versnode
> vers_tag
150 %type
<deflist
> verdep
155 INPUT_SCRIPT script_file
156 | INPUT_MRI_SCRIPT mri_script_file
157 | INPUT_VERSION_SCRIPT version_script_file
158 | INPUT_DEFSYM defsym_expr
170 lang_add_assignment
(exp_assop
($3,$2,$4));
173 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
177 PUSH_ERROR
(_
("MRI style script"));
188 mri_script_lines mri_script_command NEWLINE
196 einfo
(_
("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1);
199 config.map_filename
= "-";
201 | ORDER ordernamelist
203 | PUBLIC NAME
'=' exp
204 { mri_public
($2, $4); }
205 | PUBLIC NAME
',' exp
206 { mri_public
($2, $4); }
208 { mri_public
($2, $3); }
212 { mri_output_section
($2, $4);}
214 { mri_output_section
($2, $3);}
216 { mri_output_section
($2, $4);}
217 | ALIGN_K NAME
'=' exp
218 { mri_align
($2,$4); }
219 | ALIGN_K NAME
',' exp
220 { mri_align
($2,$4); }
221 | ALIGNMOD NAME
'=' exp
222 { mri_alignmod
($2,$4); }
223 | ALIGNMOD NAME
',' exp
224 { mri_alignmod
($2,$4); }
225 | ABSOLUTE mri_abs_name_list
226 | LOAD mri_load_name_list
229 | ALIAS NAME
',' NAME
230 { mri_alias
($2,$4,0);}
232 { mri_alias
($2,0,(int) $4);}
236 { mri_truncate
((unsigned int) $2); }
238 | EXTERN extern_name_list
240 { ldfile_open_command_file
($2); } mri_script_lines END
242 { lang_add_entry
($2, false
); }
247 ordernamelist
',' NAME
{ mri_order
($3); }
248 | ordernamelist NAME
{ mri_order
($2); }
255 | mri_load_name_list
',' NAME
{ mri_load
($3); }
260 { mri_only_load
($1); }
261 | mri_abs_name_list
',' NAME
262 { mri_only_load
($3); }
266 /* empty */ { $$
= NULL
; }
268 | casesymlist
',' NAME
273 { ldlang_add_undef
($1); }
274 | extern_name_list NAME
275 { ldlang_add_undef
($2); }
276 | extern_name_list
',' NAME
277 { ldlang_add_undef
($3); }
305 | floating_point_support
309 | TARGET_K
'(' NAME
')'
310 { lang_add_target
($3); }
311 | SEARCH_DIR
'(' filename
')'
312 { ldfile_add_library_path
($3, false
); }
313 | OUTPUT
'(' filename
')'
314 { lang_add_output
($3, 1); }
315 | OUTPUT_FORMAT
'(' NAME
')'
316 { lang_add_output_format
($3, (char *) NULL
,
318 | OUTPUT_FORMAT
'(' NAME
',' NAME
',' NAME
')'
319 { lang_add_output_format
($3, $5, $7, 1); }
320 | OUTPUT_ARCH
'(' NAME
')'
321 { ldfile_set_output_arch
($3); }
322 | FORCE_COMMON_ALLOCATION
323 { command_line.force_common_definition
= true
; }
324 | INPUT
'(' input_list
')'
326 { lang_enter_group
(); }
328 { lang_leave_group
(); }
329 | MAP
'(' filename
')'
330 { lang_add_map
($3); }
332 { ldfile_open_command_file
($2); } ifile_list END
333 | NOCROSSREFS
'(' nocrossref_list
')'
335 lang_add_nocrossref
($3);
337 | EXTERN
'(' extern_name_list
')'
342 { lang_add_input_file
($1,lang_input_file_is_search_file_enum
,
344 | input_list
',' NAME
345 { lang_add_input_file
($3,lang_input_file_is_search_file_enum
,
348 { lang_add_input_file
($2,lang_input_file_is_search_file_enum
,
351 { lang_add_input_file
($1,lang_input_file_is_l_enum
,
353 | input_list
',' LNAME
354 { lang_add_input_file
($3,lang_input_file_is_l_enum
,
357 { lang_add_input_file
($2,lang_input_file_is_l_enum
,
362 SECTIONS
'{' sec_or_group_p1
'}'
366 sec_or_group_p1 section
367 | sec_or_group_p1 statement_anywhere
373 { lang_add_entry
($3, false
); }
377 /* The '*' and '?' cases are there because the lexer returns them as
378 separate tokens rather than as NAME. */
399 $$.exclude_name_list
= NULL
;
401 | EXCLUDE_FILE
'(' exclude_name_list
')' wildcard_name
405 $$.exclude_name_list
= $3;
407 | SORT
'(' wildcard_name
')'
411 $$.exclude_name_list
= NULL
;
413 | SORT
'(' EXCLUDE_FILE
'(' exclude_name_list
')' wildcard_name
')'
417 $$.exclude_name_list
= $5;
422 exclude_name_list wildcard_name
424 struct name_list
*tmp
;
425 tmp
= (struct name_list
*) xmalloc
(sizeof
*tmp
);
433 struct name_list
*tmp
;
434 tmp
= (struct name_list
*) xmalloc
(sizeof
*tmp
);
442 file_NAME_list opt_comma wildcard_spec
444 struct wildcard_list
*tmp
;
445 tmp
= (struct wildcard_list
*) xmalloc
(sizeof
*tmp
);
453 struct wildcard_list
*tmp
;
454 tmp
= (struct wildcard_list
*) xmalloc
(sizeof
*tmp
);
461 input_section_spec_no_keep:
464 struct wildcard_spec tmp
;
466 tmp.exclude_name_list
= NULL
;
468 lang_add_wild
(&tmp
, NULL
, ldgram_had_keep
);
470 |
'[' file_NAME_list
']'
472 lang_add_wild
(NULL
, $2, ldgram_had_keep
);
474 | wildcard_spec
'(' file_NAME_list
')'
476 lang_add_wild
(&$1, $3, ldgram_had_keep
);
481 input_section_spec_no_keep
483 { ldgram_had_keep
= true
; }
484 input_section_spec_no_keep
')'
485 { ldgram_had_keep
= false
; }
490 | CREATE_OBJECT_SYMBOLS
492 lang_add_attribute
(lang_object_symbols_statement_enum
);
498 lang_add_attribute
(lang_constructors_statement_enum
);
500 | SORT
'(' CONSTRUCTORS
')'
502 constructors_sorted
= true
;
503 lang_add_attribute
(lang_constructors_statement_enum
);
506 | length
'(' mustbe_exp
')'
508 lang_add_data
((int) $1,$3);
511 | FILL
'(' mustbe_exp
')'
514 (exp_get_value_int
($3,
517 lang_first_phase_enum
));
522 statement_list statement
547 $$
= exp_get_value_int
($2,
550 lang_first_phase_enum
);
584 lang_add_assignment
(exp_assop
($2, $1, $3));
586 | NAME assign_op mustbe_exp
588 lang_add_assignment
(exp_assop
('=', $1,
594 | PROVIDE
'(' NAME
'=' mustbe_exp
')'
596 lang_add_assignment
(exp_provide
($3, $5));
606 MEMORY
'{' memory_spec memory_spec_list
'}'
610 memory_spec_list memory_spec
611 | memory_spec_list
',' memory_spec
617 { region
= lang_memory_region_lookup
($1); }
619 origin_spec opt_comma length_spec
624 ORIGIN
'=' mustbe_exp
627 exp_get_vma
($3, 0L,"origin", lang_first_phase_enum
);
632 LENGTH
'=' mustbe_exp
633 { region
->length
= exp_get_vma
($3,
636 lang_first_phase_enum
);
642 { /* dummy action to avoid bison 1.25 error message */ }
643 |
'(' attributes_list
')'
648 | attributes_list attributes_string
653 { lang_set_flags
(region
, $1, 0); }
655 { lang_set_flags
(region
, $2, 1); }
659 STARTUP
'(' filename
')'
660 { lang_startup
($3); }
664 HLL
'(' high_level_library_NAME_list
')'
666 { ldemul_hll
((char *)NULL
); }
669 high_level_library_NAME_list:
670 high_level_library_NAME_list opt_comma filename
678 SYSLIB
'(' low_level_library_NAME_list
')'
679 ; low_level_library_NAME_list
:
680 low_level_library_NAME_list opt_comma filename
681 { ldemul_syslib
($3); }
685 floating_point_support:
687 { lang_float
(true
); }
689 { lang_float
(false
); }
697 | NAME nocrossref_list
699 struct lang_nocrossref
*n
;
701 n
= (struct lang_nocrossref
*) xmalloc
(sizeof
*n
);
706 | NAME
',' nocrossref_list
708 struct lang_nocrossref
*n
;
710 n
= (struct lang_nocrossref
*) xmalloc
(sizeof
*n
);
717 mustbe_exp: { ldlex_expression
(); }
719 { ldlex_popstate
(); $$
=$2;}
724 { $$
= exp_unop
('-', $2); }
727 | NEXT
'(' exp
')' %prec UNARY
728 { $$
= exp_unop
((int) $1,$3); }
729 |
'!' exp %prec UNARY
730 { $$
= exp_unop
('!', $2); }
731 |
'+' exp %prec UNARY
733 |
'~' exp %prec UNARY
734 { $$
= exp_unop
('~', $2);}
737 { $$
= exp_binop
('*', $1, $3); }
739 { $$
= exp_binop
('/', $1, $3); }
741 { $$
= exp_binop
('%', $1, $3); }
743 { $$
= exp_binop
('+', $1, $3); }
745 { $$
= exp_binop
('-' , $1, $3); }
747 { $$
= exp_binop
(LSHIFT
, $1, $3); }
749 { $$
= exp_binop
(RSHIFT
, $1, $3); }
751 { $$
= exp_binop
(EQ
, $1, $3); }
753 { $$
= exp_binop
(NE
, $1, $3); }
755 { $$
= exp_binop
(LE
, $1, $3); }
757 { $$
= exp_binop
(GE
, $1, $3); }
759 { $$
= exp_binop
('<' , $1, $3); }
761 { $$
= exp_binop
('>' , $1, $3); }
763 { $$
= exp_binop
('&' , $1, $3); }
765 { $$
= exp_binop
('^' , $1, $3); }
767 { $$
= exp_binop
('|' , $1, $3); }
768 | exp
'?' exp
':' exp
769 { $$
= exp_trinop
('?' , $1, $3, $5); }
771 { $$
= exp_binop
(ANDAND
, $1, $3); }
773 { $$
= exp_binop
(OROR
, $1, $3); }
774 | DEFINED
'(' NAME
')'
775 { $$
= exp_nameop
(DEFINED
, $3); }
777 { $$
= exp_intop
($1); }
779 { $$
= exp_nameop
(SIZEOF_HEADERS
,0); }
781 | SIZEOF
'(' NAME
')'
782 { $$
= exp_nameop
(SIZEOF
,$3); }
784 { $$
= exp_nameop
(ADDR
,$3); }
785 | LOADADDR
'(' NAME
')'
786 { $$
= exp_nameop
(LOADADDR
,$3); }
787 | ABSOLUTE
'(' exp
')'
788 { $$
= exp_unop
(ABSOLUTE
, $3); }
789 | ALIGN_K
'(' exp
')'
790 { $$
= exp_unop
(ALIGN_K
,$3); }
792 { $$
= exp_unop
(ALIGN_K
,$3); }
794 { $$
= exp_nameop
(NAME
,$1); }
795 | MAX_K
'(' exp
',' exp
')'
796 { $$
= exp_binop
(MAX_K
, $3, $5 ); }
797 | MIN_K
'(' exp
',' exp
')'
798 { $$
= exp_binop
(MIN_K
, $3, $5 ); }
799 | ASSERT_K
'(' exp
',' NAME
')'
800 { $$
= exp_assert
($3, $5); }
805 AT
'>' NAME
{ $$
= $3; }
806 |
{ $$
= "*default*"; }
810 AT
'(' exp
')' { $$
= $3; }
814 section: NAME
{ ldlex_expression
(); }
816 opt_at
{ ldlex_popstate
(); ldlex_script
(); }
819 lang_enter_output_section_statement
($1, $3,
824 '}' { ldlex_popstate
(); ldlex_expression
(); }
825 memspec_opt memspec_at_opt phdr_opt fill_opt
828 lang_leave_output_section_statement
($14, $11, $13, $12);
832 { ldlex_expression
(); }
833 opt_exp_without_type opt_nocrossrefs opt_at
834 { ldlex_popstate
(); ldlex_script
(); }
837 lang_enter_overlay
($3, $5, (int) $4);
841 { ldlex_popstate
(); ldlex_expression
(); }
842 memspec_opt memspec_at_opt phdr_opt fill_opt
845 lang_leave_overlay
($15, $12, $14, $13);
848 |
/* The GROUP case is just enough to support the gcc
849 svr3.ifile script. It is not intended to be full
850 support. I'm not even sure what GROUP is supposed
852 GROUP
{ ldlex_expression
(); }
856 lang_add_assignment
(exp_assop
('=', ".", $3));
858 '{' sec_or_group_p1
'}'
862 NOLOAD
{ sectype
= noload_section
; }
863 | DSECT
{ sectype
= dsect_section
; }
864 | COPY
{ sectype
= copy_section
; }
865 | INFO
{ sectype
= info_section
; }
866 | OVERLAY
{ sectype
= overlay_section
; }
871 |
/* EMPTY */ { sectype
= normal_section
; }
872 |
'(' ')' { sectype
= normal_section
; }
876 exp atype
':' { $$
= $1; }
877 | atype
':' { $$
= (etree_type
*)NULL
; }
878 |
/* The BIND cases are to support the gcc svr3.ifile
879 script. They aren't intended to implement full
880 support for the BIND keyword. I'm not even sure
881 what BIND is supposed to mean. */
882 BIND
'(' exp
')' atype
':' { $$
= $3; }
883 | BIND
'(' exp
')' BLOCK
'(' exp
')' atype
':'
887 opt_exp_without_type:
889 |
':' { $$
= (etree_type
*) NULL
; }
902 |
{ $$
= "*default*"; }
912 struct lang_output_section_phdr_list
*n
;
914 n
= ((struct lang_output_section_phdr_list
*)
915 xmalloc
(sizeof
*n
));
929 lang_enter_overlay_section
($2);
931 '{' statement_list_opt
'}'
932 { ldlex_popstate
(); ldlex_expression
(); }
936 lang_leave_overlay_section
($9, $8);
942 PHDRS
'{' phdr_list
'}'
951 NAME
{ ldlex_expression
(); }
952 phdr_type phdr_qualifiers
{ ldlex_popstate
(); }
955 lang_new_phdr
($1, $3, $4.filehdr
, $4.phdrs
, $4.at
,
965 if
($1->type.node_class
== etree_name
966 && $1->type.node_code
== NAME
)
970 static const char * const phdr_types
[] =
972 "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
973 "PT_INTERP", "PT_NOTE", "PT_SHLIB",
979 i
< sizeof phdr_types
/ sizeof phdr_types
[0];
981 if
(strcmp
(s
, phdr_types
[i
]) == 0)
993 memset
(&$$
, 0, sizeof
(struct phdr_info
));
995 | NAME phdr_val phdr_qualifiers
998 if
(strcmp
($1, "FILEHDR") == 0 && $2 == NULL
)
1000 else if
(strcmp
($1, "PHDRS") == 0 && $2 == NULL
)
1002 else if
(strcmp
($1, "FLAGS") == 0 && $2 != NULL
)
1005 einfo
(_
("%X%P:%S: PHDRS syntax error at `%s'\n"), $1);
1007 | AT
'(' exp
')' phdr_qualifiers
1025 /* This syntax is used within an external version script file. */
1027 version_script_file:
1029 ldlex_version_file
();
1030 PUSH_ERROR
(_
("VERSION script"));
1039 /* This is used within a normal linker script file. */
1043 ldlex_version_script
();
1045 VERSIONK
'{' vers_nodes
'}'
1053 | vers_nodes vers_node
1057 VERS_TAG
'{' vers_tag
'}' ';'
1059 lang_register_vers_node
($1, $3, NULL
);
1061 | VERS_TAG
'{' vers_tag
'}' verdep
';'
1063 lang_register_vers_node
($1, $3, $5);
1070 $$
= lang_add_vers_depend
(NULL
, $1);
1074 $$
= lang_add_vers_depend
($1, $2);
1081 $$
= lang_new_vers_node
(NULL
, NULL
);
1085 $$
= lang_new_vers_node
($1, NULL
);
1087 | GLOBAL
':' vers_defns
';'
1089 $$
= lang_new_vers_node
($3, NULL
);
1091 | LOCAL
':' vers_defns
';'
1093 $$
= lang_new_vers_node
(NULL
, $3);
1095 | GLOBAL
':' vers_defns
';' LOCAL
':' vers_defns
';'
1097 $$
= lang_new_vers_node
($3, $7);
1104 $$
= lang_new_vers_regex
(NULL
, $1, ldgram_vers_current_lang
);
1106 | vers_defns
';' VERS_IDENTIFIER
1108 $$
= lang_new_vers_regex
($1, $3, ldgram_vers_current_lang
);
1112 $
<name
>$
= ldgram_vers_current_lang
;
1113 ldgram_vers_current_lang
= $2;
1118 ldgram_vers_current_lang
= $
<name
>4;
1127 if
(ldfile_assumed_script
)
1128 einfo
(_
("%P:%s: file format not recognized; treating as linker script\n"),
1129 ldfile_input_filename
);
1130 if
(error_index
> 0 && error_index
< ERROR_NAME_MAX
)
1131 einfo
("%P%F:%S: %s in %s\n", arg
, error_names
[error_index
-1]);
1133 einfo
("%P%F:%S: %s\n", arg
);