Add support for -e and for ENTRY in linker scripts.
[deliverable/binutils-gdb.git] / gold / yyscript.y
1 /* yyscript.y -- linker script grammer for gold. */
2
3 /* Copyright 2006, 2007 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <iant@google.com>.
5
6 This file is part of gold.
7
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 3 of the License, or
11 (at your option) any later version.
12
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.
17
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., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
22
23 /* This is a bison grammar to parse a subset of the original GNU ld
24 linker script language. */
25
26 %{
27
28 #include "config.h"
29
30 #include <stddef.h>
31 #include <stdint.h>
32
33 #include "script-c.h"
34
35 %}
36
37 /* We need to use a pure parser because we might be multi-threaded.
38 We pass some arguments through the parser to the lexer. */
39
40 %pure-parser
41
42 %parse-param {void* closure}
43 %lex-param {void* closure}
44
45 /* Since we require bison anyhow, we take advantage of it. */
46
47 %error-verbose
48
49 /* The values associated with tokens. */
50
51 %union {
52 const char* string;
53 int64_t integer;
54 }
55
56 /* Operators, including a precedence table for expressions. */
57
58 %right PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
59 %right '?' ':'
60 %left OROR
61 %left ANDAND
62 %left '|'
63 %left '^'
64 %left '&'
65 %left EQ NE
66 %left '<' '>' LE GE
67 %left LSHIFT RSHIFT
68 %left '+' '-'
69 %left '*' '/' '%'
70
71 /* Constants. */
72
73 %token <string> STRING
74 %token <integer> INTEGER
75
76 /* Keywords. This list is taken from ldgram.y and ldlex.l in the old
77 GNU linker, with the keywords which only appear in MRI mode
78 removed. Not all these keywords are actually used in this grammar.
79 In most cases the keyword is recognized as the token name in upper
80 case. The comments indicate where this is not the case. */
81
82 %token ABSOLUTE
83 %token ADDR
84 %token ALIGN_K /* ALIGN */
85 %token ASSERT_K /* ASSERT */
86 %token AS_NEEDED
87 %token AT
88 %token BIND
89 %token BLOCK
90 %token BYTE
91 %token CONSTANT
92 %token CONSTRUCTORS
93 %token COPY
94 %token CREATE_OBJECT_SYMBOLS
95 %token DATA_SEGMENT_ALIGN
96 %token DATA_SEGMENT_END
97 %token DATA_SEGMENT_RELRO_END
98 %token DEFINED
99 %token DSECT
100 %token ENTRY
101 %token EXCLUDE_FILE
102 %token EXTERN
103 %token FILL
104 %token FLOAT
105 %token FORCE_COMMON_ALLOCATION
106 %token GLOBAL /* global */
107 %token GROUP
108 %token HLL
109 %token INCLUDE
110 %token INFO
111 %token INHIBIT_COMMON_ALLOCATION
112 %token INPUT
113 %token KEEP
114 %token LENGTH /* LENGTH, l, len */
115 %token LOADADDR
116 %token LOCAL /* local */
117 %token LONG
118 %token MAP
119 %token MAX_K /* MAX */
120 %token MEMORY
121 %token MIN_K /* MIN */
122 %token NEXT
123 %token NOCROSSREFS
124 %token NOFLOAT
125 %token NOLOAD
126 %token ONLY_IF_RO
127 %token ONLY_IF_RW
128 %token ORIGIN /* ORIGIN, o, org */
129 %token OUTPUT
130 %token OUTPUT_ARCH
131 %token OUTPUT_FORMAT
132 %token OVERLAY
133 %token PHDRS
134 %token PROVIDE
135 %token PROVIDE_HIDDEN
136 %token QUAD
137 %token SEARCH_DIR
138 %token SECTIONS
139 %token SEGMENT_START
140 %token SHORT
141 %token SIZEOF
142 %token SIZEOF_HEADERS /* SIZEOF_HEADERS, sizeof_headers */
143 %token SORT_BY_ALIGNMENT
144 %token SORT_BY_NAME
145 %token SPECIAL
146 %token SQUAD
147 %token STARTUP
148 %token SUBALIGN
149 %token SYSLIB
150 %token TARGET_K /* TARGET */
151 %token TRUNCATE
152 %token VERSIONK /* VERSION */
153
154 /* Keywords, part 2. These are keywords that are unique to gold,
155 and not present in the old GNU linker. As before, unless the
156 comments say otherwise, the keyword is recognized as the token
157 name in upper case. */
158
159 %token OPTION
160
161 %%
162
163 /* A file contains a list of commands. */
164 file_list:
165 file_list file_cmd
166 | /* empty */
167 ;
168
169 /* A command which may appear at top level of a linker script. */
170 file_cmd:
171 OUTPUT_FORMAT '(' STRING ')'
172 | GROUP
173 { script_start_group(closure); }
174 '(' input_list ')'
175 { script_end_group(closure); }
176 | OPTION '(' STRING ')'
177 { script_parse_option(closure, $3); }
178 | file_or_sections_cmd
179 ;
180
181 /* A list of input file names. */
182 input_list:
183 input_list_element
184 | input_list opt_comma input_list_element
185 ;
186
187 /* An input file name. */
188 input_list_element:
189 STRING
190 { script_add_file(closure, $1); }
191 | AS_NEEDED
192 { script_start_as_needed(closure); }
193 '(' input_list ')'
194 { script_end_as_needed(closure); }
195 ;
196
197 /* A command which may appear at the top level of a linker script, or
198 within a SECTIONS block. */
199 file_or_sections_cmd:
200 ENTRY '(' STRING ')'
201 { script_set_entry(closure, $3); }
202 ;
203
204 /* An optional comma. */
205 opt_comma:
206 ','
207 | /* empty */
208 ;
209
210 %%
This page took 0.035131 seconds and 5 git commands to generate.