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