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