symtab.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022
  1. /* Symbol table.
  2. Copyright (C) 2012-2015 Free Software Foundation, Inc.
  3. Contributed by Jan Hubicka
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #include "config.h"
  17. #include "system.h"
  18. #include "coretypes.h"
  19. #include "tm.h"
  20. #include "rtl.h"
  21. #include "hash-set.h"
  22. #include "machmode.h"
  23. #include "vec.h"
  24. #include "double-int.h"
  25. #include "input.h"
  26. #include "alias.h"
  27. #include "symtab.h"
  28. #include "wide-int.h"
  29. #include "inchash.h"
  30. #include "tree.h"
  31. #include "fold-const.h"
  32. #include "print-tree.h"
  33. #include "varasm.h"
  34. #include "hashtab.h"
  35. #include "hard-reg-set.h"
  36. #include "input.h"
  37. #include "function.h"
  38. #include "emit-rtl.h"
  39. #include "predict.h"
  40. #include "basic-block.h"
  41. #include "tree-ssa-alias.h"
  42. #include "internal-fn.h"
  43. #include "gimple-expr.h"
  44. #include "is-a.h"
  45. #include "gimple.h"
  46. #include "tree-inline.h"
  47. #include "langhooks.h"
  48. #include "hash-map.h"
  49. #include "plugin-api.h"
  50. #include "ipa-ref.h"
  51. #include "cgraph.h"
  52. #include "diagnostic.h"
  53. #include "timevar.h"
  54. #include "lto-streamer.h"
  55. #include "output.h"
  56. #include "ipa-utils.h"
  57. #include "calls.h"
  58. static const char *ipa_ref_use_name[] = {"read","write","addr","alias","chkp"};
  59. const char * const ld_plugin_symbol_resolution_names[]=
  60. {
  61. "",
  62. "undef",
  63. "prevailing_def",
  64. "prevailing_def_ironly",
  65. "preempted_reg",
  66. "preempted_ir",
  67. "resolved_ir",
  68. "resolved_exec",
  69. "resolved_dyn",
  70. "prevailing_def_ironly_exp"
  71. };
  72. /* Hash asmnames ignoring the user specified marks. */
  73. hashval_t
  74. symbol_table::decl_assembler_name_hash (const_tree asmname)
  75. {
  76. if (IDENTIFIER_POINTER (asmname)[0] == '*')
  77. {
  78. const char *decl_str = IDENTIFIER_POINTER (asmname) + 1;
  79. size_t ulp_len = strlen (user_label_prefix);
  80. if (ulp_len == 0)
  81. ;
  82. else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
  83. decl_str += ulp_len;
  84. return htab_hash_string (decl_str);
  85. }
  86. return htab_hash_string (IDENTIFIER_POINTER (asmname));
  87. }
  88. /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
  89. bool
  90. symbol_table::decl_assembler_name_equal (tree decl, const_tree asmname)
  91. {
  92. tree decl_asmname = DECL_ASSEMBLER_NAME (decl);
  93. const char *decl_str;
  94. const char *asmname_str;
  95. bool test = false;
  96. if (decl_asmname == asmname)
  97. return true;
  98. decl_str = IDENTIFIER_POINTER (decl_asmname);
  99. asmname_str = IDENTIFIER_POINTER (asmname);
  100. /* If the target assembler name was set by the user, things are trickier.
  101. We have a leading '*' to begin with. After that, it's arguable what
  102. is the correct thing to do with -fleading-underscore. Arguably, we've
  103. historically been doing the wrong thing in assemble_alias by always
  104. printing the leading underscore. Since we're not changing that, make
  105. sure user_label_prefix follows the '*' before matching. */
  106. if (decl_str[0] == '*')
  107. {
  108. size_t ulp_len = strlen (user_label_prefix);
  109. decl_str ++;
  110. if (ulp_len == 0)
  111. test = true;
  112. else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
  113. decl_str += ulp_len, test=true;
  114. else
  115. decl_str --;
  116. }
  117. if (asmname_str[0] == '*')
  118. {
  119. size_t ulp_len = strlen (user_label_prefix);
  120. asmname_str ++;
  121. if (ulp_len == 0)
  122. test = true;
  123. else if (strncmp (asmname_str, user_label_prefix, ulp_len) == 0)
  124. asmname_str += ulp_len, test=true;
  125. else
  126. asmname_str --;
  127. }
  128. if (!test)
  129. return false;
  130. return strcmp (decl_str, asmname_str) == 0;
  131. }
  132. /* Returns nonzero if P1 and P2 are equal. */
  133. /* Insert NODE to assembler name hash. */
  134. void
  135. symbol_table::insert_to_assembler_name_hash (symtab_node *node,
  136. bool with_clones)
  137. {
  138. if (is_a <varpool_node *> (node) && DECL_HARD_REGISTER (node->decl))
  139. return;
  140. gcc_checking_assert (!node->previous_sharing_asm_name
  141. && !node->next_sharing_asm_name);
  142. if (assembler_name_hash)
  143. {
  144. symtab_node **aslot;
  145. cgraph_node *cnode;
  146. tree decl = node->decl;
  147. tree name = DECL_ASSEMBLER_NAME (node->decl);
  148. /* C++ FE can produce decls without associated assembler name and insert
  149. them to symtab to hold section or TLS information. */
  150. if (!name)
  151. return;
  152. hashval_t hash = decl_assembler_name_hash (name);
  153. aslot = assembler_name_hash->find_slot_with_hash (name, hash, INSERT);
  154. gcc_assert (*aslot != node);
  155. node->next_sharing_asm_name = (symtab_node *)*aslot;
  156. if (*aslot != NULL)
  157. (*aslot)->previous_sharing_asm_name = node;
  158. *aslot = node;
  159. /* Update also possible inline clones sharing a decl. */
  160. cnode = dyn_cast <cgraph_node *> (node);
  161. if (cnode && cnode->clones && with_clones)
  162. for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
  163. if (cnode->decl == decl)
  164. insert_to_assembler_name_hash (cnode, true);
  165. }
  166. }
  167. /* Remove NODE from assembler name hash. */
  168. void
  169. symbol_table::unlink_from_assembler_name_hash (symtab_node *node,
  170. bool with_clones)
  171. {
  172. if (assembler_name_hash)
  173. {
  174. cgraph_node *cnode;
  175. tree decl = node->decl;
  176. if (node->next_sharing_asm_name)
  177. node->next_sharing_asm_name->previous_sharing_asm_name
  178. = node->previous_sharing_asm_name;
  179. if (node->previous_sharing_asm_name)
  180. {
  181. node->previous_sharing_asm_name->next_sharing_asm_name
  182. = node->next_sharing_asm_name;
  183. }
  184. else
  185. {
  186. tree name = DECL_ASSEMBLER_NAME (node->decl);
  187. symtab_node **slot;
  188. if (!name)
  189. return;
  190. hashval_t hash = decl_assembler_name_hash (name);
  191. slot = assembler_name_hash->find_slot_with_hash (name, hash,
  192. NO_INSERT);
  193. gcc_assert (*slot == node);
  194. if (!node->next_sharing_asm_name)
  195. assembler_name_hash->clear_slot (slot);
  196. else
  197. *slot = node->next_sharing_asm_name;
  198. }
  199. node->next_sharing_asm_name = NULL;
  200. node->previous_sharing_asm_name = NULL;
  201. /* Update also possible inline clones sharing a decl. */
  202. cnode = dyn_cast <cgraph_node *> (node);
  203. if (cnode && cnode->clones && with_clones)
  204. for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
  205. if (cnode->decl == decl)
  206. unlink_from_assembler_name_hash (cnode, true);
  207. }
  208. }
  209. /* Arrange node to be first in its entry of assembler_name_hash. */
  210. void
  211. symbol_table::symtab_prevail_in_asm_name_hash (symtab_node *node)
  212. {
  213. unlink_from_assembler_name_hash (node, false);
  214. insert_to_assembler_name_hash (node, false);
  215. }
  216. /* Initalize asm name hash unless. */
  217. void
  218. symbol_table::symtab_initialize_asm_name_hash (void)
  219. {
  220. symtab_node *node;
  221. if (!assembler_name_hash)
  222. {
  223. assembler_name_hash = hash_table<asmname_hasher>::create_ggc (10);
  224. FOR_EACH_SYMBOL (node)
  225. insert_to_assembler_name_hash (node, false);
  226. }
  227. }
  228. /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
  229. void
  230. symbol_table::change_decl_assembler_name (tree decl, tree name)
  231. {
  232. symtab_node *node = NULL;
  233. /* We can have user ASM names on things, like global register variables, that
  234. are not in the symbol table. */
  235. if ((TREE_CODE (decl) == VAR_DECL
  236. && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
  237. || TREE_CODE (decl) == FUNCTION_DECL)
  238. node = symtab_node::get (decl);
  239. if (!DECL_ASSEMBLER_NAME_SET_P (decl))
  240. {
  241. SET_DECL_ASSEMBLER_NAME (decl, name);
  242. if (node)
  243. insert_to_assembler_name_hash (node, true);
  244. }
  245. else
  246. {
  247. if (name == DECL_ASSEMBLER_NAME (decl))
  248. return;
  249. tree alias = (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl))
  250. ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl))
  251. : NULL);
  252. if (node)
  253. unlink_from_assembler_name_hash (node, true);
  254. if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
  255. && DECL_RTL_SET_P (decl))
  256. warning (0, "%D renamed after being referenced in assembly", decl);
  257. SET_DECL_ASSEMBLER_NAME (decl, name);
  258. if (alias)
  259. {
  260. IDENTIFIER_TRANSPARENT_ALIAS (name) = 1;
  261. TREE_CHAIN (name) = alias;
  262. }
  263. if (node)
  264. insert_to_assembler_name_hash (node, true);
  265. }
  266. }
  267. /* Hash sections by their names. */
  268. hashval_t
  269. section_name_hasher::hash (section_hash_entry *n)
  270. {
  271. return htab_hash_string (n->name);
  272. }
  273. /* Return true if section P1 name equals to P2. */
  274. bool
  275. section_name_hasher::equal (section_hash_entry *n1, const char *name)
  276. {
  277. return n1->name == name || !strcmp (n1->name, name);
  278. }
  279. /* Add node into symbol table. This function is not used directly, but via
  280. cgraph/varpool node creation routines. */
  281. void
  282. symtab_node::register_symbol (void)
  283. {
  284. symtab->register_symbol (this);
  285. if (!decl->decl_with_vis.symtab_node)
  286. decl->decl_with_vis.symtab_node = this;
  287. ref_list.clear ();
  288. /* Be sure to do this last; C++ FE might create new nodes via
  289. DECL_ASSEMBLER_NAME langhook! */
  290. symtab->insert_to_assembler_name_hash (this, false);
  291. }
  292. /* Remove NODE from same comdat group. */
  293. void
  294. symtab_node::remove_from_same_comdat_group (void)
  295. {
  296. if (same_comdat_group)
  297. {
  298. symtab_node *prev;
  299. for (prev = same_comdat_group;
  300. prev->same_comdat_group != this;
  301. prev = prev->same_comdat_group)
  302. ;
  303. if (same_comdat_group == prev)
  304. prev->same_comdat_group = NULL;
  305. else
  306. prev->same_comdat_group = same_comdat_group;
  307. same_comdat_group = NULL;
  308. set_comdat_group (NULL);
  309. }
  310. }
  311. /* Remove node from symbol table. This function is not used directly, but via
  312. cgraph/varpool node removal routines. */
  313. void
  314. symtab_node::unregister (void)
  315. {
  316. remove_all_references ();
  317. remove_all_referring ();
  318. /* Remove reference to section. */
  319. set_section_for_node (NULL);
  320. remove_from_same_comdat_group ();
  321. symtab->unregister (this);
  322. /* During LTO symtab merging we temporarily corrupt decl to symtab node
  323. hash. */
  324. gcc_assert (decl->decl_with_vis.symtab_node || in_lto_p);
  325. if (decl->decl_with_vis.symtab_node == this)
  326. {
  327. symtab_node *replacement_node = NULL;
  328. if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
  329. replacement_node = cnode->find_replacement ();
  330. decl->decl_with_vis.symtab_node = replacement_node;
  331. }
  332. if (!is_a <varpool_node *> (this) || !DECL_HARD_REGISTER (decl))
  333. symtab->unlink_from_assembler_name_hash (this, false);
  334. if (in_init_priority_hash)
  335. symtab->init_priority_hash->remove (this);
  336. }
  337. /* Remove symbol from symbol table. */
  338. void
  339. symtab_node::remove (void)
  340. {
  341. if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
  342. cnode->remove ();
  343. else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
  344. vnode->remove ();
  345. }
  346. /* Add NEW_ to the same comdat group that OLD is in. */
  347. void
  348. symtab_node::add_to_same_comdat_group (symtab_node *old_node)
  349. {
  350. gcc_assert (old_node->get_comdat_group ());
  351. gcc_assert (!same_comdat_group);
  352. gcc_assert (this != old_node);
  353. set_comdat_group (old_node->get_comdat_group ());
  354. same_comdat_group = old_node;
  355. if (!old_node->same_comdat_group)
  356. old_node->same_comdat_group = this;
  357. else
  358. {
  359. symtab_node *n;
  360. for (n = old_node->same_comdat_group;
  361. n->same_comdat_group != old_node;
  362. n = n->same_comdat_group)
  363. ;
  364. n->same_comdat_group = this;
  365. }
  366. }
  367. /* Dissolve the same_comdat_group list in which NODE resides. */
  368. void
  369. symtab_node::dissolve_same_comdat_group_list (void)
  370. {
  371. symtab_node *n = this;
  372. symtab_node *next;
  373. if (!same_comdat_group)
  374. return;
  375. do
  376. {
  377. next = n->same_comdat_group;
  378. n->same_comdat_group = NULL;
  379. /* Clear comdat_group for comdat locals, since
  380. make_decl_local doesn't. */
  381. if (!TREE_PUBLIC (n->decl))
  382. n->set_comdat_group (NULL);
  383. n = next;
  384. }
  385. while (n != this);
  386. }
  387. /* Return printable assembler name of NODE.
  388. This function is used only for debugging. When assembler name
  389. is unknown go with identifier name. */
  390. const char *
  391. symtab_node::asm_name () const
  392. {
  393. if (!DECL_ASSEMBLER_NAME_SET_P (decl))
  394. return lang_hooks.decl_printable_name (decl, 2);
  395. return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
  396. }
  397. /* Return printable identifier name. */
  398. const char *
  399. symtab_node::name () const
  400. {
  401. return lang_hooks.decl_printable_name (decl, 2);
  402. }
  403. /* Return ipa reference from this symtab_node to
  404. REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
  405. of the use. */
  406. ipa_ref *
  407. symtab_node::create_reference (symtab_node *referred_node,
  408. enum ipa_ref_use use_type)
  409. {
  410. return create_reference (referred_node, use_type, NULL);
  411. }
  412. /* Return ipa reference from this symtab_node to
  413. REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
  414. of the use and STMT the statement (if it exists). */
  415. ipa_ref *
  416. symtab_node::create_reference (symtab_node *referred_node,
  417. enum ipa_ref_use use_type, gimple stmt)
  418. {
  419. ipa_ref *ref = NULL, *ref2 = NULL;
  420. ipa_ref_list *list, *list2;
  421. ipa_ref_t *old_references;
  422. gcc_checking_assert (!stmt || is_a <cgraph_node *> (this));
  423. gcc_checking_assert (use_type != IPA_REF_ALIAS || !stmt);
  424. list = &ref_list;
  425. old_references = vec_safe_address (list->references);
  426. vec_safe_grow (list->references, vec_safe_length (list->references) + 1);
  427. ref = &list->references->last ();
  428. list2 = &referred_node->ref_list;
  429. /* IPA_REF_ALIAS is always inserted at the beginning of the list. */
  430. if(use_type == IPA_REF_ALIAS)
  431. {
  432. list2->referring.safe_insert (0, ref);
  433. ref->referred_index = 0;
  434. for (unsigned int i = 1; i < list2->referring.length (); i++)
  435. list2->referring[i]->referred_index = i;
  436. }
  437. else
  438. {
  439. list2->referring.safe_push (ref);
  440. ref->referred_index = list2->referring.length () - 1;
  441. }
  442. ref->referring = this;
  443. ref->referred = referred_node;
  444. ref->stmt = stmt;
  445. ref->lto_stmt_uid = 0;
  446. ref->use = use_type;
  447. ref->speculative = 0;
  448. /* If vector was moved in memory, update pointers. */
  449. if (old_references != list->references->address ())
  450. {
  451. int i;
  452. for (i = 0; iterate_reference(i, ref2); i++)
  453. ref2->referred_ref_list ()->referring[ref2->referred_index] = ref2;
  454. }
  455. return ref;
  456. }
  457. /* If VAL is a reference to a function or a variable, add a reference from
  458. this symtab_node to the corresponding symbol table node. USE_TYPE specify
  459. type of the use and STMT the statement (if it exists). Return the new
  460. reference or NULL if none was created. */
  461. ipa_ref *
  462. symtab_node::maybe_create_reference (tree val, enum ipa_ref_use use_type,
  463. gimple stmt)
  464. {
  465. STRIP_NOPS (val);
  466. if (TREE_CODE (val) != ADDR_EXPR)
  467. return NULL;
  468. val = get_base_var (val);
  469. if (val && (TREE_CODE (val) == FUNCTION_DECL
  470. || TREE_CODE (val) == VAR_DECL))
  471. {
  472. symtab_node *referred = symtab_node::get (val);
  473. gcc_checking_assert (referred);
  474. return create_reference (referred, use_type, stmt);
  475. }
  476. return NULL;
  477. }
  478. /* Clone all references from symtab NODE to this symtab_node. */
  479. void
  480. symtab_node::clone_references (symtab_node *node)
  481. {
  482. ipa_ref *ref = NULL, *ref2 = NULL;
  483. int i;
  484. for (i = 0; node->iterate_reference (i, ref); i++)
  485. {
  486. bool speculative = ref->speculative;
  487. unsigned int stmt_uid = ref->lto_stmt_uid;
  488. ref2 = create_reference (ref->referred, ref->use, ref->stmt);
  489. ref2->speculative = speculative;
  490. ref2->lto_stmt_uid = stmt_uid;
  491. }
  492. }
  493. /* Clone all referring from symtab NODE to this symtab_node. */
  494. void
  495. symtab_node::clone_referring (symtab_node *node)
  496. {
  497. ipa_ref *ref = NULL, *ref2 = NULL;
  498. int i;
  499. for (i = 0; node->iterate_referring(i, ref); i++)
  500. {
  501. bool speculative = ref->speculative;
  502. unsigned int stmt_uid = ref->lto_stmt_uid;
  503. ref2 = ref->referring->create_reference (this, ref->use, ref->stmt);
  504. ref2->speculative = speculative;
  505. ref2->lto_stmt_uid = stmt_uid;
  506. }
  507. }
  508. /* Clone reference REF to this symtab_node and set its stmt to STMT. */
  509. ipa_ref *
  510. symtab_node::clone_reference (ipa_ref *ref, gimple stmt)
  511. {
  512. bool speculative = ref->speculative;
  513. unsigned int stmt_uid = ref->lto_stmt_uid;
  514. ipa_ref *ref2;
  515. ref2 = create_reference (ref->referred, ref->use, stmt);
  516. ref2->speculative = speculative;
  517. ref2->lto_stmt_uid = stmt_uid;
  518. return ref2;
  519. }
  520. /* Find the structure describing a reference to REFERRED_NODE
  521. and associated with statement STMT. */
  522. ipa_ref *
  523. symtab_node::find_reference (symtab_node *referred_node,
  524. gimple stmt, unsigned int lto_stmt_uid)
  525. {
  526. ipa_ref *r = NULL;
  527. int i;
  528. for (i = 0; iterate_reference (i, r); i++)
  529. if (r->referred == referred_node
  530. && !r->speculative
  531. && ((stmt && r->stmt == stmt)
  532. || (lto_stmt_uid && r->lto_stmt_uid == lto_stmt_uid)
  533. || (!stmt && !lto_stmt_uid && !r->stmt && !r->lto_stmt_uid)))
  534. return r;
  535. return NULL;
  536. }
  537. /* Remove all references that are associated with statement STMT. */
  538. void
  539. symtab_node::remove_stmt_references (gimple stmt)
  540. {
  541. ipa_ref *r = NULL;
  542. int i = 0;
  543. while (iterate_reference (i, r))
  544. if (r->stmt == stmt)
  545. r->remove_reference ();
  546. else
  547. i++;
  548. }
  549. /* Remove all stmt references in non-speculative references.
  550. Those are not maintained during inlining & clonning.
  551. The exception are speculative references that are updated along
  552. with callgraph edges associated with them. */
  553. void
  554. symtab_node::clear_stmts_in_references (void)
  555. {
  556. ipa_ref *r = NULL;
  557. int i;
  558. for (i = 0; iterate_reference (i, r); i++)
  559. if (!r->speculative)
  560. {
  561. r->stmt = NULL;
  562. r->lto_stmt_uid = 0;
  563. }
  564. }
  565. /* Remove all references in ref list. */
  566. void
  567. symtab_node::remove_all_references (void)
  568. {
  569. while (vec_safe_length (ref_list.references))
  570. ref_list.references->last ().remove_reference ();
  571. vec_free (ref_list.references);
  572. }
  573. /* Remove all referring items in ref list. */
  574. void
  575. symtab_node::remove_all_referring (void)
  576. {
  577. while (ref_list.referring.length ())
  578. ref_list.referring.last ()->remove_reference ();
  579. ref_list.referring.release ();
  580. }
  581. /* Dump references in ref list to FILE. */
  582. void
  583. symtab_node::dump_references (FILE *file)
  584. {
  585. ipa_ref *ref = NULL;
  586. int i;
  587. for (i = 0; iterate_reference (i, ref); i++)
  588. {
  589. fprintf (file, "%s/%i (%s)",
  590. ref->referred->asm_name (),
  591. ref->referred->order,
  592. ipa_ref_use_name [ref->use]);
  593. if (ref->speculative)
  594. fprintf (file, " (speculative)");
  595. }
  596. fprintf (file, "\n");
  597. }
  598. /* Dump referring in list to FILE. */
  599. void
  600. symtab_node::dump_referring (FILE *file)
  601. {
  602. ipa_ref *ref = NULL;
  603. int i;
  604. for (i = 0; iterate_referring(i, ref); i++)
  605. {
  606. fprintf (file, "%s/%i (%s)",
  607. ref->referring->asm_name (),
  608. ref->referring->order,
  609. ipa_ref_use_name [ref->use]);
  610. if (ref->speculative)
  611. fprintf (file, " (speculative)");
  612. }
  613. fprintf (file, "\n");
  614. }
  615. static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
  616. /* Dump base fields of symtab nodes to F. Not to be used directly. */
  617. void
  618. symtab_node::dump_base (FILE *f)
  619. {
  620. static const char * const visibility_types[] = {
  621. "default", "protected", "hidden", "internal"
  622. };
  623. fprintf (f, "%s/%i (%s)", asm_name (), order, name ());
  624. dump_addr (f, " @", (void *)this);
  625. fprintf (f, "\n Type: %s", symtab_type_names[type]);
  626. if (definition)
  627. fprintf (f, " definition");
  628. if (analyzed)
  629. fprintf (f, " analyzed");
  630. if (alias)
  631. fprintf (f, " alias");
  632. if (weakref)
  633. fprintf (f, " weakref");
  634. if (cpp_implicit_alias)
  635. fprintf (f, " cpp_implicit_alias");
  636. if (alias_target)
  637. fprintf (f, " target:%s",
  638. DECL_P (alias_target)
  639. ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
  640. (alias_target))
  641. : IDENTIFIER_POINTER (alias_target));
  642. if (body_removed)
  643. fprintf (f, "\n Body removed by symtab_remove_unreachable_nodes");
  644. fprintf (f, "\n Visibility:");
  645. if (in_other_partition)
  646. fprintf (f, " in_other_partition");
  647. if (used_from_other_partition)
  648. fprintf (f, " used_from_other_partition");
  649. if (force_output)
  650. fprintf (f, " force_output");
  651. if (forced_by_abi)
  652. fprintf (f, " forced_by_abi");
  653. if (externally_visible)
  654. fprintf (f, " externally_visible");
  655. if (no_reorder)
  656. fprintf (f, " no_reorder");
  657. if (resolution != LDPR_UNKNOWN)
  658. fprintf (f, " %s",
  659. ld_plugin_symbol_resolution_names[(int)resolution]);
  660. if (TREE_ASM_WRITTEN (decl))
  661. fprintf (f, " asm_written");
  662. if (DECL_EXTERNAL (decl))
  663. fprintf (f, " external");
  664. if (TREE_PUBLIC (decl))
  665. fprintf (f, " public");
  666. if (DECL_COMMON (decl))
  667. fprintf (f, " common");
  668. if (DECL_WEAK (decl))
  669. fprintf (f, " weak");
  670. if (DECL_DLLIMPORT_P (decl))
  671. fprintf (f, " dll_import");
  672. if (DECL_COMDAT (decl))
  673. fprintf (f, " comdat");
  674. if (get_comdat_group ())
  675. fprintf (f, " comdat_group:%s",
  676. IDENTIFIER_POINTER (get_comdat_group_id ()));
  677. if (DECL_ONE_ONLY (decl))
  678. fprintf (f, " one_only");
  679. if (get_section ())
  680. fprintf (f, " section:%s",
  681. get_section ());
  682. if (implicit_section)
  683. fprintf (f," (implicit_section)");
  684. if (DECL_VISIBILITY_SPECIFIED (decl))
  685. fprintf (f, " visibility_specified");
  686. if (DECL_VISIBILITY (decl))
  687. fprintf (f, " visibility:%s",
  688. visibility_types [DECL_VISIBILITY (decl)]);
  689. if (DECL_VIRTUAL_P (decl))
  690. fprintf (f, " virtual");
  691. if (DECL_ARTIFICIAL (decl))
  692. fprintf (f, " artificial");
  693. if (TREE_CODE (decl) == FUNCTION_DECL)
  694. {
  695. if (DECL_STATIC_CONSTRUCTOR (decl))
  696. fprintf (f, " constructor");
  697. if (DECL_STATIC_DESTRUCTOR (decl))
  698. fprintf (f, " destructor");
  699. }
  700. fprintf (f, "\n");
  701. if (same_comdat_group)
  702. fprintf (f, " Same comdat group as: %s/%i\n",
  703. same_comdat_group->asm_name (),
  704. same_comdat_group->order);
  705. if (next_sharing_asm_name)
  706. fprintf (f, " next sharing asm name: %i\n",
  707. next_sharing_asm_name->order);
  708. if (previous_sharing_asm_name)
  709. fprintf (f, " previous sharing asm name: %i\n",
  710. previous_sharing_asm_name->order);
  711. if (address_taken)
  712. fprintf (f, " Address is taken.\n");
  713. if (aux)
  714. {
  715. fprintf (f, " Aux:");
  716. dump_addr (f, " @", (void *)aux);
  717. }
  718. fprintf (f, " References: ");
  719. dump_references (f);
  720. fprintf (f, " Referring: ");
  721. dump_referring (f);
  722. if (lto_file_data)
  723. fprintf (f, " Read from file: %s\n",
  724. lto_file_data->file_name);
  725. }
  726. /* Dump symtab node to F. */
  727. void
  728. symtab_node::dump (FILE *f)
  729. {
  730. if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
  731. cnode->dump (f);
  732. else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
  733. vnode->dump (f);
  734. }
  735. /* Dump symbol table to F. */
  736. void
  737. symtab_node::dump_table (FILE *f)
  738. {
  739. symtab_node *node;
  740. fprintf (f, "Symbol table:\n\n");
  741. FOR_EACH_SYMBOL (node)
  742. node->dump (f);
  743. }
  744. /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
  745. Return NULL if there's no such node. */
  746. symtab_node *
  747. symtab_node::get_for_asmname (const_tree asmname)
  748. {
  749. symtab_node *node;
  750. symtab->symtab_initialize_asm_name_hash ();
  751. hashval_t hash = symtab->decl_assembler_name_hash (asmname);
  752. symtab_node **slot
  753. = symtab->assembler_name_hash->find_slot_with_hash (asmname, hash,
  754. NO_INSERT);
  755. if (slot)
  756. {
  757. node = *slot;
  758. return node;
  759. }
  760. return NULL;
  761. }
  762. /* Dump symtab node NODE to stderr. */
  763. DEBUG_FUNCTION void
  764. symtab_node::debug (void)
  765. {
  766. dump (stderr);
  767. }
  768. /* Verify common part of symtab nodes. */
  769. DEBUG_FUNCTION bool
  770. symtab_node::verify_base (void)
  771. {
  772. bool error_found = false;
  773. symtab_node *hashed_node;
  774. if (is_a <cgraph_node *> (this))
  775. {
  776. if (TREE_CODE (decl) != FUNCTION_DECL)
  777. {
  778. error ("function symbol is not function");
  779. error_found = true;
  780. }
  781. }
  782. else if (is_a <varpool_node *> (this))
  783. {
  784. if (TREE_CODE (decl) != VAR_DECL)
  785. {
  786. error ("variable symbol is not variable");
  787. error_found = true;
  788. }
  789. }
  790. else
  791. {
  792. error ("node has unknown type");
  793. error_found = true;
  794. }
  795. if (symtab->state != LTO_STREAMING)
  796. {
  797. hashed_node = symtab_node::get (decl);
  798. if (!hashed_node)
  799. {
  800. error ("node not found node->decl->decl_with_vis.symtab_node");
  801. error_found = true;
  802. }
  803. if (hashed_node != this
  804. && (!is_a <cgraph_node *> (this)
  805. || !dyn_cast <cgraph_node *> (this)->clone_of
  806. || dyn_cast <cgraph_node *> (this)->clone_of->decl != decl))
  807. {
  808. error ("node differs from node->decl->decl_with_vis.symtab_node");
  809. error_found = true;
  810. }
  811. }
  812. if (symtab->assembler_name_hash)
  813. {
  814. hashed_node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl));
  815. if (hashed_node && hashed_node->previous_sharing_asm_name)
  816. {
  817. error ("assembler name hash list corrupted");
  818. error_found = true;
  819. }
  820. while (hashed_node)
  821. {
  822. if (hashed_node == this)
  823. break;
  824. hashed_node = hashed_node->next_sharing_asm_name;
  825. }
  826. if (!hashed_node
  827. && !(is_a <varpool_node *> (this)
  828. || DECL_HARD_REGISTER (decl)))
  829. {
  830. error ("node not found in symtab assembler name hash");
  831. error_found = true;
  832. }
  833. }
  834. if (previous_sharing_asm_name
  835. && previous_sharing_asm_name->next_sharing_asm_name != this)
  836. {
  837. error ("double linked list of assembler names corrupted");
  838. error_found = true;
  839. }
  840. if (body_removed && definition)
  841. {
  842. error ("node has body_removed but is definition");
  843. error_found = true;
  844. }
  845. if (analyzed && !definition)
  846. {
  847. error ("node is analyzed byt it is not a definition");
  848. error_found = true;
  849. }
  850. if (cpp_implicit_alias && !alias)
  851. {
  852. error ("node is alias but not implicit alias");
  853. error_found = true;
  854. }
  855. if (alias && !definition && !weakref)
  856. {
  857. error ("node is alias but not definition");
  858. error_found = true;
  859. }
  860. if (weakref && !alias)
  861. {
  862. error ("node is weakref but not an alias");
  863. error_found = true;
  864. }
  865. if (same_comdat_group)
  866. {
  867. symtab_node *n = same_comdat_group;
  868. if (!n->get_comdat_group ())
  869. {
  870. error ("node is in same_comdat_group list but has no comdat_group");
  871. error_found = true;
  872. }
  873. if (n->get_comdat_group () != get_comdat_group ())
  874. {
  875. error ("same_comdat_group list across different groups");
  876. error_found = true;
  877. }
  878. if (n->type != type)
  879. {
  880. error ("mixing different types of symbol in same comdat groups is not supported");
  881. error_found = true;
  882. }
  883. if (n == this)
  884. {
  885. error ("node is alone in a comdat group");
  886. error_found = true;
  887. }
  888. do
  889. {
  890. if (!n->same_comdat_group)
  891. {
  892. error ("same_comdat_group is not a circular list");
  893. error_found = true;
  894. break;
  895. }
  896. n = n->same_comdat_group;
  897. }
  898. while (n != this);
  899. if (comdat_local_p ())
  900. {
  901. ipa_ref *ref = NULL;
  902. for (int i = 0; iterate_referring (i, ref); ++i)
  903. {
  904. if (!in_same_comdat_group_p (ref->referring))
  905. {
  906. error ("comdat-local symbol referred to by %s outside its "
  907. "comdat",
  908. identifier_to_locale (ref->referring->name()));
  909. error_found = true;
  910. }
  911. }
  912. }
  913. }
  914. if (implicit_section && !get_section ())
  915. {
  916. error ("implicit_section flag is set but section isn't");
  917. error_found = true;
  918. }
  919. if (get_section () && get_comdat_group ()
  920. && !implicit_section
  921. && !lookup_attribute ("section", DECL_ATTRIBUTES (decl)))
  922. {
  923. error ("Both section and comdat group is set");
  924. error_found = true;
  925. }
  926. /* TODO: Add string table for sections, so we do not keep holding duplicated
  927. strings. */
  928. if (alias && definition
  929. && get_section () != get_alias_target ()->get_section ()
  930. && (!get_section()
  931. || !get_alias_target ()->get_section ()
  932. || strcmp (get_section(),
  933. get_alias_target ()->get_section ())))
  934. {
  935. error ("Alias and target's section differs");
  936. get_alias_target ()->dump (stderr);
  937. error_found = true;
  938. }
  939. if (alias && definition
  940. && get_comdat_group () != get_alias_target ()->get_comdat_group ())
  941. {
  942. error ("Alias and target's comdat groups differs");
  943. get_alias_target ()->dump (stderr);
  944. error_found = true;
  945. }
  946. return error_found;
  947. }
  948. /* Verify consistency of NODE. */
  949. DEBUG_FUNCTION void
  950. symtab_node::verify (void)
  951. {
  952. if (seen_error ())
  953. return;
  954. timevar_push (TV_CGRAPH_VERIFY);
  955. if (cgraph_node *node = dyn_cast <cgraph_node *> (this))
  956. node->verify_node ();
  957. else
  958. if (verify_base ())
  959. {
  960. debug ();
  961. internal_error ("symtab_node::verify failed");
  962. }
  963. timevar_pop (TV_CGRAPH_VERIFY);
  964. }
  965. /* Verify symbol table for internal consistency. */
  966. DEBUG_FUNCTION void
  967. symtab_node::verify_symtab_nodes (void)
  968. {
  969. symtab_node *node;
  970. hash_map<tree, symtab_node *> comdat_head_map (251);
  971. FOR_EACH_SYMBOL (node)
  972. {
  973. node->verify ();
  974. if (node->get_comdat_group ())
  975. {
  976. symtab_node **entry, *s;
  977. bool existed;
  978. entry = &comdat_head_map.get_or_insert (node->get_comdat_group (),
  979. &existed);
  980. if (!existed)
  981. *entry = node;
  982. else if (!DECL_EXTERNAL (node->decl))
  983. {
  984. for (s = (*entry)->same_comdat_group;
  985. s != NULL && s != node && s != *entry;
  986. s = s->same_comdat_group)
  987. ;
  988. if (!s || s == *entry)
  989. {
  990. error ("Two symbols with same comdat_group are not linked by "
  991. "the same_comdat_group list.");
  992. (*entry)->debug ();
  993. node->debug ();
  994. internal_error ("symtab_node::verify failed");
  995. }
  996. }
  997. }
  998. }
  999. }
  1000. /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
  1001. but other code such as notice_global_symbol generates rtl. */
  1002. void
  1003. symtab_node::make_decl_local (void)
  1004. {
  1005. rtx rtl, symbol;
  1006. /* Avoid clearing comdat_groups on comdat-local decls. */
  1007. if (TREE_PUBLIC (decl) == 0)
  1008. return;
  1009. if (TREE_CODE (decl) == VAR_DECL)
  1010. {
  1011. DECL_COMMON (decl) = 0;
  1012. /* ADDRESSABLE flag is not defined for public symbols. */
  1013. TREE_ADDRESSABLE (decl) = 1;
  1014. }
  1015. else gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
  1016. DECL_COMDAT (decl) = 0;
  1017. DECL_WEAK (decl) = 0;
  1018. DECL_EXTERNAL (decl) = 0;
  1019. DECL_VISIBILITY_SPECIFIED (decl) = 0;
  1020. DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
  1021. TREE_PUBLIC (decl) = 0;
  1022. DECL_DLLIMPORT_P (decl) = 0;
  1023. if (!DECL_RTL_SET_P (decl))
  1024. return;
  1025. /* Update rtl flags. */
  1026. make_decl_rtl (decl);
  1027. rtl = DECL_RTL (decl);
  1028. if (!MEM_P (rtl))
  1029. return;
  1030. symbol = XEXP (rtl, 0);
  1031. if (GET_CODE (symbol) != SYMBOL_REF)
  1032. return;
  1033. SYMBOL_REF_WEAK (symbol) = DECL_WEAK (decl);
  1034. }
  1035. /* Walk the alias chain to return the symbol NODE is alias of.
  1036. If NODE is not an alias, return NODE.
  1037. Assumes NODE is known to be alias. */
  1038. symtab_node *
  1039. symtab_node::ultimate_alias_target_1 (enum availability *availability)
  1040. {
  1041. bool weakref_p = false;
  1042. /* To determine visibility of the target, we follow ELF semantic of aliases.
  1043. Here alias is an alternative assembler name of a given definition. Its
  1044. availability prevails the availability of its target (i.e. static alias of
  1045. weak definition is available.
  1046. Weakref is a different animal (and not part of ELF per se). It is just
  1047. alternative name of a given symbol used within one complation unit
  1048. and is translated prior hitting the object file. It inherits the
  1049. visibility of its target (i.e. weakref of non-overwritable definition
  1050. is non-overwritable, while weakref of weak definition is weak).
  1051. If we ever get into supporting targets with different semantics, a target
  1052. hook will be needed here. */
  1053. if (availability)
  1054. {
  1055. weakref_p = weakref;
  1056. if (!weakref_p)
  1057. *availability = get_availability ();
  1058. else
  1059. *availability = AVAIL_LOCAL;
  1060. }
  1061. symtab_node *node = this;
  1062. while (node)
  1063. {
  1064. if (node->alias && node->analyzed)
  1065. node = node->get_alias_target ();
  1066. else
  1067. {
  1068. if (!availability)
  1069. ;
  1070. else if (node->analyzed)
  1071. {
  1072. if (weakref_p)
  1073. {
  1074. enum availability a = node->get_availability ();
  1075. if (a < *availability)
  1076. *availability = a;
  1077. }
  1078. }
  1079. else
  1080. *availability = AVAIL_NOT_AVAILABLE;
  1081. return node;
  1082. }
  1083. if (node && availability && weakref_p)
  1084. {
  1085. enum availability a = node->get_availability ();
  1086. if (a < *availability)
  1087. *availability = a;
  1088. weakref_p = node->weakref;
  1089. }
  1090. }
  1091. if (availability)
  1092. *availability = AVAIL_NOT_AVAILABLE;
  1093. return NULL;
  1094. }
  1095. /* C++ FE sometimes change linkage flags after producing same body aliases.
  1096. FIXME: C++ produce implicit aliases for virtual functions and vtables that
  1097. are obviously equivalent. The way it is doing so is however somewhat
  1098. kludgy and interferes with the visibility code. As a result we need to
  1099. copy the visibility from the target to get things right. */
  1100. void
  1101. symtab_node::fixup_same_cpp_alias_visibility (symtab_node *target)
  1102. {
  1103. if (is_a <cgraph_node *> (this))
  1104. {
  1105. DECL_DECLARED_INLINE_P (decl)
  1106. = DECL_DECLARED_INLINE_P (target->decl);
  1107. DECL_DISREGARD_INLINE_LIMITS (decl)
  1108. = DECL_DISREGARD_INLINE_LIMITS (target->decl);
  1109. }
  1110. /* FIXME: It is not really clear why those flags should not be copied for
  1111. functions, too. */
  1112. else
  1113. {
  1114. DECL_WEAK (decl) = DECL_WEAK (target->decl);
  1115. DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
  1116. DECL_VISIBILITY (decl) = DECL_VISIBILITY (target->decl);
  1117. }
  1118. DECL_VIRTUAL_P (decl) = DECL_VIRTUAL_P (target->decl);
  1119. if (TREE_PUBLIC (decl))
  1120. {
  1121. tree group;
  1122. DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
  1123. DECL_COMDAT (decl) = DECL_COMDAT (target->decl);
  1124. group = target->get_comdat_group ();
  1125. set_comdat_group (group);
  1126. if (group && !same_comdat_group)
  1127. add_to_same_comdat_group (target);
  1128. }
  1129. externally_visible = target->externally_visible;
  1130. }
  1131. /* Set section, do not recurse into aliases.
  1132. When one wants to change section of symbol and its aliases,
  1133. use set_section. */
  1134. void
  1135. symtab_node::set_section_for_node (const char *section)
  1136. {
  1137. const char *current = get_section ();
  1138. section_hash_entry **slot;
  1139. if (current == section
  1140. || (current && section
  1141. && !strcmp (current, section)))
  1142. return;
  1143. if (current)
  1144. {
  1145. x_section->ref_count--;
  1146. if (!x_section->ref_count)
  1147. {
  1148. hashval_t hash = htab_hash_string (x_section->name);
  1149. slot = symtab->section_hash->find_slot_with_hash (x_section->name,
  1150. hash, INSERT);
  1151. ggc_free (x_section);
  1152. symtab->section_hash->clear_slot (slot);
  1153. }
  1154. x_section = NULL;
  1155. }
  1156. if (!section)
  1157. {
  1158. implicit_section = false;
  1159. return;
  1160. }
  1161. if (!symtab->section_hash)
  1162. symtab->section_hash = hash_table<section_name_hasher>::create_ggc (10);
  1163. slot = symtab->section_hash->find_slot_with_hash (section,
  1164. htab_hash_string (section),
  1165. INSERT);
  1166. if (*slot)
  1167. x_section = (section_hash_entry *)*slot;
  1168. else
  1169. {
  1170. int len = strlen (section);
  1171. *slot = x_section = ggc_cleared_alloc<section_hash_entry> ();
  1172. x_section->name = ggc_vec_alloc<char> (len + 1);
  1173. memcpy (x_section->name, section, len + 1);
  1174. }
  1175. x_section->ref_count++;
  1176. }
  1177. /* Worker for set_section. */
  1178. bool
  1179. symtab_node::set_section (symtab_node *n, void *s)
  1180. {
  1181. n->set_section_for_node ((char *)s);
  1182. return false;
  1183. }
  1184. /* Set section of symbol and its aliases. */
  1185. void
  1186. symtab_node::set_section (const char *section)
  1187. {
  1188. gcc_assert (!this->alias);
  1189. call_for_symbol_and_aliases
  1190. (symtab_node::set_section, const_cast<char *>(section), true);
  1191. }
  1192. /* Return the initialization priority. */
  1193. priority_type
  1194. symtab_node::get_init_priority ()
  1195. {
  1196. if (!this->in_init_priority_hash)
  1197. return DEFAULT_INIT_PRIORITY;
  1198. symbol_priority_map *h = symtab->init_priority_hash->get (this);
  1199. return h ? h->init : DEFAULT_INIT_PRIORITY;
  1200. }
  1201. /* Return the finalization priority. */
  1202. priority_type
  1203. cgraph_node::get_fini_priority ()
  1204. {
  1205. if (!this->in_init_priority_hash)
  1206. return DEFAULT_INIT_PRIORITY;
  1207. symbol_priority_map *h = symtab->init_priority_hash->get (this);
  1208. return h ? h->fini : DEFAULT_INIT_PRIORITY;
  1209. }
  1210. /* Return the initialization and finalization priority information for
  1211. DECL. If there is no previous priority information, a freshly
  1212. allocated structure is returned. */
  1213. symbol_priority_map *
  1214. symtab_node::priority_info (void)
  1215. {
  1216. if (!symtab->init_priority_hash)
  1217. symtab->init_priority_hash = hash_map<symtab_node *, symbol_priority_map>::create_ggc (13);
  1218. bool existed;
  1219. symbol_priority_map *h
  1220. = &symtab->init_priority_hash->get_or_insert (this, &existed);
  1221. if (!existed)
  1222. {
  1223. h->init = DEFAULT_INIT_PRIORITY;
  1224. h->fini = DEFAULT_INIT_PRIORITY;
  1225. in_init_priority_hash = true;
  1226. }
  1227. return h;
  1228. }
  1229. /* Set initialization priority to PRIORITY. */
  1230. void
  1231. symtab_node::set_init_priority (priority_type priority)
  1232. {
  1233. symbol_priority_map *h;
  1234. if (is_a <cgraph_node *> (this))
  1235. gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl));
  1236. if (priority == DEFAULT_INIT_PRIORITY)
  1237. {
  1238. gcc_assert (get_init_priority() == priority);
  1239. return;
  1240. }
  1241. h = priority_info ();
  1242. h->init = priority;
  1243. }
  1244. /* Set fialization priority to PRIORITY. */
  1245. void
  1246. cgraph_node::set_fini_priority (priority_type priority)
  1247. {
  1248. symbol_priority_map *h;
  1249. gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl));
  1250. if (priority == DEFAULT_INIT_PRIORITY)
  1251. {
  1252. gcc_assert (get_fini_priority() == priority);
  1253. return;
  1254. }
  1255. h = priority_info ();
  1256. h->fini = priority;
  1257. }
  1258. /* Worker for symtab_resolve_alias. */
  1259. bool
  1260. symtab_node::set_implicit_section (symtab_node *n,
  1261. void *data ATTRIBUTE_UNUSED)
  1262. {
  1263. n->implicit_section = true;
  1264. return false;
  1265. }
  1266. /* Add reference recording that symtab node is alias of TARGET.
  1267. The function can fail in the case of aliasing cycles; in this case
  1268. it returns false. */
  1269. bool
  1270. symtab_node::resolve_alias (symtab_node *target)
  1271. {
  1272. symtab_node *n;
  1273. gcc_assert (!analyzed && !vec_safe_length (ref_list.references));
  1274. /* Never let cycles to creep into the symbol table alias references;
  1275. those will make alias walkers to be infinite. */
  1276. for (n = target; n && n->alias;
  1277. n = n->analyzed ? n->get_alias_target () : NULL)
  1278. if (n == this)
  1279. {
  1280. if (is_a <cgraph_node *> (this))
  1281. error ("function %q+D part of alias cycle", decl);
  1282. else if (is_a <varpool_node *> (this))
  1283. error ("variable %q+D part of alias cycle", decl);
  1284. else
  1285. gcc_unreachable ();
  1286. alias = false;
  1287. return false;
  1288. }
  1289. /* "analyze" the node - i.e. mark the reference. */
  1290. definition = true;
  1291. alias = true;
  1292. analyzed = true;
  1293. create_reference (target, IPA_REF_ALIAS, NULL);
  1294. /* Add alias into the comdat group of its target unless it is already there. */
  1295. if (same_comdat_group)
  1296. remove_from_same_comdat_group ();
  1297. set_comdat_group (NULL);
  1298. if (target->get_comdat_group ())
  1299. add_to_same_comdat_group (target);
  1300. if ((get_section () != target->get_section ()
  1301. || target->get_comdat_group ()) && get_section () && !implicit_section)
  1302. {
  1303. error ("section of alias %q+D must match section of its target", decl);
  1304. }
  1305. call_for_symbol_and_aliases (symtab_node::set_section,
  1306. const_cast<char *>(target->get_section ()), true);
  1307. if (target->implicit_section)
  1308. call_for_symbol_and_aliases (set_implicit_section, NULL, true);
  1309. /* Alias targets become redundant after alias is resolved into an reference.
  1310. We do not want to keep it around or we would have to mind updating them
  1311. when renaming symbols. */
  1312. alias_target = NULL;
  1313. if (cpp_implicit_alias && symtab->state >= CONSTRUCTION)
  1314. fixup_same_cpp_alias_visibility (target);
  1315. /* If alias has address taken, so does the target. */
  1316. if (address_taken)
  1317. target->ultimate_alias_target ()->address_taken = true;
  1318. /* All non-weakref aliases of THIS are now in fact aliases of TARGET. */
  1319. ipa_ref *ref;
  1320. for (unsigned i = 0; iterate_direct_aliases (i, ref);)
  1321. {
  1322. struct symtab_node *alias_alias = ref->referring;
  1323. if (!alias_alias->weakref)
  1324. {
  1325. alias_alias->remove_all_references ();
  1326. alias_alias->create_reference (target, IPA_REF_ALIAS, NULL);
  1327. }
  1328. else i++;
  1329. }
  1330. return true;
  1331. }
  1332. /* Worker searching noninterposable alias. */
  1333. bool
  1334. symtab_node::noninterposable_alias (symtab_node *node, void *data)
  1335. {
  1336. if (decl_binds_to_current_def_p (node->decl))
  1337. {
  1338. symtab_node *fn = node->ultimate_alias_target ();
  1339. /* Ensure that the alias is well formed this may not be the case
  1340. of user defined aliases and currently it is not always the case
  1341. of C++ same body aliases (that is a bug). */
  1342. if (TREE_TYPE (node->decl) != TREE_TYPE (fn->decl)
  1343. || DECL_CONTEXT (node->decl) != DECL_CONTEXT (fn->decl)
  1344. || (TREE_CODE (node->decl) == FUNCTION_DECL
  1345. && flags_from_decl_or_type (node->decl)
  1346. != flags_from_decl_or_type (fn->decl))
  1347. || DECL_ATTRIBUTES (node->decl) != DECL_ATTRIBUTES (fn->decl))
  1348. return false;
  1349. *(symtab_node **)data = node;
  1350. return true;
  1351. }
  1352. return false;
  1353. }
  1354. /* If node can not be overwriten by static or dynamic linker to point to
  1355. different definition, return NODE. Otherwise look for alias with such
  1356. property and if none exists, introduce new one. */
  1357. symtab_node *
  1358. symtab_node::noninterposable_alias (void)
  1359. {
  1360. tree new_decl;
  1361. symtab_node *new_node = NULL;
  1362. /* First try to look up existing alias or base object
  1363. (if that is already non-overwritable). */
  1364. symtab_node *node = ultimate_alias_target ();
  1365. gcc_assert (!node->alias && !node->weakref);
  1366. node->call_for_symbol_and_aliases (symtab_node::noninterposable_alias,
  1367. (void *)&new_node, true);
  1368. if (new_node)
  1369. return new_node;
  1370. #ifndef ASM_OUTPUT_DEF
  1371. /* If aliases aren't supported by the assembler, fail. */
  1372. return NULL;
  1373. #endif
  1374. /* Otherwise create a new one. */
  1375. new_decl = copy_node (node->decl);
  1376. DECL_DLLIMPORT_P (new_decl) = 0;
  1377. DECL_NAME (new_decl) = clone_function_name (node->decl, "localalias");
  1378. if (TREE_CODE (new_decl) == FUNCTION_DECL)
  1379. DECL_STRUCT_FUNCTION (new_decl) = NULL;
  1380. DECL_INITIAL (new_decl) = NULL;
  1381. SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
  1382. SET_DECL_RTL (new_decl, NULL);
  1383. /* Update the properties. */
  1384. DECL_EXTERNAL (new_decl) = 0;
  1385. TREE_PUBLIC (new_decl) = 0;
  1386. DECL_COMDAT (new_decl) = 0;
  1387. DECL_WEAK (new_decl) = 0;
  1388. /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */
  1389. DECL_VIRTUAL_P (new_decl) = DECL_VIRTUAL_P (node->decl);
  1390. if (TREE_CODE (new_decl) == FUNCTION_DECL)
  1391. {
  1392. DECL_STATIC_CONSTRUCTOR (new_decl) = 0;
  1393. DECL_STATIC_DESTRUCTOR (new_decl) = 0;
  1394. new_node = cgraph_node::create_alias (new_decl, node->decl);
  1395. }
  1396. else
  1397. {
  1398. TREE_READONLY (new_decl) = TREE_READONLY (node->decl);
  1399. DECL_INITIAL (new_decl) = error_mark_node;
  1400. new_node = varpool_node::create_alias (new_decl, node->decl);
  1401. }
  1402. new_node->resolve_alias (node);
  1403. gcc_assert (decl_binds_to_current_def_p (new_decl)
  1404. && targetm.binds_local_p (new_decl));
  1405. return new_node;
  1406. }
  1407. /* Return true if symtab node and TARGET represents
  1408. semantically equivalent symbols. */
  1409. bool
  1410. symtab_node::semantically_equivalent_p (symtab_node *target)
  1411. {
  1412. enum availability avail;
  1413. symtab_node *ba;
  1414. symtab_node *bb;
  1415. /* Equivalent functions are equivalent. */
  1416. if (decl == target->decl)
  1417. return true;
  1418. /* If symbol is not overwritable by different implementation,
  1419. walk to the base object it defines. */
  1420. ba = ultimate_alias_target (&avail);
  1421. if (avail >= AVAIL_AVAILABLE)
  1422. {
  1423. if (target == ba)
  1424. return true;
  1425. }
  1426. else
  1427. ba = this;
  1428. bb = target->ultimate_alias_target (&avail);
  1429. if (avail >= AVAIL_AVAILABLE)
  1430. {
  1431. if (this == bb)
  1432. return true;
  1433. }
  1434. else
  1435. bb = target;
  1436. return bb == ba;
  1437. }
  1438. /* Classify symbol symtab node for partitioning. */
  1439. enum symbol_partitioning_class
  1440. symtab_node::get_partitioning_class (void)
  1441. {
  1442. /* Inline clones are always duplicated.
  1443. This include external delcarations. */
  1444. cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
  1445. if (DECL_ABSTRACT_P (decl))
  1446. return SYMBOL_EXTERNAL;
  1447. if (cnode && cnode->global.inlined_to)
  1448. return SYMBOL_DUPLICATE;
  1449. /* Weakref aliases are always duplicated. */
  1450. if (weakref)
  1451. return SYMBOL_DUPLICATE;
  1452. /* External declarations are external. */
  1453. if (DECL_EXTERNAL (decl))
  1454. return SYMBOL_EXTERNAL;
  1455. if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
  1456. {
  1457. if (alias && definition && !ultimate_alias_target ()->definition)
  1458. return SYMBOL_EXTERNAL;
  1459. /* Constant pool references use local symbol names that can not
  1460. be promoted global. We should never put into a constant pool
  1461. objects that can not be duplicated across partitions. */
  1462. if (DECL_IN_CONSTANT_POOL (decl))
  1463. return SYMBOL_DUPLICATE;
  1464. if (DECL_HARD_REGISTER (decl))
  1465. return SYMBOL_DUPLICATE;
  1466. gcc_checking_assert (vnode->definition);
  1467. }
  1468. /* Functions that are cloned may stay in callgraph even if they are unused.
  1469. Handle them as external; compute_ltrans_boundary take care to make
  1470. proper things to happen (i.e. to make them appear in the boundary but
  1471. with body streamed, so clone can me materialized). */
  1472. else if (!dyn_cast <cgraph_node *> (this)->function_symbol ()->definition)
  1473. return SYMBOL_EXTERNAL;
  1474. /* Linker discardable symbols are duplicated to every use unless they are
  1475. keyed. */
  1476. if (DECL_ONE_ONLY (decl)
  1477. && !force_output
  1478. && !forced_by_abi
  1479. && !used_from_object_file_p ())
  1480. return SYMBOL_DUPLICATE;
  1481. return SYMBOL_PARTITION;
  1482. }
  1483. /* Return true when symbol is known to be non-zero. */
  1484. bool
  1485. symtab_node::nonzero_address ()
  1486. {
  1487. /* Weakrefs may be NULL when their target is not defined. */
  1488. if (alias && weakref)
  1489. {
  1490. if (analyzed)
  1491. {
  1492. symtab_node *target = ultimate_alias_target ();
  1493. if (target->alias && target->weakref)
  1494. return false;
  1495. /* We can not recurse to target::nonzero. It is possible that the
  1496. target is used only via the alias.
  1497. We may walk references and look for strong use, but we do not know
  1498. if this strong use will survive to final binary, so be
  1499. conservative here.
  1500. ??? Maybe we could do the lookup during late optimization that
  1501. could be useful to eliminate the NULL pointer checks in LTO
  1502. programs. */
  1503. if (target->definition && !DECL_EXTERNAL (target->decl))
  1504. return true;
  1505. if (target->resolution != LDPR_UNKNOWN
  1506. && target->resolution != LDPR_UNDEF
  1507. && flag_delete_null_pointer_checks)
  1508. return true;
  1509. return false;
  1510. }
  1511. else
  1512. return false;
  1513. }
  1514. /* With !flag_delete_null_pointer_checks we assume that symbols may
  1515. bind to NULL. This is on by default on embedded targets only.
  1516. Otherwise all non-WEAK symbols must be defined and thus non-NULL or
  1517. linking fails. Important case of WEAK we want to do well are comdats.
  1518. Those are handled by later check for definition.
  1519. When parsing, beware the cases when WEAK attribute is added later. */
  1520. if (!DECL_WEAK (decl)
  1521. && flag_delete_null_pointer_checks)
  1522. {
  1523. refuse_visibility_changes = true;
  1524. return true;
  1525. }
  1526. /* If target is defined and not extern, we know it will be output and thus
  1527. it will bind to non-NULL.
  1528. Play safe for flag_delete_null_pointer_checks where weak definition maye
  1529. be re-defined by NULL. */
  1530. if (definition && !DECL_EXTERNAL (decl)
  1531. && (flag_delete_null_pointer_checks || !DECL_WEAK (decl)))
  1532. {
  1533. if (!DECL_WEAK (decl))
  1534. refuse_visibility_changes = true;
  1535. return true;
  1536. }
  1537. /* As the last resort, check the resolution info. */
  1538. if (resolution != LDPR_UNKNOWN
  1539. && resolution != LDPR_UNDEF
  1540. && flag_delete_null_pointer_checks)
  1541. return true;
  1542. return false;
  1543. }
  1544. /* Return 0 if symbol is known to have different address than S2,
  1545. Return 1 if symbol is known to have same address as S2,
  1546. return 2 otherwise. */
  1547. int
  1548. symtab_node::equal_address_to (symtab_node *s2)
  1549. {
  1550. enum availability avail1, avail2;
  1551. /* A Shortcut: equivalent symbols are always equivalent. */
  1552. if (this == s2)
  1553. return 1;
  1554. /* For non-interposable aliases, lookup and compare their actual definitions.
  1555. Also check if the symbol needs to bind to given definition. */
  1556. symtab_node *rs1 = ultimate_alias_target (&avail1);
  1557. symtab_node *rs2 = s2->ultimate_alias_target (&avail2);
  1558. bool binds_local1 = rs1->analyzed && decl_binds_to_current_def_p (this->decl);
  1559. bool binds_local2 = rs2->analyzed && decl_binds_to_current_def_p (s2->decl);
  1560. bool really_binds_local1 = binds_local1;
  1561. bool really_binds_local2 = binds_local2;
  1562. /* Addresses of vtables and virtual functions can not be used by user
  1563. code and are used only within speculation. In this case we may make
  1564. symbol equivalent to its alias even if interposition may break this
  1565. rule. Doing so will allow us to turn speculative inlining into
  1566. non-speculative more agressively. */
  1567. if (DECL_VIRTUAL_P (this->decl) && avail1 >= AVAIL_AVAILABLE)
  1568. binds_local1 = true;
  1569. if (DECL_VIRTUAL_P (s2->decl) && avail2 >= AVAIL_AVAILABLE)
  1570. binds_local2 = true;
  1571. /* If both definitions are available we know that even if they are bound
  1572. to other unit they must be defined same way and therefore we can use
  1573. equivalence test. */
  1574. if (rs1 != rs2 && avail1 >= AVAIL_AVAILABLE && avail2 >= AVAIL_AVAILABLE)
  1575. binds_local1 = binds_local2 = true;
  1576. if ((binds_local1 ? rs1 : this)
  1577. == (binds_local2 ? rs2 : s2))
  1578. {
  1579. /* We made use of the fact that alias is not weak. */
  1580. if (binds_local1 && rs1 != this)
  1581. refuse_visibility_changes = true;
  1582. if (binds_local2 && rs2 != s2)
  1583. s2->refuse_visibility_changes = true;
  1584. return 1;
  1585. }
  1586. /* If both symbols may resolve to NULL, we can not really prove them different. */
  1587. if (!nonzero_address () && !s2->nonzero_address ())
  1588. return 2;
  1589. /* Except for NULL, functions and variables never overlap. */
  1590. if (TREE_CODE (decl) != TREE_CODE (s2->decl))
  1591. return 0;
  1592. /* If one of the symbols is unresolved alias, punt. */
  1593. if (rs1->alias || rs2->alias)
  1594. return 2;
  1595. /* If we have a non-interposale definition of at least one of the symbols
  1596. and the other symbol is different, we know other unit can not interpose
  1597. it to the first symbol; all aliases of the definition needs to be
  1598. present in the current unit. */
  1599. if (((really_binds_local1 || really_binds_local2)
  1600. /* If we have both definitions and they are different, we know they
  1601. will be different even in units they binds to. */
  1602. || (binds_local1 && binds_local2))
  1603. && rs1 != rs2)
  1604. {
  1605. /* We make use of the fact that one symbol is not alias of the other
  1606. and that the definition is non-interposable. */
  1607. refuse_visibility_changes = true;
  1608. s2->refuse_visibility_changes = true;
  1609. rs1->refuse_visibility_changes = true;
  1610. rs2->refuse_visibility_changes = true;
  1611. return 0;
  1612. }
  1613. /* TODO: Alias oracle basically assume that addresses of global variables
  1614. are different unless they are declared as alias of one to another.
  1615. We probably should be consistent and use this fact here, too, and update
  1616. alias oracle to use this predicate. */
  1617. return 2;
  1618. }
  1619. /* Worker for call_for_symbol_and_aliases. */
  1620. bool
  1621. symtab_node::call_for_symbol_and_aliases_1 (bool (*callback) (symtab_node *,
  1622. void *),
  1623. void *data,
  1624. bool include_overwritable)
  1625. {
  1626. ipa_ref *ref;
  1627. FOR_EACH_ALIAS (this, ref)
  1628. {
  1629. symtab_node *alias = ref->referring;
  1630. if (include_overwritable
  1631. || alias->get_availability () > AVAIL_INTERPOSABLE)
  1632. if (alias->call_for_symbol_and_aliases (callback, data,
  1633. include_overwritable))
  1634. return true;
  1635. }
  1636. return false;
  1637. }
  1638. /* Return ture if address of N is possibly compared. */
  1639. static bool
  1640. address_matters_1 (symtab_node *n, void *)
  1641. {
  1642. struct ipa_ref *ref;
  1643. if (!n->address_can_be_compared_p ())
  1644. return false;
  1645. if (n->externally_visible || n->force_output)
  1646. return true;
  1647. for (unsigned int i = 0; n->iterate_referring (i, ref); i++)
  1648. if (ref->address_matters_p ())
  1649. return true;
  1650. return false;
  1651. }
  1652. /* Return true if symbol's address may possibly be compared to other
  1653. symbol's address. */
  1654. bool
  1655. symtab_node::address_matters_p ()
  1656. {
  1657. gcc_assert (!alias);
  1658. return call_for_symbol_and_aliases (address_matters_1, NULL, true);
  1659. }
  1660. /* Return ture if symbol's alignment may be increased. */
  1661. bool
  1662. symtab_node::can_increase_alignment_p (void)
  1663. {
  1664. symtab_node *target = ultimate_alias_target ();
  1665. /* For now support only variables. */
  1666. if (TREE_CODE (decl) != VAR_DECL)
  1667. return false;
  1668. /* With -fno-toplevel-reorder we may have already output the constant. */
  1669. if (TREE_ASM_WRITTEN (target->decl))
  1670. return false;
  1671. /* If target is already placed in an anchor, we can not touch its
  1672. alignment. */
  1673. if (DECL_RTL_SET_P (target->decl)
  1674. && MEM_P (DECL_RTL (target->decl))
  1675. && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (DECL_RTL (target->decl), 0)))
  1676. return false;
  1677. /* Constant pool entries may be shared. */
  1678. if (DECL_IN_CONSTANT_POOL (target->decl))
  1679. return false;
  1680. /* We cannot change alignment of symbols that may bind to symbols
  1681. in other translation unit that may contain a definition with lower
  1682. alignment. */
  1683. if (!decl_binds_to_current_def_p (decl))
  1684. return false;
  1685. /* When compiling partition, be sure the symbol is not output by other
  1686. partition. */
  1687. if (flag_ltrans
  1688. && (target->in_other_partition
  1689. || target->get_partitioning_class () == SYMBOL_DUPLICATE))
  1690. return false;
  1691. /* Do not override the alignment as specified by the ABI when the used
  1692. attribute is set. */
  1693. if (DECL_PRESERVE_P (decl) || DECL_PRESERVE_P (target->decl))
  1694. return false;
  1695. /* Do not override explicit alignment set by the user when an explicit
  1696. section name is also used. This is a common idiom used by many
  1697. software projects. */
  1698. if (DECL_SECTION_NAME (target->decl) != NULL && !target->implicit_section)
  1699. return false;
  1700. return true;
  1701. }
  1702. /* Worker for symtab_node::increase_alignment. */
  1703. static bool
  1704. increase_alignment_1 (symtab_node *n, void *v)
  1705. {
  1706. unsigned int align = (size_t)v;
  1707. if (DECL_ALIGN (n->decl) < align
  1708. && n->can_increase_alignment_p ())
  1709. {
  1710. DECL_ALIGN (n->decl) = align;
  1711. DECL_USER_ALIGN (n->decl) = 1;
  1712. }
  1713. return false;
  1714. }
  1715. /* Increase alignment of THIS to ALIGN. */
  1716. void
  1717. symtab_node::increase_alignment (unsigned int align)
  1718. {
  1719. gcc_assert (can_increase_alignment_p () && align < MAX_OFILE_ALIGNMENT);
  1720. ultimate_alias_target()->call_for_symbol_and_aliases (increase_alignment_1,
  1721. (void *)(size_t) align,
  1722. true);
  1723. gcc_assert (DECL_ALIGN (decl) >= align);
  1724. }
  1725. /* Helper for symtab_node::definition_alignment. */
  1726. static bool
  1727. get_alignment_1 (symtab_node *n, void *v)
  1728. {
  1729. *((unsigned int *)v) = MAX (*((unsigned int *)v), DECL_ALIGN (n->decl));
  1730. return false;
  1731. }
  1732. /* Return desired alignment of the definition. This is NOT alignment useful
  1733. to access THIS, because THIS may be interposable and DECL_ALIGN should
  1734. be used instead. It however must be guaranteed when output definition
  1735. of THIS. */
  1736. unsigned int
  1737. symtab_node::definition_alignment ()
  1738. {
  1739. unsigned int align = 0;
  1740. gcc_assert (!alias);
  1741. call_for_symbol_and_aliases (get_alignment_1, &align, true);
  1742. return align;
  1743. }