symtab.h 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977
  1. // symtab.h -- the gold symbol table -*- C++ -*-
  2. // Copyright (C) 2006-2015 Free Software Foundation, Inc.
  3. // Written by Ian Lance Taylor <iant@google.com>.
  4. // This file is part of gold.
  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. // Symbol_table
  18. // The symbol table.
  19. #ifndef GOLD_SYMTAB_H
  20. #define GOLD_SYMTAB_H
  21. #include <string>
  22. #include <utility>
  23. #include <vector>
  24. #include "elfcpp.h"
  25. #include "parameters.h"
  26. #include "stringpool.h"
  27. #include "object.h"
  28. namespace gold
  29. {
  30. class Mapfile;
  31. class Object;
  32. class Relobj;
  33. template<int size, bool big_endian>
  34. class Sized_relobj_file;
  35. template<int size, bool big_endian>
  36. class Sized_pluginobj;
  37. class Dynobj;
  38. template<int size, bool big_endian>
  39. class Sized_dynobj;
  40. template<int size, bool big_endian>
  41. class Sized_incrobj;
  42. class Versions;
  43. class Version_script_info;
  44. class Input_objects;
  45. class Output_data;
  46. class Output_section;
  47. class Output_segment;
  48. class Output_file;
  49. class Output_symtab_xindex;
  50. class Garbage_collection;
  51. class Icf;
  52. // The base class of an entry in the symbol table. The symbol table
  53. // can have a lot of entries, so we don't want this class too big.
  54. // Size dependent fields can be found in the template class
  55. // Sized_symbol. Targets may support their own derived classes.
  56. class Symbol
  57. {
  58. public:
  59. // Because we want the class to be small, we don't use any virtual
  60. // functions. But because symbols can be defined in different
  61. // places, we need to classify them. This enum is the different
  62. // sources of symbols we support.
  63. enum Source
  64. {
  65. // Symbol defined in a relocatable or dynamic input file--this is
  66. // the most common case.
  67. FROM_OBJECT,
  68. // Symbol defined in an Output_data, a special section created by
  69. // the target.
  70. IN_OUTPUT_DATA,
  71. // Symbol defined in an Output_segment, with no associated
  72. // section.
  73. IN_OUTPUT_SEGMENT,
  74. // Symbol value is constant.
  75. IS_CONSTANT,
  76. // Symbol is undefined.
  77. IS_UNDEFINED
  78. };
  79. // When the source is IN_OUTPUT_SEGMENT, we need to describe what
  80. // the offset means.
  81. enum Segment_offset_base
  82. {
  83. // From the start of the segment.
  84. SEGMENT_START,
  85. // From the end of the segment.
  86. SEGMENT_END,
  87. // From the filesz of the segment--i.e., after the loaded bytes
  88. // but before the bytes which are allocated but zeroed.
  89. SEGMENT_BSS
  90. };
  91. // Return the symbol name.
  92. const char*
  93. name() const
  94. { return this->name_; }
  95. // Return the (ANSI) demangled version of the name, if
  96. // parameters.demangle() is true. Otherwise, return the name. This
  97. // is intended to be used only for logging errors, so it's not
  98. // super-efficient.
  99. std::string
  100. demangled_name() const;
  101. // Return the symbol version. This will return NULL for an
  102. // unversioned symbol.
  103. const char*
  104. version() const
  105. { return this->version_; }
  106. void
  107. clear_version()
  108. { this->version_ = NULL; }
  109. // Return whether this version is the default for this symbol name
  110. // (eg, "foo@@V2" is a default version; "foo@V1" is not). Only
  111. // meaningful for versioned symbols.
  112. bool
  113. is_default() const
  114. {
  115. gold_assert(this->version_ != NULL);
  116. return this->is_def_;
  117. }
  118. // Set that this version is the default for this symbol name.
  119. void
  120. set_is_default()
  121. { this->is_def_ = true; }
  122. // Set that this version is not the default for this symbol name.
  123. void
  124. set_is_not_default()
  125. { this->is_def_ = false; }
  126. // Return the symbol's name as name@version (or name@@version).
  127. std::string
  128. versioned_name() const;
  129. // Return the symbol source.
  130. Source
  131. source() const
  132. { return this->source_; }
  133. // Return the object with which this symbol is associated.
  134. Object*
  135. object() const
  136. {
  137. gold_assert(this->source_ == FROM_OBJECT);
  138. return this->u_.from_object.object;
  139. }
  140. // Return the index of the section in the input relocatable or
  141. // dynamic object file.
  142. unsigned int
  143. shndx(bool* is_ordinary) const
  144. {
  145. gold_assert(this->source_ == FROM_OBJECT);
  146. *is_ordinary = this->is_ordinary_shndx_;
  147. return this->u_.from_object.shndx;
  148. }
  149. // Return the output data section with which this symbol is
  150. // associated, if the symbol was specially defined with respect to
  151. // an output data section.
  152. Output_data*
  153. output_data() const
  154. {
  155. gold_assert(this->source_ == IN_OUTPUT_DATA);
  156. return this->u_.in_output_data.output_data;
  157. }
  158. // If this symbol was defined with respect to an output data
  159. // section, return whether the value is an offset from end.
  160. bool
  161. offset_is_from_end() const
  162. {
  163. gold_assert(this->source_ == IN_OUTPUT_DATA);
  164. return this->u_.in_output_data.offset_is_from_end;
  165. }
  166. // Return the output segment with which this symbol is associated,
  167. // if the symbol was specially defined with respect to an output
  168. // segment.
  169. Output_segment*
  170. output_segment() const
  171. {
  172. gold_assert(this->source_ == IN_OUTPUT_SEGMENT);
  173. return this->u_.in_output_segment.output_segment;
  174. }
  175. // If this symbol was defined with respect to an output segment,
  176. // return the offset base.
  177. Segment_offset_base
  178. offset_base() const
  179. {
  180. gold_assert(this->source_ == IN_OUTPUT_SEGMENT);
  181. return this->u_.in_output_segment.offset_base;
  182. }
  183. // Return the symbol binding.
  184. elfcpp::STB
  185. binding() const
  186. { return this->binding_; }
  187. // Return the symbol type.
  188. elfcpp::STT
  189. type() const
  190. { return this->type_; }
  191. // Set the symbol type.
  192. void
  193. set_type(elfcpp::STT type)
  194. { this->type_ = type; }
  195. // Return true for function symbol.
  196. bool
  197. is_func() const
  198. {
  199. return (this->type_ == elfcpp::STT_FUNC
  200. || this->type_ == elfcpp::STT_GNU_IFUNC);
  201. }
  202. // Return the symbol visibility.
  203. elfcpp::STV
  204. visibility() const
  205. { return this->visibility_; }
  206. // Set the visibility.
  207. void
  208. set_visibility(elfcpp::STV visibility)
  209. { this->visibility_ = visibility; }
  210. // Override symbol visibility.
  211. void
  212. override_visibility(elfcpp::STV);
  213. // Set whether the symbol was originally a weak undef or a regular undef
  214. // when resolved by a dynamic def or by a special symbol.
  215. inline void
  216. set_undef_binding(elfcpp::STB bind)
  217. {
  218. if (!this->undef_binding_set_ || this->undef_binding_weak_)
  219. {
  220. this->undef_binding_weak_ = bind == elfcpp::STB_WEAK;
  221. this->undef_binding_set_ = true;
  222. }
  223. }
  224. // Return TRUE if a weak undef was resolved by a dynamic def or
  225. // by a special symbol.
  226. inline bool
  227. is_undef_binding_weak() const
  228. { return this->undef_binding_weak_; }
  229. // Return the non-visibility part of the st_other field.
  230. unsigned char
  231. nonvis() const
  232. { return this->nonvis_; }
  233. // Set the non-visibility part of the st_other field.
  234. void
  235. set_nonvis(unsigned int nonvis)
  236. { this->nonvis_ = nonvis; }
  237. // Return whether this symbol is a forwarder. This will never be
  238. // true of a symbol found in the hash table, but may be true of
  239. // symbol pointers attached to object files.
  240. bool
  241. is_forwarder() const
  242. { return this->is_forwarder_; }
  243. // Mark this symbol as a forwarder.
  244. void
  245. set_forwarder()
  246. { this->is_forwarder_ = true; }
  247. // Return whether this symbol has an alias in the weak aliases table
  248. // in Symbol_table.
  249. bool
  250. has_alias() const
  251. { return this->has_alias_; }
  252. // Mark this symbol as having an alias.
  253. void
  254. set_has_alias()
  255. { this->has_alias_ = true; }
  256. // Return whether this symbol needs an entry in the dynamic symbol
  257. // table.
  258. bool
  259. needs_dynsym_entry() const
  260. {
  261. return (this->needs_dynsym_entry_
  262. || (this->in_reg()
  263. && this->in_dyn()
  264. && this->is_externally_visible()));
  265. }
  266. // Mark this symbol as needing an entry in the dynamic symbol table.
  267. void
  268. set_needs_dynsym_entry()
  269. { this->needs_dynsym_entry_ = true; }
  270. // Return whether this symbol should be added to the dynamic symbol
  271. // table.
  272. bool
  273. should_add_dynsym_entry(Symbol_table*) const;
  274. // Return whether this symbol has been seen in a regular object.
  275. bool
  276. in_reg() const
  277. { return this->in_reg_; }
  278. // Mark this symbol as having been seen in a regular object.
  279. void
  280. set_in_reg()
  281. { this->in_reg_ = true; }
  282. // Return whether this symbol has been seen in a dynamic object.
  283. bool
  284. in_dyn() const
  285. { return this->in_dyn_; }
  286. // Mark this symbol as having been seen in a dynamic object.
  287. void
  288. set_in_dyn()
  289. { this->in_dyn_ = true; }
  290. // Return whether this symbol has been seen in a real ELF object.
  291. // (IN_REG will return TRUE if the symbol has been seen in either
  292. // a real ELF object or an object claimed by a plugin.)
  293. bool
  294. in_real_elf() const
  295. { return this->in_real_elf_; }
  296. // Mark this symbol as having been seen in a real ELF object.
  297. void
  298. set_in_real_elf()
  299. { this->in_real_elf_ = true; }
  300. // Return whether this symbol was defined in a section that was
  301. // discarded from the link. This is used to control some error
  302. // reporting.
  303. bool
  304. is_defined_in_discarded_section() const
  305. { return this->is_defined_in_discarded_section_; }
  306. // Mark this symbol as having been defined in a discarded section.
  307. void
  308. set_is_defined_in_discarded_section()
  309. { this->is_defined_in_discarded_section_ = true; }
  310. // Return the index of this symbol in the output file symbol table.
  311. // A value of -1U means that this symbol is not going into the
  312. // output file. This starts out as zero, and is set to a non-zero
  313. // value by Symbol_table::finalize. It is an error to ask for the
  314. // symbol table index before it has been set.
  315. unsigned int
  316. symtab_index() const
  317. {
  318. gold_assert(this->symtab_index_ != 0);
  319. return this->symtab_index_;
  320. }
  321. // Set the index of the symbol in the output file symbol table.
  322. void
  323. set_symtab_index(unsigned int index)
  324. {
  325. gold_assert(index != 0);
  326. this->symtab_index_ = index;
  327. }
  328. // Return whether this symbol already has an index in the output
  329. // file symbol table.
  330. bool
  331. has_symtab_index() const
  332. { return this->symtab_index_ != 0; }
  333. // Return the index of this symbol in the dynamic symbol table. A
  334. // value of -1U means that this symbol is not going into the dynamic
  335. // symbol table. This starts out as zero, and is set to a non-zero
  336. // during Layout::finalize. It is an error to ask for the dynamic
  337. // symbol table index before it has been set.
  338. unsigned int
  339. dynsym_index() const
  340. {
  341. gold_assert(this->dynsym_index_ != 0);
  342. return this->dynsym_index_;
  343. }
  344. // Set the index of the symbol in the dynamic symbol table.
  345. void
  346. set_dynsym_index(unsigned int index)
  347. {
  348. gold_assert(index != 0);
  349. this->dynsym_index_ = index;
  350. }
  351. // Return whether this symbol already has an index in the dynamic
  352. // symbol table.
  353. bool
  354. has_dynsym_index() const
  355. { return this->dynsym_index_ != 0; }
  356. // Return whether this symbol has an entry in the GOT section.
  357. // For a TLS symbol, this GOT entry will hold its tp-relative offset.
  358. bool
  359. has_got_offset(unsigned int got_type) const
  360. { return this->got_offsets_.get_offset(got_type) != -1U; }
  361. // Return the offset into the GOT section of this symbol.
  362. unsigned int
  363. got_offset(unsigned int got_type) const
  364. {
  365. unsigned int got_offset = this->got_offsets_.get_offset(got_type);
  366. gold_assert(got_offset != -1U);
  367. return got_offset;
  368. }
  369. // Set the GOT offset of this symbol.
  370. void
  371. set_got_offset(unsigned int got_type, unsigned int got_offset)
  372. { this->got_offsets_.set_offset(got_type, got_offset); }
  373. // Return the GOT offset list.
  374. const Got_offset_list*
  375. got_offset_list() const
  376. { return this->got_offsets_.get_list(); }
  377. // Return whether this symbol has an entry in the PLT section.
  378. bool
  379. has_plt_offset() const
  380. { return this->plt_offset_ != -1U; }
  381. // Return the offset into the PLT section of this symbol.
  382. unsigned int
  383. plt_offset() const
  384. {
  385. gold_assert(this->has_plt_offset());
  386. return this->plt_offset_;
  387. }
  388. // Set the PLT offset of this symbol.
  389. void
  390. set_plt_offset(unsigned int plt_offset)
  391. {
  392. gold_assert(plt_offset != -1U);
  393. this->plt_offset_ = plt_offset;
  394. }
  395. // Return whether this dynamic symbol needs a special value in the
  396. // dynamic symbol table.
  397. bool
  398. needs_dynsym_value() const
  399. { return this->needs_dynsym_value_; }
  400. // Set that this dynamic symbol needs a special value in the dynamic
  401. // symbol table.
  402. void
  403. set_needs_dynsym_value()
  404. {
  405. gold_assert(this->object()->is_dynamic());
  406. this->needs_dynsym_value_ = true;
  407. }
  408. // Return true if the final value of this symbol is known at link
  409. // time.
  410. bool
  411. final_value_is_known() const;
  412. // Return true if SHNDX represents a common symbol. This depends on
  413. // the target.
  414. static bool
  415. is_common_shndx(unsigned int shndx);
  416. // Return whether this is a defined symbol (not undefined or
  417. // common).
  418. bool
  419. is_defined() const
  420. {
  421. bool is_ordinary;
  422. if (this->source_ != FROM_OBJECT)
  423. return this->source_ != IS_UNDEFINED;
  424. unsigned int shndx = this->shndx(&is_ordinary);
  425. return (is_ordinary
  426. ? shndx != elfcpp::SHN_UNDEF
  427. : !Symbol::is_common_shndx(shndx));
  428. }
  429. // Return true if this symbol is from a dynamic object.
  430. bool
  431. is_from_dynobj() const
  432. {
  433. return this->source_ == FROM_OBJECT && this->object()->is_dynamic();
  434. }
  435. // Return whether this is a placeholder symbol from a plugin object.
  436. bool
  437. is_placeholder() const
  438. {
  439. return this->source_ == FROM_OBJECT && this->object()->pluginobj() != NULL;
  440. }
  441. // Return whether this is an undefined symbol.
  442. bool
  443. is_undefined() const
  444. {
  445. bool is_ordinary;
  446. return ((this->source_ == FROM_OBJECT
  447. && this->shndx(&is_ordinary) == elfcpp::SHN_UNDEF
  448. && is_ordinary)
  449. || this->source_ == IS_UNDEFINED);
  450. }
  451. // Return whether this is a weak undefined symbol.
  452. bool
  453. is_weak_undefined() const
  454. {
  455. return (this->is_undefined()
  456. && (this->binding() == elfcpp::STB_WEAK
  457. || this->is_undef_binding_weak()
  458. || parameters->options().weak_unresolved_symbols()));
  459. }
  460. // Return whether this is a strong undefined symbol.
  461. bool
  462. is_strong_undefined() const
  463. {
  464. return (this->is_undefined()
  465. && this->binding() != elfcpp::STB_WEAK
  466. && !this->is_undef_binding_weak()
  467. && !parameters->options().weak_unresolved_symbols());
  468. }
  469. // Return whether this is an absolute symbol.
  470. bool
  471. is_absolute() const
  472. {
  473. bool is_ordinary;
  474. return ((this->source_ == FROM_OBJECT
  475. && this->shndx(&is_ordinary) == elfcpp::SHN_ABS
  476. && !is_ordinary)
  477. || this->source_ == IS_CONSTANT);
  478. }
  479. // Return whether this is a common symbol.
  480. bool
  481. is_common() const
  482. {
  483. if (this->source_ != FROM_OBJECT)
  484. return false;
  485. bool is_ordinary;
  486. unsigned int shndx = this->shndx(&is_ordinary);
  487. return !is_ordinary && Symbol::is_common_shndx(shndx);
  488. }
  489. // Return whether this symbol can be seen outside this object.
  490. bool
  491. is_externally_visible() const
  492. {
  493. return ((this->visibility_ == elfcpp::STV_DEFAULT
  494. || this->visibility_ == elfcpp::STV_PROTECTED)
  495. && !this->is_forced_local_);
  496. }
  497. // Return true if this symbol can be preempted by a definition in
  498. // another link unit.
  499. bool
  500. is_preemptible() const
  501. {
  502. // It doesn't make sense to ask whether a symbol defined in
  503. // another object is preemptible.
  504. gold_assert(!this->is_from_dynobj());
  505. // It doesn't make sense to ask whether an undefined symbol
  506. // is preemptible.
  507. gold_assert(!this->is_undefined());
  508. // If a symbol does not have default visibility, it can not be
  509. // seen outside this link unit and therefore is not preemptible.
  510. if (this->visibility_ != elfcpp::STV_DEFAULT)
  511. return false;
  512. // If this symbol has been forced to be a local symbol by a
  513. // version script, then it is not visible outside this link unit
  514. // and is not preemptible.
  515. if (this->is_forced_local_)
  516. return false;
  517. // If we are not producing a shared library, then nothing is
  518. // preemptible.
  519. if (!parameters->options().shared())
  520. return false;
  521. // If the symbol was named in a --dynamic-list script, it is preemptible.
  522. if (parameters->options().in_dynamic_list(this->name()))
  523. return true;
  524. // If the user used -Bsymbolic, then nothing (else) is preemptible.
  525. if (parameters->options().Bsymbolic())
  526. return false;
  527. // If the user used -Bsymbolic-functions, then functions are not
  528. // preemptible. We explicitly check for not being STT_OBJECT,
  529. // rather than for being STT_FUNC, because that is what the GNU
  530. // linker does.
  531. if (this->type() != elfcpp::STT_OBJECT
  532. && parameters->options().Bsymbolic_functions())
  533. return false;
  534. // Otherwise the symbol is preemptible.
  535. return true;
  536. }
  537. // Return true if this symbol is a function that needs a PLT entry.
  538. bool
  539. needs_plt_entry() const
  540. {
  541. // An undefined symbol from an executable does not need a PLT entry.
  542. if (this->is_undefined() && !parameters->options().shared())
  543. return false;
  544. // An STT_GNU_IFUNC symbol always needs a PLT entry, even when
  545. // doing a static link.
  546. if (this->type() == elfcpp::STT_GNU_IFUNC)
  547. return true;
  548. // We only need a PLT entry for a function.
  549. if (!this->is_func())
  550. return false;
  551. // If we're doing a static link or a -pie link, we don't create
  552. // PLT entries.
  553. if (parameters->doing_static_link()
  554. || parameters->options().pie())
  555. return false;
  556. // We need a PLT entry if the function is defined in a dynamic
  557. // object, or is undefined when building a shared object, or if it
  558. // is subject to pre-emption.
  559. return (this->is_from_dynobj()
  560. || this->is_undefined()
  561. || this->is_preemptible());
  562. }
  563. // When determining whether a reference to a symbol needs a dynamic
  564. // relocation, we need to know several things about the reference.
  565. // These flags may be or'ed together. 0 means that the symbol
  566. // isn't referenced at all.
  567. enum Reference_flags
  568. {
  569. // A reference to the symbol's absolute address. This includes
  570. // references that cause an absolute address to be stored in the GOT.
  571. ABSOLUTE_REF = 1,
  572. // A reference that calculates the offset of the symbol from some
  573. // anchor point, such as the PC or GOT.
  574. RELATIVE_REF = 2,
  575. // A TLS-related reference.
  576. TLS_REF = 4,
  577. // A reference that can always be treated as a function call.
  578. FUNCTION_CALL = 8,
  579. // When set, says that dynamic relocations are needed even if a
  580. // symbol has a plt entry.
  581. FUNC_DESC_ABI = 16,
  582. };
  583. // Given a direct absolute or pc-relative static relocation against
  584. // the global symbol, this function returns whether a dynamic relocation
  585. // is needed.
  586. bool
  587. needs_dynamic_reloc(int flags) const
  588. {
  589. // No dynamic relocations in a static link!
  590. if (parameters->doing_static_link())
  591. return false;
  592. // A reference to an undefined symbol from an executable should be
  593. // statically resolved to 0, and does not need a dynamic relocation.
  594. // This matches gnu ld behavior.
  595. if (this->is_undefined() && !parameters->options().shared())
  596. return false;
  597. // A reference to an absolute symbol does not need a dynamic relocation.
  598. if (this->is_absolute())
  599. return false;
  600. // An absolute reference within a position-independent output file
  601. // will need a dynamic relocation.
  602. if ((flags & ABSOLUTE_REF)
  603. && parameters->options().output_is_position_independent())
  604. return true;
  605. // A function call that can branch to a local PLT entry does not need
  606. // a dynamic relocation.
  607. if ((flags & FUNCTION_CALL) && this->has_plt_offset())
  608. return false;
  609. // A reference to any PLT entry in a non-position-independent executable
  610. // does not need a dynamic relocation.
  611. if (!(flags & FUNC_DESC_ABI)
  612. && !parameters->options().output_is_position_independent()
  613. && this->has_plt_offset())
  614. return false;
  615. // A reference to a symbol defined in a dynamic object or to a
  616. // symbol that is preemptible will need a dynamic relocation.
  617. if (this->is_from_dynobj()
  618. || this->is_undefined()
  619. || this->is_preemptible())
  620. return true;
  621. // For all other cases, return FALSE.
  622. return false;
  623. }
  624. // Whether we should use the PLT offset associated with a symbol for
  625. // a relocation. FLAGS is a set of Reference_flags.
  626. bool
  627. use_plt_offset(int flags) const
  628. {
  629. // If the symbol doesn't have a PLT offset, then naturally we
  630. // don't want to use it.
  631. if (!this->has_plt_offset())
  632. return false;
  633. // For a STT_GNU_IFUNC symbol we always have to use the PLT entry.
  634. if (this->type() == elfcpp::STT_GNU_IFUNC)
  635. return true;
  636. // If we are going to generate a dynamic relocation, then we will
  637. // wind up using that, so no need to use the PLT entry.
  638. if (this->needs_dynamic_reloc(flags))
  639. return false;
  640. // If the symbol is from a dynamic object, we need to use the PLT
  641. // entry.
  642. if (this->is_from_dynobj())
  643. return true;
  644. // If we are generating a shared object, and this symbol is
  645. // undefined or preemptible, we need to use the PLT entry.
  646. if (parameters->options().shared()
  647. && (this->is_undefined() || this->is_preemptible()))
  648. return true;
  649. // If this is a call to a weak undefined symbol, we need to use
  650. // the PLT entry; the symbol may be defined by a library loaded
  651. // at runtime.
  652. if ((flags & FUNCTION_CALL) && this->is_weak_undefined())
  653. return true;
  654. // Otherwise we can use the regular definition.
  655. return false;
  656. }
  657. // Given a direct absolute static relocation against
  658. // the global symbol, where a dynamic relocation is needed, this
  659. // function returns whether a relative dynamic relocation can be used.
  660. // The caller must determine separately whether the static relocation
  661. // is compatible with a relative relocation.
  662. bool
  663. can_use_relative_reloc(bool is_function_call) const
  664. {
  665. // A function call that can branch to a local PLT entry can
  666. // use a RELATIVE relocation.
  667. if (is_function_call && this->has_plt_offset())
  668. return true;
  669. // A reference to a symbol defined in a dynamic object or to a
  670. // symbol that is preemptible can not use a RELATIVE relocation.
  671. if (this->is_from_dynobj()
  672. || this->is_undefined()
  673. || this->is_preemptible())
  674. return false;
  675. // For all other cases, return TRUE.
  676. return true;
  677. }
  678. // Return the output section where this symbol is defined. Return
  679. // NULL if the symbol has an absolute value.
  680. Output_section*
  681. output_section() const;
  682. // Set the symbol's output section. This is used for symbols
  683. // defined in scripts. This should only be called after the symbol
  684. // table has been finalized.
  685. void
  686. set_output_section(Output_section*);
  687. // Set the symbol's output segment. This is used for pre-defined
  688. // symbols whose segments aren't known until after layout is done
  689. // (e.g., __ehdr_start).
  690. void
  691. set_output_segment(Output_segment*, Segment_offset_base);
  692. // Set the symbol to undefined. This is used for pre-defined
  693. // symbols whose segments aren't known until after layout is done
  694. // (e.g., __ehdr_start).
  695. void
  696. set_undefined();
  697. // Return whether there should be a warning for references to this
  698. // symbol.
  699. bool
  700. has_warning() const
  701. { return this->has_warning_; }
  702. // Mark this symbol as having a warning.
  703. void
  704. set_has_warning()
  705. { this->has_warning_ = true; }
  706. // Return whether this symbol is defined by a COPY reloc from a
  707. // dynamic object.
  708. bool
  709. is_copied_from_dynobj() const
  710. { return this->is_copied_from_dynobj_; }
  711. // Mark this symbol as defined by a COPY reloc.
  712. void
  713. set_is_copied_from_dynobj()
  714. { this->is_copied_from_dynobj_ = true; }
  715. // Return whether this symbol is forced to visibility STB_LOCAL
  716. // by a "local:" entry in a version script.
  717. bool
  718. is_forced_local() const
  719. { return this->is_forced_local_; }
  720. // Mark this symbol as forced to STB_LOCAL visibility.
  721. void
  722. set_is_forced_local()
  723. { this->is_forced_local_ = true; }
  724. // Return true if this may need a COPY relocation.
  725. // References from an executable object to non-function symbols
  726. // defined in a dynamic object may need a COPY relocation.
  727. bool
  728. may_need_copy_reloc() const
  729. {
  730. return (parameters->options().copyreloc()
  731. && this->is_from_dynobj()
  732. && !this->is_func());
  733. }
  734. // Return true if this symbol was predefined by the linker.
  735. bool
  736. is_predefined() const
  737. { return this->is_predefined_; }
  738. // Return true if this is a C++ vtable symbol.
  739. bool
  740. is_cxx_vtable() const
  741. { return is_prefix_of("_ZTV", this->name_); }
  742. protected:
  743. // Instances of this class should always be created at a specific
  744. // size.
  745. Symbol()
  746. { memset(this, 0, sizeof *this); }
  747. // Initialize the general fields.
  748. void
  749. init_fields(const char* name, const char* version,
  750. elfcpp::STT type, elfcpp::STB binding,
  751. elfcpp::STV visibility, unsigned char nonvis);
  752. // Initialize fields from an ELF symbol in OBJECT. ST_SHNDX is the
  753. // section index, IS_ORDINARY is whether it is a normal section
  754. // index rather than a special code.
  755. template<int size, bool big_endian>
  756. void
  757. init_base_object(const char* name, const char* version, Object* object,
  758. const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
  759. bool is_ordinary);
  760. // Initialize fields for an Output_data.
  761. void
  762. init_base_output_data(const char* name, const char* version, Output_data*,
  763. elfcpp::STT, elfcpp::STB, elfcpp::STV,
  764. unsigned char nonvis, bool offset_is_from_end,
  765. bool is_predefined);
  766. // Initialize fields for an Output_segment.
  767. void
  768. init_base_output_segment(const char* name, const char* version,
  769. Output_segment* os, elfcpp::STT type,
  770. elfcpp::STB binding, elfcpp::STV visibility,
  771. unsigned char nonvis,
  772. Segment_offset_base offset_base,
  773. bool is_predefined);
  774. // Initialize fields for a constant.
  775. void
  776. init_base_constant(const char* name, const char* version, elfcpp::STT type,
  777. elfcpp::STB binding, elfcpp::STV visibility,
  778. unsigned char nonvis, bool is_predefined);
  779. // Initialize fields for an undefined symbol.
  780. void
  781. init_base_undefined(const char* name, const char* version, elfcpp::STT type,
  782. elfcpp::STB binding, elfcpp::STV visibility,
  783. unsigned char nonvis);
  784. // Override existing symbol.
  785. template<int size, bool big_endian>
  786. void
  787. override_base(const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
  788. bool is_ordinary, Object* object, const char* version);
  789. // Override existing symbol with a special symbol.
  790. void
  791. override_base_with_special(const Symbol* from);
  792. // Override symbol version.
  793. void
  794. override_version(const char* version);
  795. // Allocate a common symbol by giving it a location in the output
  796. // file.
  797. void
  798. allocate_base_common(Output_data*);
  799. private:
  800. Symbol(const Symbol&);
  801. Symbol& operator=(const Symbol&);
  802. // Symbol name (expected to point into a Stringpool).
  803. const char* name_;
  804. // Symbol version (expected to point into a Stringpool). This may
  805. // be NULL.
  806. const char* version_;
  807. union
  808. {
  809. // This struct is used if SOURCE_ == FROM_OBJECT.
  810. struct
  811. {
  812. // Object in which symbol is defined, or in which it was first
  813. // seen.
  814. Object* object;
  815. // Section number in object_ in which symbol is defined.
  816. unsigned int shndx;
  817. } from_object;
  818. // This struct is used if SOURCE_ == IN_OUTPUT_DATA.
  819. struct
  820. {
  821. // Output_data in which symbol is defined. Before
  822. // Layout::finalize the symbol's value is an offset within the
  823. // Output_data.
  824. Output_data* output_data;
  825. // True if the offset is from the end, false if the offset is
  826. // from the beginning.
  827. bool offset_is_from_end;
  828. } in_output_data;
  829. // This struct is used if SOURCE_ == IN_OUTPUT_SEGMENT.
  830. struct
  831. {
  832. // Output_segment in which the symbol is defined. Before
  833. // Layout::finalize the symbol's value is an offset.
  834. Output_segment* output_segment;
  835. // The base to use for the offset before Layout::finalize.
  836. Segment_offset_base offset_base;
  837. } in_output_segment;
  838. } u_;
  839. // The index of this symbol in the output file. If the symbol is
  840. // not going into the output file, this value is -1U. This field
  841. // starts as always holding zero. It is set to a non-zero value by
  842. // Symbol_table::finalize.
  843. unsigned int symtab_index_;
  844. // The index of this symbol in the dynamic symbol table. If the
  845. // symbol is not going into the dynamic symbol table, this value is
  846. // -1U. This field starts as always holding zero. It is set to a
  847. // non-zero value during Layout::finalize.
  848. unsigned int dynsym_index_;
  849. // The GOT section entries for this symbol. A symbol may have more
  850. // than one GOT offset (e.g., when mixing modules compiled with two
  851. // different TLS models), but will usually have at most one.
  852. Got_offset_list got_offsets_;
  853. // If this symbol has an entry in the PLT section, then this is the
  854. // offset from the start of the PLT section. This is -1U if there
  855. // is no PLT entry.
  856. unsigned int plt_offset_;
  857. // Symbol type (bits 0 to 3).
  858. elfcpp::STT type_ : 4;
  859. // Symbol binding (bits 4 to 7).
  860. elfcpp::STB binding_ : 4;
  861. // Symbol visibility (bits 8 to 9).
  862. elfcpp::STV visibility_ : 2;
  863. // Rest of symbol st_other field (bits 10 to 15).
  864. unsigned int nonvis_ : 6;
  865. // The type of symbol (bits 16 to 18).
  866. Source source_ : 3;
  867. // True if this is the default version of the symbol (bit 19).
  868. bool is_def_ : 1;
  869. // True if this symbol really forwards to another symbol. This is
  870. // used when we discover after the fact that two different entries
  871. // in the hash table really refer to the same symbol. This will
  872. // never be set for a symbol found in the hash table, but may be set
  873. // for a symbol found in the list of symbols attached to an Object.
  874. // It forwards to the symbol found in the forwarders_ map of
  875. // Symbol_table (bit 20).
  876. bool is_forwarder_ : 1;
  877. // True if the symbol has an alias in the weak_aliases table in
  878. // Symbol_table (bit 21).
  879. bool has_alias_ : 1;
  880. // True if this symbol needs to be in the dynamic symbol table (bit
  881. // 22).
  882. bool needs_dynsym_entry_ : 1;
  883. // True if we've seen this symbol in a regular object (bit 23).
  884. bool in_reg_ : 1;
  885. // True if we've seen this symbol in a dynamic object (bit 24).
  886. bool in_dyn_ : 1;
  887. // True if this is a dynamic symbol which needs a special value in
  888. // the dynamic symbol table (bit 25).
  889. bool needs_dynsym_value_ : 1;
  890. // True if there is a warning for this symbol (bit 26).
  891. bool has_warning_ : 1;
  892. // True if we are using a COPY reloc for this symbol, so that the
  893. // real definition lives in a dynamic object (bit 27).
  894. bool is_copied_from_dynobj_ : 1;
  895. // True if this symbol was forced to local visibility by a version
  896. // script (bit 28).
  897. bool is_forced_local_ : 1;
  898. // True if the field u_.from_object.shndx is an ordinary section
  899. // index, not one of the special codes from SHN_LORESERVE to
  900. // SHN_HIRESERVE (bit 29).
  901. bool is_ordinary_shndx_ : 1;
  902. // True if we've seen this symbol in a "real" ELF object (bit 30).
  903. // If the symbol has been seen in a relocatable, non-IR, object file,
  904. // it's known to be referenced from outside the IR. A reference from
  905. // a dynamic object doesn't count as a "real" ELF, and we'll simply
  906. // mark the symbol as "visible" from outside the IR. The compiler
  907. // can use this distinction to guide its handling of COMDAT symbols.
  908. bool in_real_elf_ : 1;
  909. // True if this symbol is defined in a section which was discarded
  910. // (bit 31).
  911. bool is_defined_in_discarded_section_ : 1;
  912. // True if UNDEF_BINDING_WEAK_ has been set (bit 32).
  913. bool undef_binding_set_ : 1;
  914. // True if this symbol was a weak undef resolved by a dynamic def
  915. // or by a special symbol (bit 33).
  916. bool undef_binding_weak_ : 1;
  917. // True if this symbol is a predefined linker symbol (bit 34).
  918. bool is_predefined_ : 1;
  919. };
  920. // The parts of a symbol which are size specific. Using a template
  921. // derived class like this helps us use less space on a 32-bit system.
  922. template<int size>
  923. class Sized_symbol : public Symbol
  924. {
  925. public:
  926. typedef typename elfcpp::Elf_types<size>::Elf_Addr Value_type;
  927. typedef typename elfcpp::Elf_types<size>::Elf_WXword Size_type;
  928. Sized_symbol()
  929. { }
  930. // Initialize fields from an ELF symbol in OBJECT. ST_SHNDX is the
  931. // section index, IS_ORDINARY is whether it is a normal section
  932. // index rather than a special code.
  933. template<bool big_endian>
  934. void
  935. init_object(const char* name, const char* version, Object* object,
  936. const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
  937. bool is_ordinary);
  938. // Initialize fields for an Output_data.
  939. void
  940. init_output_data(const char* name, const char* version, Output_data*,
  941. Value_type value, Size_type symsize, elfcpp::STT,
  942. elfcpp::STB, elfcpp::STV, unsigned char nonvis,
  943. bool offset_is_from_end, bool is_predefined);
  944. // Initialize fields for an Output_segment.
  945. void
  946. init_output_segment(const char* name, const char* version, Output_segment*,
  947. Value_type value, Size_type symsize, elfcpp::STT,
  948. elfcpp::STB, elfcpp::STV, unsigned char nonvis,
  949. Segment_offset_base offset_base, bool is_predefined);
  950. // Initialize fields for a constant.
  951. void
  952. init_constant(const char* name, const char* version, Value_type value,
  953. Size_type symsize, elfcpp::STT, elfcpp::STB, elfcpp::STV,
  954. unsigned char nonvis, bool is_predefined);
  955. // Initialize fields for an undefined symbol.
  956. void
  957. init_undefined(const char* name, const char* version, elfcpp::STT,
  958. elfcpp::STB, elfcpp::STV, unsigned char nonvis);
  959. // Override existing symbol.
  960. template<bool big_endian>
  961. void
  962. override(const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
  963. bool is_ordinary, Object* object, const char* version);
  964. // Override existing symbol with a special symbol.
  965. void
  966. override_with_special(const Sized_symbol<size>*);
  967. // Return the symbol's value.
  968. Value_type
  969. value() const
  970. { return this->value_; }
  971. // Return the symbol's size (we can't call this 'size' because that
  972. // is a template parameter).
  973. Size_type
  974. symsize() const
  975. { return this->symsize_; }
  976. // Set the symbol size. This is used when resolving common symbols.
  977. void
  978. set_symsize(Size_type symsize)
  979. { this->symsize_ = symsize; }
  980. // Set the symbol value. This is called when we store the final
  981. // values of the symbols into the symbol table.
  982. void
  983. set_value(Value_type value)
  984. { this->value_ = value; }
  985. // Allocate a common symbol by giving it a location in the output
  986. // file.
  987. void
  988. allocate_common(Output_data*, Value_type value);
  989. private:
  990. Sized_symbol(const Sized_symbol&);
  991. Sized_symbol& operator=(const Sized_symbol&);
  992. // Symbol value. Before Layout::finalize this is the offset in the
  993. // input section. This is set to the final value during
  994. // Layout::finalize.
  995. Value_type value_;
  996. // Symbol size.
  997. Size_type symsize_;
  998. };
  999. // A struct describing a symbol defined by the linker, where the value
  1000. // of the symbol is defined based on an output section. This is used
  1001. // for symbols defined by the linker, like "_init_array_start".
  1002. struct Define_symbol_in_section
  1003. {
  1004. // The symbol name.
  1005. const char* name;
  1006. // The name of the output section with which this symbol should be
  1007. // associated. If there is no output section with that name, the
  1008. // symbol will be defined as zero.
  1009. const char* output_section;
  1010. // The offset of the symbol within the output section. This is an
  1011. // offset from the start of the output section, unless start_at_end
  1012. // is true, in which case this is an offset from the end of the
  1013. // output section.
  1014. uint64_t value;
  1015. // The size of the symbol.
  1016. uint64_t size;
  1017. // The symbol type.
  1018. elfcpp::STT type;
  1019. // The symbol binding.
  1020. elfcpp::STB binding;
  1021. // The symbol visibility.
  1022. elfcpp::STV visibility;
  1023. // The rest of the st_other field.
  1024. unsigned char nonvis;
  1025. // If true, the value field is an offset from the end of the output
  1026. // section.
  1027. bool offset_is_from_end;
  1028. // If true, this symbol is defined only if we see a reference to it.
  1029. bool only_if_ref;
  1030. };
  1031. // A struct describing a symbol defined by the linker, where the value
  1032. // of the symbol is defined based on a segment. This is used for
  1033. // symbols defined by the linker, like "_end". We describe the
  1034. // segment with which the symbol should be associated by its
  1035. // characteristics. If no segment meets these characteristics, the
  1036. // symbol will be defined as zero. If there is more than one segment
  1037. // which meets these characteristics, we will use the first one.
  1038. struct Define_symbol_in_segment
  1039. {
  1040. // The symbol name.
  1041. const char* name;
  1042. // The segment type where the symbol should be defined, typically
  1043. // PT_LOAD.
  1044. elfcpp::PT segment_type;
  1045. // Bitmask of segment flags which must be set.
  1046. elfcpp::PF segment_flags_set;
  1047. // Bitmask of segment flags which must be clear.
  1048. elfcpp::PF segment_flags_clear;
  1049. // The offset of the symbol within the segment. The offset is
  1050. // calculated from the position set by offset_base.
  1051. uint64_t value;
  1052. // The size of the symbol.
  1053. uint64_t size;
  1054. // The symbol type.
  1055. elfcpp::STT type;
  1056. // The symbol binding.
  1057. elfcpp::STB binding;
  1058. // The symbol visibility.
  1059. elfcpp::STV visibility;
  1060. // The rest of the st_other field.
  1061. unsigned char nonvis;
  1062. // The base from which we compute the offset.
  1063. Symbol::Segment_offset_base offset_base;
  1064. // If true, this symbol is defined only if we see a reference to it.
  1065. bool only_if_ref;
  1066. };
  1067. // Specify an object/section/offset location. Used by ODR code.
  1068. struct Symbol_location
  1069. {
  1070. // Object where the symbol is defined.
  1071. Object* object;
  1072. // Section-in-object where the symbol is defined.
  1073. unsigned int shndx;
  1074. // For relocatable objects, offset-in-section where the symbol is defined.
  1075. // For dynamic objects, address where the symbol is defined.
  1076. off_t offset;
  1077. bool operator==(const Symbol_location& that) const
  1078. {
  1079. return (this->object == that.object
  1080. && this->shndx == that.shndx
  1081. && this->offset == that.offset);
  1082. }
  1083. };
  1084. // This class manages warnings. Warnings are a GNU extension. When
  1085. // we see a section named .gnu.warning.SYM in an object file, and if
  1086. // we wind using the definition of SYM from that object file, then we
  1087. // will issue a warning for any relocation against SYM from a
  1088. // different object file. The text of the warning is the contents of
  1089. // the section. This is not precisely the definition used by the old
  1090. // GNU linker; the old GNU linker treated an occurrence of
  1091. // .gnu.warning.SYM as defining a warning symbol. A warning symbol
  1092. // would trigger a warning on any reference. However, it was
  1093. // inconsistent in that a warning in a dynamic object only triggered
  1094. // if there was no definition in a regular object. This linker is
  1095. // different in that we only issue a warning if we use the symbol
  1096. // definition from the same object file as the warning section.
  1097. class Warnings
  1098. {
  1099. public:
  1100. Warnings()
  1101. : warnings_()
  1102. { }
  1103. // Add a warning for symbol NAME in object OBJ. WARNING is the text
  1104. // of the warning.
  1105. void
  1106. add_warning(Symbol_table* symtab, const char* name, Object* obj,
  1107. const std::string& warning);
  1108. // For each symbol for which we should give a warning, make a note
  1109. // on the symbol.
  1110. void
  1111. note_warnings(Symbol_table* symtab);
  1112. // Issue a warning for a reference to SYM at RELINFO's location.
  1113. template<int size, bool big_endian>
  1114. void
  1115. issue_warning(const Symbol* sym, const Relocate_info<size, big_endian>*,
  1116. size_t relnum, off_t reloffset) const;
  1117. private:
  1118. Warnings(const Warnings&);
  1119. Warnings& operator=(const Warnings&);
  1120. // What we need to know to get the warning text.
  1121. struct Warning_location
  1122. {
  1123. // The object the warning is in.
  1124. Object* object;
  1125. // The warning text.
  1126. std::string text;
  1127. Warning_location()
  1128. : object(NULL), text()
  1129. { }
  1130. void
  1131. set(Object* o, const std::string& t)
  1132. {
  1133. this->object = o;
  1134. this->text = t;
  1135. }
  1136. };
  1137. // A mapping from warning symbol names (canonicalized in
  1138. // Symbol_table's namepool_ field) to warning information.
  1139. typedef Unordered_map<const char*, Warning_location> Warning_table;
  1140. Warning_table warnings_;
  1141. };
  1142. // The main linker symbol table.
  1143. class Symbol_table
  1144. {
  1145. public:
  1146. // The different places where a symbol definition can come from.
  1147. enum Defined
  1148. {
  1149. // Defined in an object file--the normal case.
  1150. OBJECT,
  1151. // Defined for a COPY reloc.
  1152. COPY,
  1153. // Defined on the command line using --defsym.
  1154. DEFSYM,
  1155. // Defined (so to speak) on the command line using -u.
  1156. UNDEFINED,
  1157. // Defined in a linker script.
  1158. SCRIPT,
  1159. // Predefined by the linker.
  1160. PREDEFINED,
  1161. // Defined by the linker during an incremental base link, but not
  1162. // a predefined symbol (e.g., common, defined in script).
  1163. INCREMENTAL_BASE,
  1164. };
  1165. // The order in which we sort common symbols.
  1166. enum Sort_commons_order
  1167. {
  1168. SORT_COMMONS_BY_SIZE_DESCENDING,
  1169. SORT_COMMONS_BY_ALIGNMENT_DESCENDING,
  1170. SORT_COMMONS_BY_ALIGNMENT_ASCENDING
  1171. };
  1172. // COUNT is an estimate of how many symbols will be inserted in the
  1173. // symbol table. It's ok to put 0 if you don't know; a correct
  1174. // guess will just save some CPU by reducing hashtable resizes.
  1175. Symbol_table(unsigned int count, const Version_script_info& version_script);
  1176. ~Symbol_table();
  1177. void
  1178. set_icf(Icf* icf)
  1179. { this->icf_ = icf;}
  1180. Icf*
  1181. icf() const
  1182. { return this->icf_; }
  1183. // Returns true if ICF determined that this is a duplicate section.
  1184. bool
  1185. is_section_folded(Relobj* obj, unsigned int shndx) const;
  1186. void
  1187. set_gc(Garbage_collection* gc)
  1188. { this->gc_ = gc; }
  1189. Garbage_collection*
  1190. gc() const
  1191. { return this->gc_; }
  1192. // During garbage collection, this keeps undefined symbols.
  1193. void
  1194. gc_mark_undef_symbols(Layout*);
  1195. // This tells garbage collection that this symbol is referenced.
  1196. void
  1197. gc_mark_symbol(Symbol* sym);
  1198. // During garbage collection, this keeps sections that correspond to
  1199. // symbols seen in dynamic objects.
  1200. inline void
  1201. gc_mark_dyn_syms(Symbol* sym);
  1202. // Add COUNT external symbols from the relocatable object RELOBJ to
  1203. // the symbol table. SYMS is the symbols, SYMNDX_OFFSET is the
  1204. // offset in the symbol table of the first symbol, SYM_NAMES is
  1205. // their names, SYM_NAME_SIZE is the size of SYM_NAMES. This sets
  1206. // SYMPOINTERS to point to the symbols in the symbol table. It sets
  1207. // *DEFINED to the number of defined symbols.
  1208. template<int size, bool big_endian>
  1209. void
  1210. add_from_relobj(Sized_relobj_file<size, big_endian>* relobj,
  1211. const unsigned char* syms, size_t count,
  1212. size_t symndx_offset, const char* sym_names,
  1213. size_t sym_name_size,
  1214. typename Sized_relobj_file<size, big_endian>::Symbols*,
  1215. size_t* defined);
  1216. // Add one external symbol from the plugin object OBJ to the symbol table.
  1217. // Returns a pointer to the resolved symbol in the symbol table.
  1218. template<int size, bool big_endian>
  1219. Symbol*
  1220. add_from_pluginobj(Sized_pluginobj<size, big_endian>* obj,
  1221. const char* name, const char* ver,
  1222. elfcpp::Sym<size, big_endian>* sym);
  1223. // Add COUNT dynamic symbols from the dynamic object DYNOBJ to the
  1224. // symbol table. SYMS is the symbols. SYM_NAMES is their names.
  1225. // SYM_NAME_SIZE is the size of SYM_NAMES. The other parameters are
  1226. // symbol version data.
  1227. template<int size, bool big_endian>
  1228. void
  1229. add_from_dynobj(Sized_dynobj<size, big_endian>* dynobj,
  1230. const unsigned char* syms, size_t count,
  1231. const char* sym_names, size_t sym_name_size,
  1232. const unsigned char* versym, size_t versym_size,
  1233. const std::vector<const char*>*,
  1234. typename Sized_relobj_file<size, big_endian>::Symbols*,
  1235. size_t* defined);
  1236. // Add one external symbol from the incremental object OBJ to the symbol
  1237. // table. Returns a pointer to the resolved symbol in the symbol table.
  1238. template<int size, bool big_endian>
  1239. Sized_symbol<size>*
  1240. add_from_incrobj(Object* obj, const char* name,
  1241. const char* ver, elfcpp::Sym<size, big_endian>* sym);
  1242. // Define a special symbol based on an Output_data. It is a
  1243. // multiple definition error if this symbol is already defined.
  1244. Symbol*
  1245. define_in_output_data(const char* name, const char* version, Defined,
  1246. Output_data*, uint64_t value, uint64_t symsize,
  1247. elfcpp::STT type, elfcpp::STB binding,
  1248. elfcpp::STV visibility, unsigned char nonvis,
  1249. bool offset_is_from_end, bool only_if_ref);
  1250. // Define a special symbol based on an Output_segment. It is a
  1251. // multiple definition error if this symbol is already defined.
  1252. Symbol*
  1253. define_in_output_segment(const char* name, const char* version, Defined,
  1254. Output_segment*, uint64_t value, uint64_t symsize,
  1255. elfcpp::STT type, elfcpp::STB binding,
  1256. elfcpp::STV visibility, unsigned char nonvis,
  1257. Symbol::Segment_offset_base, bool only_if_ref);
  1258. // Define a special symbol with a constant value. It is a multiple
  1259. // definition error if this symbol is already defined.
  1260. Symbol*
  1261. define_as_constant(const char* name, const char* version, Defined,
  1262. uint64_t value, uint64_t symsize, elfcpp::STT type,
  1263. elfcpp::STB binding, elfcpp::STV visibility,
  1264. unsigned char nonvis, bool only_if_ref,
  1265. bool force_override);
  1266. // Define a set of symbols in output sections. If ONLY_IF_REF is
  1267. // true, only define them if they are referenced.
  1268. void
  1269. define_symbols(const Layout*, int count, const Define_symbol_in_section*,
  1270. bool only_if_ref);
  1271. // Define a set of symbols in output segments. If ONLY_IF_REF is
  1272. // true, only defined them if they are referenced.
  1273. void
  1274. define_symbols(const Layout*, int count, const Define_symbol_in_segment*,
  1275. bool only_if_ref);
  1276. // Define SYM using a COPY reloc. POSD is the Output_data where the
  1277. // symbol should be defined--typically a .dyn.bss section. VALUE is
  1278. // the offset within POSD.
  1279. template<int size>
  1280. void
  1281. define_with_copy_reloc(Sized_symbol<size>* sym, Output_data* posd,
  1282. typename elfcpp::Elf_types<size>::Elf_Addr);
  1283. // Look up a symbol.
  1284. Symbol*
  1285. lookup(const char*, const char* version = NULL) const;
  1286. // Return the real symbol associated with the forwarder symbol FROM.
  1287. Symbol*
  1288. resolve_forwards(const Symbol* from) const;
  1289. // Return the sized version of a symbol in this table.
  1290. template<int size>
  1291. Sized_symbol<size>*
  1292. get_sized_symbol(Symbol*) const;
  1293. template<int size>
  1294. const Sized_symbol<size>*
  1295. get_sized_symbol(const Symbol*) const;
  1296. // Return the count of undefined symbols seen.
  1297. size_t
  1298. saw_undefined() const
  1299. { return this->saw_undefined_; }
  1300. // Allocate the common symbols
  1301. void
  1302. allocate_commons(Layout*, Mapfile*);
  1303. // Add a warning for symbol NAME in object OBJ. WARNING is the text
  1304. // of the warning.
  1305. void
  1306. add_warning(const char* name, Object* obj, const std::string& warning)
  1307. { this->warnings_.add_warning(this, name, obj, warning); }
  1308. // Canonicalize a symbol name for use in the hash table.
  1309. const char*
  1310. canonicalize_name(const char* name)
  1311. { return this->namepool_.add(name, true, NULL); }
  1312. // Possibly issue a warning for a reference to SYM at LOCATION which
  1313. // is in OBJ.
  1314. template<int size, bool big_endian>
  1315. void
  1316. issue_warning(const Symbol* sym,
  1317. const Relocate_info<size, big_endian>* relinfo,
  1318. size_t relnum, off_t reloffset) const
  1319. { this->warnings_.issue_warning(sym, relinfo, relnum, reloffset); }
  1320. // Check candidate_odr_violations_ to find symbols with the same name
  1321. // but apparently different definitions (different source-file/line-no).
  1322. void
  1323. detect_odr_violations(const Task*, const char* output_file_name) const;
  1324. // Add any undefined symbols named on the command line to the symbol
  1325. // table.
  1326. void
  1327. add_undefined_symbols_from_command_line(Layout*);
  1328. // SYM is defined using a COPY reloc. Return the dynamic object
  1329. // where the original definition was found.
  1330. Dynobj*
  1331. get_copy_source(const Symbol* sym) const;
  1332. // Set the dynamic symbol indexes. INDEX is the index of the first
  1333. // global dynamic symbol. Pointers to the symbols are stored into
  1334. // the vector. The names are stored into the Stringpool. This
  1335. // returns an updated dynamic symbol index.
  1336. unsigned int
  1337. set_dynsym_indexes(unsigned int index, std::vector<Symbol*>*,
  1338. Stringpool*, Versions*);
  1339. // Finalize the symbol table after we have set the final addresses
  1340. // of all the input sections. This sets the final symbol indexes,
  1341. // values and adds the names to *POOL. *PLOCAL_SYMCOUNT is the
  1342. // index of the first global symbol. OFF is the file offset of the
  1343. // global symbol table, DYNOFF is the offset of the globals in the
  1344. // dynamic symbol table, DYN_GLOBAL_INDEX is the index of the first
  1345. // global dynamic symbol, and DYNCOUNT is the number of global
  1346. // dynamic symbols. This records the parameters, and returns the
  1347. // new file offset. It updates *PLOCAL_SYMCOUNT if it created any
  1348. // local symbols.
  1349. off_t
  1350. finalize(off_t off, off_t dynoff, size_t dyn_global_index, size_t dyncount,
  1351. Stringpool* pool, unsigned int* plocal_symcount);
  1352. // Set the final file offset of the symbol table.
  1353. void
  1354. set_file_offset(off_t off)
  1355. { this->offset_ = off; }
  1356. // Status code of Symbol_table::compute_final_value.
  1357. enum Compute_final_value_status
  1358. {
  1359. // No error.
  1360. CFVS_OK,
  1361. // Unsupported symbol section.
  1362. CFVS_UNSUPPORTED_SYMBOL_SECTION,
  1363. // No output section.
  1364. CFVS_NO_OUTPUT_SECTION
  1365. };
  1366. // Compute the final value of SYM and store status in location PSTATUS.
  1367. // During relaxation, this may be called multiple times for a symbol to
  1368. // compute its would-be final value in each relaxation pass.
  1369. template<int size>
  1370. typename Sized_symbol<size>::Value_type
  1371. compute_final_value(const Sized_symbol<size>* sym,
  1372. Compute_final_value_status* pstatus) const;
  1373. // Return the index of the first global symbol.
  1374. unsigned int
  1375. first_global_index() const
  1376. { return this->first_global_index_; }
  1377. // Return the total number of symbols in the symbol table.
  1378. unsigned int
  1379. output_count() const
  1380. { return this->output_count_; }
  1381. // Write out the global symbols.
  1382. void
  1383. write_globals(const Stringpool*, const Stringpool*,
  1384. Output_symtab_xindex*, Output_symtab_xindex*,
  1385. Output_file*) const;
  1386. // Write out a section symbol. Return the updated offset.
  1387. void
  1388. write_section_symbol(const Output_section*, Output_symtab_xindex*,
  1389. Output_file*, off_t) const;
  1390. // Loop over all symbols, applying the function F to each.
  1391. template<int size, typename F>
  1392. void
  1393. for_all_symbols(F f) const
  1394. {
  1395. for (Symbol_table_type::const_iterator p = this->table_.begin();
  1396. p != this->table_.end();
  1397. ++p)
  1398. {
  1399. Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(p->second);
  1400. f(sym);
  1401. }
  1402. }
  1403. // Dump statistical information to stderr.
  1404. void
  1405. print_stats() const;
  1406. // Return the version script information.
  1407. const Version_script_info&
  1408. version_script() const
  1409. { return version_script_; }
  1410. private:
  1411. Symbol_table(const Symbol_table&);
  1412. Symbol_table& operator=(const Symbol_table&);
  1413. // The type of the list of common symbols.
  1414. typedef std::vector<Symbol*> Commons_type;
  1415. // The type of the symbol hash table.
  1416. typedef std::pair<Stringpool::Key, Stringpool::Key> Symbol_table_key;
  1417. // The hash function. The key values are Stringpool keys.
  1418. struct Symbol_table_hash
  1419. {
  1420. inline size_t
  1421. operator()(const Symbol_table_key& key) const
  1422. {
  1423. return key.first ^ key.second;
  1424. }
  1425. };
  1426. struct Symbol_table_eq
  1427. {
  1428. bool
  1429. operator()(const Symbol_table_key&, const Symbol_table_key&) const;
  1430. };
  1431. typedef Unordered_map<Symbol_table_key, Symbol*, Symbol_table_hash,
  1432. Symbol_table_eq> Symbol_table_type;
  1433. // A map from symbol name (as a pointer into the namepool) to all
  1434. // the locations the symbols is (weakly) defined (and certain other
  1435. // conditions are met). This map will be used later to detect
  1436. // possible One Definition Rule (ODR) violations.
  1437. struct Symbol_location_hash
  1438. {
  1439. size_t operator()(const Symbol_location& loc) const
  1440. { return reinterpret_cast<uintptr_t>(loc.object) ^ loc.offset ^ loc.shndx; }
  1441. };
  1442. typedef Unordered_map<const char*,
  1443. Unordered_set<Symbol_location, Symbol_location_hash> >
  1444. Odr_map;
  1445. // Make FROM a forwarder symbol to TO.
  1446. void
  1447. make_forwarder(Symbol* from, Symbol* to);
  1448. // Add a symbol.
  1449. template<int size, bool big_endian>
  1450. Sized_symbol<size>*
  1451. add_from_object(Object*, const char* name, Stringpool::Key name_key,
  1452. const char* version, Stringpool::Key version_key,
  1453. bool def, const elfcpp::Sym<size, big_endian>& sym,
  1454. unsigned int st_shndx, bool is_ordinary,
  1455. unsigned int orig_st_shndx);
  1456. // Define a default symbol.
  1457. template<int size, bool big_endian>
  1458. void
  1459. define_default_version(Sized_symbol<size>*, bool,
  1460. Symbol_table_type::iterator);
  1461. // Resolve symbols.
  1462. template<int size, bool big_endian>
  1463. void
  1464. resolve(Sized_symbol<size>* to,
  1465. const elfcpp::Sym<size, big_endian>& sym,
  1466. unsigned int st_shndx, bool is_ordinary,
  1467. unsigned int orig_st_shndx,
  1468. Object*, const char* version,
  1469. bool is_default_version);
  1470. template<int size, bool big_endian>
  1471. void
  1472. resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from);
  1473. // Record that a symbol is forced to be local by a version script or
  1474. // by visibility.
  1475. void
  1476. force_local(Symbol*);
  1477. // Adjust NAME and *NAME_KEY for wrapping.
  1478. const char*
  1479. wrap_symbol(const char* name, Stringpool::Key* name_key);
  1480. // Whether we should override a symbol, based on flags in
  1481. // resolve.cc.
  1482. static bool
  1483. should_override(const Symbol*, unsigned int, elfcpp::STT, Defined,
  1484. Object*, bool*, bool*, bool);
  1485. // Report a problem in symbol resolution.
  1486. static void
  1487. report_resolve_problem(bool is_error, const char* msg, const Symbol* to,
  1488. Defined, Object* object);
  1489. // Override a symbol.
  1490. template<int size, bool big_endian>
  1491. void
  1492. override(Sized_symbol<size>* tosym,
  1493. const elfcpp::Sym<size, big_endian>& fromsym,
  1494. unsigned int st_shndx, bool is_ordinary,
  1495. Object* object, const char* version);
  1496. // Whether we should override a symbol with a special symbol which
  1497. // is automatically defined by the linker.
  1498. static bool
  1499. should_override_with_special(const Symbol*, elfcpp::STT, Defined);
  1500. // Override a symbol with a special symbol.
  1501. template<int size>
  1502. void
  1503. override_with_special(Sized_symbol<size>* tosym,
  1504. const Sized_symbol<size>* fromsym);
  1505. // Record all weak alias sets for a dynamic object.
  1506. template<int size>
  1507. void
  1508. record_weak_aliases(std::vector<Sized_symbol<size>*>*);
  1509. // Define a special symbol.
  1510. template<int size, bool big_endian>
  1511. Sized_symbol<size>*
  1512. define_special_symbol(const char** pname, const char** pversion,
  1513. bool only_if_ref, Sized_symbol<size>** poldsym,
  1514. bool* resolve_oldsym);
  1515. // Define a symbol in an Output_data, sized version.
  1516. template<int size>
  1517. Sized_symbol<size>*
  1518. do_define_in_output_data(const char* name, const char* version, Defined,
  1519. Output_data*,
  1520. typename elfcpp::Elf_types<size>::Elf_Addr value,
  1521. typename elfcpp::Elf_types<size>::Elf_WXword ssize,
  1522. elfcpp::STT type, elfcpp::STB binding,
  1523. elfcpp::STV visibility, unsigned char nonvis,
  1524. bool offset_is_from_end, bool only_if_ref);
  1525. // Define a symbol in an Output_segment, sized version.
  1526. template<int size>
  1527. Sized_symbol<size>*
  1528. do_define_in_output_segment(
  1529. const char* name, const char* version, Defined, Output_segment* os,
  1530. typename elfcpp::Elf_types<size>::Elf_Addr value,
  1531. typename elfcpp::Elf_types<size>::Elf_WXword ssize,
  1532. elfcpp::STT type, elfcpp::STB binding,
  1533. elfcpp::STV visibility, unsigned char nonvis,
  1534. Symbol::Segment_offset_base offset_base, bool only_if_ref);
  1535. // Define a symbol as a constant, sized version.
  1536. template<int size>
  1537. Sized_symbol<size>*
  1538. do_define_as_constant(
  1539. const char* name, const char* version, Defined,
  1540. typename elfcpp::Elf_types<size>::Elf_Addr value,
  1541. typename elfcpp::Elf_types<size>::Elf_WXword ssize,
  1542. elfcpp::STT type, elfcpp::STB binding,
  1543. elfcpp::STV visibility, unsigned char nonvis,
  1544. bool only_if_ref, bool force_override);
  1545. // Add any undefined symbols named on the command line to the symbol
  1546. // table, sized version.
  1547. template<int size>
  1548. void
  1549. do_add_undefined_symbols_from_command_line(Layout*);
  1550. // Add one undefined symbol.
  1551. template<int size>
  1552. void
  1553. add_undefined_symbol_from_command_line(const char* name);
  1554. // Types of common symbols.
  1555. enum Commons_section_type
  1556. {
  1557. COMMONS_NORMAL,
  1558. COMMONS_TLS,
  1559. COMMONS_SMALL,
  1560. COMMONS_LARGE
  1561. };
  1562. // Allocate the common symbols, sized version.
  1563. template<int size>
  1564. void
  1565. do_allocate_commons(Layout*, Mapfile*, Sort_commons_order);
  1566. // Allocate the common symbols from one list.
  1567. template<int size>
  1568. void
  1569. do_allocate_commons_list(Layout*, Commons_section_type, Commons_type*,
  1570. Mapfile*, Sort_commons_order);
  1571. // Returns all of the lines attached to LOC, not just the one the
  1572. // instruction actually came from. This helps the ODR checker avoid
  1573. // false positives.
  1574. static std::vector<std::string>
  1575. linenos_from_loc(const Task* task, const Symbol_location& loc);
  1576. // Implement detect_odr_violations.
  1577. template<int size, bool big_endian>
  1578. void
  1579. sized_detect_odr_violations() const;
  1580. // Finalize symbols specialized for size.
  1581. template<int size>
  1582. off_t
  1583. sized_finalize(off_t, Stringpool*, unsigned int*);
  1584. // Finalize a symbol. Return whether it should be added to the
  1585. // symbol table.
  1586. template<int size>
  1587. bool
  1588. sized_finalize_symbol(Symbol*);
  1589. // Add a symbol the final symtab by setting its index.
  1590. template<int size>
  1591. void
  1592. add_to_final_symtab(Symbol*, Stringpool*, unsigned int* pindex, off_t* poff);
  1593. // Write globals specialized for size and endianness.
  1594. template<int size, bool big_endian>
  1595. void
  1596. sized_write_globals(const Stringpool*, const Stringpool*,
  1597. Output_symtab_xindex*, Output_symtab_xindex*,
  1598. Output_file*) const;
  1599. // Write out a symbol to P.
  1600. template<int size, bool big_endian>
  1601. void
  1602. sized_write_symbol(Sized_symbol<size>*,
  1603. typename elfcpp::Elf_types<size>::Elf_Addr value,
  1604. unsigned int shndx, elfcpp::STB,
  1605. const Stringpool*, unsigned char* p) const;
  1606. // Possibly warn about an undefined symbol from a dynamic object.
  1607. void
  1608. warn_about_undefined_dynobj_symbol(Symbol*) const;
  1609. // Write out a section symbol, specialized for size and endianness.
  1610. template<int size, bool big_endian>
  1611. void
  1612. sized_write_section_symbol(const Output_section*, Output_symtab_xindex*,
  1613. Output_file*, off_t) const;
  1614. // The type of the list of symbols which have been forced local.
  1615. typedef std::vector<Symbol*> Forced_locals;
  1616. // A map from symbols with COPY relocs to the dynamic objects where
  1617. // they are defined.
  1618. typedef Unordered_map<const Symbol*, Dynobj*> Copied_symbol_dynobjs;
  1619. // We increment this every time we see a new undefined symbol, for
  1620. // use in archive groups.
  1621. size_t saw_undefined_;
  1622. // The index of the first global symbol in the output file.
  1623. unsigned int first_global_index_;
  1624. // The file offset within the output symtab section where we should
  1625. // write the table.
  1626. off_t offset_;
  1627. // The number of global symbols we want to write out.
  1628. unsigned int output_count_;
  1629. // The file offset of the global dynamic symbols, or 0 if none.
  1630. off_t dynamic_offset_;
  1631. // The index of the first global dynamic symbol.
  1632. unsigned int first_dynamic_global_index_;
  1633. // The number of global dynamic symbols, or 0 if none.
  1634. unsigned int dynamic_count_;
  1635. // The symbol hash table.
  1636. Symbol_table_type table_;
  1637. // A pool of symbol names. This is used for all global symbols.
  1638. // Entries in the hash table point into this pool.
  1639. Stringpool namepool_;
  1640. // Forwarding symbols.
  1641. Unordered_map<const Symbol*, Symbol*> forwarders_;
  1642. // Weak aliases. A symbol in this list points to the next alias.
  1643. // The aliases point to each other in a circular list.
  1644. Unordered_map<Symbol*, Symbol*> weak_aliases_;
  1645. // We don't expect there to be very many common symbols, so we keep
  1646. // a list of them. When we find a common symbol we add it to this
  1647. // list. It is possible that by the time we process the list the
  1648. // symbol is no longer a common symbol. It may also have become a
  1649. // forwarder.
  1650. Commons_type commons_;
  1651. // This is like the commons_ field, except that it holds TLS common
  1652. // symbols.
  1653. Commons_type tls_commons_;
  1654. // This is for small common symbols.
  1655. Commons_type small_commons_;
  1656. // This is for large common symbols.
  1657. Commons_type large_commons_;
  1658. // A list of symbols which have been forced to be local. We don't
  1659. // expect there to be very many of them, so we keep a list of them
  1660. // rather than walking the whole table to find them.
  1661. Forced_locals forced_locals_;
  1662. // Manage symbol warnings.
  1663. Warnings warnings_;
  1664. // Manage potential One Definition Rule (ODR) violations.
  1665. Odr_map candidate_odr_violations_;
  1666. // When we emit a COPY reloc for a symbol, we define it in an
  1667. // Output_data. When it's time to emit version information for it,
  1668. // we need to know the dynamic object in which we found the original
  1669. // definition. This maps symbols with COPY relocs to the dynamic
  1670. // object where they were defined.
  1671. Copied_symbol_dynobjs copied_symbol_dynobjs_;
  1672. // Information parsed from the version script, if any.
  1673. const Version_script_info& version_script_;
  1674. Garbage_collection* gc_;
  1675. Icf* icf_;
  1676. };
  1677. // We inline get_sized_symbol for efficiency.
  1678. template<int size>
  1679. Sized_symbol<size>*
  1680. Symbol_table::get_sized_symbol(Symbol* sym) const
  1681. {
  1682. gold_assert(size == parameters->target().get_size());
  1683. return static_cast<Sized_symbol<size>*>(sym);
  1684. }
  1685. template<int size>
  1686. const Sized_symbol<size>*
  1687. Symbol_table::get_sized_symbol(const Symbol* sym) const
  1688. {
  1689. gold_assert(size == parameters->target().get_size());
  1690. return static_cast<const Sized_symbol<size>*>(sym);
  1691. }
  1692. } // End namespace gold.
  1693. #endif // !defined(GOLD_SYMTAB_H)