ldlex.l 22 KB

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