| 1 | %{
|
|---|
| 2 |
|
|---|
| 3 | /* Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
|
|---|
| 4 | 2000, 2001, 2002 Free Software Foundation, Inc.
|
|---|
| 5 |
|
|---|
| 6 | This file is part of GLD, the Gnu Linker.
|
|---|
| 7 |
|
|---|
| 8 | GLD is free software; you can redistribute it and/or modify
|
|---|
| 9 | it under the terms of the GNU General Public License as published by
|
|---|
| 10 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 11 | any later version.
|
|---|
| 12 |
|
|---|
| 13 | GLD is distributed in the hope that it will be useful,
|
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 16 | GNU General Public License for more details.
|
|---|
| 17 |
|
|---|
| 18 | You should have received a copy of the GNU General Public License
|
|---|
| 19 | along with GLD; see the file COPYING. If not, write to the Free
|
|---|
| 20 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|---|
| 21 | 02111-1307, USA. */
|
|---|
| 22 |
|
|---|
| 23 | /*
|
|---|
| 24 | This was written by steve chamberlain
|
|---|
| 25 | sac@cygnus.com
|
|---|
| 26 | */
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 | #include "ansidecl.h"
|
|---|
| 30 | #include <stdio.h>
|
|---|
| 31 |
|
|---|
| 32 | #ifdef MPW
|
|---|
| 33 | /* Prevent enum redefinition problems. */
|
|---|
| 34 | #define TRUE_FALSE_ALREADY_DEFINED
|
|---|
| 35 | #endif /* MPW */
|
|---|
| 36 |
|
|---|
| 37 | #include "bfd.h"
|
|---|
| 38 | #include "sysdep.h"
|
|---|
| 39 | #include "safe-ctype.h"
|
|---|
| 40 | #include "bfdlink.h"
|
|---|
| 41 | #include "ld.h"
|
|---|
| 42 | #include "ldmisc.h"
|
|---|
| 43 | #include "ldexp.h"
|
|---|
| 44 | #include "ldlang.h"
|
|---|
| 45 | #include <ldgram.h>
|
|---|
| 46 | #include "ldfile.h"
|
|---|
| 47 | #include "ldlex.h"
|
|---|
| 48 | #include "ldmain.h"
|
|---|
| 49 | #include "libiberty.h"
|
|---|
| 50 |
|
|---|
| 51 | /* The type of top-level parser input.
|
|---|
| 52 | yylex and yyparse (indirectly) both check this. */
|
|---|
| 53 | input_type parser_input;
|
|---|
| 54 |
|
|---|
| 55 | /* Line number in the current input file.
|
|---|
| 56 | (FIXME Actually, it doesn't appear to get reset for each file?) */
|
|---|
| 57 | unsigned int lineno = 1;
|
|---|
| 58 |
|
|---|
| 59 | /* The string we are currently lexing, or NULL if we are reading a
|
|---|
| 60 | file. */
|
|---|
| 61 | const char *lex_string = NULL;
|
|---|
| 62 |
|
|---|
| 63 | /* Support for flex reading from more than one input file (stream).
|
|---|
| 64 | `include_stack' is flex's input state for each open file;
|
|---|
| 65 | `file_name_stack' is the file names. `lineno_stack' is the current
|
|---|
| 66 | line numbers.
|
|---|
| 67 |
|
|---|
| 68 | If `include_stack_ptr' is 0, we haven't started reading anything yet.
|
|---|
| 69 | Otherwise, stack elements 0 through `include_stack_ptr - 1' are valid. */
|
|---|
| 70 |
|
|---|
| 71 | #undef YY_INPUT
|
|---|
| 72 | #define YY_INPUT(buf,result,max_size) yy_input(buf, &result, max_size)
|
|---|
| 73 |
|
|---|
| 74 | #define MAX_INCLUDE_DEPTH 10
|
|---|
| 75 | static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
|
|---|
| 76 | static const char *file_name_stack[MAX_INCLUDE_DEPTH];
|
|---|
| 77 | static unsigned int lineno_stack[MAX_INCLUDE_DEPTH];
|
|---|
| 78 | static unsigned int include_stack_ptr = 0;
|
|---|
| 79 | static int vers_node_nesting = 0;
|
|---|
| 80 |
|
|---|
| 81 | static YY_BUFFER_STATE yy_create_string_buffer PARAMS ((const char *string,
|
|---|
| 82 | size_t size));
|
|---|
| 83 | static void yy_input PARAMS ((char *, int *result, int max_size));
|
|---|
| 84 |
|
|---|
| 85 | static void comment PARAMS ((void));
|
|---|
| 86 | static void lex_warn_invalid PARAMS ((char *where, char *what));
|
|---|
| 87 |
|
|---|
| 88 | /* STATES
|
|---|
| 89 | EXPRESSION definitely in an expression
|
|---|
| 90 | SCRIPT definitely in a script
|
|---|
| 91 | BOTH either EXPRESSION or SCRIPT
|
|---|
| 92 | DEFSYMEXP in an argument to -defsym
|
|---|
| 93 | MRI in an MRI script
|
|---|
| 94 | VERS_START starting a Sun style mapfile
|
|---|
| 95 | VERS_SCRIPT a Sun style mapfile
|
|---|
| 96 | VERS_NODE a node within a Sun style mapfile
|
|---|
| 97 | */
|
|---|
| 98 | #define RTOKEN(x) { yylval.token = x; return x; }
|
|---|
| 99 |
|
|---|
| 100 | /* Some versions of flex want this. */
|
|---|
| 101 | #ifndef yywrap
|
|---|
| 102 | int yywrap () { return 1; }
|
|---|
| 103 | #endif
|
|---|
| 104 | %}
|
|---|
| 105 |
|
|---|
| 106 | %a 4000
|
|---|
| 107 | %o 5000
|
|---|
| 108 |
|
|---|
| 109 | CMDFILENAMECHAR [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~]
|
|---|
| 110 | CMDFILENAMECHAR1 [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~]
|
|---|
| 111 | FILENAMECHAR1 [_a-zA-Z\/\.\\\$\_\~]
|
|---|
| 112 | SYMBOLCHARN [_a-zA-Z\/\.\\\$\_\~0-9]
|
|---|
| 113 | FILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~]
|
|---|
| 114 | WILDCHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~\?\*]
|
|---|
| 115 | WHITE [ \t\n\r]+
|
|---|
| 116 |
|
|---|
| 117 | NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~]
|
|---|
| 118 |
|
|---|
| 119 | V_TAG [.$_a-zA-Z][._a-zA-Z0-9]*
|
|---|
| 120 | V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^]([*?.$_a-zA-Z0-9\[\]\-\!\^]|::)*
|
|---|
| 121 |
|
|---|
| 122 | %s SCRIPT
|
|---|
| 123 | %s EXPRESSION
|
|---|
| 124 | %s BOTH
|
|---|
| 125 | %s DEFSYMEXP
|
|---|
| 126 | %s MRI
|
|---|
| 127 | %s VERS_START
|
|---|
| 128 | %s VERS_SCRIPT
|
|---|
| 129 | %s VERS_NODE
|
|---|
| 130 | %%
|
|---|
| 131 |
|
|---|
| 132 | if (parser_input != input_selected)
|
|---|
| 133 | {
|
|---|
| 134 | /* The first token of the input determines the initial parser state. */
|
|---|
| 135 | input_type t = parser_input;
|
|---|
| 136 | parser_input = input_selected;
|
|---|
| 137 | switch (t)
|
|---|
| 138 | {
|
|---|
| 139 | case input_script: return INPUT_SCRIPT; break;
|
|---|
| 140 | case input_mri_script: return INPUT_MRI_SCRIPT; break;
|
|---|
| 141 | case input_version_script: return INPUT_VERSION_SCRIPT; break;
|
|---|
| 142 | case input_defsym: return INPUT_DEFSYM; break;
|
|---|
| 143 | default: abort ();
|
|---|
| 144 | }
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | <BOTH,SCRIPT,EXPRESSION,VERS_START,VERS_NODE,VERS_SCRIPT>"/*" { comment(); }
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 | <DEFSYMEXP>"-" { RTOKEN('-');}
|
|---|
| 151 | <DEFSYMEXP>"+" { RTOKEN('+');}
|
|---|
| 152 | <DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = xstrdup(yytext); return NAME; }
|
|---|
| 153 | <DEFSYMEXP>"=" { RTOKEN('='); }
|
|---|
| 154 |
|
|---|
| 155 | <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
|
|---|
| 156 | yylval.integer = bfd_scan_vma (yytext+1, 0,16);
|
|---|
| 157 | yylval.bigint.str = (char *) 0;
|
|---|
| 158 | return INT;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | <MRI,EXPRESSION>([0-9A-Fa-f])+(H|h|X|x|B|b|O|o|D|d) {
|
|---|
| 162 | int ibase ;
|
|---|
| 163 | switch (yytext[yyleng-1]) {
|
|---|
| 164 | case 'X':
|
|---|
| 165 | case 'x':
|
|---|
| 166 | case 'H':
|
|---|
| 167 | case 'h':
|
|---|
| 168 | ibase = 16;
|
|---|
| 169 | break;
|
|---|
| 170 | case 'O':
|
|---|
| 171 | case 'o':
|
|---|
| 172 | ibase = 8;
|
|---|
| 173 | break;
|
|---|
| 174 | case 'B':
|
|---|
| 175 | case 'b':
|
|---|
| 176 | ibase = 2;
|
|---|
| 177 | break;
|
|---|
| 178 | default:
|
|---|
| 179 | ibase = 10;
|
|---|
| 180 | }
|
|---|
| 181 | yylval.integer = bfd_scan_vma (yytext, 0,
|
|---|
| 182 | ibase);
|
|---|
| 183 | yylval.bigint.str = (char *) 0;
|
|---|
| 184 | return INT;
|
|---|
| 185 | }
|
|---|
| 186 | <SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>((("$"|0[xX])([0-9A-Fa-f])+)|(([0-9])+))(M|K|m|k)? {
|
|---|
| 187 | char *s = yytext;
|
|---|
| 188 | int ibase = 0;
|
|---|
| 189 |
|
|---|
| 190 | if (*s == '$')
|
|---|
| 191 | {
|
|---|
| 192 | ++s;
|
|---|
| 193 | ibase = 16;
|
|---|
| 194 | }
|
|---|
| 195 | yylval.integer = bfd_scan_vma (s, 0, ibase);
|
|---|
| 196 | yylval.bigint.str = (char *) 0;
|
|---|
| 197 | if (yytext[yyleng-1] == 'M'
|
|---|
| 198 | || yytext[yyleng-1] == 'm')
|
|---|
| 199 | {
|
|---|
| 200 | yylval.integer *= 1024 * 1024;
|
|---|
| 201 | }
|
|---|
| 202 | else if (yytext[yyleng-1] == 'K'
|
|---|
| 203 | || yytext[yyleng-1]=='k')
|
|---|
| 204 | {
|
|---|
| 205 | yylval.integer *= 1024;
|
|---|
| 206 | }
|
|---|
| 207 | else if (yytext[0] == '0'
|
|---|
| 208 | && (yytext[1] == 'x'
|
|---|
| 209 | || yytext[1] == 'X'))
|
|---|
| 210 | {
|
|---|
| 211 | yylval.bigint.str = xstrdup (yytext + 2);
|
|---|
| 212 | }
|
|---|
| 213 | return INT;
|
|---|
| 214 | }
|
|---|
| 215 | <BOTH,SCRIPT,EXPRESSION,MRI>"]" { RTOKEN(']');}
|
|---|
| 216 | <BOTH,SCRIPT,EXPRESSION,MRI>"[" { RTOKEN('[');}
|
|---|
| 217 | <BOTH,SCRIPT,EXPRESSION,MRI>"<<=" { RTOKEN(LSHIFTEQ);}
|
|---|
| 218 | <BOTH,SCRIPT,EXPRESSION,MRI>">>=" { RTOKEN(RSHIFTEQ);}
|
|---|
| 219 | <BOTH,SCRIPT,EXPRESSION,MRI>"||" { RTOKEN(OROR);}
|
|---|
| 220 | <BOTH,SCRIPT,EXPRESSION,MRI>"==" { RTOKEN(EQ);}
|
|---|
| 221 | <BOTH,SCRIPT,EXPRESSION,MRI>"!=" { RTOKEN(NE);}
|
|---|
| 222 | <BOTH,SCRIPT,EXPRESSION,MRI>">=" { RTOKEN(GE);}
|
|---|
| 223 | <BOTH,SCRIPT,EXPRESSION,MRI>"<=" { RTOKEN(LE);}
|
|---|
| 224 | <BOTH,SCRIPT,EXPRESSION,MRI>"<<" { RTOKEN(LSHIFT);}
|
|---|
| 225 | <BOTH,SCRIPT,EXPRESSION,MRI>">>" { RTOKEN(RSHIFT);}
|
|---|
| 226 | <BOTH,SCRIPT,EXPRESSION,MRI>"+=" { RTOKEN(PLUSEQ);}
|
|---|
| 227 | <BOTH,SCRIPT,EXPRESSION,MRI>"-=" { RTOKEN(MINUSEQ);}
|
|---|
| 228 | <BOTH,SCRIPT,EXPRESSION,MRI>"*=" { RTOKEN(MULTEQ);}
|
|---|
| 229 | <BOTH,SCRIPT,EXPRESSION,MRI>"/=" { RTOKEN(DIVEQ);}
|
|---|
| 230 | <BOTH,SCRIPT,EXPRESSION,MRI>"&=" { RTOKEN(ANDEQ);}
|
|---|
| 231 | <BOTH,SCRIPT,EXPRESSION,MRI>"|=" { RTOKEN(OREQ);}
|
|---|
| 232 | <BOTH,SCRIPT,EXPRESSION,MRI>"&&" { RTOKEN(ANDAND);}
|
|---|
| 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,EXPRESSION,MRI>"<" { RTOKEN('<');}
|
|---|
| 246 | <BOTH,SCRIPT,EXPRESSION,MRI>"=" { RTOKEN('=');}
|
|---|
| 247 | <BOTH,SCRIPT,EXPRESSION,MRI>"}" { RTOKEN('}') ; }
|
|---|
| 248 | <BOTH,SCRIPT,EXPRESSION,MRI>"{" { RTOKEN('{'); }
|
|---|
| 249 | <BOTH,SCRIPT,EXPRESSION,MRI>")" { RTOKEN(')');}
|
|---|
| 250 | <BOTH,SCRIPT,EXPRESSION,MRI>"(" { RTOKEN('(');}
|
|---|
| 251 | <BOTH,SCRIPT,EXPRESSION,MRI>":" { RTOKEN(':'); }
|
|---|
| 252 | <BOTH,SCRIPT,EXPRESSION,MRI>";" { RTOKEN(';');}
|
|---|
| 253 | <BOTH,SCRIPT>"MEMORY" { RTOKEN(MEMORY);}
|
|---|
| 254 | <BOTH,SCRIPT>"ORIGIN" { RTOKEN(ORIGIN);}
|
|---|
| 255 | <BOTH,SCRIPT>"VERSION" { RTOKEN(VERSIONK);}
|
|---|
| 256 | <EXPRESSION,BOTH,SCRIPT>"BLOCK" { RTOKEN(BLOCK);}
|
|---|
| 257 | <EXPRESSION,BOTH,SCRIPT>"BIND" { RTOKEN(BIND);}
|
|---|
| 258 | <BOTH,SCRIPT>"LENGTH" { RTOKEN(LENGTH);}
|
|---|
| 259 | <EXPRESSION,BOTH,SCRIPT>"ALIGN" { RTOKEN(ALIGN_K);}
|
|---|
| 260 | <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_ALIGN" { RTOKEN(DATA_SEGMENT_ALIGN);}
|
|---|
| 261 | <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_END" { RTOKEN(DATA_SEGMENT_END);}
|
|---|
| 262 | <EXPRESSION,BOTH,SCRIPT>"ADDR" { RTOKEN(ADDR);}
|
|---|
| 263 | <EXPRESSION,BOTH,SCRIPT>"LOADADDR" { RTOKEN(LOADADDR);}
|
|---|
| 264 | <EXPRESSION,BOTH>"MAX" { RTOKEN(MAX_K); }
|
|---|
| 265 | <EXPRESSION,BOTH>"MIN" { RTOKEN(MIN_K); }
|
|---|
| 266 | <EXPRESSION,BOTH>"ASSERT" { RTOKEN(ASSERT_K); }
|
|---|
| 267 | <BOTH,SCRIPT>"ENTRY" { RTOKEN(ENTRY);}
|
|---|
| 268 | <BOTH,SCRIPT,MRI>"EXTERN" { RTOKEN(EXTERN);}
|
|---|
| 269 | <EXPRESSION,BOTH,SCRIPT>"NEXT" { RTOKEN(NEXT);}
|
|---|
| 270 | <EXPRESSION,BOTH,SCRIPT>"sizeof_headers" { RTOKEN(SIZEOF_HEADERS);}
|
|---|
| 271 | <EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS" { RTOKEN(SIZEOF_HEADERS);}
|
|---|
| 272 | <BOTH,SCRIPT>"MAP" { RTOKEN(MAP);}
|
|---|
| 273 | <EXPRESSION,BOTH,SCRIPT>"SIZEOF" { RTOKEN(SIZEOF);}
|
|---|
| 274 | <BOTH,SCRIPT>"TARGET" { RTOKEN(TARGET_K);}
|
|---|
| 275 | <BOTH,SCRIPT>"SEARCH_DIR" { RTOKEN(SEARCH_DIR);}
|
|---|
| 276 | <BOTH,SCRIPT>"OUTPUT" { RTOKEN(OUTPUT);}
|
|---|
| 277 | <BOTH,SCRIPT>"INPUT" { RTOKEN(INPUT);}
|
|---|
| 278 | <EXPRESSION,BOTH,SCRIPT>"GROUP" { RTOKEN(GROUP);}
|
|---|
| 279 | <EXPRESSION,BOTH,SCRIPT>"DEFINED" { RTOKEN(DEFINED);}
|
|---|
| 280 | <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);}
|
|---|
| 281 | <BOTH,SCRIPT>"CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);}
|
|---|
| 282 | <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);}
|
|---|
| 283 | <BOTH,SCRIPT>"INHIBIT_COMMON_ALLOCATION" { RTOKEN(INHIBIT_COMMON_ALLOCATION);}
|
|---|
| 284 | <BOTH,SCRIPT>"SECTIONS" { RTOKEN(SECTIONS);}
|
|---|
| 285 | <BOTH,SCRIPT>"FILL" { RTOKEN(FILL);}
|
|---|
| 286 | <BOTH,SCRIPT>"STARTUP" { RTOKEN(STARTUP);}
|
|---|
| 287 | <BOTH,SCRIPT>"OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT);}
|
|---|
| 288 | <BOTH,SCRIPT>"OUTPUT_ARCH" { RTOKEN( OUTPUT_ARCH);}
|
|---|
| 289 | <BOTH,SCRIPT>"HLL" { RTOKEN(HLL);}
|
|---|
| 290 | <BOTH,SCRIPT>"SYSLIB" { RTOKEN(SYSLIB);}
|
|---|
| 291 | <BOTH,SCRIPT>"FLOAT" { RTOKEN(FLOAT);}
|
|---|
| 292 | <BOTH,SCRIPT>"QUAD" { RTOKEN( QUAD);}
|
|---|
| 293 | <BOTH,SCRIPT>"SQUAD" { RTOKEN( SQUAD);}
|
|---|
| 294 | <BOTH,SCRIPT>"LONG" { RTOKEN( LONG);}
|
|---|
| 295 | <BOTH,SCRIPT>"SHORT" { RTOKEN( SHORT);}
|
|---|
| 296 | <BOTH,SCRIPT>"BYTE" { RTOKEN( BYTE);}
|
|---|
| 297 | <BOTH,SCRIPT>"NOFLOAT" { RTOKEN(NOFLOAT);}
|
|---|
| 298 | <EXPRESSION,BOTH,SCRIPT>"NOCROSSREFS" { RTOKEN(NOCROSSREFS);}
|
|---|
| 299 | <BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY); }
|
|---|
| 300 | <BOTH,SCRIPT>"SORT" { RTOKEN(SORT); }
|
|---|
| 301 | <EXPRESSION,BOTH,SCRIPT>"NOLOAD" { RTOKEN(NOLOAD);}
|
|---|
| 302 | <EXPRESSION,BOTH,SCRIPT>"DSECT" { RTOKEN(DSECT);}
|
|---|
| 303 | <EXPRESSION,BOTH,SCRIPT>"COPY" { RTOKEN(COPY);}
|
|---|
| 304 | <EXPRESSION,BOTH,SCRIPT>"INFO" { RTOKEN(INFO);}
|
|---|
| 305 | <EXPRESSION,BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY);}
|
|---|
| 306 | <BOTH,SCRIPT>"o" { RTOKEN(ORIGIN);}
|
|---|
| 307 | <BOTH,SCRIPT>"org" { RTOKEN(ORIGIN);}
|
|---|
| 308 | <BOTH,SCRIPT>"l" { RTOKEN( LENGTH);}
|
|---|
| 309 | <BOTH,SCRIPT>"len" { RTOKEN( LENGTH);}
|
|---|
| 310 | <BOTH,SCRIPT>"INCLUDE" { RTOKEN(INCLUDE);}
|
|---|
| 311 | <BOTH,SCRIPT>"PHDRS" { RTOKEN (PHDRS); }
|
|---|
| 312 | <EXPRESSION,BOTH,SCRIPT>"AT" { RTOKEN(AT);}
|
|---|
| 313 | <EXPRESSION,BOTH,SCRIPT>"PROVIDE" { RTOKEN(PROVIDE); }
|
|---|
| 314 | <EXPRESSION,BOTH,SCRIPT>"KEEP" { RTOKEN(KEEP); }
|
|---|
| 315 | <EXPRESSION,BOTH,SCRIPT>"EXCLUDE_FILE" { RTOKEN(EXCLUDE_FILE); }
|
|---|
| 316 | <MRI>"#".*\n? { ++ lineno; }
|
|---|
| 317 | <MRI>"\n" { ++ lineno; RTOKEN(NEWLINE); }
|
|---|
| 318 | <MRI>"*".* { /* Mri comment line */ }
|
|---|
| 319 | <MRI>";".* { /* Mri comment line */ }
|
|---|
| 320 | <MRI>"END" { RTOKEN(ENDWORD); }
|
|---|
| 321 | <MRI>"ALIGNMOD" { RTOKEN(ALIGNMOD);}
|
|---|
| 322 | <MRI>"ALIGN" { RTOKEN(ALIGN_K);}
|
|---|
| 323 | <MRI>"CHIP" { RTOKEN(CHIP); }
|
|---|
| 324 | <MRI>"BASE" { RTOKEN(BASE); }
|
|---|
| 325 | <MRI>"ALIAS" { RTOKEN(ALIAS); }
|
|---|
| 326 | <MRI>"TRUNCATE" { RTOKEN(TRUNCATE); }
|
|---|
| 327 | <MRI>"LOAD" { RTOKEN(LOAD); }
|
|---|
| 328 | <MRI>"PUBLIC" { RTOKEN(PUBLIC); }
|
|---|
| 329 | <MRI>"ORDER" { RTOKEN(ORDER); }
|
|---|
| 330 | <MRI>"NAME" { RTOKEN(NAMEWORD); }
|
|---|
| 331 | <MRI>"FORMAT" { RTOKEN(FORMAT); }
|
|---|
| 332 | <MRI>"CASE" { RTOKEN(CASE); }
|
|---|
| 333 | <MRI>"START" { RTOKEN(START); }
|
|---|
| 334 | <MRI>"LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
|
|---|
| 335 | <MRI>"SECT" { RTOKEN(SECT); }
|
|---|
| 336 | <EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE" { RTOKEN(ABSOLUTE); }
|
|---|
| 337 | <MRI>"end" { RTOKEN(ENDWORD); }
|
|---|
| 338 | <MRI>"alignmod" { RTOKEN(ALIGNMOD);}
|
|---|
| 339 | <MRI>"align" { RTOKEN(ALIGN_K);}
|
|---|
| 340 | <MRI>"chip" { RTOKEN(CHIP); }
|
|---|
| 341 | <MRI>"base" { RTOKEN(BASE); }
|
|---|
| 342 | <MRI>"alias" { RTOKEN(ALIAS); }
|
|---|
| 343 | <MRI>"truncate" { RTOKEN(TRUNCATE); }
|
|---|
| 344 | <MRI>"load" { RTOKEN(LOAD); }
|
|---|
| 345 | <MRI>"public" { RTOKEN(PUBLIC); }
|
|---|
| 346 | <MRI>"order" { RTOKEN(ORDER); }
|
|---|
| 347 | <MRI>"name" { RTOKEN(NAMEWORD); }
|
|---|
| 348 | <MRI>"format" { RTOKEN(FORMAT); }
|
|---|
| 349 | <MRI>"case" { RTOKEN(CASE); }
|
|---|
| 350 | <MRI>"extern" { RTOKEN(EXTERN); }
|
|---|
| 351 | <MRI>"start" { RTOKEN(START); }
|
|---|
| 352 | <MRI>"list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
|
|---|
| 353 | <MRI>"sect" { RTOKEN(SECT); }
|
|---|
| 354 | <EXPRESSION,BOTH,SCRIPT,MRI>"absolute" { RTOKEN(ABSOLUTE); }
|
|---|
| 355 |
|
|---|
| 356 | <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
|
|---|
| 357 | /* Filename without commas, needed to parse mri stuff */
|
|---|
| 358 | yylval.name = xstrdup(yytext);
|
|---|
| 359 | return NAME;
|
|---|
| 360 | }
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 | <BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}* {
|
|---|
| 364 | yylval.name = xstrdup(yytext);
|
|---|
| 365 | return NAME;
|
|---|
| 366 | }
|
|---|
| 367 | <BOTH,EXPRESSION>"-l"{FILENAMECHAR}+ {
|
|---|
| 368 | yylval.name = xstrdup (yytext + 2);
|
|---|
| 369 | return LNAME;
|
|---|
| 370 | }
|
|---|
| 371 | <SCRIPT>{WILDCHAR}* {
|
|---|
| 372 | /* Annoyingly, this pattern can match comments, and we have
|
|---|
| 373 | longest match issues to consider. So if the first two
|
|---|
| 374 | characters are a comment opening, put the input back and
|
|---|
| 375 | try again. */
|
|---|
| 376 | if (yytext[0] == '/' && yytext[1] == '*')
|
|---|
| 377 | {
|
|---|
| 378 | yyless(2);
|
|---|
| 379 | comment ();
|
|---|
| 380 | }
|
|---|
| 381 | else
|
|---|
| 382 | {
|
|---|
| 383 | yylval.name = xstrdup(yytext);
|
|---|
| 384 | return NAME;
|
|---|
| 385 | }
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 | <EXPRESSION,BOTH,SCRIPT,VERS_NODE>"\""[^\"]*"\"" {
|
|---|
| 389 | /* No matter the state, quotes
|
|---|
| 390 | give what's inside */
|
|---|
| 391 | yylval.name = xstrdup(yytext+1);
|
|---|
| 392 | yylval.name[yyleng-2] = 0;
|
|---|
| 393 | return NAME;
|
|---|
| 394 | }
|
|---|
| 395 | <BOTH,SCRIPT,EXPRESSION>"\n" { lineno++;}
|
|---|
| 396 | <MRI,BOTH,SCRIPT,EXPRESSION>[ \t\r]+ { }
|
|---|
| 397 |
|
|---|
| 398 | <VERS_NODE,VERS_SCRIPT>[:,;] { return *yytext; }
|
|---|
| 399 |
|
|---|
| 400 | <VERS_NODE>global { RTOKEN(GLOBAL); }
|
|---|
| 401 |
|
|---|
| 402 | <VERS_NODE>local { RTOKEN(LOCAL); }
|
|---|
| 403 |
|
|---|
| 404 | <VERS_NODE>extern { RTOKEN(EXTERN); }
|
|---|
| 405 |
|
|---|
| 406 | <VERS_NODE>{V_IDENTIFIER} { yylval.name = xstrdup (yytext);
|
|---|
| 407 | return VERS_IDENTIFIER; }
|
|---|
| 408 |
|
|---|
| 409 | <VERS_SCRIPT>{V_TAG} { yylval.name = xstrdup (yytext);
|
|---|
| 410 | return VERS_TAG; }
|
|---|
| 411 |
|
|---|
| 412 | <VERS_START>"{" { BEGIN(VERS_SCRIPT); return *yytext; }
|
|---|
| 413 |
|
|---|
| 414 | <VERS_SCRIPT>"{" { BEGIN(VERS_NODE);
|
|---|
| 415 | vers_node_nesting = 0;
|
|---|
| 416 | return *yytext;
|
|---|
| 417 | }
|
|---|
| 418 | <VERS_SCRIPT>"}" { return *yytext; }
|
|---|
| 419 | <VERS_NODE>"{" { vers_node_nesting++; return *yytext; }
|
|---|
| 420 | <VERS_NODE>"}" { if (--vers_node_nesting < 0)
|
|---|
| 421 | BEGIN(VERS_SCRIPT);
|
|---|
| 422 | return *yytext;
|
|---|
| 423 | }
|
|---|
| 424 |
|
|---|
| 425 | <VERS_START,VERS_NODE,VERS_SCRIPT>[\n] { lineno++; }
|
|---|
| 426 |
|
|---|
| 427 | <VERS_START,VERS_NODE,VERS_SCRIPT>#.* { /* Eat up comments */ }
|
|---|
| 428 |
|
|---|
| 429 | <VERS_START,VERS_NODE,VERS_SCRIPT>[ \t\r]+ { /* Eat up whitespace */ }
|
|---|
| 430 |
|
|---|
| 431 | <<EOF>> {
|
|---|
| 432 | include_stack_ptr--;
|
|---|
| 433 |
|
|---|
| 434 | if (include_stack_ptr == 0)
|
|---|
| 435 | {
|
|---|
| 436 | yyterminate();
|
|---|
| 437 | }
|
|---|
| 438 | else
|
|---|
| 439 | {
|
|---|
| 440 | yy_switch_to_buffer(include_stack[include_stack_ptr]);
|
|---|
| 441 | }
|
|---|
| 442 |
|
|---|
| 443 | ldfile_input_filename = file_name_stack[include_stack_ptr - 1];
|
|---|
| 444 | lineno = lineno_stack[include_stack_ptr];
|
|---|
| 445 |
|
|---|
| 446 | return END;
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 | <SCRIPT,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>. lex_warn_invalid(" in script", yytext);
|
|---|
| 450 | <EXPRESSION,DEFSYMEXP,BOTH>. lex_warn_invalid(" in expression", yytext);
|
|---|
| 451 |
|
|---|
| 452 | %%
|
|---|
| 453 | |
|---|
| 454 |
|
|---|
| 455 |
|
|---|
| 456 | /* Switch flex to reading script file NAME, open on FILE,
|
|---|
| 457 | saving the current input info on the include stack. */
|
|---|
| 458 |
|
|---|
| 459 | void
|
|---|
| 460 | lex_push_file (file, name)
|
|---|
| 461 | FILE *file;
|
|---|
| 462 | const char *name;
|
|---|
| 463 | {
|
|---|
| 464 | if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
|
|---|
| 465 | {
|
|---|
| 466 | einfo("%F:includes nested too deeply\n");
|
|---|
| 467 | }
|
|---|
| 468 | file_name_stack[include_stack_ptr] = name;
|
|---|
| 469 | lineno_stack[include_stack_ptr] = lineno;
|
|---|
| 470 | include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
|
|---|
| 471 |
|
|---|
| 472 | include_stack_ptr++;
|
|---|
| 473 | lineno = 1;
|
|---|
| 474 | yyin = file;
|
|---|
| 475 | yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
|
|---|
| 476 | }
|
|---|
| 477 |
|
|---|
| 478 | /* Return a newly created flex input buffer containing STRING,
|
|---|
| 479 | which is SIZE bytes long. */
|
|---|
| 480 |
|
|---|
| 481 | static YY_BUFFER_STATE
|
|---|
| 482 | yy_create_string_buffer (string, size)
|
|---|
| 483 | const char *string;
|
|---|
| 484 | size_t size;
|
|---|
| 485 | {
|
|---|
| 486 | YY_BUFFER_STATE b;
|
|---|
| 487 |
|
|---|
| 488 | /* Calls to m-alloc get turned by sed into xm-alloc. */
|
|---|
| 489 | b = (YY_BUFFER_STATE) malloc (sizeof (struct yy_buffer_state));
|
|---|
| 490 | b->yy_input_file = 0;
|
|---|
| 491 | b->yy_buf_size = size;
|
|---|
| 492 |
|
|---|
| 493 | /* yy_ch_buf has to be 2 characters longer than the size given because
|
|---|
| 494 | we need to put in 2 end-of-buffer characters. */
|
|---|
| 495 | b->yy_ch_buf = (char *) malloc ((unsigned) (b->yy_buf_size + 3));
|
|---|
| 496 |
|
|---|
| 497 | b->yy_ch_buf[0] = '\n';
|
|---|
| 498 | strcpy (b->yy_ch_buf+1, string);
|
|---|
| 499 | b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;
|
|---|
| 500 | b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;
|
|---|
| 501 | b->yy_n_chars = size+1;
|
|---|
| 502 | b->yy_buf_pos = &b->yy_ch_buf[1];
|
|---|
| 503 |
|
|---|
| 504 | b->yy_is_our_buffer = 1;
|
|---|
| 505 | b->yy_is_interactive = 0;
|
|---|
| 506 | b->yy_at_bol = 1;
|
|---|
| 507 | b->yy_fill_buffer = 0;
|
|---|
| 508 |
|
|---|
| 509 | /* flex 2.4.7 changed the interface. FIXME: We should not be using
|
|---|
| 510 | a flex internal interface in the first place! */
|
|---|
| 511 | #ifdef YY_BUFFER_NEW
|
|---|
| 512 | b->yy_buffer_status = YY_BUFFER_NEW;
|
|---|
| 513 | #else
|
|---|
| 514 | b->yy_eof_status = EOF_NOT_SEEN;
|
|---|
| 515 | #endif
|
|---|
| 516 |
|
|---|
| 517 | return b;
|
|---|
| 518 | }
|
|---|
| 519 |
|
|---|
| 520 | /* Switch flex to reading from STRING, saving the current input info
|
|---|
| 521 | on the include stack. */
|
|---|
| 522 |
|
|---|
| 523 | void
|
|---|
| 524 | lex_redirect (string)
|
|---|
| 525 | const char *string;
|
|---|
| 526 | {
|
|---|
| 527 | YY_BUFFER_STATE tmp;
|
|---|
| 528 |
|
|---|
| 529 | yy_init = 0;
|
|---|
| 530 | if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
|
|---|
| 531 | {
|
|---|
| 532 | einfo("%F: macros nested too deeply\n");
|
|---|
| 533 | }
|
|---|
| 534 | file_name_stack[include_stack_ptr] = "redirect";
|
|---|
| 535 | lineno_stack[include_stack_ptr] = lineno;
|
|---|
| 536 | include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
|
|---|
| 537 | include_stack_ptr++;
|
|---|
| 538 | lineno = 1;
|
|---|
| 539 | tmp = yy_create_string_buffer (string, strlen (string));
|
|---|
| 540 | yy_switch_to_buffer (tmp);
|
|---|
| 541 | }
|
|---|
| 542 | |
|---|
| 543 |
|
|---|
| 544 | /* Functions to switch to a different flex start condition,
|
|---|
| 545 | saving the current start condition on `state_stack'. */
|
|---|
| 546 |
|
|---|
| 547 | static int state_stack[MAX_INCLUDE_DEPTH * 2];
|
|---|
| 548 | static int *state_stack_p = state_stack;
|
|---|
| 549 |
|
|---|
| 550 | void
|
|---|
| 551 | ldlex_script ()
|
|---|
| 552 | {
|
|---|
| 553 | *(state_stack_p)++ = yy_start;
|
|---|
| 554 | BEGIN (SCRIPT);
|
|---|
| 555 | }
|
|---|
| 556 |
|
|---|
| 557 | void
|
|---|
| 558 | ldlex_mri_script ()
|
|---|
| 559 | {
|
|---|
| 560 | *(state_stack_p)++ = yy_start;
|
|---|
| 561 | BEGIN (MRI);
|
|---|
| 562 | }
|
|---|
| 563 |
|
|---|
| 564 | void
|
|---|
| 565 | ldlex_version_script ()
|
|---|
| 566 | {
|
|---|
| 567 | *(state_stack_p)++ = yy_start;
|
|---|
| 568 | BEGIN (VERS_START);
|
|---|
| 569 | }
|
|---|
| 570 |
|
|---|
| 571 | void
|
|---|
| 572 | ldlex_version_file ()
|
|---|
| 573 | {
|
|---|
| 574 | *(state_stack_p)++ = yy_start;
|
|---|
| 575 | BEGIN (VERS_SCRIPT);
|
|---|
| 576 | }
|
|---|
| 577 |
|
|---|
| 578 | void
|
|---|
| 579 | ldlex_defsym ()
|
|---|
| 580 | {
|
|---|
| 581 | *(state_stack_p)++ = yy_start;
|
|---|
| 582 | BEGIN (DEFSYMEXP);
|
|---|
| 583 | }
|
|---|
| 584 |
|
|---|
| 585 | void
|
|---|
| 586 | ldlex_expression ()
|
|---|
| 587 | {
|
|---|
| 588 | *(state_stack_p)++ = yy_start;
|
|---|
| 589 | BEGIN (EXPRESSION);
|
|---|
| 590 | }
|
|---|
| 591 |
|
|---|
| 592 | void
|
|---|
| 593 | ldlex_both ()
|
|---|
| 594 | {
|
|---|
| 595 | *(state_stack_p)++ = yy_start;
|
|---|
| 596 | BEGIN (BOTH);
|
|---|
| 597 | }
|
|---|
| 598 |
|
|---|
| 599 | void
|
|---|
| 600 | ldlex_popstate ()
|
|---|
| 601 | {
|
|---|
| 602 | yy_start = *(--state_stack_p);
|
|---|
| 603 | }
|
|---|
| 604 | |
|---|
| 605 |
|
|---|
| 606 |
|
|---|
| 607 | /* Place up to MAX_SIZE characters in BUF and return in *RESULT
|
|---|
| 608 | either the number of characters read, or 0 to indicate EOF. */
|
|---|
| 609 |
|
|---|
| 610 | static void
|
|---|
| 611 | yy_input (buf, result, max_size)
|
|---|
| 612 | char *buf;
|
|---|
| 613 | int *result;
|
|---|
| 614 | int max_size;
|
|---|
| 615 | {
|
|---|
| 616 | *result = 0;
|
|---|
| 617 | if (YY_CURRENT_BUFFER->yy_input_file)
|
|---|
| 618 | {
|
|---|
| 619 | if (yyin)
|
|---|
| 620 | {
|
|---|
| 621 | *result = fread ((char *) buf, 1, max_size, yyin);
|
|---|
| 622 | if (*result < max_size && ferror (yyin))
|
|---|
| 623 | einfo ("%F%P: read in flex scanner failed\n");
|
|---|
| 624 | }
|
|---|
| 625 | }
|
|---|
| 626 | }
|
|---|
| 627 |
|
|---|
| 628 | /* Eat the rest of a C-style comment. */
|
|---|
| 629 |
|
|---|
| 630 | static void
|
|---|
| 631 | comment ()
|
|---|
| 632 | {
|
|---|
| 633 | int c;
|
|---|
| 634 |
|
|---|
| 635 | while (1)
|
|---|
| 636 | {
|
|---|
| 637 | c = input();
|
|---|
| 638 | while (c != '*' && c != EOF)
|
|---|
| 639 | {
|
|---|
| 640 | if (c == '\n')
|
|---|
| 641 | lineno++;
|
|---|
| 642 | c = input();
|
|---|
| 643 | }
|
|---|
| 644 |
|
|---|
| 645 | if (c == '*')
|
|---|
| 646 | {
|
|---|
| 647 | c = input();
|
|---|
| 648 | while (c == '*')
|
|---|
| 649 | c = input();
|
|---|
| 650 | if (c == '/')
|
|---|
| 651 | break; /* found the end */
|
|---|
| 652 | }
|
|---|
| 653 |
|
|---|
| 654 | if (c == '\n')
|
|---|
| 655 | lineno++;
|
|---|
| 656 |
|
|---|
| 657 | if (c == EOF)
|
|---|
| 658 | {
|
|---|
| 659 | einfo( "%F%P: EOF in comment\n");
|
|---|
| 660 | break;
|
|---|
| 661 | }
|
|---|
| 662 | }
|
|---|
| 663 | }
|
|---|
| 664 |
|
|---|
| 665 | /* Warn the user about a garbage character WHAT in the input
|
|---|
| 666 | in context WHERE. */
|
|---|
| 667 |
|
|---|
| 668 | static void
|
|---|
| 669 | lex_warn_invalid (where, what)
|
|---|
| 670 | char *where, *what;
|
|---|
| 671 | {
|
|---|
| 672 | char buf[5];
|
|---|
| 673 |
|
|---|
| 674 | /* If we have found an input file whose format we do not recognize,
|
|---|
| 675 | and we are therefore treating it as a linker script, and we find
|
|---|
| 676 | an invalid character, then most likely this is a real object file
|
|---|
| 677 | of some different format. Treat it as such. */
|
|---|
| 678 | if (ldfile_assumed_script)
|
|---|
| 679 | {
|
|---|
| 680 | bfd_set_error (bfd_error_file_not_recognized);
|
|---|
| 681 | einfo ("%F%s: file not recognized: %E\n", ldfile_input_filename);
|
|---|
| 682 | }
|
|---|
| 683 |
|
|---|
| 684 | if (! ISPRINT (*what))
|
|---|
| 685 | {
|
|---|
| 686 | sprintf (buf, "\\%03o", (unsigned int) *what);
|
|---|
| 687 | what = buf;
|
|---|
| 688 | }
|
|---|
| 689 |
|
|---|
| 690 | einfo ("%P:%S: ignoring invalid character `%s'%s\n", what, where);
|
|---|
| 691 | }
|
|---|