Replace __end_SECNAME with __stop_SECNAME
[deliverable/binutils-gdb.git] / ld / ldlex.l
... / ...
CommitLineData
1%option nounput
2
3%{
4
5/* Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
6 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
7 Free Software Foundation, Inc.
8 Written by Steve Chamberlain of Cygnus Support.
9
10 This file is part of the GNU Binutils.
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
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.
21
22 You should have received a copy of the GNU General Public License
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. */
26
27#include "bfd.h"
28#include "safe-ctype.h"
29#include "bfdlink.h"
30#include "ld.h"
31#include "ldmisc.h"
32#include "ldexp.h"
33#include "ldlang.h"
34#include <ldgram.h>
35#include "ldfile.h"
36#include "ldlex.h"
37#include "ldmain.h"
38#include "libiberty.h"
39
40/* The type of top-level parser input.
41 yylex and yyparse (indirectly) both check this. */
42input_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?) */
46unsigned int lineno = 1;
47
48/* The string we are currently lexing, or NULL if we are reading a
49 file. */
50const 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
61#define YY_INPUT(buf,result,max_size) result = yy_input (buf, max_size)
62
63#ifndef YY_NO_UNPUT
64#define YY_NO_UNPUT
65#endif
66
67#define MAX_INCLUDE_DEPTH 10
68static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
69static const char *file_name_stack[MAX_INCLUDE_DEPTH];
70static unsigned int lineno_stack[MAX_INCLUDE_DEPTH];
71static unsigned int sysrooted_stack[MAX_INCLUDE_DEPTH];
72static unsigned int include_stack_ptr = 0;
73static int vers_node_nesting = 0;
74
75static int yy_input (char *, int);
76static void comment (void);
77static void lex_warn_invalid (char *where, char *what);
78
79/* STATES
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
93int yywrap (void) { return 1; }
94#endif
95%}
96
97%a 4000
98%o 5000
99
100CMDFILENAMECHAR [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~]
101CMDFILENAMECHAR1 [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~]
102FILENAMECHAR1 [_a-zA-Z\/\.\\\$\_\~]
103SYMBOLCHARN [_a-zA-Z\/\.\\\$\_\~0-9]
104FILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~]
105WILDCHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~\?\*\^\!]
106WHITE [ \t\n\r]+
107
108NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~]
109
110V_TAG [.$_a-zA-Z][._a-zA-Z0-9]*
111V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
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;
133 case input_dynamic_list: return INPUT_DYNAMIC_LIST; break;
134 case input_defsym: return INPUT_DEFSYM; break;
135 default: abort ();
136 }
137 }
138
139<BOTH,SCRIPT,EXPRESSION,VERS_START,VERS_NODE,VERS_SCRIPT>"/*" { comment (); }
140
141
142<DEFSYMEXP>"-" { RTOKEN('-');}
143<DEFSYMEXP>"+" { RTOKEN('+');}
144<DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = xstrdup (yytext); return NAME; }
145<DEFSYMEXP>"=" { RTOKEN('='); }
146
147<MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
148 yylval.integer = bfd_scan_vma (yytext + 1, 0, 16);
149 yylval.bigint.str = NULL;
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 ;
155 switch (yytext[yyleng - 1]) {
156 case 'X':
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);
175 yylval.bigint.str = NULL;
176 return INT;
177 }
178<SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>((("$"|0[xX])([0-9A-Fa-f])+)|(([0-9])+))(M|K|m|k)? {
179 char *s = yytext;
180 int ibase = 0;
181
182 if (*s == '$')
183 {
184 ++s;
185 ibase = 16;
186 }
187 yylval.integer = bfd_scan_vma (s, 0, ibase);
188 yylval.bigint.str = NULL;
189 if (yytext[yyleng - 1] == 'M'
190 || yytext[yyleng - 1] == 'm')
191 {
192 yylval.integer *= 1024 * 1024;
193 }
194 else if (yytext[yyleng - 1] == 'K'
195 || yytext[yyleng - 1]=='k')
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 }
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('<');}
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('(');}
243<BOTH,SCRIPT,EXPRESSION,MRI>":" { RTOKEN(':'); }
244<BOTH,SCRIPT,EXPRESSION,MRI>";" { RTOKEN(';');}
245<BOTH,SCRIPT>"MEMORY" { RTOKEN(MEMORY);}
246<BOTH,SCRIPT>"REGION_ALIAS" { RTOKEN(REGION_ALIAS);}
247<BOTH,SCRIPT>"LD_FEATURE" { RTOKEN(LD_FEATURE);}
248<BOTH,SCRIPT,EXPRESSION>"ORIGIN" { RTOKEN(ORIGIN);}
249<BOTH,SCRIPT>"VERSION" { RTOKEN(VERSIONK);}
250<EXPRESSION,BOTH,SCRIPT>"BLOCK" { RTOKEN(BLOCK);}
251<EXPRESSION,BOTH,SCRIPT>"BIND" { RTOKEN(BIND);}
252<BOTH,SCRIPT,EXPRESSION>"LENGTH" { RTOKEN(LENGTH);}
253<EXPRESSION,BOTH,SCRIPT>"ALIGN" { RTOKEN(ALIGN_K);}
254<EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_ALIGN" { RTOKEN(DATA_SEGMENT_ALIGN);}
255<EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_RELRO_END" { RTOKEN(DATA_SEGMENT_RELRO_END);}
256<EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_END" { RTOKEN(DATA_SEGMENT_END);}
257<EXPRESSION,BOTH,SCRIPT>"ADDR" { RTOKEN(ADDR);}
258<EXPRESSION,BOTH,SCRIPT>"LOADADDR" { RTOKEN(LOADADDR);}
259<EXPRESSION,BOTH,SCRIPT>"ALIGNOF" { RTOKEN(ALIGNOF); }
260<EXPRESSION,BOTH>"MAX" { RTOKEN(MAX_K); }
261<EXPRESSION,BOTH>"MIN" { RTOKEN(MIN_K); }
262<EXPRESSION,BOTH,SCRIPT>"ASSERT" { RTOKEN(ASSERT_K); }
263<BOTH,SCRIPT>"ENTRY" { RTOKEN(ENTRY);}
264<BOTH,SCRIPT,MRI>"EXTERN" { RTOKEN(EXTERN);}
265<EXPRESSION,BOTH,SCRIPT>"NEXT" { RTOKEN(NEXT);}
266<EXPRESSION,BOTH,SCRIPT>"sizeof_headers" { RTOKEN(SIZEOF_HEADERS);}
267<EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS" { RTOKEN(SIZEOF_HEADERS);}
268<EXPRESSION,BOTH,SCRIPT>"SEGMENT_START" { RTOKEN(SEGMENT_START);}
269<BOTH,SCRIPT>"MAP" { RTOKEN(MAP);}
270<EXPRESSION,BOTH,SCRIPT>"SIZEOF" { RTOKEN(SIZEOF);}
271<BOTH,SCRIPT>"TARGET" { RTOKEN(TARGET_K);}
272<BOTH,SCRIPT>"SEARCH_DIR" { RTOKEN(SEARCH_DIR);}
273<BOTH,SCRIPT>"OUTPUT" { RTOKEN(OUTPUT);}
274<BOTH,SCRIPT>"INPUT" { RTOKEN(INPUT);}
275<EXPRESSION,BOTH,SCRIPT>"GROUP" { RTOKEN(GROUP);}
276<EXPRESSION,BOTH,SCRIPT>"AS_NEEDED" { RTOKEN(AS_NEEDED);}
277<EXPRESSION,BOTH,SCRIPT>"DEFINED" { RTOKEN(DEFINED);}
278<BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);}
279<BOTH,SCRIPT>"CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);}
280<BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);}
281<BOTH,SCRIPT>"INHIBIT_COMMON_ALLOCATION" { RTOKEN(INHIBIT_COMMON_ALLOCATION);}
282<BOTH,SCRIPT>"SECTIONS" { RTOKEN(SECTIONS);}
283<BOTH,SCRIPT>"INSERT" { RTOKEN(INSERT_K);}
284<BOTH,SCRIPT>"AFTER" { RTOKEN(AFTER);}
285<BOTH,SCRIPT>"BEFORE" { RTOKEN(BEFORE);}
286<BOTH,SCRIPT>"FILL" { RTOKEN(FILL);}
287<BOTH,SCRIPT>"STARTUP" { RTOKEN(STARTUP);}
288<BOTH,SCRIPT>"OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT);}
289<BOTH,SCRIPT>"OUTPUT_ARCH" { RTOKEN( OUTPUT_ARCH);}
290<BOTH,SCRIPT>"HLL" { RTOKEN(HLL);}
291<BOTH,SCRIPT>"SYSLIB" { RTOKEN(SYSLIB);}
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);}
298<BOTH,SCRIPT>"NOFLOAT" { RTOKEN(NOFLOAT);}
299<EXPRESSION,BOTH,SCRIPT>"NOCROSSREFS" { RTOKEN(NOCROSSREFS);}
300<BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY); }
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); }
304<BOTH,SCRIPT>"SORT_BY_INIT_PRIORITY" { RTOKEN(SORT_BY_INIT_PRIORITY); }
305<EXPRESSION,BOTH,SCRIPT>"NOLOAD" { RTOKEN(NOLOAD);}
306<EXPRESSION,BOTH,SCRIPT>"DSECT" { RTOKEN(DSECT);}
307<EXPRESSION,BOTH,SCRIPT>"COPY" { RTOKEN(COPY);}
308<EXPRESSION,BOTH,SCRIPT>"INFO" { RTOKEN(INFO);}
309<EXPRESSION,BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY);}
310<EXPRESSION,BOTH,SCRIPT>"ONLY_IF_RO" { RTOKEN(ONLY_IF_RO); }
311<EXPRESSION,BOTH,SCRIPT>"ONLY_IF_RW" { RTOKEN(ONLY_IF_RW); }
312<EXPRESSION,BOTH,SCRIPT>"SPECIAL" { RTOKEN(SPECIAL); }
313<BOTH,SCRIPT>"o" { RTOKEN(ORIGIN);}
314<BOTH,SCRIPT>"org" { RTOKEN(ORIGIN);}
315<BOTH,SCRIPT>"l" { RTOKEN( LENGTH);}
316<BOTH,SCRIPT>"len" { RTOKEN( LENGTH);}
317<EXPRESSION,BOTH,SCRIPT>"INPUT_SECTION_FLAGS" { RTOKEN(INPUT_SECTION_FLAGS); }
318<EXPRESSION,BOTH,SCRIPT>"INCLUDE" { RTOKEN(INCLUDE);}
319<BOTH,SCRIPT>"PHDRS" { RTOKEN (PHDRS); }
320<EXPRESSION,BOTH,SCRIPT>"AT" { RTOKEN(AT);}
321<EXPRESSION,BOTH,SCRIPT>"SUBALIGN" { RTOKEN(SUBALIGN);}
322<EXPRESSION,BOTH,SCRIPT>"PROVIDE" { RTOKEN(PROVIDE); }
323<EXPRESSION,BOTH,SCRIPT>"PROVIDE_HIDDEN" { RTOKEN(PROVIDE_HIDDEN); }
324<EXPRESSION,BOTH,SCRIPT>"KEEP" { RTOKEN(KEEP); }
325<EXPRESSION,BOTH,SCRIPT>"EXCLUDE_FILE" { RTOKEN(EXCLUDE_FILE); }
326<EXPRESSION,BOTH,SCRIPT>"CONSTANT" { RTOKEN(CONSTANT);}
327<MRI>"#".*\n? { ++ lineno; }
328<MRI>"\n" { ++ lineno; RTOKEN(NEWLINE); }
329<MRI>"*".* { /* Mri comment line */ }
330<MRI>";".* { /* Mri comment line */ }
331<MRI>"END" { RTOKEN(ENDWORD); }
332<MRI>"ALIGNMOD" { RTOKEN(ALIGNMOD);}
333<MRI>"ALIGN" { RTOKEN(ALIGN_K);}
334<MRI>"CHIP" { RTOKEN(CHIP); }
335<MRI>"BASE" { RTOKEN(BASE); }
336<MRI>"ALIAS" { RTOKEN(ALIAS); }
337<MRI>"TRUNCATE" { RTOKEN(TRUNCATE); }
338<MRI>"LOAD" { RTOKEN(LOAD); }
339<MRI>"PUBLIC" { RTOKEN(PUBLIC); }
340<MRI>"ORDER" { RTOKEN(ORDER); }
341<MRI>"NAME" { RTOKEN(NAMEWORD); }
342<MRI>"FORMAT" { RTOKEN(FORMAT); }
343<MRI>"CASE" { RTOKEN(CASE); }
344<MRI>"START" { RTOKEN(START); }
345<MRI>"LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
346<MRI>"SECT" { RTOKEN(SECT); }
347<EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE" { RTOKEN(ABSOLUTE); }
348<MRI>"end" { RTOKEN(ENDWORD); }
349<MRI>"alignmod" { RTOKEN(ALIGNMOD);}
350<MRI>"align" { RTOKEN(ALIGN_K);}
351<MRI>"chip" { RTOKEN(CHIP); }
352<MRI>"base" { RTOKEN(BASE); }
353<MRI>"alias" { RTOKEN(ALIAS); }
354<MRI>"truncate" { RTOKEN(TRUNCATE); }
355<MRI>"load" { RTOKEN(LOAD); }
356<MRI>"public" { RTOKEN(PUBLIC); }
357<MRI>"order" { RTOKEN(ORDER); }
358<MRI>"name" { RTOKEN(NAMEWORD); }
359<MRI>"format" { RTOKEN(FORMAT); }
360<MRI>"case" { RTOKEN(CASE); }
361<MRI>"extern" { RTOKEN(EXTERN); }
362<MRI>"start" { RTOKEN(START); }
363<MRI>"list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
364<MRI>"sect" { RTOKEN(SECT); }
365<EXPRESSION,BOTH,SCRIPT,MRI>"absolute" { RTOKEN(ABSOLUTE); }
366
367<MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
368/* Filename without commas, needed to parse mri stuff */
369 yylval.name = xstrdup (yytext);
370 return NAME;
371 }
372
373
374<BOTH>{FILENAMECHAR1}{FILENAMECHAR}* {
375 yylval.name = xstrdup (yytext);
376 return NAME;
377 }
378<BOTH>"-l"{FILENAMECHAR}+ {
379 yylval.name = xstrdup (yytext + 2);
380 return LNAME;
381 }
382<EXPRESSION>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
383 yylval.name = xstrdup (yytext);
384 return NAME;
385 }
386<EXPRESSION>"-l"{NOCFILENAMECHAR}+ {
387 yylval.name = xstrdup (yytext + 2);
388 return LNAME;
389 }
390<SCRIPT>{WILDCHAR}* {
391 /* Annoyingly, this pattern can match comments, and we have
392 longest match issues to consider. So if the first two
393 characters are a comment opening, put the input back and
394 try again. */
395 if (yytext[0] == '/' && yytext[1] == '*')
396 {
397 yyless (2);
398 comment ();
399 }
400 else
401 {
402 yylval.name = xstrdup (yytext);
403 return NAME;
404 }
405 }
406
407<EXPRESSION,BOTH,SCRIPT,VERS_NODE>"\""[^\"]*"\"" {
408 /* No matter the state, quotes
409 give what's inside */
410 yylval.name = xstrdup (yytext + 1);
411 yylval.name[yyleng - 2] = 0;
412 return NAME;
413 }
414<BOTH,SCRIPT,EXPRESSION>"\n" { lineno++;}
415<MRI,BOTH,SCRIPT,EXPRESSION>[ \t\r]+ { }
416
417<VERS_NODE,VERS_SCRIPT>[:,;] { return *yytext; }
418
419<VERS_NODE>global { RTOKEN(GLOBAL); }
420
421<VERS_NODE>local { RTOKEN(LOCAL); }
422
423<VERS_NODE>extern { RTOKEN(EXTERN); }
424
425<VERS_NODE>{V_IDENTIFIER} { yylval.name = xstrdup (yytext);
426 return VERS_IDENTIFIER; }
427
428<VERS_SCRIPT>{V_TAG} { yylval.name = xstrdup (yytext);
429 return VERS_TAG; }
430
431<VERS_START>"{" { BEGIN(VERS_SCRIPT); return *yytext; }
432
433<VERS_SCRIPT>"{" { BEGIN(VERS_NODE);
434 vers_node_nesting = 0;
435 return *yytext;
436 }
437<VERS_SCRIPT>"}" { return *yytext; }
438<VERS_NODE>"{" { vers_node_nesting++; return *yytext; }
439<VERS_NODE>"}" { if (--vers_node_nesting < 0)
440 BEGIN(VERS_SCRIPT);
441 return *yytext;
442 }
443
444<VERS_START,VERS_NODE,VERS_SCRIPT>[\n] { lineno++; }
445
446<VERS_START,VERS_NODE,VERS_SCRIPT>#.* { /* Eat up comments */ }
447
448<VERS_START,VERS_NODE,VERS_SCRIPT>[ \t\r]+ { /* Eat up whitespace */ }
449
450<<EOF>> {
451 include_stack_ptr--;
452 if (include_stack_ptr == 0)
453 yyterminate ();
454 else
455 yy_switch_to_buffer (include_stack[include_stack_ptr]);
456
457 lineno = lineno_stack[include_stack_ptr];
458 input_flags.sysrooted = sysrooted_stack[include_stack_ptr];
459
460 return END;
461}
462
463<SCRIPT,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>. lex_warn_invalid (" in script", yytext);
464<EXPRESSION,DEFSYMEXP,BOTH>. lex_warn_invalid (" in expression", yytext);
465
466%%
467\f
468
469/* Switch flex to reading script file NAME, open on FILE,
470 saving the current input info on the include stack. */
471
472void
473lex_push_file (FILE *file, const char *name, unsigned int sysrooted)
474{
475 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
476 {
477 einfo ("%F:includes nested too deeply\n");
478 }
479 file_name_stack[include_stack_ptr] = name;
480 lineno_stack[include_stack_ptr] = lineno;
481 sysrooted_stack[include_stack_ptr] = input_flags.sysrooted;
482 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
483
484 include_stack_ptr++;
485 lineno = 1;
486 input_flags.sysrooted = sysrooted;
487 yyin = file;
488 yy_switch_to_buffer (yy_create_buffer (yyin, YY_BUF_SIZE));
489}
490
491/* Return a newly created flex input buffer containing STRING,
492 which is SIZE bytes long. */
493
494static YY_BUFFER_STATE
495yy_create_string_buffer (const char *string, size_t size)
496{
497 YY_BUFFER_STATE b;
498
499 /* Calls to m-alloc get turned by sed into xm-alloc. */
500 b = malloc (sizeof (struct yy_buffer_state));
501 b->yy_input_file = 0;
502 b->yy_buf_size = size;
503
504 /* yy_ch_buf has to be 2 characters longer than the size given because
505 we need to put in 2 end-of-buffer characters. */
506 b->yy_ch_buf = malloc ((unsigned) (b->yy_buf_size + 3));
507
508 b->yy_ch_buf[0] = '\n';
509 strcpy (b->yy_ch_buf+1, string);
510 b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;
511 b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;
512 b->yy_n_chars = size+1;
513 b->yy_buf_pos = &b->yy_ch_buf[1];
514
515 b->yy_is_our_buffer = 1;
516 b->yy_is_interactive = 0;
517 b->yy_at_bol = 1;
518 b->yy_fill_buffer = 0;
519
520 /* flex 2.4.7 changed the interface. FIXME: We should not be using
521 a flex internal interface in the first place! */
522#ifdef YY_BUFFER_NEW
523 b->yy_buffer_status = YY_BUFFER_NEW;
524#else
525 b->yy_eof_status = EOF_NOT_SEEN;
526#endif
527
528 return b;
529}
530
531/* Switch flex to reading from STRING, saving the current input info
532 on the include stack. */
533
534void
535lex_redirect (const char *string, const char *fake_filename, unsigned int count)
536{
537 YY_BUFFER_STATE tmp;
538
539 yy_init = 0;
540 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
541 {
542 einfo("%F: macros nested too deeply\n");
543 }
544 file_name_stack[include_stack_ptr] = fake_filename;
545 lineno_stack[include_stack_ptr] = lineno;
546 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
547 include_stack_ptr++;
548 lineno = count;
549 tmp = yy_create_string_buffer (string, strlen (string));
550 yy_switch_to_buffer (tmp);
551}
552\f
553/* Functions to switch to a different flex start condition,
554 saving the current start condition on `state_stack'. */
555
556static int state_stack[MAX_INCLUDE_DEPTH * 2];
557static int *state_stack_p = state_stack;
558
559void
560ldlex_script (void)
561{
562 *(state_stack_p)++ = yy_start;
563 BEGIN (SCRIPT);
564}
565
566void
567ldlex_mri_script (void)
568{
569 *(state_stack_p)++ = yy_start;
570 BEGIN (MRI);
571}
572
573void
574ldlex_version_script (void)
575{
576 *(state_stack_p)++ = yy_start;
577 BEGIN (VERS_START);
578}
579
580void
581ldlex_version_file (void)
582{
583 *(state_stack_p)++ = yy_start;
584 BEGIN (VERS_SCRIPT);
585}
586
587void
588ldlex_defsym (void)
589{
590 *(state_stack_p)++ = yy_start;
591 BEGIN (DEFSYMEXP);
592}
593
594void
595ldlex_expression (void)
596{
597 *(state_stack_p)++ = yy_start;
598 BEGIN (EXPRESSION);
599}
600
601void
602ldlex_both (void)
603{
604 *(state_stack_p)++ = yy_start;
605 BEGIN (BOTH);
606}
607
608void
609ldlex_popstate (void)
610{
611 yy_start = *(--state_stack_p);
612}
613
614/* Return the current file name, or the previous file if no file is
615 current. */
616
617const char*
618ldlex_filename (void)
619{
620 return file_name_stack[include_stack_ptr - (include_stack_ptr != 0)];
621}
622\f
623
624/* Place up to MAX_SIZE characters in BUF and return
625 either the number of characters read, or 0 to indicate EOF. */
626
627static int
628yy_input (char *buf, int max_size)
629{
630 int result = 0;
631 if (YY_CURRENT_BUFFER->yy_input_file)
632 {
633 if (yyin)
634 {
635 result = fread (buf, 1, max_size, yyin);
636 if (result < max_size && ferror (yyin))
637 einfo ("%F%P: read in flex scanner failed\n");
638 }
639 }
640 return result;
641}
642
643/* Eat the rest of a C-style comment. */
644
645static void
646comment (void)
647{
648 int c;
649
650 while (1)
651 {
652 c = input();
653 while (c != '*' && c != EOF)
654 {
655 if (c == '\n')
656 lineno++;
657 c = input();
658 }
659
660 if (c == '*')
661 {
662 c = input();
663 while (c == '*')
664 c = input();
665 if (c == '/')
666 break; /* found the end */
667 }
668
669 if (c == '\n')
670 lineno++;
671
672 if (c == EOF)
673 {
674 einfo( "%F%P: EOF in comment\n");
675 break;
676 }
677 }
678}
679
680/* Warn the user about a garbage character WHAT in the input
681 in context WHERE. */
682
683static void
684lex_warn_invalid (char *where, char *what)
685{
686 char buf[5];
687
688 /* If we have found an input file whose format we do not recognize,
689 and we are therefore treating it as a linker script, and we find
690 an invalid character, then most likely this is a real object file
691 of some different format. Treat it as such. */
692 if (ldfile_assumed_script)
693 {
694 bfd_set_error (bfd_error_file_not_recognized);
695 einfo ("%F%s: file not recognized: %E\n", ldlex_filename ());
696 }
697
698 if (! ISPRINT (*what))
699 {
700 sprintf (buf, "\\%03o", *(unsigned char *) what);
701 what = buf;
702 }
703
704 einfo ("%P:%S: ignoring invalid character `%s'%s\n", NULL, what, where);
705}
This page took 0.024598 seconds and 4 git commands to generate.