1 %option nounput noyywrap
5 /* Copyright (C) 1991-2024 Free Software Foundation, Inc.
6 Written by Steve Chamberlain of Cygnus Support.
8 This file is part of the GNU Binutils.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 MA 02110-1301, USA. */
26 #include "safe-ctype.h"
37 #include "libiberty.h"
39 /* The type of top-level parser input.
40 yylex and yyparse (indirectly) both check this. */
41 input_type parser_input;
43 /* Line number in the current input file. */
46 /* The string we are currently lexing, or NULL if we are reading a
48 const char *lex_string = NULL;
50 /* Support for flex reading from more than one input file (stream).
51 `include_stack' is flex's input state for each open file;
52 `file_name_stack' is the file names. `lineno_stack' is the current
55 If `include_stack_ptr' is 0, we haven't started reading anything yet.
56 Otherwise, stack elements 0 through `include_stack_ptr - 1' are valid. */
59 #define YY_INPUT(buf,result,max_size) result = yy_input (buf, max_size)
65 #define MAX_INCLUDE_DEPTH 10
66 static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
67 static const char *file_name_stack[MAX_INCLUDE_DEPTH];
68 static unsigned int lineno_stack[MAX_INCLUDE_DEPTH];
69 static unsigned int sysrooted_stack[MAX_INCLUDE_DEPTH];
70 static unsigned int include_stack_ptr = 0;
71 static int vers_node_nesting = 0;
73 static int yy_input (char *, int);
74 static void comment (void);
75 static void lex_warn_invalid (char *where, char *what);
78 EXPRESSION in an expression
80 INPUTLIST in a script, a filename-list
82 WILD inside the braces of an output section or overlay,
83 for input section wildcards
84 VERS_START starting a Sun style mapfile
85 VERS_SCRIPT a Sun style mapfile
86 VERS_NODE a node within a Sun style mapfile
88 #define RTOKEN(x) { yylval.token = x; return x; }
95 WILDCHAR [_a-zA-Z0-9\/\.\\\$\~\-\+\:\[\]\,\=\?\*\^\!]
96 FILENAMECHAR [_a-zA-Z0-9\/\.\\\$\~\-\+\:\[\]\,\=]
97 NOCFILENAMECHAR [_a-zA-Z0-9\/\.\\\$\~\-\+\:\[\]]
98 SYMBOLNAMECHAR [_a-zA-Z0-9\/\.\\\$\~]
99 FILENAMECHAR1 [_a-zA-Z\/\.\\\$\~]
100 SYMBOLNAMECHAR1 [_a-zA-Z\.\\\$]
103 V_TAG [.$_a-zA-Z][._a-zA-Z0-9]*
104 V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
116 if (parser_input != input_selected)
118 /* The first token of the input determines the initial parser state. */
119 input_type t = parser_input;
120 parser_input = input_selected;
123 case input_script: return INPUT_SCRIPT; break;
124 case input_mri_script: return INPUT_MRI_SCRIPT; break;
125 case input_version_script: return INPUT_VERSION_SCRIPT; break;
126 case input_dynamic_list: return INPUT_DYNAMIC_LIST; break;
127 case input_defsym: return INPUT_DEFSYM; break;
132 <SCRIPT,EXPRESSION,VERS_START,VERS_NODE,VERS_SCRIPT,INPUTLIST>"/*" {
135 <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
136 yylval.integer = strtoull (yytext + 1, 0, 16);
137 yylval.bigint.str = NULL;
141 <MRI,EXPRESSION>([0-9A-Fa-f])+(H|h|X|x|B|b|O|o|D|d) {
143 switch (yytext[yyleng - 1]) {
161 yylval.integer = strtoull (yytext, 0, ibase);
162 yylval.bigint.str = NULL;
165 <SCRIPT,MRI,EXPRESSION>((("$"|0[xX])([0-9A-Fa-f])+)|(([0-9])+))(M|K|m|k)? {
174 yylval.integer = strtoull (s, 0, ibase);
175 yylval.bigint.str = NULL;
176 if (yytext[yyleng - 1] == 'M'
177 || yytext[yyleng - 1] == 'm')
179 yylval.integer *= 1024 * 1024;
181 else if (yytext[yyleng - 1] == 'K'
182 || yytext[yyleng - 1]=='k')
184 yylval.integer *= 1024;
186 else if (yytext[0] == '0'
188 || yytext[1] == 'X'))
190 yylval.bigint.str = xstrdup (yytext + 2);
195 /* Some tokens that only appear in expressions must be enabled for
196 states other than EXPRESSION, since parser lookahead means they
197 must be recognised before the parser switches the lexer out of
198 SCRIPT or WILD state into EXPRESSION state.
200 This sort of thing happens for example with NAME in ldgram.y
201 "section" rule, which is immediately followed by ldlex_expression.
202 However, if you follow the grammar from "sec_or_group_p1" you see
203 "assignment" appearing in "statement_anywhere". Now,
204 "assignment" also has NAME as its first token, just like
205 "section". So the parser can't know whether it is in the
206 "section" or the "assignment" rule until it has scanned the next
207 token to find an assignment operator. Thus the next token after
208 NAME in the "section" rule may be lexed before the lexer is
209 switched to EXPRESSION state, and there are quite a number of
210 optional components. The first token in all those components
211 must be able to be lexed in SCRIPT state, as well as the
212 assignment operators. In fact, due to "opt_exp_with_type",
213 anything that can appear on the left hand side of "exp" might
214 need to be lexed in SCRIPT state.
216 MRI mode tends to cover everything in MRI scripts.
218 <MRI,WILD>"]" { RTOKEN(']'); }
219 <MRI,WILD>"[" { RTOKEN('['); }
220 <SCRIPT,EXPRESSION,MRI,WILD>"<<=" { RTOKEN(LSHIFTEQ); }
221 <SCRIPT,EXPRESSION,MRI,WILD>">>=" { RTOKEN(RSHIFTEQ); }
222 <EXPRESSION,MRI>"||" { RTOKEN(OROR); }
223 <EXPRESSION,MRI>"==" { RTOKEN(EQ); }
224 <EXPRESSION,MRI>"!=" { RTOKEN(NE); }
225 <EXPRESSION,MRI>">=" { RTOKEN(GE); }
226 <EXPRESSION,MRI>"<=" { RTOKEN(LE); }
227 <EXPRESSION,MRI>"<<" { RTOKEN(LSHIFT); }
228 <EXPRESSION,MRI>">>" { RTOKEN(RSHIFT); }
229 <SCRIPT,EXPRESSION,MRI,WILD>"+=" { RTOKEN(PLUSEQ); }
230 <SCRIPT,EXPRESSION,MRI,WILD>"-=" { RTOKEN(MINUSEQ); }
231 <SCRIPT,EXPRESSION,MRI,WILD>"*=" { RTOKEN(MULTEQ); }
232 <SCRIPT,EXPRESSION,MRI,WILD>"/=" { RTOKEN(DIVEQ); }
233 <SCRIPT,EXPRESSION,MRI,WILD>"&=" { RTOKEN(ANDEQ); }
234 <SCRIPT,EXPRESSION,MRI,WILD>"|=" { RTOKEN(OREQ); }
235 <SCRIPT,EXPRESSION,MRI,WILD>"^=" { RTOKEN(XOREQ); }
236 <EXPRESSION,MRI>"&&" { RTOKEN(ANDAND); }
237 <SCRIPT,EXPRESSION,MRI>">" { RTOKEN('>'); }
238 <SCRIPT,EXPRESSION,MRI,INPUTLIST>"," { RTOKEN(','); }
239 <EXPRESSION,MRI,WILD>"&" { RTOKEN('&'); }
240 <EXPRESSION,MRI>"|" { RTOKEN('|'); }
241 <SCRIPT,EXPRESSION,MRI>"~" { RTOKEN('~'); }
242 <SCRIPT,EXPRESSION,MRI>"!" { RTOKEN('!'); }
243 <EXPRESSION,MRI>"?" { RTOKEN('?'); }
244 <EXPRESSION,MRI>"*" { RTOKEN('*'); }
245 <SCRIPT,EXPRESSION,MRI>"+" { RTOKEN('+'); }
246 <SCRIPT,EXPRESSION,MRI>"-" { RTOKEN('-'); }
247 <EXPRESSION,MRI>"/" { RTOKEN('/'); }
248 <EXPRESSION,MRI>"%" { RTOKEN('%'); }
249 <EXPRESSION,MRI>"<" { RTOKEN('<'); }
250 <EXPRESSION,MRI>"^" { RTOKEN('^'); }
251 <SCRIPT,EXPRESSION,MRI,WILD>"=" { RTOKEN('='); }
252 <SCRIPT,EXPRESSION,MRI,WILD>"}" { RTOKEN('}'); }
253 <SCRIPT,EXPRESSION,MRI,WILD>"{" { RTOKEN('{'); }
254 <SCRIPT,EXPRESSION,MRI,WILD,INPUTLIST>")" { RTOKEN(')'); }
255 <SCRIPT,EXPRESSION,MRI,WILD,INPUTLIST>"(" { RTOKEN('('); }
256 <SCRIPT,EXPRESSION,MRI>":" { RTOKEN(':'); }
257 <SCRIPT,EXPRESSION,MRI,WILD>";" { RTOKEN(';'); }
258 <SCRIPT>"MEMORY" { RTOKEN(MEMORY); }
259 <SCRIPT>"REGION_ALIAS" { RTOKEN(REGION_ALIAS); }
260 <SCRIPT>"LD_FEATURE" { RTOKEN(LD_FEATURE); }
261 <SCRIPT,EXPRESSION>"ORIGIN" { RTOKEN(ORIGIN); }
262 <SCRIPT>"VERSION" { RTOKEN(VERSIONK); }
263 <SCRIPT,EXPRESSION>"BLOCK" { RTOKEN(BLOCK); }
264 <SCRIPT,EXPRESSION>"BIND" { RTOKEN(BIND); }
265 <SCRIPT,EXPRESSION>"LENGTH" { RTOKEN(LENGTH); }
266 <SCRIPT,EXPRESSION>"ALIGN" { RTOKEN(ALIGN_K); }
267 <SCRIPT,EXPRESSION>"DATA_SEGMENT_ALIGN" { RTOKEN(DATA_SEGMENT_ALIGN); }
268 <SCRIPT,EXPRESSION>"DATA_SEGMENT_RELRO_END" { RTOKEN(DATA_SEGMENT_RELRO_END); }
269 <SCRIPT,EXPRESSION>"DATA_SEGMENT_END" { RTOKEN(DATA_SEGMENT_END); }
270 <SCRIPT,EXPRESSION>"ADDR" { RTOKEN(ADDR); }
271 <SCRIPT,EXPRESSION>"LOADADDR" { RTOKEN(LOADADDR); }
272 <SCRIPT,EXPRESSION>"ALIGNOF" { RTOKEN(ALIGNOF); }
273 <SCRIPT,EXPRESSION>"ABSOLUTE" { RTOKEN(ABSOLUTE); }
274 <SCRIPT,EXPRESSION>"MAX" { RTOKEN(MAX_K); }
275 <SCRIPT,EXPRESSION>"MIN" { RTOKEN(MIN_K); }
276 <SCRIPT,EXPRESSION>"LOG2CEIL" { RTOKEN(LOG2CEIL); }
277 <SCRIPT,EXPRESSION,WILD>"ASSERT" { RTOKEN(ASSERT_K); }
278 <SCRIPT>"ENTRY" { RTOKEN(ENTRY); }
279 <SCRIPT,MRI>"EXTERN" { RTOKEN(EXTERN); }
280 <SCRIPT,EXPRESSION>"NEXT" { RTOKEN(NEXT); }
281 <SCRIPT,EXPRESSION>"SIZEOF_HEADERS" { RTOKEN(SIZEOF_HEADERS); }
282 <SCRIPT,EXPRESSION>"SEGMENT_START" { RTOKEN(SEGMENT_START); }
283 <SCRIPT>"MAP" { RTOKEN(MAP); }
284 <SCRIPT,EXPRESSION>"SIZEOF" { RTOKEN(SIZEOF); }
285 <SCRIPT>"TARGET" { RTOKEN(TARGET_K); }
286 <SCRIPT>"SEARCH_DIR" { RTOKEN(SEARCH_DIR); }
287 <SCRIPT>"OUTPUT" { RTOKEN(OUTPUT); }
288 <SCRIPT>"INPUT" { RTOKEN(INPUT); }
289 <SCRIPT>"GROUP" { RTOKEN(GROUP); }
290 <INPUTLIST>"AS_NEEDED" { RTOKEN(AS_NEEDED); }
291 <SCRIPT,EXPRESSION>"DEFINED" { RTOKEN(DEFINED); }
292 <WILD>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS); }
293 <WILD>"CONSTRUCTORS" { RTOKEN(CONSTRUCTORS); }
294 <SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION); }
295 <SCRIPT>"FORCE_GROUP_ALLOCATION" { RTOKEN(FORCE_GROUP_ALLOCATION); }
296 <SCRIPT>"INHIBIT_COMMON_ALLOCATION" { RTOKEN(INHIBIT_COMMON_ALLOCATION); }
297 <SCRIPT>"SECTIONS" { RTOKEN(SECTIONS); }
298 <SCRIPT>"INSERT" { RTOKEN(INSERT_K); }
299 <SCRIPT>"AFTER" { RTOKEN(AFTER); }
300 <SCRIPT>"BEFORE" { RTOKEN(BEFORE); }
301 <WILD>"FILL" { RTOKEN(FILL); }
302 <SCRIPT>"STARTUP" { RTOKEN(STARTUP); }
303 <SCRIPT>"OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT); }
304 <SCRIPT>"OUTPUT_ARCH" { RTOKEN(OUTPUT_ARCH); }
305 <SCRIPT>"HLL" { RTOKEN(HLL); }
306 <SCRIPT>"SYSLIB" { RTOKEN(SYSLIB); }
307 <SCRIPT>"FLOAT" { RTOKEN(FLOAT); }
308 <WILD>"QUAD" { RTOKEN(QUAD); }
309 <WILD>"SQUAD" { RTOKEN(SQUAD); }
310 <WILD>"LONG" { RTOKEN(LONG); }
311 <WILD>"SHORT" { RTOKEN(SHORT); }
312 <WILD>"BYTE" { RTOKEN(BYTE); }
313 <WILD>"ASCIZ" { RTOKEN(ASCIZ); }
314 <WILD>"LINKER_VERSION" { RTOKEN(LINKER_VERSION); }
315 <SCRIPT>"NOFLOAT" { RTOKEN(NOFLOAT); }
316 <SCRIPT,EXPRESSION>"NOCROSSREFS" { RTOKEN(NOCROSSREFS); }
317 <SCRIPT,EXPRESSION>"NOCROSSREFS_TO" { RTOKEN(NOCROSSREFS_TO); }
318 <SCRIPT,EXPRESSION>"OVERLAY" { RTOKEN(OVERLAY); }
319 <WILD>"SORT_BY_NAME" { RTOKEN(SORT_BY_NAME); }
320 <WILD>"SORT_BY_ALIGNMENT" { RTOKEN(SORT_BY_ALIGNMENT); }
321 <WILD>"SORT" { RTOKEN(SORT_BY_NAME); }
322 <WILD>"SORT_BY_INIT_PRIORITY" { RTOKEN(SORT_BY_INIT_PRIORITY); }
323 <WILD>"SORT_NONE" { RTOKEN(SORT_NONE); }
324 <WILD>"REVERSE" { RTOKEN(REVERSE); }
325 <EXPRESSION>"NOLOAD" { RTOKEN(NOLOAD); }
326 <EXPRESSION>"READONLY" { RTOKEN(READONLY); }
327 <EXPRESSION>"DSECT" { RTOKEN(DSECT); }
328 <EXPRESSION>"COPY" { RTOKEN(COPY); }
329 <EXPRESSION>"INFO" { RTOKEN(INFO); }
330 <EXPRESSION>"TYPE" { RTOKEN(TYPE); }
331 <SCRIPT,EXPRESSION>"ONLY_IF_RO" { RTOKEN(ONLY_IF_RO); }
332 <SCRIPT,EXPRESSION>"ONLY_IF_RW" { RTOKEN(ONLY_IF_RW); }
333 <SCRIPT,EXPRESSION>"SPECIAL" { RTOKEN(SPECIAL); }
334 <SCRIPT>"o" { RTOKEN(ORIGIN); }
335 <SCRIPT>"org" { RTOKEN(ORIGIN); }
336 <SCRIPT>"l" { RTOKEN(LENGTH); }
337 <SCRIPT>"len" { RTOKEN(LENGTH); }
338 <WILD>"INPUT_SECTION_FLAGS" { RTOKEN(INPUT_SECTION_FLAGS); }
339 <SCRIPT,EXPRESSION,WILD,MRI>"INCLUDE" { RTOKEN(INCLUDE);}
340 <SCRIPT>"PHDRS" { RTOKEN(PHDRS); }
341 <SCRIPT,EXPRESSION,WILD>"AT" { RTOKEN(AT);}
342 <SCRIPT,EXPRESSION>"ALIGN_WITH_INPUT" { RTOKEN(ALIGN_WITH_INPUT);}
343 <SCRIPT,EXPRESSION>"SUBALIGN" { RTOKEN(SUBALIGN);}
344 <SCRIPT,EXPRESSION,WILD>"HIDDEN" { RTOKEN(HIDDEN); }
345 <SCRIPT,EXPRESSION,WILD>"PROVIDE" { RTOKEN(PROVIDE); }
346 <SCRIPT,EXPRESSION,WILD>"PROVIDE_HIDDEN" { RTOKEN(PROVIDE_HIDDEN); }
347 <WILD>"KEEP" { RTOKEN(KEEP); }
348 <WILD>"EXCLUDE_FILE" { RTOKEN(EXCLUDE_FILE); }
349 <SCRIPT,EXPRESSION>"CONSTANT" { RTOKEN(CONSTANT);}
351 <MRI>"#".*\n? { ++ lineno; }
352 <MRI>"\n" { ++ lineno; RTOKEN(NEWLINE); }
353 <MRI>"*".* { /* Mri comment line */ }
354 <MRI>";".* { /* Mri comment line */ }
355 <MRI>"END" { RTOKEN(ENDWORD); }
356 <MRI>"ABSOLUTE" { RTOKEN(ABSOLUTE); }
357 <MRI>"ALIGNMOD" { RTOKEN(ALIGNMOD);}
358 <MRI>"ALIGN" { RTOKEN(ALIGN_K);}
359 <MRI>"CHIP" { RTOKEN(CHIP); }
360 <MRI>"BASE" { RTOKEN(BASE); }
361 <MRI>"ALIAS" { RTOKEN(ALIAS); }
362 <MRI>"TRUNCATE" { RTOKEN(TRUNCATE); }
363 <MRI>"LOAD" { RTOKEN(LOAD); }
364 <MRI>"PUBLIC" { RTOKEN(PUBLIC); }
365 <MRI>"ORDER" { RTOKEN(ORDER); }
366 <MRI>"NAME" { RTOKEN(NAMEWORD); }
367 <MRI>"FORMAT" { RTOKEN(FORMAT); }
368 <MRI>"CASE" { RTOKEN(CASE); }
369 <MRI>"START" { RTOKEN(START); }
370 <MRI>"LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
371 <MRI>"SECT" { RTOKEN(SECT); }
372 <MRI>"end" { RTOKEN(ENDWORD); }
373 <MRI>"absolute" { RTOKEN(ABSOLUTE); }
374 <MRI>"alignmod" { RTOKEN(ALIGNMOD);}
375 <MRI>"align" { RTOKEN(ALIGN_K);}
376 <MRI>"chip" { RTOKEN(CHIP); }
377 <MRI>"base" { RTOKEN(BASE); }
378 <MRI>"alias" { RTOKEN(ALIAS); }
379 <MRI>"truncate" { RTOKEN(TRUNCATE); }
380 <MRI>"load" { RTOKEN(LOAD); }
381 <MRI>"public" { RTOKEN(PUBLIC); }
382 <MRI>"order" { RTOKEN(ORDER); }
383 <MRI>"name" { RTOKEN(NAMEWORD); }
384 <MRI>"format" { RTOKEN(FORMAT); }
385 <MRI>"case" { RTOKEN(CASE); }
386 <MRI>"extern" { RTOKEN(EXTERN); }
387 <MRI>"start" { RTOKEN(START); }
388 <MRI>"list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
389 <MRI>"sect" { RTOKEN(SECT); }
391 <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
392 /* Filename without commas, needed to parse mri stuff */
393 yylval.name = xstrdup (yytext);
398 <SCRIPT,INPUTLIST>{FILENAMECHAR1}{FILENAMECHAR}* {
399 yylval.name = xstrdup (yytext);
402 <INPUTLIST>"="{FILENAMECHAR1}{FILENAMECHAR}* {
403 /* Filename to be prefixed by --sysroot or when non-sysrooted, nothing. */
404 yylval.name = xstrdup (yytext);
407 <INPUTLIST>"-l"{FILENAMECHAR}+ {
408 yylval.name = xstrdup (yytext + 2);
411 <EXPRESSION>{SYMBOLNAMECHAR1}{SYMBOLNAMECHAR}* {
412 yylval.name = xstrdup (yytext);
415 /* The following rule is to prevent a fill expression on the output
416 section before /DISCARD/ interpreting the '/' as a divide. */
417 <EXPRESSION>"/DISCARD/" {
418 yylval.name = xstrdup (yytext);
422 /* Annoyingly, this pattern can match comments, and we have
423 longest match issues to consider. So if the first two
424 characters are a comment opening, put the input back and
426 if (yytext[0] == '/' && yytext[1] == '*')
433 yylval.name = xstrdup (yytext);
438 <SCRIPT,EXPRESSION,WILD,VERS_NODE,INPUTLIST>"\""[^\"]*"\"" {
439 /* No matter the state, quotes give what's inside. */
440 yylval.name = xmemdup (yytext + 1, yyleng - 2, yyleng - 1);
444 <SCRIPT,EXPRESSION,WILD,VERS_START,VERS_NODE,VERS_SCRIPT,INPUTLIST>"\n" {
446 <MRI,SCRIPT,EXPRESSION,WILD,VERS_START,VERS_NODE,VERS_SCRIPT,INPUTLIST>[ \t\r]+ {
447 /* Eat up whitespace */ }
448 <SCRIPT,EXPRESSION,WILD,VERS_START,VERS_NODE,VERS_SCRIPT>#.* {
449 /* Eat up comments */ }
451 <VERS_NODE,VERS_SCRIPT>[:,;] { return *yytext; }
453 <VERS_NODE>global { RTOKEN(GLOBAL); }
455 <VERS_NODE>local { RTOKEN(LOCAL); }
457 <VERS_NODE>extern { RTOKEN(EXTERN); }
459 <VERS_NODE>{V_IDENTIFIER} { yylval.name = xstrdup (yytext);
460 return VERS_IDENTIFIER; }
462 <VERS_SCRIPT>{V_TAG} { yylval.name = xstrdup (yytext);
465 <VERS_START>"{" { BEGIN(VERS_SCRIPT); return *yytext; }
467 <VERS_SCRIPT>"{" { BEGIN(VERS_NODE);
468 vers_node_nesting = 0;
471 <VERS_SCRIPT>"}" { return *yytext; }
472 <VERS_NODE>"{" { vers_node_nesting++; return *yytext; }
473 <VERS_NODE>"}" { if (--vers_node_nesting < 0)
480 if (include_stack_ptr == 0)
486 yy_switch_to_buffer (include_stack[include_stack_ptr]);
488 lineno = lineno_stack[include_stack_ptr];
489 input_flags.sysrooted = sysrooted_stack[include_stack_ptr];
494 <SCRIPT,WILD,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>. lex_warn_invalid (_(" in script"), yytext);
495 <EXPRESSION>. lex_warn_invalid (_(" in expression"), yytext);
500 /* Switch flex to reading script file NAME, open on FILE,
501 saving the current input info on the include stack. */
504 lex_push_file (FILE *file, const char *name, unsigned int sysrooted)
506 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
508 einfo (_("%F:includes nested too deeply\n"));
510 file_name_stack[include_stack_ptr] = name;
511 lineno_stack[include_stack_ptr] = lineno;
512 sysrooted_stack[include_stack_ptr] = input_flags.sysrooted;
513 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
517 input_flags.sysrooted = sysrooted;
519 yy_switch_to_buffer (yy_create_buffer (yyin, YY_BUF_SIZE));
522 /* Return a newly created flex input buffer containing STRING,
523 which is SIZE bytes long. */
525 static YY_BUFFER_STATE
526 yy_create_string_buffer (const char *string, size_t size)
530 b = xmalloc (sizeof (struct yy_buffer_state));
531 b->yy_input_file = 0;
532 b->yy_buf_size = size;
534 /* yy_ch_buf has to be 2 characters longer than the size given because
535 we need to put in 2 end-of-buffer characters. */
536 b->yy_ch_buf = xmalloc ((size_t) b->yy_buf_size + 3);
538 b->yy_ch_buf[0] = '\n';
539 strcpy (b->yy_ch_buf+1, string);
540 b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;
541 b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;
542 b->yy_n_chars = size+1;
543 b->yy_buf_pos = &b->yy_ch_buf[1];
545 b->yy_is_our_buffer = 1;
546 b->yy_is_interactive = 0;
548 b->yy_fill_buffer = 0;
550 /* flex 2.4.7 changed the interface. FIXME: We should not be using
551 a flex internal interface in the first place! */
553 b->yy_buffer_status = YY_BUFFER_NEW;
555 b->yy_eof_status = EOF_NOT_SEEN;
561 /* Switch flex to reading from STRING, saving the current input info
562 on the include stack. */
565 lex_redirect (const char *string, const char *fake_filename, unsigned int count)
570 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
572 einfo (_("%F: macros nested too deeply\n"));
574 file_name_stack[include_stack_ptr] = fake_filename;
575 lineno_stack[include_stack_ptr] = lineno;
576 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
579 tmp = yy_create_string_buffer (string, strlen (string));
580 yy_switch_to_buffer (tmp);
583 /* Functions to switch to a different flex start condition,
584 saving the current start condition on `state_stack'. */
586 static int state_stack[MAX_INCLUDE_DEPTH * 2];
587 static int *state_stack_p = state_stack;
592 *(state_stack_p)++ = yy_start;
597 ldlex_inputlist (void)
599 *(state_stack_p)++ = yy_start;
604 ldlex_mri_script (void)
606 *(state_stack_p)++ = yy_start;
611 ldlex_version_script (void)
613 *(state_stack_p)++ = yy_start;
618 ldlex_version_file (void)
620 *(state_stack_p)++ = yy_start;
625 ldlex_expression (void)
627 *(state_stack_p)++ = yy_start;
634 *(state_stack_p)++ = yy_start;
639 ldlex_popstate (void)
641 yy_start = *(--state_stack_p);
644 /* In cases where the parser needs to look ahead and the context
645 changes from expression to script or vice-versa, throw away a
646 NAME. What constitutes a NAME depends on context. */
654 /* Return the current file name, or the previous file if no file is
658 ldlex_filename (void)
660 return file_name_stack[include_stack_ptr - (include_stack_ptr != 0)];
664 /* Place up to MAX_SIZE characters in BUF and return
665 either the number of characters read, or 0 to indicate EOF. */
668 yy_input (char *buf, int max_size)
671 if (YY_CURRENT_BUFFER != NULL && YY_CURRENT_BUFFER->yy_input_file)
675 result = fread (buf, 1, max_size, yyin);
676 if (result < max_size && ferror (yyin))
677 einfo (_("%F%P: read in flex scanner failed\n"));
683 /* Eat the rest of a C-style comment. */
693 while (c != '*' && c != 0)
706 break; /* found the end */
714 einfo (_("%F%P: EOF in comment\n"));
720 /* Warn the user about a garbage character WHAT in the input
724 lex_warn_invalid (char *where, char *what)
728 /* If we have found an input file whose format we do not recognize,
729 and we are therefore treating it as a linker script, and we find
730 an invalid character, then most likely this is a real object file
731 of some different format. Treat it as such. */
732 if (ldfile_assumed_script)
734 bfd_set_error (bfd_error_file_not_recognized);
735 einfo (_("%F%s: file not recognized: %E\n"), ldlex_filename ());
738 if (! ISPRINT (*what))
740 sprintf (buf, "\\%03o", *(unsigned char *) what);
744 einfo (_("%P:%pS: ignoring invalid character `%s'%s\n"), NULL, what, where);