ldgram.y 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483
  1. /* A YACC grammar to parse a superset of the AT&T linker scripting language.
  2. Copyright (C) 1991-2015 Free Software Foundation, Inc.
  3. Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
  4. This file is part of the GNU Binutils.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. %{
  18. /*
  19. */
  20. #define DONTDECLARE_MALLOC
  21. #include "sysdep.h"
  22. #include "bfd.h"
  23. #include "bfdlink.h"
  24. #include "ld.h"
  25. #include "ldexp.h"
  26. #include "ldver.h"
  27. #include "ldlang.h"
  28. #include "ldfile.h"
  29. #include "ldemul.h"
  30. #include "ldmisc.h"
  31. #include "ldmain.h"
  32. #include "mri.h"
  33. #include "ldctor.h"
  34. #include "ldlex.h"
  35. #ifndef YYDEBUG
  36. #define YYDEBUG 1
  37. #endif
  38. static enum section_type sectype;
  39. static lang_memory_region_type *region;
  40. bfd_boolean ldgram_had_keep = FALSE;
  41. char *ldgram_vers_current_lang = NULL;
  42. #define ERROR_NAME_MAX 20
  43. static char *error_names[ERROR_NAME_MAX];
  44. static int error_index;
  45. #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
  46. #define POP_ERROR() error_index--;
  47. %}
  48. %union {
  49. bfd_vma integer;
  50. struct big_int
  51. {
  52. bfd_vma integer;
  53. char *str;
  54. } bigint;
  55. fill_type *fill;
  56. char *name;
  57. const char *cname;
  58. struct wildcard_spec wildcard;
  59. struct wildcard_list *wildcard_list;
  60. struct name_list *name_list;
  61. struct flag_info_list *flag_info_list;
  62. struct flag_info *flag_info;
  63. int token;
  64. union etree_union *etree;
  65. struct phdr_info
  66. {
  67. bfd_boolean filehdr;
  68. bfd_boolean phdrs;
  69. union etree_union *at;
  70. union etree_union *flags;
  71. } phdr;
  72. struct lang_nocrossref *nocrossref;
  73. struct lang_output_section_phdr_list *section_phdr;
  74. struct bfd_elf_version_deps *deflist;
  75. struct bfd_elf_version_expr *versyms;
  76. struct bfd_elf_version_tree *versnode;
  77. }
  78. %type <etree> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val
  79. %type <etree> opt_exp_without_type opt_subalign opt_align
  80. %type <fill> fill_opt fill_exp
  81. %type <name_list> exclude_name_list
  82. %type <wildcard_list> file_NAME_list
  83. %type <flag_info_list> sect_flag_list
  84. %type <flag_info> sect_flags
  85. %type <name> memspec_opt casesymlist
  86. %type <name> memspec_at_opt
  87. %type <cname> wildcard_name
  88. %type <wildcard> wildcard_spec
  89. %token <bigint> INT
  90. %token <name> NAME LNAME
  91. %type <integer> length
  92. %type <phdr> phdr_qualifiers
  93. %type <nocrossref> nocrossref_list
  94. %type <section_phdr> phdr_opt
  95. %type <integer> opt_nocrossrefs
  96. %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
  97. %right <token> '?' ':'
  98. %left <token> OROR
  99. %left <token> ANDAND
  100. %left <token> '|'
  101. %left <token> '^'
  102. %left <token> '&'
  103. %left <token> EQ NE
  104. %left <token> '<' '>' LE GE
  105. %left <token> LSHIFT RSHIFT
  106. %left <token> '+' '-'
  107. %left <token> '*' '/' '%'
  108. %right UNARY
  109. %token END
  110. %left <token> '('
  111. %token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
  112. %token SECTIONS PHDRS INSERT_K AFTER BEFORE
  113. %token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
  114. %token SORT_BY_NAME SORT_BY_ALIGNMENT SORT_NONE
  115. %token SORT_BY_INIT_PRIORITY
  116. %token '{' '}'
  117. %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
  118. %token INHIBIT_COMMON_ALLOCATION
  119. %token SEGMENT_START
  120. %token INCLUDE
  121. %token MEMORY
  122. %token REGION_ALIAS
  123. %token LD_FEATURE
  124. %token NOLOAD DSECT COPY INFO OVERLAY
  125. %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY
  126. %token <integer> NEXT
  127. %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K
  128. %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS
  129. %token ORIGIN FILL
  130. %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
  131. %token ALIGNMOD AT SUBALIGN HIDDEN PROVIDE PROVIDE_HIDDEN AS_NEEDED
  132. %type <token> assign_op atype attributes_opt sect_constraint opt_align_with_input
  133. %type <name> filename
  134. %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
  135. %token LOG2CEIL FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
  136. %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
  137. %token <name> VERS_TAG VERS_IDENTIFIER
  138. %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
  139. %token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL INPUT_SECTION_FLAGS ALIGN_WITH_INPUT
  140. %token EXCLUDE_FILE
  141. %token CONSTANT
  142. %type <versyms> vers_defns
  143. %type <versnode> vers_tag
  144. %type <deflist> verdep
  145. %token INPUT_DYNAMIC_LIST
  146. %%
  147. file:
  148. INPUT_SCRIPT script_file
  149. | INPUT_MRI_SCRIPT mri_script_file
  150. | INPUT_VERSION_SCRIPT version_script_file
  151. | INPUT_DYNAMIC_LIST dynamic_list_file
  152. | INPUT_DEFSYM defsym_expr
  153. ;
  154. filename: NAME;
  155. defsym_expr:
  156. { ldlex_defsym(); }
  157. NAME '=' exp
  158. {
  159. ldlex_popstate();
  160. lang_add_assignment (exp_defsym ($2, $4));
  161. }
  162. ;
  163. /* SYNTAX WITHIN AN MRI SCRIPT FILE */
  164. mri_script_file:
  165. {
  166. ldlex_mri_script ();
  167. PUSH_ERROR (_("MRI style script"));
  168. }
  169. mri_script_lines
  170. {
  171. ldlex_popstate ();
  172. mri_draw_tree ();
  173. POP_ERROR ();
  174. }
  175. ;
  176. mri_script_lines:
  177. mri_script_lines mri_script_command NEWLINE
  178. |
  179. ;
  180. mri_script_command:
  181. CHIP exp
  182. | CHIP exp ',' exp
  183. | NAME {
  184. einfo(_("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1);
  185. }
  186. | LIST {
  187. config.map_filename = "-";
  188. }
  189. | ORDER ordernamelist
  190. | ENDWORD
  191. | PUBLIC NAME '=' exp
  192. { mri_public($2, $4); }
  193. | PUBLIC NAME ',' exp
  194. { mri_public($2, $4); }
  195. | PUBLIC NAME exp
  196. { mri_public($2, $3); }
  197. | FORMAT NAME
  198. { mri_format($2); }
  199. | SECT NAME ',' exp
  200. { mri_output_section($2, $4);}
  201. | SECT NAME exp
  202. { mri_output_section($2, $3);}
  203. | SECT NAME '=' exp
  204. { mri_output_section($2, $4);}
  205. | ALIGN_K NAME '=' exp
  206. { mri_align($2,$4); }
  207. | ALIGN_K NAME ',' exp
  208. { mri_align($2,$4); }
  209. | ALIGNMOD NAME '=' exp
  210. { mri_alignmod($2,$4); }
  211. | ALIGNMOD NAME ',' exp
  212. { mri_alignmod($2,$4); }
  213. | ABSOLUTE mri_abs_name_list
  214. | LOAD mri_load_name_list
  215. | NAMEWORD NAME
  216. { mri_name($2); }
  217. | ALIAS NAME ',' NAME
  218. { mri_alias($2,$4,0);}
  219. | ALIAS NAME ',' INT
  220. { mri_alias ($2, 0, (int) $4.integer); }
  221. | BASE exp
  222. { mri_base($2); }
  223. | TRUNCATE INT
  224. { mri_truncate ((unsigned int) $2.integer); }
  225. | CASE casesymlist
  226. | EXTERN extern_name_list
  227. | INCLUDE filename
  228. { ldlex_script (); ldfile_open_command_file($2); }
  229. mri_script_lines END
  230. { ldlex_popstate (); }
  231. | START NAME
  232. { lang_add_entry ($2, FALSE); }
  233. |
  234. ;
  235. ordernamelist:
  236. ordernamelist ',' NAME { mri_order($3); }
  237. | ordernamelist NAME { mri_order($2); }
  238. |
  239. ;
  240. mri_load_name_list:
  241. NAME
  242. { mri_load($1); }
  243. | mri_load_name_list ',' NAME { mri_load($3); }
  244. ;
  245. mri_abs_name_list:
  246. NAME
  247. { mri_only_load($1); }
  248. | mri_abs_name_list ',' NAME
  249. { mri_only_load($3); }
  250. ;
  251. casesymlist:
  252. /* empty */ { $$ = NULL; }
  253. | NAME
  254. | casesymlist ',' NAME
  255. ;
  256. /* Parsed as expressions so that commas separate entries */
  257. extern_name_list:
  258. { ldlex_expression (); }
  259. extern_name_list_body
  260. { ldlex_popstate (); }
  261. extern_name_list_body:
  262. NAME
  263. { ldlang_add_undef ($1, FALSE); }
  264. | extern_name_list_body NAME
  265. { ldlang_add_undef ($2, FALSE); }
  266. | extern_name_list_body ',' NAME
  267. { ldlang_add_undef ($3, FALSE); }
  268. ;
  269. script_file:
  270. { ldlex_both(); }
  271. ifile_list
  272. { ldlex_popstate(); }
  273. ;
  274. ifile_list:
  275. ifile_list ifile_p1
  276. |
  277. ;
  278. ifile_p1:
  279. memory
  280. | sections
  281. | phdrs
  282. | startup
  283. | high_level_library
  284. | low_level_library
  285. | floating_point_support
  286. | statement_anywhere
  287. | version
  288. | ';'
  289. | TARGET_K '(' NAME ')'
  290. { lang_add_target($3); }
  291. | SEARCH_DIR '(' filename ')'
  292. { ldfile_add_library_path ($3, FALSE); }
  293. | OUTPUT '(' filename ')'
  294. { lang_add_output($3, 1); }
  295. | OUTPUT_FORMAT '(' NAME ')'
  296. { lang_add_output_format ($3, (char *) NULL,
  297. (char *) NULL, 1); }
  298. | OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')'
  299. { lang_add_output_format ($3, $5, $7, 1); }
  300. | OUTPUT_ARCH '(' NAME ')'
  301. { ldfile_set_output_arch ($3, bfd_arch_unknown); }
  302. | FORCE_COMMON_ALLOCATION
  303. { command_line.force_common_definition = TRUE ; }
  304. | INHIBIT_COMMON_ALLOCATION
  305. { command_line.inhibit_common_definition = TRUE ; }
  306. | INPUT '(' input_list ')'
  307. | GROUP
  308. { lang_enter_group (); }
  309. '(' input_list ')'
  310. { lang_leave_group (); }
  311. | MAP '(' filename ')'
  312. { lang_add_map($3); }
  313. | INCLUDE filename
  314. { ldlex_script (); ldfile_open_command_file($2); }
  315. ifile_list END
  316. { ldlex_popstate (); }
  317. | NOCROSSREFS '(' nocrossref_list ')'
  318. {
  319. lang_add_nocrossref ($3);
  320. }
  321. | EXTERN '(' extern_name_list ')'
  322. | INSERT_K AFTER NAME
  323. { lang_add_insert ($3, 0); }
  324. | INSERT_K BEFORE NAME
  325. { lang_add_insert ($3, 1); }
  326. | REGION_ALIAS '(' NAME ',' NAME ')'
  327. { lang_memory_region_alias ($3, $5); }
  328. | LD_FEATURE '(' NAME ')'
  329. { lang_ld_feature ($3); }
  330. ;
  331. input_list:
  332. { ldlex_inputlist(); }
  333. input_list1
  334. { ldlex_popstate(); }
  335. input_list1:
  336. NAME
  337. { lang_add_input_file($1,lang_input_file_is_search_file_enum,
  338. (char *)NULL); }
  339. | input_list1 ',' NAME
  340. { lang_add_input_file($3,lang_input_file_is_search_file_enum,
  341. (char *)NULL); }
  342. | input_list1 NAME
  343. { lang_add_input_file($2,lang_input_file_is_search_file_enum,
  344. (char *)NULL); }
  345. | LNAME
  346. { lang_add_input_file($1,lang_input_file_is_l_enum,
  347. (char *)NULL); }
  348. | input_list1 ',' LNAME
  349. { lang_add_input_file($3,lang_input_file_is_l_enum,
  350. (char *)NULL); }
  351. | input_list1 LNAME
  352. { lang_add_input_file($2,lang_input_file_is_l_enum,
  353. (char *)NULL); }
  354. | AS_NEEDED '('
  355. { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
  356. input_flags.add_DT_NEEDED_for_regular = TRUE; }
  357. input_list1 ')'
  358. { input_flags.add_DT_NEEDED_for_regular = $<integer>3; }
  359. | input_list1 ',' AS_NEEDED '('
  360. { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
  361. input_flags.add_DT_NEEDED_for_regular = TRUE; }
  362. input_list1 ')'
  363. { input_flags.add_DT_NEEDED_for_regular = $<integer>5; }
  364. | input_list1 AS_NEEDED '('
  365. { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
  366. input_flags.add_DT_NEEDED_for_regular = TRUE; }
  367. input_list1 ')'
  368. { input_flags.add_DT_NEEDED_for_regular = $<integer>4; }
  369. ;
  370. sections:
  371. SECTIONS '{' sec_or_group_p1 '}'
  372. ;
  373. sec_or_group_p1:
  374. sec_or_group_p1 section
  375. | sec_or_group_p1 statement_anywhere
  376. |
  377. ;
  378. statement_anywhere:
  379. ENTRY '(' NAME ')'
  380. { lang_add_entry ($3, FALSE); }
  381. | assignment end
  382. | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')'
  383. { ldlex_popstate ();
  384. lang_add_assignment (exp_assert ($4, $6)); }
  385. ;
  386. /* The '*' and '?' cases are there because the lexer returns them as
  387. separate tokens rather than as NAME. */
  388. wildcard_name:
  389. NAME
  390. {
  391. $$ = $1;
  392. }
  393. | '*'
  394. {
  395. $$ = "*";
  396. }
  397. | '?'
  398. {
  399. $$ = "?";
  400. }
  401. ;
  402. wildcard_spec:
  403. wildcard_name
  404. {
  405. $$.name = $1;
  406. $$.sorted = none;
  407. $$.exclude_name_list = NULL;
  408. $$.section_flag_list = NULL;
  409. }
  410. | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
  411. {
  412. $$.name = $5;
  413. $$.sorted = none;
  414. $$.exclude_name_list = $3;
  415. $$.section_flag_list = NULL;
  416. }
  417. | SORT_BY_NAME '(' wildcard_name ')'
  418. {
  419. $$.name = $3;
  420. $$.sorted = by_name;
  421. $$.exclude_name_list = NULL;
  422. $$.section_flag_list = NULL;
  423. }
  424. | SORT_BY_ALIGNMENT '(' wildcard_name ')'
  425. {
  426. $$.name = $3;
  427. $$.sorted = by_alignment;
  428. $$.exclude_name_list = NULL;
  429. $$.section_flag_list = NULL;
  430. }
  431. | SORT_NONE '(' wildcard_name ')'
  432. {
  433. $$.name = $3;
  434. $$.sorted = by_none;
  435. $$.exclude_name_list = NULL;
  436. $$.section_flag_list = NULL;
  437. }
  438. | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
  439. {
  440. $$.name = $5;
  441. $$.sorted = by_name_alignment;
  442. $$.exclude_name_list = NULL;
  443. $$.section_flag_list = NULL;
  444. }
  445. | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_name ')' ')'
  446. {
  447. $$.name = $5;
  448. $$.sorted = by_name;
  449. $$.exclude_name_list = NULL;
  450. $$.section_flag_list = NULL;
  451. }
  452. | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_name ')' ')'
  453. {
  454. $$.name = $5;
  455. $$.sorted = by_alignment_name;
  456. $$.exclude_name_list = NULL;
  457. $$.section_flag_list = NULL;
  458. }
  459. | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
  460. {
  461. $$.name = $5;
  462. $$.sorted = by_alignment;
  463. $$.exclude_name_list = NULL;
  464. $$.section_flag_list = NULL;
  465. }
  466. | SORT_BY_NAME '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')'
  467. {
  468. $$.name = $7;
  469. $$.sorted = by_name;
  470. $$.exclude_name_list = $5;
  471. $$.section_flag_list = NULL;
  472. }
  473. | SORT_BY_INIT_PRIORITY '(' wildcard_name ')'
  474. {
  475. $$.name = $3;
  476. $$.sorted = by_init_priority;
  477. $$.exclude_name_list = NULL;
  478. $$.section_flag_list = NULL;
  479. }
  480. ;
  481. sect_flag_list: NAME
  482. {
  483. struct flag_info_list *n;
  484. n = ((struct flag_info_list *) xmalloc (sizeof *n));
  485. if ($1[0] == '!')
  486. {
  487. n->with = without_flags;
  488. n->name = &$1[1];
  489. }
  490. else
  491. {
  492. n->with = with_flags;
  493. n->name = $1;
  494. }
  495. n->valid = FALSE;
  496. n->next = NULL;
  497. $$ = n;
  498. }
  499. | sect_flag_list '&' NAME
  500. {
  501. struct flag_info_list *n;
  502. n = ((struct flag_info_list *) xmalloc (sizeof *n));
  503. if ($3[0] == '!')
  504. {
  505. n->with = without_flags;
  506. n->name = &$3[1];
  507. }
  508. else
  509. {
  510. n->with = with_flags;
  511. n->name = $3;
  512. }
  513. n->valid = FALSE;
  514. n->next = $1;
  515. $$ = n;
  516. }
  517. ;
  518. sect_flags:
  519. INPUT_SECTION_FLAGS '(' sect_flag_list ')'
  520. {
  521. struct flag_info *n;
  522. n = ((struct flag_info *) xmalloc (sizeof *n));
  523. n->flag_list = $3;
  524. n->flags_initialized = FALSE;
  525. n->not_with_flags = 0;
  526. n->only_with_flags = 0;
  527. $$ = n;
  528. }
  529. ;
  530. exclude_name_list:
  531. exclude_name_list wildcard_name
  532. {
  533. struct name_list *tmp;
  534. tmp = (struct name_list *) xmalloc (sizeof *tmp);
  535. tmp->name = $2;
  536. tmp->next = $1;
  537. $$ = tmp;
  538. }
  539. |
  540. wildcard_name
  541. {
  542. struct name_list *tmp;
  543. tmp = (struct name_list *) xmalloc (sizeof *tmp);
  544. tmp->name = $1;
  545. tmp->next = NULL;
  546. $$ = tmp;
  547. }
  548. ;
  549. file_NAME_list:
  550. file_NAME_list opt_comma wildcard_spec
  551. {
  552. struct wildcard_list *tmp;
  553. tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
  554. tmp->next = $1;
  555. tmp->spec = $3;
  556. $$ = tmp;
  557. }
  558. |
  559. wildcard_spec
  560. {
  561. struct wildcard_list *tmp;
  562. tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
  563. tmp->next = NULL;
  564. tmp->spec = $1;
  565. $$ = tmp;
  566. }
  567. ;
  568. input_section_spec_no_keep:
  569. NAME
  570. {
  571. struct wildcard_spec tmp;
  572. tmp.name = $1;
  573. tmp.exclude_name_list = NULL;
  574. tmp.sorted = none;
  575. tmp.section_flag_list = NULL;
  576. lang_add_wild (&tmp, NULL, ldgram_had_keep);
  577. }
  578. | sect_flags NAME
  579. {
  580. struct wildcard_spec tmp;
  581. tmp.name = $2;
  582. tmp.exclude_name_list = NULL;
  583. tmp.sorted = none;
  584. tmp.section_flag_list = $1;
  585. lang_add_wild (&tmp, NULL, ldgram_had_keep);
  586. }
  587. | '[' file_NAME_list ']'
  588. {
  589. lang_add_wild (NULL, $2, ldgram_had_keep);
  590. }
  591. | sect_flags '[' file_NAME_list ']'
  592. {
  593. struct wildcard_spec tmp;
  594. tmp.name = NULL;
  595. tmp.exclude_name_list = NULL;
  596. tmp.sorted = none;
  597. tmp.section_flag_list = $1;
  598. lang_add_wild (&tmp, $3, ldgram_had_keep);
  599. }
  600. | wildcard_spec '(' file_NAME_list ')'
  601. {
  602. lang_add_wild (&$1, $3, ldgram_had_keep);
  603. }
  604. | sect_flags wildcard_spec '(' file_NAME_list ')'
  605. {
  606. $2.section_flag_list = $1;
  607. lang_add_wild (&$2, $4, ldgram_had_keep);
  608. }
  609. ;
  610. input_section_spec:
  611. input_section_spec_no_keep
  612. | KEEP '('
  613. { ldgram_had_keep = TRUE; }
  614. input_section_spec_no_keep ')'
  615. { ldgram_had_keep = FALSE; }
  616. ;
  617. statement:
  618. assignment end
  619. | CREATE_OBJECT_SYMBOLS
  620. {
  621. lang_add_attribute(lang_object_symbols_statement_enum);
  622. }
  623. | ';'
  624. | CONSTRUCTORS
  625. {
  626. lang_add_attribute(lang_constructors_statement_enum);
  627. }
  628. | SORT_BY_NAME '(' CONSTRUCTORS ')'
  629. {
  630. constructors_sorted = TRUE;
  631. lang_add_attribute (lang_constructors_statement_enum);
  632. }
  633. | input_section_spec
  634. | length '(' mustbe_exp ')'
  635. {
  636. lang_add_data ((int) $1, $3);
  637. }
  638. | FILL '(' fill_exp ')'
  639. {
  640. lang_add_fill ($3);
  641. }
  642. | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')' end
  643. { ldlex_popstate ();
  644. lang_add_assignment (exp_assert ($4, $6)); }
  645. | INCLUDE filename
  646. { ldlex_script (); ldfile_open_command_file($2); }
  647. statement_list_opt END
  648. { ldlex_popstate (); }
  649. ;
  650. statement_list:
  651. statement_list statement
  652. | statement
  653. ;
  654. statement_list_opt:
  655. /* empty */
  656. | statement_list
  657. ;
  658. length:
  659. QUAD
  660. { $$ = $1; }
  661. | SQUAD
  662. { $$ = $1; }
  663. | LONG
  664. { $$ = $1; }
  665. | SHORT
  666. { $$ = $1; }
  667. | BYTE
  668. { $$ = $1; }
  669. ;
  670. fill_exp:
  671. mustbe_exp
  672. {
  673. $$ = exp_get_fill ($1, 0, "fill value");
  674. }
  675. ;
  676. fill_opt:
  677. '=' fill_exp
  678. { $$ = $2; }
  679. | { $$ = (fill_type *) 0; }
  680. ;
  681. assign_op:
  682. PLUSEQ
  683. { $$ = '+'; }
  684. | MINUSEQ
  685. { $$ = '-'; }
  686. | MULTEQ
  687. { $$ = '*'; }
  688. | DIVEQ
  689. { $$ = '/'; }
  690. | LSHIFTEQ
  691. { $$ = LSHIFT; }
  692. | RSHIFTEQ
  693. { $$ = RSHIFT; }
  694. | ANDEQ
  695. { $$ = '&'; }
  696. | OREQ
  697. { $$ = '|'; }
  698. ;
  699. end: ';' | ','
  700. ;
  701. assignment:
  702. NAME '=' mustbe_exp
  703. {
  704. lang_add_assignment (exp_assign ($1, $3, FALSE));
  705. }
  706. | NAME assign_op mustbe_exp
  707. {
  708. lang_add_assignment (exp_assign ($1,
  709. exp_binop ($2,
  710. exp_nameop (NAME,
  711. $1),
  712. $3), FALSE));
  713. }
  714. | HIDDEN '(' NAME '=' mustbe_exp ')'
  715. {
  716. lang_add_assignment (exp_assign ($3, $5, TRUE));
  717. }
  718. | PROVIDE '(' NAME '=' mustbe_exp ')'
  719. {
  720. lang_add_assignment (exp_provide ($3, $5, FALSE));
  721. }
  722. | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')'
  723. {
  724. lang_add_assignment (exp_provide ($3, $5, TRUE));
  725. }
  726. ;
  727. opt_comma:
  728. ',' | ;
  729. memory:
  730. MEMORY '{' memory_spec_list_opt '}'
  731. ;
  732. memory_spec_list_opt: memory_spec_list | ;
  733. memory_spec_list:
  734. memory_spec_list opt_comma memory_spec
  735. | memory_spec
  736. ;
  737. memory_spec: NAME
  738. { region = lang_memory_region_lookup ($1, TRUE); }
  739. attributes_opt ':'
  740. origin_spec opt_comma length_spec
  741. {}
  742. | INCLUDE filename
  743. { ldlex_script (); ldfile_open_command_file($2); }
  744. memory_spec_list_opt END
  745. { ldlex_popstate (); }
  746. ;
  747. origin_spec:
  748. ORIGIN '=' mustbe_exp
  749. {
  750. region->origin_exp = $3;
  751. region->current = region->origin;
  752. }
  753. ;
  754. length_spec:
  755. LENGTH '=' mustbe_exp
  756. {
  757. region->length_exp = $3;
  758. }
  759. ;
  760. attributes_opt:
  761. /* empty */
  762. { /* dummy action to avoid bison 1.25 error message */ }
  763. | '(' attributes_list ')'
  764. ;
  765. attributes_list:
  766. attributes_string
  767. | attributes_list attributes_string
  768. ;
  769. attributes_string:
  770. NAME
  771. { lang_set_flags (region, $1, 0); }
  772. | '!' NAME
  773. { lang_set_flags (region, $2, 1); }
  774. ;
  775. startup:
  776. STARTUP '(' filename ')'
  777. { lang_startup($3); }
  778. ;
  779. high_level_library:
  780. HLL '(' high_level_library_NAME_list ')'
  781. | HLL '(' ')'
  782. { ldemul_hll((char *)NULL); }
  783. ;
  784. high_level_library_NAME_list:
  785. high_level_library_NAME_list opt_comma filename
  786. { ldemul_hll($3); }
  787. | filename
  788. { ldemul_hll($1); }
  789. ;
  790. low_level_library:
  791. SYSLIB '(' low_level_library_NAME_list ')'
  792. ; low_level_library_NAME_list:
  793. low_level_library_NAME_list opt_comma filename
  794. { ldemul_syslib($3); }
  795. |
  796. ;
  797. floating_point_support:
  798. FLOAT
  799. { lang_float(TRUE); }
  800. | NOFLOAT
  801. { lang_float(FALSE); }
  802. ;
  803. nocrossref_list:
  804. /* empty */
  805. {
  806. $$ = NULL;
  807. }
  808. | NAME nocrossref_list
  809. {
  810. struct lang_nocrossref *n;
  811. n = (struct lang_nocrossref *) xmalloc (sizeof *n);
  812. n->name = $1;
  813. n->next = $2;
  814. $$ = n;
  815. }
  816. | NAME ',' nocrossref_list
  817. {
  818. struct lang_nocrossref *n;
  819. n = (struct lang_nocrossref *) xmalloc (sizeof *n);
  820. n->name = $1;
  821. n->next = $3;
  822. $$ = n;
  823. }
  824. ;
  825. mustbe_exp: { ldlex_expression (); }
  826. exp
  827. { ldlex_popstate (); $$=$2;}
  828. ;
  829. exp :
  830. '-' exp %prec UNARY
  831. { $$ = exp_unop ('-', $2); }
  832. | '(' exp ')'
  833. { $$ = $2; }
  834. | NEXT '(' exp ')' %prec UNARY
  835. { $$ = exp_unop ((int) $1,$3); }
  836. | '!' exp %prec UNARY
  837. { $$ = exp_unop ('!', $2); }
  838. | '+' exp %prec UNARY
  839. { $$ = $2; }
  840. | '~' exp %prec UNARY
  841. { $$ = exp_unop ('~', $2);}
  842. | exp '*' exp
  843. { $$ = exp_binop ('*', $1, $3); }
  844. | exp '/' exp
  845. { $$ = exp_binop ('/', $1, $3); }
  846. | exp '%' exp
  847. { $$ = exp_binop ('%', $1, $3); }
  848. | exp '+' exp
  849. { $$ = exp_binop ('+', $1, $3); }
  850. | exp '-' exp
  851. { $$ = exp_binop ('-' , $1, $3); }
  852. | exp LSHIFT exp
  853. { $$ = exp_binop (LSHIFT , $1, $3); }
  854. | exp RSHIFT exp
  855. { $$ = exp_binop (RSHIFT , $1, $3); }
  856. | exp EQ exp
  857. { $$ = exp_binop (EQ , $1, $3); }
  858. | exp NE exp
  859. { $$ = exp_binop (NE , $1, $3); }
  860. | exp LE exp
  861. { $$ = exp_binop (LE , $1, $3); }
  862. | exp GE exp
  863. { $$ = exp_binop (GE , $1, $3); }
  864. | exp '<' exp
  865. { $$ = exp_binop ('<' , $1, $3); }
  866. | exp '>' exp
  867. { $$ = exp_binop ('>' , $1, $3); }
  868. | exp '&' exp
  869. { $$ = exp_binop ('&' , $1, $3); }
  870. | exp '^' exp
  871. { $$ = exp_binop ('^' , $1, $3); }
  872. | exp '|' exp
  873. { $$ = exp_binop ('|' , $1, $3); }
  874. | exp '?' exp ':' exp
  875. { $$ = exp_trinop ('?' , $1, $3, $5); }
  876. | exp ANDAND exp
  877. { $$ = exp_binop (ANDAND , $1, $3); }
  878. | exp OROR exp
  879. { $$ = exp_binop (OROR , $1, $3); }
  880. | DEFINED '(' NAME ')'
  881. { $$ = exp_nameop (DEFINED, $3); }
  882. | INT
  883. { $$ = exp_bigintop ($1.integer, $1.str); }
  884. | SIZEOF_HEADERS
  885. { $$ = exp_nameop (SIZEOF_HEADERS,0); }
  886. | ALIGNOF '(' NAME ')'
  887. { $$ = exp_nameop (ALIGNOF,$3); }
  888. | SIZEOF '(' NAME ')'
  889. { $$ = exp_nameop (SIZEOF,$3); }
  890. | ADDR '(' NAME ')'
  891. { $$ = exp_nameop (ADDR,$3); }
  892. | LOADADDR '(' NAME ')'
  893. { $$ = exp_nameop (LOADADDR,$3); }
  894. | CONSTANT '(' NAME ')'
  895. { $$ = exp_nameop (CONSTANT,$3); }
  896. | ABSOLUTE '(' exp ')'
  897. { $$ = exp_unop (ABSOLUTE, $3); }
  898. | ALIGN_K '(' exp ')'
  899. { $$ = exp_unop (ALIGN_K,$3); }
  900. | ALIGN_K '(' exp ',' exp ')'
  901. { $$ = exp_binop (ALIGN_K,$3,$5); }
  902. | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
  903. { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); }
  904. | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
  905. { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
  906. | DATA_SEGMENT_END '(' exp ')'
  907. { $$ = exp_unop (DATA_SEGMENT_END, $3); }
  908. | SEGMENT_START '(' NAME ',' exp ')'
  909. { /* The operands to the expression node are
  910. placed in the opposite order from the way
  911. in which they appear in the script as
  912. that allows us to reuse more code in
  913. fold_binary. */
  914. $$ = exp_binop (SEGMENT_START,
  915. $5,
  916. exp_nameop (NAME, $3)); }
  917. | BLOCK '(' exp ')'
  918. { $$ = exp_unop (ALIGN_K,$3); }
  919. | NAME
  920. { $$ = exp_nameop (NAME,$1); }
  921. | MAX_K '(' exp ',' exp ')'
  922. { $$ = exp_binop (MAX_K, $3, $5 ); }
  923. | MIN_K '(' exp ',' exp ')'
  924. { $$ = exp_binop (MIN_K, $3, $5 ); }
  925. | ASSERT_K '(' exp ',' NAME ')'
  926. { $$ = exp_assert ($3, $5); }
  927. | ORIGIN '(' NAME ')'
  928. { $$ = exp_nameop (ORIGIN, $3); }
  929. | LENGTH '(' NAME ')'
  930. { $$ = exp_nameop (LENGTH, $3); }
  931. | LOG2CEIL '(' exp ')'
  932. { $$ = exp_unop (LOG2CEIL, $3); }
  933. ;
  934. memspec_at_opt:
  935. AT '>' NAME { $$ = $3; }
  936. | { $$ = 0; }
  937. ;
  938. opt_at:
  939. AT '(' exp ')' { $$ = $3; }
  940. | { $$ = 0; }
  941. ;
  942. opt_align:
  943. ALIGN_K '(' exp ')' { $$ = $3; }
  944. | { $$ = 0; }
  945. ;
  946. opt_align_with_input:
  947. ALIGN_WITH_INPUT { $$ = ALIGN_WITH_INPUT; }
  948. | { $$ = 0; }
  949. ;
  950. opt_subalign:
  951. SUBALIGN '(' exp ')' { $$ = $3; }
  952. | { $$ = 0; }
  953. ;
  954. sect_constraint:
  955. ONLY_IF_RO { $$ = ONLY_IF_RO; }
  956. | ONLY_IF_RW { $$ = ONLY_IF_RW; }
  957. | SPECIAL { $$ = SPECIAL; }
  958. | { $$ = 0; }
  959. ;
  960. section: NAME { ldlex_expression(); }
  961. opt_exp_with_type
  962. opt_at
  963. opt_align
  964. opt_align_with_input
  965. opt_subalign { ldlex_popstate (); ldlex_script (); }
  966. sect_constraint
  967. '{'
  968. {
  969. lang_enter_output_section_statement($1, $3,
  970. sectype,
  971. $5, $7, $4, $9, $6);
  972. }
  973. statement_list_opt
  974. '}' { ldlex_popstate (); ldlex_expression (); }
  975. memspec_opt memspec_at_opt phdr_opt fill_opt
  976. {
  977. ldlex_popstate ();
  978. lang_leave_output_section_statement ($18, $15, $17, $16);
  979. }
  980. opt_comma
  981. {}
  982. | OVERLAY
  983. { ldlex_expression (); }
  984. opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
  985. { ldlex_popstate (); ldlex_script (); }
  986. '{'
  987. {
  988. lang_enter_overlay ($3, $6);
  989. }
  990. overlay_section
  991. '}'
  992. { ldlex_popstate (); ldlex_expression (); }
  993. memspec_opt memspec_at_opt phdr_opt fill_opt
  994. {
  995. ldlex_popstate ();
  996. lang_leave_overlay ($5, (int) $4,
  997. $16, $13, $15, $14);
  998. }
  999. opt_comma
  1000. | /* The GROUP case is just enough to support the gcc
  1001. svr3.ifile script. It is not intended to be full
  1002. support. I'm not even sure what GROUP is supposed
  1003. to mean. */
  1004. GROUP { ldlex_expression (); }
  1005. opt_exp_with_type
  1006. {
  1007. ldlex_popstate ();
  1008. lang_add_assignment (exp_assign (".", $3, FALSE));
  1009. }
  1010. '{' sec_or_group_p1 '}'
  1011. | INCLUDE filename
  1012. { ldlex_script (); ldfile_open_command_file($2); }
  1013. sec_or_group_p1 END
  1014. { ldlex_popstate (); }
  1015. ;
  1016. type:
  1017. NOLOAD { sectype = noload_section; }
  1018. | DSECT { sectype = noalloc_section; }
  1019. | COPY { sectype = noalloc_section; }
  1020. | INFO { sectype = noalloc_section; }
  1021. | OVERLAY { sectype = noalloc_section; }
  1022. ;
  1023. atype:
  1024. '(' type ')'
  1025. | /* EMPTY */ { sectype = normal_section; }
  1026. | '(' ')' { sectype = normal_section; }
  1027. ;
  1028. opt_exp_with_type:
  1029. exp atype ':' { $$ = $1; }
  1030. | atype ':' { $$ = (etree_type *)NULL; }
  1031. | /* The BIND cases are to support the gcc svr3.ifile
  1032. script. They aren't intended to implement full
  1033. support for the BIND keyword. I'm not even sure
  1034. what BIND is supposed to mean. */
  1035. BIND '(' exp ')' atype ':' { $$ = $3; }
  1036. | BIND '(' exp ')' BLOCK '(' exp ')' atype ':'
  1037. { $$ = $3; }
  1038. ;
  1039. opt_exp_without_type:
  1040. exp ':' { $$ = $1; }
  1041. | ':' { $$ = (etree_type *) NULL; }
  1042. ;
  1043. opt_nocrossrefs:
  1044. /* empty */
  1045. { $$ = 0; }
  1046. | NOCROSSREFS
  1047. { $$ = 1; }
  1048. ;
  1049. memspec_opt:
  1050. '>' NAME
  1051. { $$ = $2; }
  1052. | { $$ = DEFAULT_MEMORY_REGION; }
  1053. ;
  1054. phdr_opt:
  1055. /* empty */
  1056. {
  1057. $$ = NULL;
  1058. }
  1059. | phdr_opt ':' NAME
  1060. {
  1061. struct lang_output_section_phdr_list *n;
  1062. n = ((struct lang_output_section_phdr_list *)
  1063. xmalloc (sizeof *n));
  1064. n->name = $3;
  1065. n->used = FALSE;
  1066. n->next = $1;
  1067. $$ = n;
  1068. }
  1069. ;
  1070. overlay_section:
  1071. /* empty */
  1072. | overlay_section
  1073. NAME
  1074. {
  1075. ldlex_script ();
  1076. lang_enter_overlay_section ($2);
  1077. }
  1078. '{' statement_list_opt '}'
  1079. { ldlex_popstate (); ldlex_expression (); }
  1080. phdr_opt fill_opt
  1081. {
  1082. ldlex_popstate ();
  1083. lang_leave_overlay_section ($9, $8);
  1084. }
  1085. opt_comma
  1086. ;
  1087. phdrs:
  1088. PHDRS '{' phdr_list '}'
  1089. ;
  1090. phdr_list:
  1091. /* empty */
  1092. | phdr_list phdr
  1093. ;
  1094. phdr:
  1095. NAME { ldlex_expression (); }
  1096. phdr_type phdr_qualifiers { ldlex_popstate (); }
  1097. ';'
  1098. {
  1099. lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at,
  1100. $4.flags);
  1101. }
  1102. ;
  1103. phdr_type:
  1104. exp
  1105. {
  1106. $$ = $1;
  1107. if ($1->type.node_class == etree_name
  1108. && $1->type.node_code == NAME)
  1109. {
  1110. const char *s;
  1111. unsigned int i;
  1112. static const char * const phdr_types[] =
  1113. {
  1114. "PT_NULL", "PT_LOAD", "PT_DYNAMIC",
  1115. "PT_INTERP", "PT_NOTE", "PT_SHLIB",
  1116. "PT_PHDR", "PT_TLS"
  1117. };
  1118. s = $1->name.name;
  1119. for (i = 0;
  1120. i < sizeof phdr_types / sizeof phdr_types[0];
  1121. i++)
  1122. if (strcmp (s, phdr_types[i]) == 0)
  1123. {
  1124. $$ = exp_intop (i);
  1125. break;
  1126. }
  1127. if (i == sizeof phdr_types / sizeof phdr_types[0])
  1128. {
  1129. if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
  1130. $$ = exp_intop (0x6474e550);
  1131. else if (strcmp (s, "PT_GNU_STACK") == 0)
  1132. $$ = exp_intop (0x6474e551);
  1133. else
  1134. {
  1135. einfo (_("\
  1136. %X%P:%S: unknown phdr type `%s' (try integer literal)\n"),
  1137. NULL, s);
  1138. $$ = exp_intop (0);
  1139. }
  1140. }
  1141. }
  1142. }
  1143. ;
  1144. phdr_qualifiers:
  1145. /* empty */
  1146. {
  1147. memset (&$$, 0, sizeof (struct phdr_info));
  1148. }
  1149. | NAME phdr_val phdr_qualifiers
  1150. {
  1151. $$ = $3;
  1152. if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL)
  1153. $$.filehdr = TRUE;
  1154. else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL)
  1155. $$.phdrs = TRUE;
  1156. else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
  1157. $$.flags = $2;
  1158. else
  1159. einfo (_("%X%P:%S: PHDRS syntax error at `%s'\n"),
  1160. NULL, $1);
  1161. }
  1162. | AT '(' exp ')' phdr_qualifiers
  1163. {
  1164. $$ = $5;
  1165. $$.at = $3;
  1166. }
  1167. ;
  1168. phdr_val:
  1169. /* empty */
  1170. {
  1171. $$ = NULL;
  1172. }
  1173. | '(' exp ')'
  1174. {
  1175. $$ = $2;
  1176. }
  1177. ;
  1178. dynamic_list_file:
  1179. {
  1180. ldlex_version_file ();
  1181. PUSH_ERROR (_("dynamic list"));
  1182. }
  1183. dynamic_list_nodes
  1184. {
  1185. ldlex_popstate ();
  1186. POP_ERROR ();
  1187. }
  1188. ;
  1189. dynamic_list_nodes:
  1190. dynamic_list_node
  1191. | dynamic_list_nodes dynamic_list_node
  1192. ;
  1193. dynamic_list_node:
  1194. '{' dynamic_list_tag '}' ';'
  1195. ;
  1196. dynamic_list_tag:
  1197. vers_defns ';'
  1198. {
  1199. lang_append_dynamic_list ($1);
  1200. }
  1201. ;
  1202. /* This syntax is used within an external version script file. */
  1203. version_script_file:
  1204. {
  1205. ldlex_version_file ();
  1206. PUSH_ERROR (_("VERSION script"));
  1207. }
  1208. vers_nodes
  1209. {
  1210. ldlex_popstate ();
  1211. POP_ERROR ();
  1212. }
  1213. ;
  1214. /* This is used within a normal linker script file. */
  1215. version:
  1216. {
  1217. ldlex_version_script ();
  1218. }
  1219. VERSIONK '{' vers_nodes '}'
  1220. {
  1221. ldlex_popstate ();
  1222. }
  1223. ;
  1224. vers_nodes:
  1225. vers_node
  1226. | vers_nodes vers_node
  1227. ;
  1228. vers_node:
  1229. '{' vers_tag '}' ';'
  1230. {
  1231. lang_register_vers_node (NULL, $2, NULL);
  1232. }
  1233. | VERS_TAG '{' vers_tag '}' ';'
  1234. {
  1235. lang_register_vers_node ($1, $3, NULL);
  1236. }
  1237. | VERS_TAG '{' vers_tag '}' verdep ';'
  1238. {
  1239. lang_register_vers_node ($1, $3, $5);
  1240. }
  1241. ;
  1242. verdep:
  1243. VERS_TAG
  1244. {
  1245. $$ = lang_add_vers_depend (NULL, $1);
  1246. }
  1247. | verdep VERS_TAG
  1248. {
  1249. $$ = lang_add_vers_depend ($1, $2);
  1250. }
  1251. ;
  1252. vers_tag:
  1253. /* empty */
  1254. {
  1255. $$ = lang_new_vers_node (NULL, NULL);
  1256. }
  1257. | vers_defns ';'
  1258. {
  1259. $$ = lang_new_vers_node ($1, NULL);
  1260. }
  1261. | GLOBAL ':' vers_defns ';'
  1262. {
  1263. $$ = lang_new_vers_node ($3, NULL);
  1264. }
  1265. | LOCAL ':' vers_defns ';'
  1266. {
  1267. $$ = lang_new_vers_node (NULL, $3);
  1268. }
  1269. | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
  1270. {
  1271. $$ = lang_new_vers_node ($3, $7);
  1272. }
  1273. ;
  1274. vers_defns:
  1275. VERS_IDENTIFIER
  1276. {
  1277. $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, FALSE);
  1278. }
  1279. | NAME
  1280. {
  1281. $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, TRUE);
  1282. }
  1283. | vers_defns ';' VERS_IDENTIFIER
  1284. {
  1285. $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, FALSE);
  1286. }
  1287. | vers_defns ';' NAME
  1288. {
  1289. $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, TRUE);
  1290. }
  1291. | vers_defns ';' EXTERN NAME '{'
  1292. {
  1293. $<name>$ = ldgram_vers_current_lang;
  1294. ldgram_vers_current_lang = $4;
  1295. }
  1296. vers_defns opt_semicolon '}'
  1297. {
  1298. struct bfd_elf_version_expr *pat;
  1299. for (pat = $7; pat->next != NULL; pat = pat->next);
  1300. pat->next = $1;
  1301. $$ = $7;
  1302. ldgram_vers_current_lang = $<name>6;
  1303. }
  1304. | EXTERN NAME '{'
  1305. {
  1306. $<name>$ = ldgram_vers_current_lang;
  1307. ldgram_vers_current_lang = $2;
  1308. }
  1309. vers_defns opt_semicolon '}'
  1310. {
  1311. $$ = $5;
  1312. ldgram_vers_current_lang = $<name>4;
  1313. }
  1314. | GLOBAL
  1315. {
  1316. $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, FALSE);
  1317. }
  1318. | vers_defns ';' GLOBAL
  1319. {
  1320. $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, FALSE);
  1321. }
  1322. | LOCAL
  1323. {
  1324. $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, FALSE);
  1325. }
  1326. | vers_defns ';' LOCAL
  1327. {
  1328. $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, FALSE);
  1329. }
  1330. | EXTERN
  1331. {
  1332. $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, FALSE);
  1333. }
  1334. | vers_defns ';' EXTERN
  1335. {
  1336. $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, FALSE);
  1337. }
  1338. ;
  1339. opt_semicolon:
  1340. /* empty */
  1341. | ';'
  1342. ;
  1343. %%
  1344. void
  1345. yyerror(arg)
  1346. const char *arg;
  1347. {
  1348. if (ldfile_assumed_script)
  1349. einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
  1350. ldlex_filename ());
  1351. if (error_index > 0 && error_index < ERROR_NAME_MAX)
  1352. einfo ("%P%F:%S: %s in %s\n", NULL, arg, error_names[error_index - 1]);
  1353. else
  1354. einfo ("%P%F:%S: %s\n", NULL, arg);
  1355. }