]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/ldlex.l
PR28217, Syntax error when memory region contains a hyphen
[thirdparty/binutils-gdb.git] / ld / ldlex.l
1 %option nounput noyywrap
2
3 %{
4
5 /* Copyright (C) 1991-2021 Free Software Foundation, Inc.
6 Written by Steve Chamberlain of Cygnus Support.
7
8 This file is part of the GNU Binutils.
9
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.
14
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.
19
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. */
24
25 #include "bfd.h"
26 #include "safe-ctype.h"
27 #include "bfdlink.h"
28 #include "ctf-api.h"
29 #include "ld.h"
30 #include "ldmisc.h"
31 #include "ldexp.h"
32 #include "ldlang.h"
33 #include <ldgram.h>
34 #include "ldfile.h"
35 #include "ldlex.h"
36 #include "ldmain.h"
37 #include "libiberty.h"
38
39 /* The type of top-level parser input.
40 yylex and yyparse (indirectly) both check this. */
41 input_type parser_input;
42
43 /* Line number in the current input file. */
44 unsigned int lineno;
45
46 /* The string we are currently lexing, or NULL if we are reading a
47 file. */
48 const char *lex_string = NULL;
49
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
53 line numbers.
54
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. */
57
58 #undef YY_INPUT
59 #define YY_INPUT(buf,result,max_size) result = yy_input (buf, max_size)
60
61 #ifndef YY_NO_UNPUT
62 #define YY_NO_UNPUT
63 #endif
64
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;
72
73 static int yy_input (char *, int);
74 static void comment (void);
75 static void lex_warn_invalid (char *where, char *what);
76
77 /* STATES
78 EXPRESSION in an expression
79 SCRIPT in a script
80 INPUTLIST in a script, a filename-list
81 MRI in an MRI script
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
87 */
88 #define RTOKEN(x) { yylval.token = x; return x; }
89
90 %}
91
92 %a 4000
93 %o 5000
94
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\.\\\$]
101 WHITE [ \t\n\r]+
102
103 V_TAG [.$_a-zA-Z][._a-zA-Z0-9]*
104 V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
105
106 %s SCRIPT
107 %s INPUTLIST
108 %s EXPRESSION
109 %s MRI
110 %s WILD
111 %s VERS_START
112 %s VERS_SCRIPT
113 %s VERS_NODE
114 %%
115
116 if (parser_input != input_selected)
117 {
118 /* The first token of the input determines the initial parser state. */
119 input_type t = parser_input;
120 parser_input = input_selected;
121 switch (t)
122 {
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;
128 default: abort ();
129 }
130 }
131
132 <SCRIPT,EXPRESSION,VERS_START,VERS_NODE,VERS_SCRIPT,INPUTLIST>"/*" {
133 comment (); }
134
135 <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
136 yylval.integer = bfd_scan_vma (yytext + 1, 0, 16);
137 yylval.bigint.str = NULL;
138 return INT;
139 }
140
141 <MRI,EXPRESSION>([0-9A-Fa-f])+(H|h|X|x|B|b|O|o|D|d) {
142 int ibase ;
143 switch (yytext[yyleng - 1]) {
144 case 'X':
145 case 'x':
146 case 'H':
147 case 'h':
148 ibase = 16;
149 break;
150 case 'O':
151 case 'o':
152 ibase = 8;
153 break;
154 case 'B':
155 case 'b':
156 ibase = 2;
157 break;
158 default:
159 ibase = 10;
160 }
161 yylval.integer = bfd_scan_vma (yytext, 0,
162 ibase);
163 yylval.bigint.str = NULL;
164 return INT;
165 }
166 <SCRIPT,MRI,EXPRESSION>((("$"|0[xX])([0-9A-Fa-f])+)|(([0-9])+))(M|K|m|k)? {
167 char *s = yytext;
168 int ibase = 0;
169
170 if (*s == '$')
171 {
172 ++s;
173 ibase = 16;
174 }
175 yylval.integer = bfd_scan_vma (s, 0, ibase);
176 yylval.bigint.str = NULL;
177 if (yytext[yyleng - 1] == 'M'
178 || yytext[yyleng - 1] == 'm')
179 {
180 yylval.integer *= 1024 * 1024;
181 }
182 else if (yytext[yyleng - 1] == 'K'
183 || yytext[yyleng - 1]=='k')
184 {
185 yylval.integer *= 1024;
186 }
187 else if (yytext[0] == '0'
188 && (yytext[1] == 'x'
189 || yytext[1] == 'X'))
190 {
191 yylval.bigint.str = xstrdup (yytext + 2);
192 }
193 return INT;
194 }
195 <SCRIPT,EXPRESSION,MRI,WILD>"]" { RTOKEN(']');}
196 <SCRIPT,EXPRESSION,MRI,WILD>"[" { RTOKEN('[');}
197 <SCRIPT,EXPRESSION,MRI,WILD>"<<=" { RTOKEN(LSHIFTEQ);}
198 <SCRIPT,EXPRESSION,MRI,WILD>">>=" { RTOKEN(RSHIFTEQ);}
199 <SCRIPT,EXPRESSION,MRI>"||" { RTOKEN(OROR);}
200 <SCRIPT,EXPRESSION,MRI>"==" { RTOKEN(EQ);}
201 <SCRIPT,EXPRESSION,MRI>"!=" { RTOKEN(NE);}
202 <SCRIPT,EXPRESSION,MRI>">=" { RTOKEN(GE);}
203 <SCRIPT,EXPRESSION,MRI>"<=" { RTOKEN(LE);}
204 <SCRIPT,EXPRESSION,MRI>"<<" { RTOKEN(LSHIFT);}
205 <SCRIPT,EXPRESSION,MRI>">>" { RTOKEN(RSHIFT);}
206 <SCRIPT,EXPRESSION,MRI,WILD>"+=" { RTOKEN(PLUSEQ);}
207 <SCRIPT,EXPRESSION,MRI,WILD>"-=" { RTOKEN(MINUSEQ);}
208 <SCRIPT,EXPRESSION,MRI,WILD>"*=" { RTOKEN(MULTEQ);}
209 <SCRIPT,EXPRESSION,MRI,WILD>"/=" { RTOKEN(DIVEQ);}
210 <SCRIPT,EXPRESSION,MRI,WILD>"&=" { RTOKEN(ANDEQ);}
211 <SCRIPT,EXPRESSION,MRI,WILD>"|=" { RTOKEN(OREQ);}
212 <SCRIPT,EXPRESSION,MRI>"&&" { RTOKEN(ANDAND);}
213 <SCRIPT,EXPRESSION,MRI>">" { RTOKEN('>');}
214 <SCRIPT,EXPRESSION,MRI,INPUTLIST>"," { RTOKEN(',');}
215 <SCRIPT,EXPRESSION,MRI,WILD>"&" { RTOKEN('&');}
216 <SCRIPT,EXPRESSION,MRI>"|" { RTOKEN('|');}
217 <SCRIPT,EXPRESSION,MRI>"~" { RTOKEN('~');}
218 <SCRIPT,EXPRESSION,MRI>"!" { RTOKEN('!');}
219 <SCRIPT,EXPRESSION,MRI>"?" { RTOKEN('?');}
220 <SCRIPT,EXPRESSION,MRI>"*" { RTOKEN('*');}
221 <SCRIPT,EXPRESSION,MRI>"+" { RTOKEN('+');}
222 <SCRIPT,EXPRESSION,MRI>"-" { RTOKEN('-');}
223 <SCRIPT,EXPRESSION,MRI>"/" { RTOKEN('/');}
224 <SCRIPT,EXPRESSION,MRI>"%" { RTOKEN('%');}
225 <SCRIPT,EXPRESSION,MRI>"<" { RTOKEN('<');}
226 <SCRIPT,EXPRESSION,MRI,WILD>"=" { RTOKEN('=');}
227 <SCRIPT,EXPRESSION,MRI,WILD>"}" { RTOKEN('}'); }
228 <SCRIPT,EXPRESSION,MRI,WILD>"{" { RTOKEN('{'); }
229 <SCRIPT,EXPRESSION,MRI,WILD,INPUTLIST>")" { RTOKEN(')');}
230 <SCRIPT,EXPRESSION,MRI,WILD,INPUTLIST>"(" { RTOKEN('(');}
231 <SCRIPT,EXPRESSION,MRI>":" { RTOKEN(':'); }
232 <SCRIPT,EXPRESSION,MRI,WILD>";" { RTOKEN(';');}
233 <SCRIPT>"MEMORY" { RTOKEN(MEMORY);}
234 <SCRIPT>"REGION_ALIAS" { RTOKEN(REGION_ALIAS);}
235 <SCRIPT>"LD_FEATURE" { RTOKEN(LD_FEATURE);}
236 <SCRIPT,EXPRESSION>"ORIGIN" { RTOKEN(ORIGIN);}
237 <SCRIPT>"VERSION" { RTOKEN(VERSIONK);}
238 <SCRIPT,EXPRESSION>"BLOCK" { RTOKEN(BLOCK);}
239 <SCRIPT,EXPRESSION>"BIND" { RTOKEN(BIND);}
240 <SCRIPT,EXPRESSION>"LENGTH" { RTOKEN(LENGTH);}
241 <SCRIPT,EXPRESSION>"ALIGN" { RTOKEN(ALIGN_K);}
242 <SCRIPT,EXPRESSION>"DATA_SEGMENT_ALIGN" { RTOKEN(DATA_SEGMENT_ALIGN);}
243 <SCRIPT,EXPRESSION>"DATA_SEGMENT_RELRO_END" { RTOKEN(DATA_SEGMENT_RELRO_END);}
244 <SCRIPT,EXPRESSION>"DATA_SEGMENT_END" { RTOKEN(DATA_SEGMENT_END);}
245 <SCRIPT,EXPRESSION>"ADDR" { RTOKEN(ADDR);}
246 <SCRIPT,EXPRESSION>"LOADADDR" { RTOKEN(LOADADDR);}
247 <SCRIPT,EXPRESSION>"ALIGNOF" { RTOKEN(ALIGNOF); }
248 <EXPRESSION>"MAX" { RTOKEN(MAX_K); }
249 <EXPRESSION>"MIN" { RTOKEN(MIN_K); }
250 <EXPRESSION>"LOG2CEIL" { RTOKEN(LOG2CEIL); }
251 <SCRIPT,EXPRESSION,WILD>"ASSERT" { RTOKEN(ASSERT_K); }
252 <SCRIPT,WILD>"ENTRY" { RTOKEN(ENTRY);}
253 <SCRIPT,MRI>"EXTERN" { RTOKEN(EXTERN);}
254 <SCRIPT,EXPRESSION>"NEXT" { RTOKEN(NEXT);}
255 <SCRIPT,EXPRESSION>"sizeof_headers" { RTOKEN(SIZEOF_HEADERS);}
256 <SCRIPT,EXPRESSION>"SIZEOF_HEADERS" { RTOKEN(SIZEOF_HEADERS);}
257 <SCRIPT,EXPRESSION>"SEGMENT_START" { RTOKEN(SEGMENT_START);}
258 <SCRIPT>"MAP" { RTOKEN(MAP);}
259 <SCRIPT,EXPRESSION>"SIZEOF" { RTOKEN(SIZEOF);}
260 <SCRIPT>"TARGET" { RTOKEN(TARGET_K);}
261 <SCRIPT>"SEARCH_DIR" { RTOKEN(SEARCH_DIR);}
262 <SCRIPT>"OUTPUT" { RTOKEN(OUTPUT);}
263 <SCRIPT>"INPUT" { RTOKEN(INPUT);}
264 <SCRIPT,EXPRESSION,WILD>"GROUP" { RTOKEN(GROUP);}
265 <SCRIPT,EXPRESSION,INPUTLIST>"AS_NEEDED" { RTOKEN(AS_NEEDED);}
266 <SCRIPT,EXPRESSION>"DEFINED" { RTOKEN(DEFINED);}
267 <SCRIPT,WILD>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);}
268 <SCRIPT,WILD>"CONSTRUCTORS" { RTOKEN(CONSTRUCTORS);}
269 <SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);}
270 <SCRIPT>"FORCE_GROUP_ALLOCATION" { RTOKEN(FORCE_GROUP_ALLOCATION);}
271 <SCRIPT>"INHIBIT_COMMON_ALLOCATION" { RTOKEN(INHIBIT_COMMON_ALLOCATION);}
272 <SCRIPT>"SECTIONS" { RTOKEN(SECTIONS);}
273 <SCRIPT>"INSERT" { RTOKEN(INSERT_K);}
274 <SCRIPT>"AFTER" { RTOKEN(AFTER);}
275 <SCRIPT>"BEFORE" { RTOKEN(BEFORE);}
276 <SCRIPT,WILD>"FILL" { RTOKEN(FILL);}
277 <SCRIPT>"STARTUP" { RTOKEN(STARTUP);}
278 <SCRIPT>"OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT);}
279 <SCRIPT>"OUTPUT_ARCH" { RTOKEN(OUTPUT_ARCH);}
280 <SCRIPT>"HLL" { RTOKEN(HLL);}
281 <SCRIPT>"SYSLIB" { RTOKEN(SYSLIB);}
282 <SCRIPT>"FLOAT" { RTOKEN(FLOAT);}
283 <SCRIPT,WILD>"QUAD" { RTOKEN( QUAD);}
284 <SCRIPT,WILD>"SQUAD" { RTOKEN( SQUAD);}
285 <SCRIPT,WILD>"LONG" { RTOKEN( LONG);}
286 <SCRIPT,WILD>"SHORT" { RTOKEN( SHORT);}
287 <SCRIPT,WILD>"BYTE" { RTOKEN( BYTE);}
288 <SCRIPT>"NOFLOAT" { RTOKEN(NOFLOAT);}
289 <SCRIPT,EXPRESSION>"NOCROSSREFS" { RTOKEN(NOCROSSREFS);}
290 <SCRIPT,EXPRESSION>"NOCROSSREFS_TO" { RTOKEN(NOCROSSREFS_TO);}
291 <SCRIPT>"OVERLAY" { RTOKEN(OVERLAY); }
292 <SCRIPT,WILD>"SORT_BY_NAME" { RTOKEN(SORT_BY_NAME); }
293 <SCRIPT,WILD>"SORT_BY_ALIGNMENT" { RTOKEN(SORT_BY_ALIGNMENT); }
294 <SCRIPT,WILD>"SORT" { RTOKEN(SORT_BY_NAME); }
295 <SCRIPT,WILD>"SORT_BY_INIT_PRIORITY" { RTOKEN(SORT_BY_INIT_PRIORITY); }
296 <SCRIPT,WILD>"SORT_NONE" { RTOKEN(SORT_NONE); }
297 <SCRIPT,EXPRESSION>"NOLOAD" { RTOKEN(NOLOAD);}
298 <SCRIPT,EXPRESSION>"READONLY" { RTOKEN(READONLY);}
299 <SCRIPT,EXPRESSION>"DSECT" { RTOKEN(DSECT);}
300 <SCRIPT,EXPRESSION>"COPY" { RTOKEN(COPY);}
301 <SCRIPT,EXPRESSION>"INFO" { RTOKEN(INFO);}
302 <SCRIPT,EXPRESSION>"OVERLAY" { RTOKEN(OVERLAY);}
303 <EXPRESSION>"ONLY_IF_RO" { RTOKEN(ONLY_IF_RO); }
304 <EXPRESSION>"ONLY_IF_RW" { RTOKEN(ONLY_IF_RW); }
305 <EXPRESSION>"SPECIAL" { RTOKEN(SPECIAL); }
306 <SCRIPT>"o" { RTOKEN(ORIGIN);}
307 <SCRIPT>"org" { RTOKEN(ORIGIN);}
308 <SCRIPT>"l" { RTOKEN( LENGTH);}
309 <SCRIPT>"len" { RTOKEN( LENGTH);}
310 <SCRIPT,EXPRESSION,WILD>"INPUT_SECTION_FLAGS" { RTOKEN(INPUT_SECTION_FLAGS); }
311 <SCRIPT,EXPRESSION,WILD>"INCLUDE" { RTOKEN(INCLUDE);}
312 <SCRIPT>"PHDRS" { RTOKEN (PHDRS); }
313 <SCRIPT,EXPRESSION,WILD>"AT" { RTOKEN(AT);}
314 <SCRIPT,EXPRESSION>"ALIGN_WITH_INPUT" { RTOKEN(ALIGN_WITH_INPUT);}
315 <SCRIPT,EXPRESSION>"SUBALIGN" { RTOKEN(SUBALIGN);}
316 <SCRIPT,EXPRESSION,WILD>"HIDDEN" { RTOKEN(HIDDEN); }
317 <SCRIPT,EXPRESSION,WILD>"PROVIDE" { RTOKEN(PROVIDE); }
318 <SCRIPT,EXPRESSION,WILD>"PROVIDE_HIDDEN" { RTOKEN(PROVIDE_HIDDEN); }
319 <SCRIPT,EXPRESSION,WILD>"KEEP" { RTOKEN(KEEP); }
320 <SCRIPT,EXPRESSION,WILD>"EXCLUDE_FILE" { RTOKEN(EXCLUDE_FILE); }
321 <SCRIPT,EXPRESSION>"CONSTANT" { RTOKEN(CONSTANT);}
322
323 <MRI>"#".*\n? { ++ lineno; }
324 <MRI>"\n" { ++ lineno; RTOKEN(NEWLINE); }
325 <MRI>"*".* { /* Mri comment line */ }
326 <MRI>";".* { /* Mri comment line */ }
327 <MRI>"END" { RTOKEN(ENDWORD); }
328 <MRI>"ALIGNMOD" { RTOKEN(ALIGNMOD);}
329 <MRI>"ALIGN" { RTOKEN(ALIGN_K);}
330 <MRI>"CHIP" { RTOKEN(CHIP); }
331 <MRI>"BASE" { RTOKEN(BASE); }
332 <MRI>"ALIAS" { RTOKEN(ALIAS); }
333 <MRI>"TRUNCATE" { RTOKEN(TRUNCATE); }
334 <MRI>"LOAD" { RTOKEN(LOAD); }
335 <MRI>"PUBLIC" { RTOKEN(PUBLIC); }
336 <MRI>"ORDER" { RTOKEN(ORDER); }
337 <MRI>"NAME" { RTOKEN(NAMEWORD); }
338 <MRI>"FORMAT" { RTOKEN(FORMAT); }
339 <MRI>"CASE" { RTOKEN(CASE); }
340 <MRI>"START" { RTOKEN(START); }
341 <MRI>"LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
342 <MRI>"SECT" { RTOKEN(SECT); }
343 <SCRIPT,EXPRESSION,MRI>"ABSOLUTE" { RTOKEN(ABSOLUTE); }
344 <MRI>"end" { RTOKEN(ENDWORD); }
345 <MRI>"alignmod" { RTOKEN(ALIGNMOD);}
346 <MRI>"align" { RTOKEN(ALIGN_K);}
347 <MRI>"chip" { RTOKEN(CHIP); }
348 <MRI>"base" { RTOKEN(BASE); }
349 <MRI>"alias" { RTOKEN(ALIAS); }
350 <MRI>"truncate" { RTOKEN(TRUNCATE); }
351 <MRI>"load" { RTOKEN(LOAD); }
352 <MRI>"public" { RTOKEN(PUBLIC); }
353 <MRI>"order" { RTOKEN(ORDER); }
354 <MRI>"name" { RTOKEN(NAMEWORD); }
355 <MRI>"format" { RTOKEN(FORMAT); }
356 <MRI>"case" { RTOKEN(CASE); }
357 <MRI>"extern" { RTOKEN(EXTERN); }
358 <MRI>"start" { RTOKEN(START); }
359 <MRI>"list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
360 <MRI>"sect" { RTOKEN(SECT); }
361 <SCRIPT,EXPRESSION,MRI>"absolute" { RTOKEN(ABSOLUTE); }
362
363 <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
364 /* Filename without commas, needed to parse mri stuff */
365 yylval.name = xstrdup (yytext);
366 return NAME;
367 }
368
369
370 <SCRIPT,INPUTLIST>{FILENAMECHAR1}{FILENAMECHAR}* {
371 yylval.name = xstrdup (yytext);
372 return NAME;
373 }
374 <INPUTLIST>"="{FILENAMECHAR1}{FILENAMECHAR}* {
375 /* Filename to be prefixed by --sysroot or when non-sysrooted, nothing. */
376 yylval.name = xstrdup (yytext);
377 return NAME;
378 }
379 <INPUTLIST>"-l"{FILENAMECHAR}+ {
380 yylval.name = xstrdup (yytext + 2);
381 return LNAME;
382 }
383 <EXPRESSION>{SYMBOLNAMECHAR1}{SYMBOLNAMECHAR}* {
384 yylval.name = xstrdup (yytext);
385 return NAME;
386 }
387 <EXPRESSION>"/DISCARD/" {
388 yylval.name = xstrdup (yytext);
389 return NAME;
390 }
391 <EXPRESSION>"-l"{NOCFILENAMECHAR}+ {
392 yylval.name = xstrdup (yytext + 2);
393 return LNAME;
394 }
395 <WILD>{WILDCHAR}* {
396 /* Annoyingly, this pattern can match comments, and we have
397 longest match issues to consider. So if the first two
398 characters are a comment opening, put the input back and
399 try again. */
400 if (yytext[0] == '/' && yytext[1] == '*')
401 {
402 yyless (2);
403 comment ();
404 }
405 else
406 {
407 yylval.name = xstrdup (yytext);
408 return NAME;
409 }
410 }
411
412 <SCRIPT,EXPRESSION,WILD,VERS_NODE,INPUTLIST>"\""[^\"]*"\"" {
413 /* No matter the state, quotes
414 give what's inside. */
415 bfd_size_type len;
416 yylval.name = xstrdup (yytext + 1);
417 /* PR ld/20906. A corrupt input file
418 can contain bogus strings. */
419 len = strlen (yylval.name);
420 if (len > (bfd_size_type) yyleng - 2)
421 len = yyleng - 2;
422 yylval.name[len] = 0;
423 return NAME;
424 }
425
426 <SCRIPT,EXPRESSION,WILD,VERS_START,VERS_NODE,VERS_SCRIPT,INPUTLIST>"\n" {
427 lineno++; }
428 <MRI,SCRIPT,EXPRESSION,WILD,VERS_START,VERS_NODE,VERS_SCRIPT,INPUTLIST>[ \t\r]+ {
429 /* Eat up whitespace */ }
430 <SCRIPT,EXPRESSION,WILD,VERS_START,VERS_NODE,VERS_SCRIPT>#.* {
431 /* Eat up comments */ }
432
433 <VERS_NODE,VERS_SCRIPT>[:,;] { return *yytext; }
434
435 <VERS_NODE>global { RTOKEN(GLOBAL); }
436
437 <VERS_NODE>local { RTOKEN(LOCAL); }
438
439 <VERS_NODE>extern { RTOKEN(EXTERN); }
440
441 <VERS_NODE>{V_IDENTIFIER} { yylval.name = xstrdup (yytext);
442 return VERS_IDENTIFIER; }
443
444 <VERS_SCRIPT>{V_TAG} { yylval.name = xstrdup (yytext);
445 return VERS_TAG; }
446
447 <VERS_START>"{" { BEGIN(VERS_SCRIPT); return *yytext; }
448
449 <VERS_SCRIPT>"{" { BEGIN(VERS_NODE);
450 vers_node_nesting = 0;
451 return *yytext;
452 }
453 <VERS_SCRIPT>"}" { return *yytext; }
454 <VERS_NODE>"{" { vers_node_nesting++; return *yytext; }
455 <VERS_NODE>"}" { if (--vers_node_nesting < 0)
456 BEGIN(VERS_SCRIPT);
457 return *yytext;
458 }
459
460 <<EOF>> {
461 include_stack_ptr--;
462 if (include_stack_ptr == 0)
463 {
464 lineno = 0;
465 yyterminate ();
466 }
467 else
468 yy_switch_to_buffer (include_stack[include_stack_ptr]);
469
470 lineno = lineno_stack[include_stack_ptr];
471 input_flags.sysrooted = sysrooted_stack[include_stack_ptr];
472
473 return END;
474 }
475
476 <SCRIPT,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>. lex_warn_invalid (" in script", yytext);
477 <EXPRESSION>. lex_warn_invalid (" in expression", yytext);
478
479 %%
480 \f
481
482 /* Switch flex to reading script file NAME, open on FILE,
483 saving the current input info on the include stack. */
484
485 void
486 lex_push_file (FILE *file, const char *name, unsigned int sysrooted)
487 {
488 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
489 {
490 einfo (_("%F:includes nested too deeply\n"));
491 }
492 file_name_stack[include_stack_ptr] = name;
493 lineno_stack[include_stack_ptr] = lineno;
494 sysrooted_stack[include_stack_ptr] = input_flags.sysrooted;
495 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
496
497 include_stack_ptr++;
498 lineno = 1;
499 input_flags.sysrooted = sysrooted;
500 yyin = file;
501 yy_switch_to_buffer (yy_create_buffer (yyin, YY_BUF_SIZE));
502 }
503
504 /* Return a newly created flex input buffer containing STRING,
505 which is SIZE bytes long. */
506
507 static YY_BUFFER_STATE
508 yy_create_string_buffer (const char *string, size_t size)
509 {
510 YY_BUFFER_STATE b;
511
512 b = xmalloc (sizeof (struct yy_buffer_state));
513 b->yy_input_file = 0;
514 b->yy_buf_size = size;
515
516 /* yy_ch_buf has to be 2 characters longer than the size given because
517 we need to put in 2 end-of-buffer characters. */
518 b->yy_ch_buf = xmalloc ((size_t) b->yy_buf_size + 3);
519
520 b->yy_ch_buf[0] = '\n';
521 strcpy (b->yy_ch_buf+1, string);
522 b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;
523 b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;
524 b->yy_n_chars = size+1;
525 b->yy_buf_pos = &b->yy_ch_buf[1];
526
527 b->yy_is_our_buffer = 1;
528 b->yy_is_interactive = 0;
529 b->yy_at_bol = 1;
530 b->yy_fill_buffer = 0;
531
532 /* flex 2.4.7 changed the interface. FIXME: We should not be using
533 a flex internal interface in the first place! */
534 #ifdef YY_BUFFER_NEW
535 b->yy_buffer_status = YY_BUFFER_NEW;
536 #else
537 b->yy_eof_status = EOF_NOT_SEEN;
538 #endif
539
540 return b;
541 }
542
543 /* Switch flex to reading from STRING, saving the current input info
544 on the include stack. */
545
546 void
547 lex_redirect (const char *string, const char *fake_filename, unsigned int count)
548 {
549 YY_BUFFER_STATE tmp;
550
551 yy_init = 0;
552 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
553 {
554 einfo (_("%F: macros nested too deeply\n"));
555 }
556 file_name_stack[include_stack_ptr] = fake_filename;
557 lineno_stack[include_stack_ptr] = lineno;
558 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
559 include_stack_ptr++;
560 lineno = count;
561 tmp = yy_create_string_buffer (string, strlen (string));
562 yy_switch_to_buffer (tmp);
563 }
564 \f
565 /* Functions to switch to a different flex start condition,
566 saving the current start condition on `state_stack'. */
567
568 static int state_stack[MAX_INCLUDE_DEPTH * 2];
569 static int *state_stack_p = state_stack;
570
571 void
572 ldlex_script (void)
573 {
574 *(state_stack_p)++ = yy_start;
575 BEGIN (SCRIPT);
576 }
577
578 void
579 ldlex_inputlist (void)
580 {
581 *(state_stack_p)++ = yy_start;
582 BEGIN (INPUTLIST);
583 }
584
585 void
586 ldlex_mri_script (void)
587 {
588 *(state_stack_p)++ = yy_start;
589 BEGIN (MRI);
590 }
591
592 void
593 ldlex_version_script (void)
594 {
595 *(state_stack_p)++ = yy_start;
596 BEGIN (VERS_START);
597 }
598
599 void
600 ldlex_version_file (void)
601 {
602 *(state_stack_p)++ = yy_start;
603 BEGIN (VERS_SCRIPT);
604 }
605
606 void
607 ldlex_expression (void)
608 {
609 *(state_stack_p)++ = yy_start;
610 BEGIN (EXPRESSION);
611 }
612
613 void
614 ldlex_wild (void)
615 {
616 *(state_stack_p)++ = yy_start;
617 BEGIN (WILD);
618 }
619
620 void
621 ldlex_popstate (void)
622 {
623 yy_start = *(--state_stack_p);
624 }
625
626 /* In cases where the parser needs to look ahead and the context
627 changes from expression to script or vice-versa, throw away a
628 NAME. What constitutes a NAME depends on context. */
629
630 void
631 ldlex_backup (void)
632 {
633 yyless (0);
634 }
635
636 /* Return the current file name, or the previous file if no file is
637 current. */
638
639 const char*
640 ldlex_filename (void)
641 {
642 return file_name_stack[include_stack_ptr - (include_stack_ptr != 0)];
643 }
644 \f
645
646 /* Place up to MAX_SIZE characters in BUF and return
647 either the number of characters read, or 0 to indicate EOF. */
648
649 static int
650 yy_input (char *buf, int max_size)
651 {
652 int result = 0;
653 if (YY_CURRENT_BUFFER->yy_input_file)
654 {
655 if (yyin)
656 {
657 result = fread (buf, 1, max_size, yyin);
658 if (result < max_size && ferror (yyin))
659 einfo (_("%F%P: read in flex scanner failed\n"));
660 }
661 }
662 return result;
663 }
664
665 /* Eat the rest of a C-style comment. */
666
667 static void
668 comment (void)
669 {
670 int c;
671
672 while (1)
673 {
674 c = input();
675 while (c != '*' && c != 0)
676 {
677 if (c == '\n')
678 lineno++;
679 c = input();
680 }
681
682 if (c == '*')
683 {
684 c = input();
685 while (c == '*')
686 c = input();
687 if (c == '/')
688 break; /* found the end */
689 }
690
691 if (c == '\n')
692 lineno++;
693
694 if (c == 0)
695 {
696 einfo (_("%F%P: EOF in comment\n"));
697 break;
698 }
699 }
700 }
701
702 /* Warn the user about a garbage character WHAT in the input
703 in context WHERE. */
704
705 static void
706 lex_warn_invalid (char *where, char *what)
707 {
708 char buf[5];
709
710 /* If we have found an input file whose format we do not recognize,
711 and we are therefore treating it as a linker script, and we find
712 an invalid character, then most likely this is a real object file
713 of some different format. Treat it as such. */
714 if (ldfile_assumed_script)
715 {
716 bfd_set_error (bfd_error_file_not_recognized);
717 einfo (_("%F%s: file not recognized: %E\n"), ldlex_filename ());
718 }
719
720 if (! ISPRINT (*what))
721 {
722 sprintf (buf, "\\%03o", *(unsigned char *) what);
723 what = buf;
724 }
725
726 einfo (_("%P:%pS: ignoring invalid character `%s'%s\n"), NULL, what, where);
727 }