Commit | Line | Data |
---|---|---|
cfdf38f2 BE |
1 | %option nounput |
2 | ||
252b5132 RH |
3 | %{ |
4 | ||
729c05fc | 5 | /* Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
dab69f68 | 6 | 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 |
3db64b00 | 7 | Free Software Foundation, Inc. |
f96b4a7b | 8 | Written by Steve Chamberlain of Cygnus Support. |
252b5132 | 9 | |
f96b4a7b | 10 | This file is part of the GNU Binutils. |
252b5132 | 11 | |
f96b4a7b | 12 | This program is free software; you can redistribute it and/or modify |
3ec57632 | 13 | it under the terms of the GNU General Public License as published by |
f96b4a7b NC |
14 | the Free Software Foundation; either version 3 of the License, or |
15 | (at your option) any later version. | |
252b5132 | 16 | |
f96b4a7b | 17 | This program is distributed in the hope that it will be useful, |
3ec57632 NC |
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | GNU General Public License for more details. | |
252b5132 | 21 | |
3ec57632 | 22 | You should have received a copy of the GNU General Public License |
f96b4a7b NC |
23 | along with this program; if not, write to the Free Software |
24 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
25 | MA 02110-1301, USA. */ | |
252b5132 | 26 | |
3db64b00 | 27 | #include "bfd.h" |
3882b010 | 28 | #include "safe-ctype.h" |
e3e942e9 | 29 | #include "bfdlink.h" |
252b5132 | 30 | #include "ld.h" |
252b5132 RH |
31 | #include "ldmisc.h" |
32 | #include "ldexp.h" | |
33 | #include "ldlang.h" | |
df2a7313 | 34 | #include <ldgram.h> |
252b5132 RH |
35 | #include "ldfile.h" |
36 | #include "ldlex.h" | |
37 | #include "ldmain.h" | |
d1b2b2dc | 38 | #include "libiberty.h" |
252b5132 RH |
39 | |
40 | /* The type of top-level parser input. | |
41 | yylex and yyparse (indirectly) both check this. */ | |
42 | input_type parser_input; | |
43 | ||
44 | /* Line number in the current input file. | |
45 | (FIXME Actually, it doesn't appear to get reset for each file?) */ | |
46 | unsigned int lineno = 1; | |
47 | ||
48 | /* The string we are currently lexing, or NULL if we are reading a | |
49 | file. */ | |
50 | const char *lex_string = NULL; | |
51 | ||
52 | /* Support for flex reading from more than one input file (stream). | |
53 | `include_stack' is flex's input state for each open file; | |
54 | `file_name_stack' is the file names. `lineno_stack' is the current | |
55 | line numbers. | |
56 | ||
57 | If `include_stack_ptr' is 0, we haven't started reading anything yet. | |
58 | Otherwise, stack elements 0 through `include_stack_ptr - 1' are valid. */ | |
59 | ||
60 | #undef YY_INPUT | |
d05c651b | 61 | #define YY_INPUT(buf,result,max_size) result = yy_input (buf, max_size) |
252b5132 | 62 | |
5b806d27 | 63 | #ifndef YY_NO_UNPUT |
297ba367 | 64 | #define YY_NO_UNPUT |
5b806d27 | 65 | #endif |
297ba367 | 66 | |
252b5132 RH |
67 | #define MAX_INCLUDE_DEPTH 10 |
68 | static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH]; | |
69 | static const char *file_name_stack[MAX_INCLUDE_DEPTH]; | |
70 | static unsigned int lineno_stack[MAX_INCLUDE_DEPTH]; | |
f4a23d42 | 71 | static unsigned int sysrooted_stack[MAX_INCLUDE_DEPTH]; |
252b5132 RH |
72 | static unsigned int include_stack_ptr = 0; |
73 | static int vers_node_nesting = 0; | |
74 | ||
d05c651b | 75 | static int yy_input (char *, int); |
1579bae1 AM |
76 | static void comment (void); |
77 | static void lex_warn_invalid (char *where, char *what); | |
252b5132 | 78 | |
1579bae1 | 79 | /* STATES |
252b5132 RH |
80 | EXPRESSION definitely in an expression |
81 | SCRIPT definitely in a script | |
82 | BOTH either EXPRESSION or SCRIPT | |
83 | DEFSYMEXP in an argument to -defsym | |
84 | MRI in an MRI script | |
85 | VERS_START starting a Sun style mapfile | |
86 | VERS_SCRIPT a Sun style mapfile | |
87 | VERS_NODE a node within a Sun style mapfile | |
88 | */ | |
89 | #define RTOKEN(x) { yylval.token = x; return x; } | |
90 | ||
91 | /* Some versions of flex want this. */ | |
92 | #ifndef yywrap | |
1579bae1 | 93 | int yywrap (void) { return 1; } |
252b5132 RH |
94 | #endif |
95 | %} | |
96 | ||
97 | %a 4000 | |
98 | %o 5000 | |
99 | ||
100 | CMDFILENAMECHAR [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~] | |
101 | CMDFILENAMECHAR1 [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~] | |
102 | FILENAMECHAR1 [_a-zA-Z\/\.\\\$\_\~] | |
103 | SYMBOLCHARN [_a-zA-Z\/\.\\\$\_\~0-9] | |
104 | FILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~] | |
107c6e11 | 105 | WILDCHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~\?\*\^\!] |
1579bae1 | 106 | WHITE [ \t\n\r]+ |
252b5132 RH |
107 | |
108 | NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~] | |
109 | ||
110 | V_TAG [.$_a-zA-Z][._a-zA-Z0-9]* | |
5e35cbc2 | 111 | V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)* |
252b5132 RH |
112 | |
113 | %s SCRIPT | |
114 | %s EXPRESSION | |
115 | %s BOTH | |
116 | %s DEFSYMEXP | |
117 | %s MRI | |
118 | %s VERS_START | |
119 | %s VERS_SCRIPT | |
120 | %s VERS_NODE | |
121 | %% | |
122 | ||
123 | if (parser_input != input_selected) | |
124 | { | |
125 | /* The first token of the input determines the initial parser state. */ | |
126 | input_type t = parser_input; | |
127 | parser_input = input_selected; | |
128 | switch (t) | |
129 | { | |
130 | case input_script: return INPUT_SCRIPT; break; | |
131 | case input_mri_script: return INPUT_MRI_SCRIPT; break; | |
132 | case input_version_script: return INPUT_VERSION_SCRIPT; break; | |
55255dae | 133 | case input_dynamic_list: return INPUT_DYNAMIC_LIST; break; |
252b5132 RH |
134 | case input_defsym: return INPUT_DEFSYM; break; |
135 | default: abort (); | |
136 | } | |
137 | } | |
138 | ||
1579bae1 | 139 | <BOTH,SCRIPT,EXPRESSION,VERS_START,VERS_NODE,VERS_SCRIPT>"/*" { comment (); } |
252b5132 RH |
140 | |
141 | ||
142 | <DEFSYMEXP>"-" { RTOKEN('-');} | |
143 | <DEFSYMEXP>"+" { RTOKEN('+');} | |
1579bae1 | 144 | <DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = xstrdup (yytext); return NAME; } |
252b5132 RH |
145 | <DEFSYMEXP>"=" { RTOKEN('='); } |
146 | ||
147 | <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ { | |
1579bae1 AM |
148 | yylval.integer = bfd_scan_vma (yytext + 1, 0, 16); |
149 | yylval.bigint.str = NULL; | |
252b5132 RH |
150 | return INT; |
151 | } | |
152 | ||
153 | <MRI,EXPRESSION>([0-9A-Fa-f])+(H|h|X|x|B|b|O|o|D|d) { | |
154 | int ibase ; | |
1579bae1 AM |
155 | switch (yytext[yyleng - 1]) { |
156 | case 'X': | |
252b5132 RH |
157 | case 'x': |
158 | case 'H': | |
159 | case 'h': | |
160 | ibase = 16; | |
161 | break; | |
162 | case 'O': | |
163 | case 'o': | |
164 | ibase = 8; | |
165 | break; | |
166 | case 'B': | |
167 | case 'b': | |
168 | ibase = 2; | |
169 | break; | |
170 | default: | |
171 | ibase = 10; | |
172 | } | |
173 | yylval.integer = bfd_scan_vma (yytext, 0, | |
174 | ibase); | |
1579bae1 | 175 | yylval.bigint.str = NULL; |
252b5132 RH |
176 | return INT; |
177 | } | |
2c382fb6 | 178 | <SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>((("$"|0[xX])([0-9A-Fa-f])+)|(([0-9])+))(M|K|m|k)? { |
252b5132 | 179 | char *s = yytext; |
2c382fb6 | 180 | int ibase = 0; |
252b5132 RH |
181 | |
182 | if (*s == '$') | |
2c382fb6 AM |
183 | { |
184 | ++s; | |
185 | ibase = 16; | |
186 | } | |
187 | yylval.integer = bfd_scan_vma (s, 0, ibase); | |
1579bae1 AM |
188 | yylval.bigint.str = NULL; |
189 | if (yytext[yyleng - 1] == 'M' | |
190 | || yytext[yyleng - 1] == 'm') | |
2c382fb6 AM |
191 | { |
192 | yylval.integer *= 1024 * 1024; | |
193 | } | |
1579bae1 AM |
194 | else if (yytext[yyleng - 1] == 'K' |
195 | || yytext[yyleng - 1]=='k') | |
2c382fb6 AM |
196 | { |
197 | yylval.integer *= 1024; | |
198 | } | |
199 | else if (yytext[0] == '0' | |
200 | && (yytext[1] == 'x' | |
201 | || yytext[1] == 'X')) | |
202 | { | |
203 | yylval.bigint.str = xstrdup (yytext + 2); | |
204 | } | |
252b5132 RH |
205 | return INT; |
206 | } | |
207 | <BOTH,SCRIPT,EXPRESSION,MRI>"]" { RTOKEN(']');} | |
208 | <BOTH,SCRIPT,EXPRESSION,MRI>"[" { RTOKEN('[');} | |
209 | <BOTH,SCRIPT,EXPRESSION,MRI>"<<=" { RTOKEN(LSHIFTEQ);} | |
210 | <BOTH,SCRIPT,EXPRESSION,MRI>">>=" { RTOKEN(RSHIFTEQ);} | |
211 | <BOTH,SCRIPT,EXPRESSION,MRI>"||" { RTOKEN(OROR);} | |
212 | <BOTH,SCRIPT,EXPRESSION,MRI>"==" { RTOKEN(EQ);} | |
213 | <BOTH,SCRIPT,EXPRESSION,MRI>"!=" { RTOKEN(NE);} | |
214 | <BOTH,SCRIPT,EXPRESSION,MRI>">=" { RTOKEN(GE);} | |
215 | <BOTH,SCRIPT,EXPRESSION,MRI>"<=" { RTOKEN(LE);} | |
216 | <BOTH,SCRIPT,EXPRESSION,MRI>"<<" { RTOKEN(LSHIFT);} | |
217 | <BOTH,SCRIPT,EXPRESSION,MRI>">>" { RTOKEN(RSHIFT);} | |
218 | <BOTH,SCRIPT,EXPRESSION,MRI>"+=" { RTOKEN(PLUSEQ);} | |
219 | <BOTH,SCRIPT,EXPRESSION,MRI>"-=" { RTOKEN(MINUSEQ);} | |
220 | <BOTH,SCRIPT,EXPRESSION,MRI>"*=" { RTOKEN(MULTEQ);} | |
221 | <BOTH,SCRIPT,EXPRESSION,MRI>"/=" { RTOKEN(DIVEQ);} | |
222 | <BOTH,SCRIPT,EXPRESSION,MRI>"&=" { RTOKEN(ANDEQ);} | |
223 | <BOTH,SCRIPT,EXPRESSION,MRI>"|=" { RTOKEN(OREQ);} | |
224 | <BOTH,SCRIPT,EXPRESSION,MRI>"&&" { RTOKEN(ANDAND);} | |
225 | <BOTH,SCRIPT,EXPRESSION,MRI>">" { RTOKEN('>');} | |
226 | <BOTH,SCRIPT,EXPRESSION,MRI>"," { RTOKEN(',');} | |
227 | <BOTH,SCRIPT,EXPRESSION,MRI>"&" { RTOKEN('&');} | |
228 | <BOTH,SCRIPT,EXPRESSION,MRI>"|" { RTOKEN('|');} | |
229 | <BOTH,SCRIPT,EXPRESSION,MRI>"~" { RTOKEN('~');} | |
230 | <BOTH,SCRIPT,EXPRESSION,MRI>"!" { RTOKEN('!');} | |
231 | <BOTH,SCRIPT,EXPRESSION,MRI>"?" { RTOKEN('?');} | |
232 | <BOTH,SCRIPT,EXPRESSION,MRI>"*" { RTOKEN('*');} | |
233 | <BOTH,SCRIPT,EXPRESSION,MRI>"+" { RTOKEN('+');} | |
234 | <BOTH,SCRIPT,EXPRESSION,MRI>"-" { RTOKEN('-');} | |
235 | <BOTH,SCRIPT,EXPRESSION,MRI>"/" { RTOKEN('/');} | |
236 | <BOTH,SCRIPT,EXPRESSION,MRI>"%" { RTOKEN('%');} | |
237 | <BOTH,SCRIPT,EXPRESSION,MRI>"<" { RTOKEN('<');} | |
3ec57632 NC |
238 | <BOTH,SCRIPT,EXPRESSION,MRI>"=" { RTOKEN('=');} |
239 | <BOTH,SCRIPT,EXPRESSION,MRI>"}" { RTOKEN('}') ; } | |
240 | <BOTH,SCRIPT,EXPRESSION,MRI>"{" { RTOKEN('{'); } | |
241 | <BOTH,SCRIPT,EXPRESSION,MRI>")" { RTOKEN(')');} | |
242 | <BOTH,SCRIPT,EXPRESSION,MRI>"(" { RTOKEN('(');} | |
252b5132 RH |
243 | <BOTH,SCRIPT,EXPRESSION,MRI>":" { RTOKEN(':'); } |
244 | <BOTH,SCRIPT,EXPRESSION,MRI>";" { RTOKEN(';');} | |
3ec57632 | 245 | <BOTH,SCRIPT>"MEMORY" { RTOKEN(MEMORY);} |
4a93e180 | 246 | <BOTH,SCRIPT>"REGION_ALIAS" { RTOKEN(REGION_ALIAS);} |
01554a74 | 247 | <BOTH,SCRIPT>"LD_FEATURE" { RTOKEN(LD_FEATURE);} |
3ec57632 NC |
248 | <BOTH,SCRIPT,EXPRESSION>"ORIGIN" { RTOKEN(ORIGIN);} |
249 | <BOTH,SCRIPT>"VERSION" { RTOKEN(VERSIONK);} | |
252b5132 RH |
250 | <EXPRESSION,BOTH,SCRIPT>"BLOCK" { RTOKEN(BLOCK);} |
251 | <EXPRESSION,BOTH,SCRIPT>"BIND" { RTOKEN(BIND);} | |
3ec57632 NC |
252 | <BOTH,SCRIPT,EXPRESSION>"LENGTH" { RTOKEN(LENGTH);} |
253 | <EXPRESSION,BOTH,SCRIPT>"ALIGN" { RTOKEN(ALIGN_K);} | |
2d20f7bf | 254 | <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_ALIGN" { RTOKEN(DATA_SEGMENT_ALIGN);} |
8c37241b | 255 | <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_RELRO_END" { RTOKEN(DATA_SEGMENT_RELRO_END);} |
2d20f7bf | 256 | <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_END" { RTOKEN(DATA_SEGMENT_END);} |
3ec57632 NC |
257 | <EXPRESSION,BOTH,SCRIPT>"ADDR" { RTOKEN(ADDR);} |
258 | <EXPRESSION,BOTH,SCRIPT>"LOADADDR" { RTOKEN(LOADADDR);} | |
362c1d1a | 259 | <EXPRESSION,BOTH,SCRIPT>"ALIGNOF" { RTOKEN(ALIGNOF); } |
252b5132 RH |
260 | <EXPRESSION,BOTH>"MAX" { RTOKEN(MAX_K); } |
261 | <EXPRESSION,BOTH>"MIN" { RTOKEN(MIN_K); } | |
8545d1a9 | 262 | <EXPRESSION,BOTH,SCRIPT>"ASSERT" { RTOKEN(ASSERT_K); } |
252b5132 RH |
263 | <BOTH,SCRIPT>"ENTRY" { RTOKEN(ENTRY);} |
264 | <BOTH,SCRIPT,MRI>"EXTERN" { RTOKEN(EXTERN);} | |
3ec57632 | 265 | <EXPRESSION,BOTH,SCRIPT>"NEXT" { RTOKEN(NEXT);} |
252b5132 RH |
266 | <EXPRESSION,BOTH,SCRIPT>"sizeof_headers" { RTOKEN(SIZEOF_HEADERS);} |
267 | <EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS" { RTOKEN(SIZEOF_HEADERS);} | |
ba916c8a | 268 | <EXPRESSION,BOTH,SCRIPT>"SEGMENT_START" { RTOKEN(SEGMENT_START);} |
252b5132 | 269 | <BOTH,SCRIPT>"MAP" { RTOKEN(MAP);} |
3ec57632 NC |
270 | <EXPRESSION,BOTH,SCRIPT>"SIZEOF" { RTOKEN(SIZEOF);} |
271 | <BOTH,SCRIPT>"TARGET" { RTOKEN(TARGET_K);} | |
252b5132 | 272 | <BOTH,SCRIPT>"SEARCH_DIR" { RTOKEN(SEARCH_DIR);} |
3ec57632 | 273 | <BOTH,SCRIPT>"OUTPUT" { RTOKEN(OUTPUT);} |
252b5132 RH |
274 | <BOTH,SCRIPT>"INPUT" { RTOKEN(INPUT);} |
275 | <EXPRESSION,BOTH,SCRIPT>"GROUP" { RTOKEN(GROUP);} | |
b717d30e | 276 | <EXPRESSION,BOTH,SCRIPT>"AS_NEEDED" { RTOKEN(AS_NEEDED);} |
3ec57632 | 277 | <EXPRESSION,BOTH,SCRIPT>"DEFINED" { RTOKEN(DEFINED);} |
252b5132 RH |
278 | <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);} |
279 | <BOTH,SCRIPT>"CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);} | |
3ec57632 | 280 | <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);} |
4818e05f | 281 | <BOTH,SCRIPT>"INHIBIT_COMMON_ALLOCATION" { RTOKEN(INHIBIT_COMMON_ALLOCATION);} |
3ec57632 | 282 | <BOTH,SCRIPT>"SECTIONS" { RTOKEN(SECTIONS);} |
53d25da6 AM |
283 | <BOTH,SCRIPT>"INSERT" { RTOKEN(INSERT_K);} |
284 | <BOTH,SCRIPT>"AFTER" { RTOKEN(AFTER);} | |
285 | <BOTH,SCRIPT>"BEFORE" { RTOKEN(BEFORE);} | |
252b5132 | 286 | <BOTH,SCRIPT>"FILL" { RTOKEN(FILL);} |
3ec57632 | 287 | <BOTH,SCRIPT>"STARTUP" { RTOKEN(STARTUP);} |
252b5132 RH |
288 | <BOTH,SCRIPT>"OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT);} |
289 | <BOTH,SCRIPT>"OUTPUT_ARCH" { RTOKEN( OUTPUT_ARCH);} | |
290 | <BOTH,SCRIPT>"HLL" { RTOKEN(HLL);} | |
3ec57632 | 291 | <BOTH,SCRIPT>"SYSLIB" { RTOKEN(SYSLIB);} |
252b5132 RH |
292 | <BOTH,SCRIPT>"FLOAT" { RTOKEN(FLOAT);} |
293 | <BOTH,SCRIPT>"QUAD" { RTOKEN( QUAD);} | |
294 | <BOTH,SCRIPT>"SQUAD" { RTOKEN( SQUAD);} | |
295 | <BOTH,SCRIPT>"LONG" { RTOKEN( LONG);} | |
296 | <BOTH,SCRIPT>"SHORT" { RTOKEN( SHORT);} | |
297 | <BOTH,SCRIPT>"BYTE" { RTOKEN( BYTE);} | |
3ec57632 | 298 | <BOTH,SCRIPT>"NOFLOAT" { RTOKEN(NOFLOAT);} |
252b5132 RH |
299 | <EXPRESSION,BOTH,SCRIPT>"NOCROSSREFS" { RTOKEN(NOCROSSREFS);} |
300 | <BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY); } | |
bcaa7b3e L |
301 | <BOTH,SCRIPT>"SORT_BY_NAME" { RTOKEN(SORT_BY_NAME); } |
302 | <BOTH,SCRIPT>"SORT_BY_ALIGNMENT" { RTOKEN(SORT_BY_ALIGNMENT); } | |
303 | <BOTH,SCRIPT>"SORT" { RTOKEN(SORT_BY_NAME); } | |
02ecc8e9 | 304 | <BOTH,SCRIPT>"SORT_BY_INIT_PRIORITY" { RTOKEN(SORT_BY_INIT_PRIORITY); } |
eda680f8 | 305 | <BOTH,SCRIPT>"SORT_NONE" { RTOKEN(SORT_NONE); } |
252b5132 RH |
306 | <EXPRESSION,BOTH,SCRIPT>"NOLOAD" { RTOKEN(NOLOAD);} |
307 | <EXPRESSION,BOTH,SCRIPT>"DSECT" { RTOKEN(DSECT);} | |
308 | <EXPRESSION,BOTH,SCRIPT>"COPY" { RTOKEN(COPY);} | |
309 | <EXPRESSION,BOTH,SCRIPT>"INFO" { RTOKEN(INFO);} | |
310 | <EXPRESSION,BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY);} | |
0841712e JJ |
311 | <EXPRESSION,BOTH,SCRIPT>"ONLY_IF_RO" { RTOKEN(ONLY_IF_RO); } |
312 | <EXPRESSION,BOTH,SCRIPT>"ONLY_IF_RW" { RTOKEN(ONLY_IF_RW); } | |
0cf7d72c | 313 | <EXPRESSION,BOTH,SCRIPT>"SPECIAL" { RTOKEN(SPECIAL); } |
252b5132 RH |
314 | <BOTH,SCRIPT>"o" { RTOKEN(ORIGIN);} |
315 | <BOTH,SCRIPT>"org" { RTOKEN(ORIGIN);} | |
316 | <BOTH,SCRIPT>"l" { RTOKEN( LENGTH);} | |
317 | <BOTH,SCRIPT>"len" { RTOKEN( LENGTH);} | |
ae17ab41 | 318 | <EXPRESSION,BOTH,SCRIPT>"INPUT_SECTION_FLAGS" { RTOKEN(INPUT_SECTION_FLAGS); } |
4006703d | 319 | <EXPRESSION,BOTH,SCRIPT>"INCLUDE" { RTOKEN(INCLUDE);} |
252b5132 | 320 | <BOTH,SCRIPT>"PHDRS" { RTOKEN (PHDRS); } |
3ec57632 NC |
321 | <EXPRESSION,BOTH,SCRIPT>"AT" { RTOKEN(AT);} |
322 | <EXPRESSION,BOTH,SCRIPT>"SUBALIGN" { RTOKEN(SUBALIGN);} | |
eb8476a6 | 323 | <EXPRESSION,BOTH,SCRIPT>"HIDDEN" { RTOKEN(HIDDEN); } |
3ec57632 | 324 | <EXPRESSION,BOTH,SCRIPT>"PROVIDE" { RTOKEN(PROVIDE); } |
7af8e998 | 325 | <EXPRESSION,BOTH,SCRIPT>"PROVIDE_HIDDEN" { RTOKEN(PROVIDE_HIDDEN); } |
252b5132 | 326 | <EXPRESSION,BOTH,SCRIPT>"KEEP" { RTOKEN(KEEP); } |
3ec57632 | 327 | <EXPRESSION,BOTH,SCRIPT>"EXCLUDE_FILE" { RTOKEN(EXCLUDE_FILE); } |
24718e3b | 328 | <EXPRESSION,BOTH,SCRIPT>"CONSTANT" { RTOKEN(CONSTANT);} |
252b5132 RH |
329 | <MRI>"#".*\n? { ++ lineno; } |
330 | <MRI>"\n" { ++ lineno; RTOKEN(NEWLINE); } | |
331 | <MRI>"*".* { /* Mri comment line */ } | |
332 | <MRI>";".* { /* Mri comment line */ } | |
333 | <MRI>"END" { RTOKEN(ENDWORD); } | |
3ec57632 NC |
334 | <MRI>"ALIGNMOD" { RTOKEN(ALIGNMOD);} |
335 | <MRI>"ALIGN" { RTOKEN(ALIGN_K);} | |
252b5132 RH |
336 | <MRI>"CHIP" { RTOKEN(CHIP); } |
337 | <MRI>"BASE" { RTOKEN(BASE); } | |
3ec57632 NC |
338 | <MRI>"ALIAS" { RTOKEN(ALIAS); } |
339 | <MRI>"TRUNCATE" { RTOKEN(TRUNCATE); } | |
252b5132 RH |
340 | <MRI>"LOAD" { RTOKEN(LOAD); } |
341 | <MRI>"PUBLIC" { RTOKEN(PUBLIC); } | |
342 | <MRI>"ORDER" { RTOKEN(ORDER); } | |
343 | <MRI>"NAME" { RTOKEN(NAMEWORD); } | |
344 | <MRI>"FORMAT" { RTOKEN(FORMAT); } | |
345 | <MRI>"CASE" { RTOKEN(CASE); } | |
346 | <MRI>"START" { RTOKEN(START); } | |
347 | <MRI>"LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ } | |
348 | <MRI>"SECT" { RTOKEN(SECT); } | |
349 | <EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE" { RTOKEN(ABSOLUTE); } | |
350 | <MRI>"end" { RTOKEN(ENDWORD); } | |
3ec57632 NC |
351 | <MRI>"alignmod" { RTOKEN(ALIGNMOD);} |
352 | <MRI>"align" { RTOKEN(ALIGN_K);} | |
252b5132 RH |
353 | <MRI>"chip" { RTOKEN(CHIP); } |
354 | <MRI>"base" { RTOKEN(BASE); } | |
3ec57632 NC |
355 | <MRI>"alias" { RTOKEN(ALIAS); } |
356 | <MRI>"truncate" { RTOKEN(TRUNCATE); } | |
252b5132 RH |
357 | <MRI>"load" { RTOKEN(LOAD); } |
358 | <MRI>"public" { RTOKEN(PUBLIC); } | |
359 | <MRI>"order" { RTOKEN(ORDER); } | |
360 | <MRI>"name" { RTOKEN(NAMEWORD); } | |
361 | <MRI>"format" { RTOKEN(FORMAT); } | |
362 | <MRI>"case" { RTOKEN(CASE); } | |
363 | <MRI>"extern" { RTOKEN(EXTERN); } | |
364 | <MRI>"start" { RTOKEN(START); } | |
365 | <MRI>"list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ } | |
366 | <MRI>"sect" { RTOKEN(SECT); } | |
367 | <EXPRESSION,BOTH,SCRIPT,MRI>"absolute" { RTOKEN(ABSOLUTE); } | |
368 | ||
369 | <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* { | |
370 | /* Filename without commas, needed to parse mri stuff */ | |
1579bae1 | 371 | yylval.name = xstrdup (yytext); |
252b5132 RH |
372 | return NAME; |
373 | } | |
374 | ||
375 | ||
8545d1a9 | 376 | <BOTH>{FILENAMECHAR1}{FILENAMECHAR}* { |
1579bae1 | 377 | yylval.name = xstrdup (yytext); |
252b5132 RH |
378 | return NAME; |
379 | } | |
8545d1a9 NS |
380 | <BOTH>"-l"{FILENAMECHAR}+ { |
381 | yylval.name = xstrdup (yytext + 2); | |
382 | return LNAME; | |
383 | } | |
384 | <EXPRESSION>{FILENAMECHAR1}{NOCFILENAMECHAR}* { | |
385 | yylval.name = xstrdup (yytext); | |
386 | return NAME; | |
387 | } | |
388 | <EXPRESSION>"-l"{NOCFILENAMECHAR}+ { | |
d1b2b2dc | 389 | yylval.name = xstrdup (yytext + 2); |
252b5132 RH |
390 | return LNAME; |
391 | } | |
392 | <SCRIPT>{WILDCHAR}* { | |
393 | /* Annoyingly, this pattern can match comments, and we have | |
394 | longest match issues to consider. So if the first two | |
395 | characters are a comment opening, put the input back and | |
396 | try again. */ | |
397 | if (yytext[0] == '/' && yytext[1] == '*') | |
398 | { | |
1579bae1 | 399 | yyless (2); |
252b5132 RH |
400 | comment (); |
401 | } | |
402 | else | |
403 | { | |
1579bae1 | 404 | yylval.name = xstrdup (yytext); |
252b5132 RH |
405 | return NAME; |
406 | } | |
407 | } | |
408 | ||
409 | <EXPRESSION,BOTH,SCRIPT,VERS_NODE>"\""[^\"]*"\"" { | |
410 | /* No matter the state, quotes | |
411 | give what's inside */ | |
1579bae1 AM |
412 | yylval.name = xstrdup (yytext + 1); |
413 | yylval.name[yyleng - 2] = 0; | |
252b5132 RH |
414 | return NAME; |
415 | } | |
416 | <BOTH,SCRIPT,EXPRESSION>"\n" { lineno++;} | |
417 | <MRI,BOTH,SCRIPT,EXPRESSION>[ \t\r]+ { } | |
418 | ||
419 | <VERS_NODE,VERS_SCRIPT>[:,;] { return *yytext; } | |
420 | ||
421 | <VERS_NODE>global { RTOKEN(GLOBAL); } | |
422 | ||
423 | <VERS_NODE>local { RTOKEN(LOCAL); } | |
424 | ||
425 | <VERS_NODE>extern { RTOKEN(EXTERN); } | |
426 | ||
d1b2b2dc | 427 | <VERS_NODE>{V_IDENTIFIER} { yylval.name = xstrdup (yytext); |
252b5132 RH |
428 | return VERS_IDENTIFIER; } |
429 | ||
d1b2b2dc | 430 | <VERS_SCRIPT>{V_TAG} { yylval.name = xstrdup (yytext); |
252b5132 RH |
431 | return VERS_TAG; } |
432 | ||
433 | <VERS_START>"{" { BEGIN(VERS_SCRIPT); return *yytext; } | |
434 | ||
1579bae1 | 435 | <VERS_SCRIPT>"{" { BEGIN(VERS_NODE); |
252b5132 RH |
436 | vers_node_nesting = 0; |
437 | return *yytext; | |
438 | } | |
439 | <VERS_SCRIPT>"}" { return *yytext; } | |
440 | <VERS_NODE>"{" { vers_node_nesting++; return *yytext; } | |
441 | <VERS_NODE>"}" { if (--vers_node_nesting < 0) | |
442 | BEGIN(VERS_SCRIPT); | |
443 | return *yytext; | |
444 | } | |
445 | ||
446 | <VERS_START,VERS_NODE,VERS_SCRIPT>[\n] { lineno++; } | |
447 | ||
448 | <VERS_START,VERS_NODE,VERS_SCRIPT>#.* { /* Eat up comments */ } | |
449 | ||
450 | <VERS_START,VERS_NODE,VERS_SCRIPT>[ \t\r]+ { /* Eat up whitespace */ } | |
451 | ||
452 | <<EOF>> { | |
453 | include_stack_ptr--; | |
1579bae1 | 454 | if (include_stack_ptr == 0) |
1579bae1 | 455 | yyterminate (); |
1579bae1 | 456 | else |
1579bae1 | 457 | yy_switch_to_buffer (include_stack[include_stack_ptr]); |
b47c4208 | 458 | |
b47c4208 | 459 | lineno = lineno_stack[include_stack_ptr]; |
f4a23d42 | 460 | input_flags.sysrooted = sysrooted_stack[include_stack_ptr]; |
252b5132 RH |
461 | |
462 | return END; | |
463 | } | |
464 | ||
1579bae1 AM |
465 | <SCRIPT,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>. lex_warn_invalid (" in script", yytext); |
466 | <EXPRESSION,DEFSYMEXP,BOTH>. lex_warn_invalid (" in expression", yytext); | |
467 | ||
252b5132 RH |
468 | %% |
469 | \f | |
470 | ||
471 | /* Switch flex to reading script file NAME, open on FILE, | |
472 | saving the current input info on the include stack. */ | |
473 | ||
474 | void | |
f4a23d42 | 475 | lex_push_file (FILE *file, const char *name, unsigned int sysrooted) |
252b5132 | 476 | { |
1579bae1 | 477 | if (include_stack_ptr >= MAX_INCLUDE_DEPTH) |
252b5132 | 478 | { |
1579bae1 | 479 | einfo ("%F:includes nested too deeply\n"); |
252b5132 RH |
480 | } |
481 | file_name_stack[include_stack_ptr] = name; | |
b47c4208 | 482 | lineno_stack[include_stack_ptr] = lineno; |
f4a23d42 | 483 | sysrooted_stack[include_stack_ptr] = input_flags.sysrooted; |
252b5132 RH |
484 | include_stack[include_stack_ptr] = YY_CURRENT_BUFFER; |
485 | ||
486 | include_stack_ptr++; | |
b47c4208 | 487 | lineno = 1; |
f4a23d42 | 488 | input_flags.sysrooted = sysrooted; |
252b5132 | 489 | yyin = file; |
1579bae1 | 490 | yy_switch_to_buffer (yy_create_buffer (yyin, YY_BUF_SIZE)); |
252b5132 RH |
491 | } |
492 | ||
493 | /* Return a newly created flex input buffer containing STRING, | |
494 | which is SIZE bytes long. */ | |
495 | ||
1579bae1 AM |
496 | static YY_BUFFER_STATE |
497 | yy_create_string_buffer (const char *string, size_t size) | |
252b5132 RH |
498 | { |
499 | YY_BUFFER_STATE b; | |
500 | ||
501 | /* Calls to m-alloc get turned by sed into xm-alloc. */ | |
1579bae1 | 502 | b = malloc (sizeof (struct yy_buffer_state)); |
252b5132 RH |
503 | b->yy_input_file = 0; |
504 | b->yy_buf_size = size; | |
505 | ||
506 | /* yy_ch_buf has to be 2 characters longer than the size given because | |
507 | we need to put in 2 end-of-buffer characters. */ | |
1579bae1 | 508 | b->yy_ch_buf = malloc ((unsigned) (b->yy_buf_size + 3)); |
252b5132 RH |
509 | |
510 | b->yy_ch_buf[0] = '\n'; | |
511 | strcpy (b->yy_ch_buf+1, string); | |
512 | b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR; | |
513 | b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR; | |
514 | b->yy_n_chars = size+1; | |
515 | b->yy_buf_pos = &b->yy_ch_buf[1]; | |
516 | ||
dca7760f AM |
517 | b->yy_is_our_buffer = 1; |
518 | b->yy_is_interactive = 0; | |
519 | b->yy_at_bol = 1; | |
520 | b->yy_fill_buffer = 0; | |
521 | ||
252b5132 RH |
522 | /* flex 2.4.7 changed the interface. FIXME: We should not be using |
523 | a flex internal interface in the first place! */ | |
524 | #ifdef YY_BUFFER_NEW | |
525 | b->yy_buffer_status = YY_BUFFER_NEW; | |
526 | #else | |
527 | b->yy_eof_status = EOF_NOT_SEEN; | |
528 | #endif | |
529 | ||
530 | return b; | |
531 | } | |
532 | ||
533 | /* Switch flex to reading from STRING, saving the current input info | |
534 | on the include stack. */ | |
535 | ||
536 | void | |
dab69f68 | 537 | lex_redirect (const char *string, const char *fake_filename, unsigned int count) |
252b5132 RH |
538 | { |
539 | YY_BUFFER_STATE tmp; | |
540 | ||
541 | yy_init = 0; | |
1579bae1 | 542 | if (include_stack_ptr >= MAX_INCLUDE_DEPTH) |
252b5132 RH |
543 | { |
544 | einfo("%F: macros nested too deeply\n"); | |
545 | } | |
dab69f68 | 546 | file_name_stack[include_stack_ptr] = fake_filename; |
b47c4208 | 547 | lineno_stack[include_stack_ptr] = lineno; |
252b5132 RH |
548 | include_stack[include_stack_ptr] = YY_CURRENT_BUFFER; |
549 | include_stack_ptr++; | |
dab69f68 | 550 | lineno = count; |
252b5132 RH |
551 | tmp = yy_create_string_buffer (string, strlen (string)); |
552 | yy_switch_to_buffer (tmp); | |
252b5132 RH |
553 | } |
554 | \f | |
555 | /* Functions to switch to a different flex start condition, | |
556 | saving the current start condition on `state_stack'. */ | |
557 | ||
558 | static int state_stack[MAX_INCLUDE_DEPTH * 2]; | |
559 | static int *state_stack_p = state_stack; | |
560 | ||
561 | void | |
1579bae1 | 562 | ldlex_script (void) |
252b5132 RH |
563 | { |
564 | *(state_stack_p)++ = yy_start; | |
565 | BEGIN (SCRIPT); | |
566 | } | |
567 | ||
568 | void | |
1579bae1 | 569 | ldlex_mri_script (void) |
252b5132 RH |
570 | { |
571 | *(state_stack_p)++ = yy_start; | |
572 | BEGIN (MRI); | |
573 | } | |
574 | ||
575 | void | |
1579bae1 | 576 | ldlex_version_script (void) |
252b5132 RH |
577 | { |
578 | *(state_stack_p)++ = yy_start; | |
579 | BEGIN (VERS_START); | |
580 | } | |
581 | ||
582 | void | |
1579bae1 | 583 | ldlex_version_file (void) |
252b5132 RH |
584 | { |
585 | *(state_stack_p)++ = yy_start; | |
586 | BEGIN (VERS_SCRIPT); | |
587 | } | |
588 | ||
589 | void | |
1579bae1 | 590 | ldlex_defsym (void) |
252b5132 RH |
591 | { |
592 | *(state_stack_p)++ = yy_start; | |
593 | BEGIN (DEFSYMEXP); | |
594 | } | |
1579bae1 | 595 | |
252b5132 | 596 | void |
1579bae1 | 597 | ldlex_expression (void) |
252b5132 RH |
598 | { |
599 | *(state_stack_p)++ = yy_start; | |
600 | BEGIN (EXPRESSION); | |
601 | } | |
602 | ||
603 | void | |
1579bae1 | 604 | ldlex_both (void) |
252b5132 RH |
605 | { |
606 | *(state_stack_p)++ = yy_start; | |
607 | BEGIN (BOTH); | |
608 | } | |
609 | ||
610 | void | |
1579bae1 | 611 | ldlex_popstate (void) |
252b5132 RH |
612 | { |
613 | yy_start = *(--state_stack_p); | |
614 | } | |
dab69f68 AM |
615 | |
616 | /* Return the current file name, or the previous file if no file is | |
617 | current. */ | |
618 | ||
619 | const char* | |
620 | ldlex_filename (void) | |
621 | { | |
622 | return file_name_stack[include_stack_ptr - (include_stack_ptr != 0)]; | |
623 | } | |
252b5132 RH |
624 | \f |
625 | ||
d05c651b | 626 | /* Place up to MAX_SIZE characters in BUF and return |
252b5132 RH |
627 | either the number of characters read, or 0 to indicate EOF. */ |
628 | ||
d05c651b AS |
629 | static int |
630 | yy_input (char *buf, int max_size) | |
252b5132 | 631 | { |
d05c651b | 632 | int result = 0; |
731e28d8 | 633 | if (YY_CURRENT_BUFFER->yy_input_file) |
252b5132 RH |
634 | { |
635 | if (yyin) | |
636 | { | |
d05c651b AS |
637 | result = fread (buf, 1, max_size, yyin); |
638 | if (result < max_size && ferror (yyin)) | |
252b5132 RH |
639 | einfo ("%F%P: read in flex scanner failed\n"); |
640 | } | |
641 | } | |
d05c651b | 642 | return result; |
252b5132 RH |
643 | } |
644 | ||
645 | /* Eat the rest of a C-style comment. */ | |
646 | ||
647 | static void | |
1579bae1 | 648 | comment (void) |
252b5132 RH |
649 | { |
650 | int c; | |
651 | ||
652 | while (1) | |
653 | { | |
654 | c = input(); | |
1579bae1 | 655 | while (c != '*' && c != EOF) |
252b5132 RH |
656 | { |
657 | if (c == '\n') | |
658 | lineno++; | |
659 | c = input(); | |
660 | } | |
661 | ||
662 | if (c == '*') | |
663 | { | |
664 | c = input(); | |
665 | while (c == '*') | |
666 | c = input(); | |
667 | if (c == '/') | |
668 | break; /* found the end */ | |
669 | } | |
670 | ||
671 | if (c == '\n') | |
672 | lineno++; | |
673 | ||
674 | if (c == EOF) | |
675 | { | |
676 | einfo( "%F%P: EOF in comment\n"); | |
677 | break; | |
678 | } | |
679 | } | |
680 | } | |
681 | ||
682 | /* Warn the user about a garbage character WHAT in the input | |
683 | in context WHERE. */ | |
684 | ||
685 | static void | |
1579bae1 | 686 | lex_warn_invalid (char *where, char *what) |
252b5132 RH |
687 | { |
688 | char buf[5]; | |
689 | ||
690 | /* If we have found an input file whose format we do not recognize, | |
691 | and we are therefore treating it as a linker script, and we find | |
692 | an invalid character, then most likely this is a real object file | |
693 | of some different format. Treat it as such. */ | |
694 | if (ldfile_assumed_script) | |
695 | { | |
696 | bfd_set_error (bfd_error_file_not_recognized); | |
dab69f68 | 697 | einfo ("%F%s: file not recognized: %E\n", ldlex_filename ()); |
252b5132 RH |
698 | } |
699 | ||
3882b010 | 700 | if (! ISPRINT (*what)) |
252b5132 | 701 | { |
c3a7b120 | 702 | sprintf (buf, "\\%03o", *(unsigned char *) what); |
252b5132 RH |
703 | what = buf; |
704 | } | |
705 | ||
dab69f68 | 706 | einfo ("%P:%S: ignoring invalid character `%s'%s\n", NULL, what, where); |
252b5132 | 707 | } |