dynobj.cc 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021
  1. // dynobj.cc -- dynamic object support for gold
  2. // Copyright (C) 2006-2022 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. #include "gold.h"
  18. #include <vector>
  19. #include <cstring>
  20. #include "elfcpp.h"
  21. #include "parameters.h"
  22. #include "script.h"
  23. #include "symtab.h"
  24. #include "dynobj.h"
  25. namespace gold
  26. {
  27. // Class Dynobj.
  28. // Sets up the default soname_ to use, in the (rare) cases we never
  29. // see a DT_SONAME entry.
  30. Dynobj::Dynobj(const std::string& name, Input_file* input_file, off_t offset)
  31. : Object(name, input_file, true, offset),
  32. needed_(),
  33. unknown_needed_(UNKNOWN_NEEDED_UNSET)
  34. {
  35. // This will be overridden by a DT_SONAME entry, hopefully. But if
  36. // we never see a DT_SONAME entry, our rule is to use the dynamic
  37. // object's filename. The only exception is when the dynamic object
  38. // is part of an archive (so the filename is the archive's
  39. // filename). In that case, we use just the dynobj's name-in-archive.
  40. if (input_file == NULL)
  41. this->soname_ = name;
  42. else
  43. {
  44. this->soname_ = input_file->found_name();
  45. if (this->offset() != 0)
  46. {
  47. std::string::size_type open_paren = this->name().find('(');
  48. std::string::size_type close_paren = this->name().find(')');
  49. if (open_paren != std::string::npos
  50. && close_paren != std::string::npos)
  51. {
  52. // It's an archive, and name() is of the form 'foo.a(bar.so)'.
  53. open_paren += 1;
  54. this->soname_ = this->name().substr(open_paren,
  55. close_paren - open_paren);
  56. }
  57. }
  58. }
  59. }
  60. // Class Sized_dynobj.
  61. template<int size, bool big_endian>
  62. Sized_dynobj<size, big_endian>::Sized_dynobj(
  63. const std::string& name,
  64. Input_file* input_file,
  65. off_t offset,
  66. const elfcpp::Ehdr<size, big_endian>& ehdr)
  67. : Dynobj(name, input_file, offset),
  68. elf_file_(this, ehdr),
  69. dynsym_shndx_(-1U),
  70. symbols_(NULL),
  71. defined_count_(0)
  72. {
  73. }
  74. // Set up the object.
  75. template<int size, bool big_endian>
  76. void
  77. Sized_dynobj<size, big_endian>::setup()
  78. {
  79. const unsigned int shnum = this->elf_file_.shnum();
  80. this->set_shnum(shnum);
  81. }
  82. // Find the SHT_DYNSYM section and the various version sections, and
  83. // the dynamic section, given the section headers.
  84. template<int size, bool big_endian>
  85. void
  86. Sized_dynobj<size, big_endian>::find_dynsym_sections(
  87. const unsigned char* pshdrs,
  88. unsigned int* pversym_shndx,
  89. unsigned int* pverdef_shndx,
  90. unsigned int* pverneed_shndx,
  91. unsigned int* pdynamic_shndx)
  92. {
  93. *pversym_shndx = -1U;
  94. *pverdef_shndx = -1U;
  95. *pverneed_shndx = -1U;
  96. *pdynamic_shndx = -1U;
  97. unsigned int symtab_shndx = 0;
  98. unsigned int xindex_shndx = 0;
  99. unsigned int xindex_link = 0;
  100. const unsigned int shnum = this->shnum();
  101. const unsigned char* p = pshdrs;
  102. for (unsigned int i = 0; i < shnum; ++i, p += This::shdr_size)
  103. {
  104. typename This::Shdr shdr(p);
  105. unsigned int* pi;
  106. switch (shdr.get_sh_type())
  107. {
  108. case elfcpp::SHT_DYNSYM:
  109. this->dynsym_shndx_ = i;
  110. if (xindex_shndx > 0 && xindex_link == i)
  111. {
  112. Xindex* xindex = new Xindex(this->elf_file_.large_shndx_offset());
  113. xindex->read_symtab_xindex<size, big_endian>(this, xindex_shndx,
  114. pshdrs);
  115. this->set_xindex(xindex);
  116. }
  117. pi = NULL;
  118. break;
  119. case elfcpp::SHT_SYMTAB:
  120. symtab_shndx = i;
  121. pi = NULL;
  122. break;
  123. case elfcpp::SHT_GNU_versym:
  124. pi = pversym_shndx;
  125. break;
  126. case elfcpp::SHT_GNU_verdef:
  127. pi = pverdef_shndx;
  128. break;
  129. case elfcpp::SHT_GNU_verneed:
  130. pi = pverneed_shndx;
  131. break;
  132. case elfcpp::SHT_DYNAMIC:
  133. pi = pdynamic_shndx;
  134. break;
  135. case elfcpp::SHT_SYMTAB_SHNDX:
  136. xindex_shndx = i;
  137. xindex_link = this->adjust_shndx(shdr.get_sh_link());
  138. if (xindex_link == this->dynsym_shndx_)
  139. {
  140. Xindex* xindex = new Xindex(this->elf_file_.large_shndx_offset());
  141. xindex->read_symtab_xindex<size, big_endian>(this, xindex_shndx,
  142. pshdrs);
  143. this->set_xindex(xindex);
  144. }
  145. pi = NULL;
  146. break;
  147. default:
  148. pi = NULL;
  149. break;
  150. }
  151. if (pi == NULL)
  152. continue;
  153. if (*pi != -1U)
  154. this->error(_("unexpected duplicate type %u section: %u, %u"),
  155. shdr.get_sh_type(), *pi, i);
  156. *pi = i;
  157. }
  158. // If there is no dynamic symbol table, use the normal symbol table.
  159. // On some SVR4 systems, a shared library is stored in an archive.
  160. // The version stored in the archive only has a normal symbol table.
  161. // It has an SONAME entry which points to another copy in the file
  162. // system which has a dynamic symbol table as usual. This is way of
  163. // addressing the issues which glibc addresses using GROUP with
  164. // libc_nonshared.a.
  165. if (this->dynsym_shndx_ == -1U && symtab_shndx != 0)
  166. {
  167. this->dynsym_shndx_ = symtab_shndx;
  168. if (xindex_shndx > 0 && xindex_link == symtab_shndx)
  169. {
  170. Xindex* xindex = new Xindex(this->elf_file_.large_shndx_offset());
  171. xindex->read_symtab_xindex<size, big_endian>(this, xindex_shndx,
  172. pshdrs);
  173. this->set_xindex(xindex);
  174. }
  175. }
  176. }
  177. // Read the contents of section SHNDX. PSHDRS points to the section
  178. // headers. TYPE is the expected section type. LINK is the expected
  179. // section link. Store the data in *VIEW and *VIEW_SIZE. The
  180. // section's sh_info field is stored in *VIEW_INFO.
  181. template<int size, bool big_endian>
  182. void
  183. Sized_dynobj<size, big_endian>::read_dynsym_section(
  184. const unsigned char* pshdrs,
  185. unsigned int shndx,
  186. elfcpp::SHT type,
  187. unsigned int link,
  188. File_view** view,
  189. section_size_type* view_size,
  190. unsigned int* view_info)
  191. {
  192. if (shndx == -1U)
  193. {
  194. *view = NULL;
  195. *view_size = 0;
  196. *view_info = 0;
  197. return;
  198. }
  199. typename This::Shdr shdr(pshdrs + shndx * This::shdr_size);
  200. gold_assert(shdr.get_sh_type() == type);
  201. if (this->adjust_shndx(shdr.get_sh_link()) != link)
  202. this->error(_("unexpected link in section %u header: %u != %u"),
  203. shndx, this->adjust_shndx(shdr.get_sh_link()), link);
  204. *view = this->get_lasting_view(shdr.get_sh_offset(), shdr.get_sh_size(),
  205. true, false);
  206. *view_size = convert_to_section_size_type(shdr.get_sh_size());
  207. *view_info = shdr.get_sh_info();
  208. }
  209. // Read the dynamic tags. Set the soname field if this shared object
  210. // has a DT_SONAME tag. Record the DT_NEEDED tags. PSHDRS points to
  211. // the section headers. DYNAMIC_SHNDX is the section index of the
  212. // SHT_DYNAMIC section. STRTAB_SHNDX, STRTAB, and STRTAB_SIZE are the
  213. // section index and contents of a string table which may be the one
  214. // associated with the SHT_DYNAMIC section.
  215. template<int size, bool big_endian>
  216. void
  217. Sized_dynobj<size, big_endian>::read_dynamic(const unsigned char* pshdrs,
  218. unsigned int dynamic_shndx,
  219. unsigned int strtab_shndx,
  220. const unsigned char* strtabu,
  221. off_t strtab_size)
  222. {
  223. typename This::Shdr dynamicshdr(pshdrs + dynamic_shndx * This::shdr_size);
  224. gold_assert(dynamicshdr.get_sh_type() == elfcpp::SHT_DYNAMIC);
  225. const off_t dynamic_size = dynamicshdr.get_sh_size();
  226. const unsigned char* pdynamic = this->get_view(dynamicshdr.get_sh_offset(),
  227. dynamic_size, true, false);
  228. const unsigned int link = this->adjust_shndx(dynamicshdr.get_sh_link());
  229. if (link != strtab_shndx)
  230. {
  231. if (link >= this->shnum())
  232. {
  233. this->error(_("DYNAMIC section %u link out of range: %u"),
  234. dynamic_shndx, link);
  235. return;
  236. }
  237. typename This::Shdr strtabshdr(pshdrs + link * This::shdr_size);
  238. if (strtabshdr.get_sh_type() != elfcpp::SHT_STRTAB)
  239. {
  240. this->error(_("DYNAMIC section %u link %u is not a strtab"),
  241. dynamic_shndx, link);
  242. return;
  243. }
  244. strtab_size = strtabshdr.get_sh_size();
  245. strtabu = this->get_view(strtabshdr.get_sh_offset(), strtab_size, false,
  246. false);
  247. }
  248. const char* const strtab = reinterpret_cast<const char*>(strtabu);
  249. for (const unsigned char* p = pdynamic;
  250. p < pdynamic + dynamic_size;
  251. p += This::dyn_size)
  252. {
  253. typename This::Dyn dyn(p);
  254. switch (dyn.get_d_tag())
  255. {
  256. case elfcpp::DT_NULL:
  257. // We should always see DT_NULL at the end of the dynamic
  258. // tags.
  259. return;
  260. case elfcpp::DT_SONAME:
  261. {
  262. off_t val = dyn.get_d_val();
  263. if (val >= strtab_size)
  264. this->error(_("DT_SONAME value out of range: %lld >= %lld"),
  265. static_cast<long long>(val),
  266. static_cast<long long>(strtab_size));
  267. else
  268. this->set_soname_string(strtab + val);
  269. }
  270. break;
  271. case elfcpp::DT_NEEDED:
  272. {
  273. off_t val = dyn.get_d_val();
  274. if (val >= strtab_size)
  275. this->error(_("DT_NEEDED value out of range: %lld >= %lld"),
  276. static_cast<long long>(val),
  277. static_cast<long long>(strtab_size));
  278. else
  279. this->add_needed(strtab + val);
  280. }
  281. break;
  282. default:
  283. break;
  284. }
  285. }
  286. this->error(_("missing DT_NULL in dynamic segment"));
  287. }
  288. // Read the symbols and sections from a dynamic object. We read the
  289. // dynamic symbols, not the normal symbols.
  290. template<int size, bool big_endian>
  291. void
  292. Sized_dynobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
  293. {
  294. this->base_read_symbols(sd);
  295. }
  296. // Read the symbols and sections from a dynamic object. We read the
  297. // dynamic symbols, not the normal symbols. This is common code for
  298. // all target-specific overrides of do_read_symbols().
  299. template<int size, bool big_endian>
  300. void
  301. Sized_dynobj<size, big_endian>::base_read_symbols(Read_symbols_data* sd)
  302. {
  303. this->read_section_data(&this->elf_file_, sd);
  304. const unsigned char* const pshdrs = sd->section_headers->data();
  305. unsigned int versym_shndx;
  306. unsigned int verdef_shndx;
  307. unsigned int verneed_shndx;
  308. unsigned int dynamic_shndx;
  309. this->find_dynsym_sections(pshdrs, &versym_shndx, &verdef_shndx,
  310. &verneed_shndx, &dynamic_shndx);
  311. unsigned int strtab_shndx = -1U;
  312. sd->symbols = NULL;
  313. sd->symbols_size = 0;
  314. sd->external_symbols_offset = 0;
  315. sd->symbol_names = NULL;
  316. sd->symbol_names_size = 0;
  317. sd->versym = NULL;
  318. sd->versym_size = 0;
  319. sd->verdef = NULL;
  320. sd->verdef_size = 0;
  321. sd->verdef_info = 0;
  322. sd->verneed = NULL;
  323. sd->verneed_size = 0;
  324. sd->verneed_info = 0;
  325. const unsigned char* namesu = sd->section_names->data();
  326. const char* names = reinterpret_cast<const char*>(namesu);
  327. if (memmem(names, sd->section_names_size, ".zdebug_", 8) != NULL)
  328. {
  329. Compressed_section_map* compressed_sections =
  330. build_compressed_section_map<size, big_endian>(
  331. pshdrs, this->shnum(), names, sd->section_names_size, this, true);
  332. if (compressed_sections != NULL)
  333. this->set_compressed_sections(compressed_sections);
  334. }
  335. if (this->dynsym_shndx_ != -1U)
  336. {
  337. // Get the dynamic symbols.
  338. typename This::Shdr dynsymshdr(pshdrs
  339. + this->dynsym_shndx_ * This::shdr_size);
  340. sd->symbols = this->get_lasting_view(dynsymshdr.get_sh_offset(),
  341. dynsymshdr.get_sh_size(), true,
  342. false);
  343. sd->symbols_size =
  344. convert_to_section_size_type(dynsymshdr.get_sh_size());
  345. // Get the symbol names.
  346. strtab_shndx = this->adjust_shndx(dynsymshdr.get_sh_link());
  347. if (strtab_shndx >= this->shnum())
  348. {
  349. this->error(_("invalid dynamic symbol table name index: %u"),
  350. strtab_shndx);
  351. return;
  352. }
  353. typename This::Shdr strtabshdr(pshdrs + strtab_shndx * This::shdr_size);
  354. if (strtabshdr.get_sh_type() != elfcpp::SHT_STRTAB)
  355. {
  356. this->error(_("dynamic symbol table name section "
  357. "has wrong type: %u"),
  358. static_cast<unsigned int>(strtabshdr.get_sh_type()));
  359. return;
  360. }
  361. sd->symbol_names = this->get_lasting_view(strtabshdr.get_sh_offset(),
  362. strtabshdr.get_sh_size(),
  363. false, false);
  364. sd->symbol_names_size =
  365. convert_to_section_size_type(strtabshdr.get_sh_size());
  366. // Get the version information.
  367. unsigned int dummy;
  368. this->read_dynsym_section(pshdrs, versym_shndx, elfcpp::SHT_GNU_versym,
  369. this->dynsym_shndx_,
  370. &sd->versym, &sd->versym_size, &dummy);
  371. // We require that the version definition and need section link
  372. // to the same string table as the dynamic symbol table. This
  373. // is not a technical requirement, but it always happens in
  374. // practice. We could change this if necessary.
  375. this->read_dynsym_section(pshdrs, verdef_shndx, elfcpp::SHT_GNU_verdef,
  376. strtab_shndx, &sd->verdef, &sd->verdef_size,
  377. &sd->verdef_info);
  378. this->read_dynsym_section(pshdrs, verneed_shndx, elfcpp::SHT_GNU_verneed,
  379. strtab_shndx, &sd->verneed, &sd->verneed_size,
  380. &sd->verneed_info);
  381. }
  382. // Read the SHT_DYNAMIC section to find whether this shared object
  383. // has a DT_SONAME tag and to record any DT_NEEDED tags. This
  384. // doesn't really have anything to do with reading the symbols, but
  385. // this is a convenient place to do it.
  386. if (dynamic_shndx != -1U)
  387. this->read_dynamic(pshdrs, dynamic_shndx, strtab_shndx,
  388. (sd->symbol_names == NULL
  389. ? NULL
  390. : sd->symbol_names->data()),
  391. sd->symbol_names_size);
  392. }
  393. // Return the Xindex structure to use for object with lots of
  394. // sections.
  395. template<int size, bool big_endian>
  396. Xindex*
  397. Sized_dynobj<size, big_endian>::do_initialize_xindex()
  398. {
  399. gold_assert(this->dynsym_shndx_ != -1U);
  400. Xindex* xindex = new Xindex(this->elf_file_.large_shndx_offset());
  401. xindex->initialize_symtab_xindex<size, big_endian>(this, this->dynsym_shndx_);
  402. return xindex;
  403. }
  404. // Lay out the input sections for a dynamic object. We don't want to
  405. // include sections from a dynamic object, so all that we actually do
  406. // here is check for .gnu.warning and .note.GNU-split-stack sections.
  407. template<int size, bool big_endian>
  408. void
  409. Sized_dynobj<size, big_endian>::do_layout(Symbol_table* symtab,
  410. Layout*,
  411. Read_symbols_data* sd)
  412. {
  413. const unsigned int shnum = this->shnum();
  414. if (shnum == 0)
  415. return;
  416. // Get the section headers.
  417. const unsigned char* pshdrs = sd->section_headers->data();
  418. // Get the section names.
  419. const unsigned char* pnamesu = sd->section_names->data();
  420. const char* pnames = reinterpret_cast<const char*>(pnamesu);
  421. // Skip the first, dummy, section.
  422. pshdrs += This::shdr_size;
  423. for (unsigned int i = 1; i < shnum; ++i, pshdrs += This::shdr_size)
  424. {
  425. typename This::Shdr shdr(pshdrs);
  426. if (shdr.get_sh_name() >= sd->section_names_size)
  427. {
  428. this->error(_("bad section name offset for section %u: %lu"),
  429. i, static_cast<unsigned long>(shdr.get_sh_name()));
  430. return;
  431. }
  432. const char* name = pnames + shdr.get_sh_name();
  433. this->handle_gnu_warning_section(name, i, symtab);
  434. this->handle_split_stack_section(name);
  435. }
  436. delete sd->section_headers;
  437. sd->section_headers = NULL;
  438. delete sd->section_names;
  439. sd->section_names = NULL;
  440. }
  441. // Add an entry to the vector mapping version numbers to version
  442. // strings.
  443. template<int size, bool big_endian>
  444. void
  445. Sized_dynobj<size, big_endian>::set_version_map(
  446. Version_map* version_map,
  447. unsigned int ndx,
  448. const char* name) const
  449. {
  450. if (ndx >= version_map->size())
  451. version_map->resize(ndx + 1);
  452. if ((*version_map)[ndx] != NULL)
  453. this->error(_("duplicate definition for version %u"), ndx);
  454. (*version_map)[ndx] = name;
  455. }
  456. // Add mappings for the version definitions to VERSION_MAP.
  457. template<int size, bool big_endian>
  458. void
  459. Sized_dynobj<size, big_endian>::make_verdef_map(
  460. Read_symbols_data* sd,
  461. Version_map* version_map) const
  462. {
  463. if (sd->verdef == NULL)
  464. return;
  465. const char* names = reinterpret_cast<const char*>(sd->symbol_names->data());
  466. section_size_type names_size = sd->symbol_names_size;
  467. const unsigned char* pverdef = sd->verdef->data();
  468. section_size_type verdef_size = sd->verdef_size;
  469. const unsigned int count = sd->verdef_info;
  470. const unsigned char* p = pverdef;
  471. for (unsigned int i = 0; i < count; ++i)
  472. {
  473. elfcpp::Verdef<size, big_endian> verdef(p);
  474. if (verdef.get_vd_version() != elfcpp::VER_DEF_CURRENT)
  475. {
  476. this->error(_("unexpected verdef version %u"),
  477. verdef.get_vd_version());
  478. return;
  479. }
  480. const section_size_type vd_ndx = verdef.get_vd_ndx();
  481. // The GNU linker clears the VERSYM_HIDDEN bit. I'm not
  482. // sure why.
  483. // The first Verdaux holds the name of this version. Subsequent
  484. // ones are versions that this one depends upon, which we don't
  485. // care about here.
  486. const section_size_type vd_cnt = verdef.get_vd_cnt();
  487. if (vd_cnt < 1)
  488. {
  489. this->error(_("verdef vd_cnt field too small: %u"),
  490. static_cast<unsigned int>(vd_cnt));
  491. return;
  492. }
  493. const section_size_type vd_aux = verdef.get_vd_aux();
  494. if ((p - pverdef) + vd_aux >= verdef_size)
  495. {
  496. this->error(_("verdef vd_aux field out of range: %u"),
  497. static_cast<unsigned int>(vd_aux));
  498. return;
  499. }
  500. const unsigned char* pvda = p + vd_aux;
  501. elfcpp::Verdaux<size, big_endian> verdaux(pvda);
  502. const section_size_type vda_name = verdaux.get_vda_name();
  503. if (vda_name >= names_size)
  504. {
  505. this->error(_("verdaux vda_name field out of range: %u"),
  506. static_cast<unsigned int>(vda_name));
  507. return;
  508. }
  509. this->set_version_map(version_map, vd_ndx, names + vda_name);
  510. const section_size_type vd_next = verdef.get_vd_next();
  511. if ((p - pverdef) + vd_next >= verdef_size)
  512. {
  513. this->error(_("verdef vd_next field out of range: %u"),
  514. static_cast<unsigned int>(vd_next));
  515. return;
  516. }
  517. p += vd_next;
  518. }
  519. }
  520. // Add mappings for the required versions to VERSION_MAP.
  521. template<int size, bool big_endian>
  522. void
  523. Sized_dynobj<size, big_endian>::make_verneed_map(
  524. Read_symbols_data* sd,
  525. Version_map* version_map) const
  526. {
  527. if (sd->verneed == NULL)
  528. return;
  529. const char* names = reinterpret_cast<const char*>(sd->symbol_names->data());
  530. section_size_type names_size = sd->symbol_names_size;
  531. const unsigned char* pverneed = sd->verneed->data();
  532. const section_size_type verneed_size = sd->verneed_size;
  533. const unsigned int count = sd->verneed_info;
  534. const unsigned char* p = pverneed;
  535. for (unsigned int i = 0; i < count; ++i)
  536. {
  537. elfcpp::Verneed<size, big_endian> verneed(p);
  538. if (verneed.get_vn_version() != elfcpp::VER_NEED_CURRENT)
  539. {
  540. this->error(_("unexpected verneed version %u"),
  541. verneed.get_vn_version());
  542. return;
  543. }
  544. const section_size_type vn_aux = verneed.get_vn_aux();
  545. if ((p - pverneed) + vn_aux >= verneed_size)
  546. {
  547. this->error(_("verneed vn_aux field out of range: %u"),
  548. static_cast<unsigned int>(vn_aux));
  549. return;
  550. }
  551. const unsigned int vn_cnt = verneed.get_vn_cnt();
  552. const unsigned char* pvna = p + vn_aux;
  553. for (unsigned int j = 0; j < vn_cnt; ++j)
  554. {
  555. elfcpp::Vernaux<size, big_endian> vernaux(pvna);
  556. const unsigned int vna_name = vernaux.get_vna_name();
  557. if (vna_name >= names_size)
  558. {
  559. this->error(_("vernaux vna_name field out of range: %u"),
  560. static_cast<unsigned int>(vna_name));
  561. return;
  562. }
  563. this->set_version_map(version_map, vernaux.get_vna_other(),
  564. names + vna_name);
  565. const section_size_type vna_next = vernaux.get_vna_next();
  566. if ((pvna - pverneed) + vna_next >= verneed_size)
  567. {
  568. this->error(_("verneed vna_next field out of range: %u"),
  569. static_cast<unsigned int>(vna_next));
  570. return;
  571. }
  572. pvna += vna_next;
  573. }
  574. const section_size_type vn_next = verneed.get_vn_next();
  575. if ((p - pverneed) + vn_next >= verneed_size)
  576. {
  577. this->error(_("verneed vn_next field out of range: %u"),
  578. static_cast<unsigned int>(vn_next));
  579. return;
  580. }
  581. p += vn_next;
  582. }
  583. }
  584. // Create a vector mapping version numbers to version strings.
  585. template<int size, bool big_endian>
  586. void
  587. Sized_dynobj<size, big_endian>::make_version_map(
  588. Read_symbols_data* sd,
  589. Version_map* version_map) const
  590. {
  591. if (sd->verdef == NULL && sd->verneed == NULL)
  592. return;
  593. // A guess at the maximum version number we will see. If this is
  594. // wrong we will be less efficient but still correct.
  595. version_map->reserve(sd->verdef_info + sd->verneed_info * 10);
  596. this->make_verdef_map(sd, version_map);
  597. this->make_verneed_map(sd, version_map);
  598. }
  599. // Add the dynamic symbols to the symbol table.
  600. template<int size, bool big_endian>
  601. void
  602. Sized_dynobj<size, big_endian>::do_add_symbols(Symbol_table* symtab,
  603. Read_symbols_data* sd,
  604. Layout*)
  605. {
  606. if (sd->symbols == NULL)
  607. {
  608. gold_assert(sd->symbol_names == NULL);
  609. gold_assert(sd->versym == NULL && sd->verdef == NULL
  610. && sd->verneed == NULL);
  611. return;
  612. }
  613. const int sym_size = This::sym_size;
  614. const size_t symcount = sd->symbols_size / sym_size;
  615. gold_assert(sd->external_symbols_offset == 0);
  616. if (symcount * sym_size != sd->symbols_size)
  617. {
  618. this->error(_("size of dynamic symbols is not multiple of symbol size"));
  619. return;
  620. }
  621. Version_map version_map;
  622. this->make_version_map(sd, &version_map);
  623. // If printing symbol counts or a cross reference table or
  624. // preparing for an incremental link, we want to track symbols.
  625. if (parameters->options().user_set_print_symbol_counts()
  626. || parameters->options().cref()
  627. || parameters->incremental())
  628. {
  629. this->symbols_ = new Symbols();
  630. this->symbols_->resize(symcount);
  631. }
  632. const char* sym_names =
  633. reinterpret_cast<const char*>(sd->symbol_names->data());
  634. symtab->add_from_dynobj(this, sd->symbols->data(), symcount,
  635. sym_names, sd->symbol_names_size,
  636. (sd->versym == NULL
  637. ? NULL
  638. : sd->versym->data()),
  639. sd->versym_size,
  640. &version_map,
  641. this->symbols_,
  642. &this->defined_count_);
  643. delete sd->symbols;
  644. sd->symbols = NULL;
  645. delete sd->symbol_names;
  646. sd->symbol_names = NULL;
  647. if (sd->versym != NULL)
  648. {
  649. delete sd->versym;
  650. sd->versym = NULL;
  651. }
  652. if (sd->verdef != NULL)
  653. {
  654. delete sd->verdef;
  655. sd->verdef = NULL;
  656. }
  657. if (sd->verneed != NULL)
  658. {
  659. delete sd->verneed;
  660. sd->verneed = NULL;
  661. }
  662. // This is normally the last time we will read any data from this
  663. // file.
  664. this->clear_view_cache_marks();
  665. }
  666. template<int size, bool big_endian>
  667. Archive::Should_include
  668. Sized_dynobj<size, big_endian>::do_should_include_member(Symbol_table*,
  669. Layout*,
  670. Read_symbols_data*,
  671. std::string*)
  672. {
  673. return Archive::SHOULD_INCLUDE_YES;
  674. }
  675. // Iterate over global symbols, calling a visitor class V for each.
  676. template<int size, bool big_endian>
  677. void
  678. Sized_dynobj<size, big_endian>::do_for_all_global_symbols(
  679. Read_symbols_data* sd,
  680. Library_base::Symbol_visitor_base* v)
  681. {
  682. const char* sym_names =
  683. reinterpret_cast<const char*>(sd->symbol_names->data());
  684. const unsigned char* syms =
  685. sd->symbols->data() + sd->external_symbols_offset;
  686. const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
  687. size_t symcount = ((sd->symbols_size - sd->external_symbols_offset)
  688. / sym_size);
  689. const unsigned char* p = syms;
  690. for (size_t i = 0; i < symcount; ++i, p += sym_size)
  691. {
  692. elfcpp::Sym<size, big_endian> sym(p);
  693. if (sym.get_st_shndx() != elfcpp::SHN_UNDEF
  694. && sym.get_st_bind() != elfcpp::STB_LOCAL)
  695. v->visit(sym_names + sym.get_st_name());
  696. }
  697. }
  698. // Iterate over local symbols, calling a visitor class V for each GOT offset
  699. // associated with a local symbol.
  700. template<int size, bool big_endian>
  701. void
  702. Sized_dynobj<size, big_endian>::do_for_all_local_got_entries(
  703. Got_offset_list::Visitor*) const
  704. {
  705. }
  706. // Get symbol counts.
  707. template<int size, bool big_endian>
  708. void
  709. Sized_dynobj<size, big_endian>::do_get_global_symbol_counts(
  710. const Symbol_table*,
  711. size_t* defined,
  712. size_t* used) const
  713. {
  714. *defined = this->defined_count_;
  715. size_t count = 0;
  716. for (typename Symbols::const_iterator p = this->symbols_->begin();
  717. p != this->symbols_->end();
  718. ++p)
  719. if (*p != NULL
  720. && (*p)->source() == Symbol::FROM_OBJECT
  721. && (*p)->object() == this
  722. && (*p)->is_defined()
  723. && (*p)->has_dynsym_index())
  724. ++count;
  725. *used = count;
  726. }
  727. // Given a vector of hash codes, compute the number of hash buckets to
  728. // use.
  729. unsigned int
  730. Dynobj::compute_bucket_count(const std::vector<uint32_t>& hashcodes,
  731. bool for_gnu_hash_table)
  732. {
  733. // FIXME: Implement optional hash table optimization.
  734. // Array used to determine the number of hash table buckets to use
  735. // based on the number of symbols there are. If there are fewer
  736. // than 3 symbols we use 1 bucket, fewer than 17 symbols we use 3
  737. // buckets, fewer than 37 we use 17 buckets, and so forth. We never
  738. // use more than 262147 buckets. This is straight from the old GNU
  739. // linker.
  740. static const unsigned int buckets[] =
  741. {
  742. 1, 3, 17, 37, 67, 97, 131, 197, 263, 521, 1031, 2053, 4099, 8209,
  743. 16411, 32771, 65537, 131101, 262147
  744. };
  745. const int buckets_count = sizeof buckets / sizeof buckets[0];
  746. unsigned int symcount = hashcodes.size();
  747. unsigned int ret = 1;
  748. const double full_fraction
  749. = 1.0 - parameters->options().hash_bucket_empty_fraction();
  750. for (int i = 0; i < buckets_count; ++i)
  751. {
  752. if (symcount < buckets[i] * full_fraction)
  753. break;
  754. ret = buckets[i];
  755. }
  756. if (for_gnu_hash_table && ret < 2)
  757. ret = 2;
  758. return ret;
  759. }
  760. // The standard ELF hash function. This hash function must not
  761. // change, as the dynamic linker uses it also.
  762. uint32_t
  763. Dynobj::elf_hash(const char* name)
  764. {
  765. const unsigned char* nameu = reinterpret_cast<const unsigned char*>(name);
  766. uint32_t h = 0;
  767. unsigned char c;
  768. while ((c = *nameu++) != '\0')
  769. {
  770. h = (h << 4) + c;
  771. uint32_t g = h & 0xf0000000;
  772. if (g != 0)
  773. {
  774. h ^= g >> 24;
  775. // The ELF ABI says h &= ~g, but using xor is equivalent in
  776. // this case (since g was set from h) and may save one
  777. // instruction.
  778. h ^= g;
  779. }
  780. }
  781. return h;
  782. }
  783. // Create a standard ELF hash table, setting *PPHASH and *PHASHLEN.
  784. // DYNSYMS is a vector with all the global dynamic symbols.
  785. // LOCAL_DYNSYM_COUNT is the number of local symbols in the dynamic
  786. // symbol table.
  787. void
  788. Dynobj::create_elf_hash_table(const std::vector<Symbol*>& dynsyms,
  789. unsigned int local_dynsym_count,
  790. unsigned char** pphash,
  791. unsigned int* phashlen)
  792. {
  793. unsigned int dynsym_count = dynsyms.size();
  794. // Get the hash values for all the symbols.
  795. std::vector<uint32_t> dynsym_hashvals(dynsym_count);
  796. for (unsigned int i = 0; i < dynsym_count; ++i)
  797. dynsym_hashvals[i] = Dynobj::elf_hash(dynsyms[i]->name());
  798. const unsigned int bucketcount =
  799. Dynobj::compute_bucket_count(dynsym_hashvals, false);
  800. std::vector<uint32_t> bucket(bucketcount);
  801. std::vector<uint32_t> chain(local_dynsym_count + dynsym_count);
  802. for (unsigned int i = 0; i < dynsym_count; ++i)
  803. {
  804. unsigned int dynsym_index = dynsyms[i]->dynsym_index();
  805. unsigned int bucketpos = dynsym_hashvals[i] % bucketcount;
  806. chain[dynsym_index] = bucket[bucketpos];
  807. bucket[bucketpos] = dynsym_index;
  808. }
  809. int size = parameters->target().hash_entry_size();
  810. unsigned int hashlen = ((2
  811. + bucketcount
  812. + local_dynsym_count
  813. + dynsym_count)
  814. * size / 8);
  815. unsigned char* phash = new unsigned char[hashlen];
  816. bool big_endian = parameters->target().is_big_endian();
  817. if (size == 32)
  818. {
  819. if (big_endian)
  820. {
  821. #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
  822. Dynobj::sized_create_elf_hash_table<32, true>(bucket, chain, phash,
  823. hashlen);
  824. #else
  825. gold_unreachable();
  826. #endif
  827. }
  828. else
  829. {
  830. #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
  831. Dynobj::sized_create_elf_hash_table<32, false>(bucket, chain, phash,
  832. hashlen);
  833. #else
  834. gold_unreachable();
  835. #endif
  836. }
  837. }
  838. else if (size == 64)
  839. {
  840. if (big_endian)
  841. {
  842. #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
  843. Dynobj::sized_create_elf_hash_table<64, true>(bucket, chain, phash,
  844. hashlen);
  845. #else
  846. gold_unreachable();
  847. #endif
  848. }
  849. else
  850. {
  851. #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
  852. Dynobj::sized_create_elf_hash_table<64, false>(bucket, chain, phash,
  853. hashlen);
  854. #else
  855. gold_unreachable();
  856. #endif
  857. }
  858. }
  859. else
  860. gold_unreachable();
  861. *pphash = phash;
  862. *phashlen = hashlen;
  863. }
  864. // Fill in an ELF hash table.
  865. template<int size, bool big_endian>
  866. void
  867. Dynobj::sized_create_elf_hash_table(const std::vector<uint32_t>& bucket,
  868. const std::vector<uint32_t>& chain,
  869. unsigned char* phash,
  870. unsigned int hashlen)
  871. {
  872. unsigned char* p = phash;
  873. const unsigned int bucketcount = bucket.size();
  874. const unsigned int chaincount = chain.size();
  875. elfcpp::Swap<size, big_endian>::writeval(p, bucketcount);
  876. p += size / 8;
  877. elfcpp::Swap<size, big_endian>::writeval(p, chaincount);
  878. p += size / 8;
  879. for (unsigned int i = 0; i < bucketcount; ++i)
  880. {
  881. elfcpp::Swap<size, big_endian>::writeval(p, bucket[i]);
  882. p += size / 8;
  883. }
  884. for (unsigned int i = 0; i < chaincount; ++i)
  885. {
  886. elfcpp::Swap<size, big_endian>::writeval(p, chain[i]);
  887. p += size / 8;
  888. }
  889. gold_assert(static_cast<unsigned int>(p - phash) == hashlen);
  890. }
  891. // The hash function used for the GNU hash table. This hash function
  892. // must not change, as the dynamic linker uses it also.
  893. uint32_t
  894. Dynobj::gnu_hash(const char* name)
  895. {
  896. const unsigned char* nameu = reinterpret_cast<const unsigned char*>(name);
  897. uint32_t h = 5381;
  898. unsigned char c;
  899. while ((c = *nameu++) != '\0')
  900. h = (h << 5) + h + c;
  901. return h;
  902. }
  903. // Create a GNU hash table, setting *PPHASH and *PHASHLEN. GNU hash
  904. // tables are an extension to ELF which are recognized by the GNU
  905. // dynamic linker. They are referenced using dynamic tag DT_GNU_HASH.
  906. // TARGET is the target. DYNSYMS is a vector with all the global
  907. // symbols which will be going into the dynamic symbol table.
  908. // LOCAL_DYNSYM_COUNT is the number of local symbols in the dynamic
  909. // symbol table.
  910. void
  911. Dynobj::create_gnu_hash_table(const std::vector<Symbol*>& dynsyms,
  912. unsigned int local_dynsym_count,
  913. unsigned char** pphash,
  914. unsigned int* phashlen)
  915. {
  916. const unsigned int count = dynsyms.size();
  917. // Sort the dynamic symbols into two vectors. Symbols which we do
  918. // not want to put into the hash table we store into
  919. // UNHASHED_DYNSYMS. Symbols which we do want to store we put into
  920. // HASHED_DYNSYMS. DYNSYM_HASHVALS is parallel to HASHED_DYNSYMS,
  921. // and records the hash codes.
  922. std::vector<Symbol*> unhashed_dynsyms;
  923. unhashed_dynsyms.reserve(count);
  924. std::vector<Symbol*> hashed_dynsyms;
  925. hashed_dynsyms.reserve(count);
  926. std::vector<uint32_t> dynsym_hashvals;
  927. dynsym_hashvals.reserve(count);
  928. for (unsigned int i = 0; i < count; ++i)
  929. {
  930. Symbol* sym = dynsyms[i];
  931. if (!sym->needs_dynsym_value()
  932. && (sym->is_undefined()
  933. || sym->is_from_dynobj()
  934. || sym->is_forced_local()))
  935. unhashed_dynsyms.push_back(sym);
  936. else
  937. {
  938. hashed_dynsyms.push_back(sym);
  939. dynsym_hashvals.push_back(Dynobj::gnu_hash(sym->name()));
  940. }
  941. }
  942. // Put the unhashed symbols at the start of the global portion of
  943. // the dynamic symbol table.
  944. const unsigned int unhashed_count = unhashed_dynsyms.size();
  945. unsigned int unhashed_dynsym_index = local_dynsym_count;
  946. for (unsigned int i = 0; i < unhashed_count; ++i)
  947. {
  948. unhashed_dynsyms[i]->set_dynsym_index(unhashed_dynsym_index);
  949. ++unhashed_dynsym_index;
  950. }
  951. // For the actual data generation we call out to a templatized
  952. // function.
  953. int size = parameters->target().get_size();
  954. bool big_endian = parameters->target().is_big_endian();
  955. if (size == 32)
  956. {
  957. if (big_endian)
  958. {
  959. #ifdef HAVE_TARGET_32_BIG
  960. Dynobj::sized_create_gnu_hash_table<32, true>(hashed_dynsyms,
  961. dynsym_hashvals,
  962. unhashed_dynsym_index,
  963. pphash,
  964. phashlen);
  965. #else
  966. gold_unreachable();
  967. #endif
  968. }
  969. else
  970. {
  971. #ifdef HAVE_TARGET_32_LITTLE
  972. Dynobj::sized_create_gnu_hash_table<32, false>(hashed_dynsyms,
  973. dynsym_hashvals,
  974. unhashed_dynsym_index,
  975. pphash,
  976. phashlen);
  977. #else
  978. gold_unreachable();
  979. #endif
  980. }
  981. }
  982. else if (size == 64)
  983. {
  984. if (big_endian)
  985. {
  986. #ifdef HAVE_TARGET_64_BIG
  987. Dynobj::sized_create_gnu_hash_table<64, true>(hashed_dynsyms,
  988. dynsym_hashvals,
  989. unhashed_dynsym_index,
  990. pphash,
  991. phashlen);
  992. #else
  993. gold_unreachable();
  994. #endif
  995. }
  996. else
  997. {
  998. #ifdef HAVE_TARGET_64_LITTLE
  999. Dynobj::sized_create_gnu_hash_table<64, false>(hashed_dynsyms,
  1000. dynsym_hashvals,
  1001. unhashed_dynsym_index,
  1002. pphash,
  1003. phashlen);
  1004. #else
  1005. gold_unreachable();
  1006. #endif
  1007. }
  1008. }
  1009. else
  1010. gold_unreachable();
  1011. }
  1012. // Create the actual data for a GNU hash table. This is just a copy
  1013. // of the code from the old GNU linker.
  1014. template<int size, bool big_endian>
  1015. void
  1016. Dynobj::sized_create_gnu_hash_table(
  1017. const std::vector<Symbol*>& hashed_dynsyms,
  1018. const std::vector<uint32_t>& dynsym_hashvals,
  1019. unsigned int unhashed_dynsym_count,
  1020. unsigned char** pphash,
  1021. unsigned int* phashlen)
  1022. {
  1023. if (hashed_dynsyms.empty())
  1024. {
  1025. // Special case for the empty hash table.
  1026. unsigned int hashlen = 5 * 4 + size / 8;
  1027. unsigned char* phash = new unsigned char[hashlen];
  1028. // One empty bucket.
  1029. elfcpp::Swap<32, big_endian>::writeval(phash, 1);
  1030. // Symbol index above unhashed symbols.
  1031. elfcpp::Swap<32, big_endian>::writeval(phash + 4, unhashed_dynsym_count);
  1032. // One word for bitmask.
  1033. elfcpp::Swap<32, big_endian>::writeval(phash + 8, 1);
  1034. // Only bloom filter.
  1035. elfcpp::Swap<32, big_endian>::writeval(phash + 12, 0);
  1036. // No valid hashes.
  1037. elfcpp::Swap<size, big_endian>::writeval(phash + 16, 0);
  1038. // No hashes in only bucket.
  1039. elfcpp::Swap<32, big_endian>::writeval(phash + 16 + size / 8, 0);
  1040. *phashlen = hashlen;
  1041. *pphash = phash;
  1042. return;
  1043. }
  1044. const unsigned int bucketcount =
  1045. Dynobj::compute_bucket_count(dynsym_hashvals, true);
  1046. const unsigned int nsyms = hashed_dynsyms.size();
  1047. uint32_t maskbitslog2 = 1;
  1048. uint32_t x = nsyms >> 1;
  1049. while (x != 0)
  1050. {
  1051. ++maskbitslog2;
  1052. x >>= 1;
  1053. }
  1054. if (maskbitslog2 < 3)
  1055. maskbitslog2 = 5;
  1056. else if (((1U << (maskbitslog2 - 2)) & nsyms) != 0)
  1057. maskbitslog2 += 3;
  1058. else
  1059. maskbitslog2 += 2;
  1060. uint32_t shift1;
  1061. if (size == 32)
  1062. shift1 = 5;
  1063. else
  1064. {
  1065. if (maskbitslog2 == 5)
  1066. maskbitslog2 = 6;
  1067. shift1 = 6;
  1068. }
  1069. uint32_t mask = (1U << shift1) - 1U;
  1070. uint32_t shift2 = maskbitslog2;
  1071. uint32_t maskbits = 1U << maskbitslog2;
  1072. uint32_t maskwords = 1U << (maskbitslog2 - shift1);
  1073. typedef typename elfcpp::Elf_types<size>::Elf_WXword Word;
  1074. std::vector<Word> bitmask(maskwords);
  1075. std::vector<uint32_t> counts(bucketcount);
  1076. std::vector<uint32_t> indx(bucketcount);
  1077. uint32_t symindx = unhashed_dynsym_count;
  1078. // Count the number of times each hash bucket is used.
  1079. for (unsigned int i = 0; i < nsyms; ++i)
  1080. ++counts[dynsym_hashvals[i] % bucketcount];
  1081. unsigned int cnt = symindx;
  1082. for (unsigned int i = 0; i < bucketcount; ++i)
  1083. {
  1084. indx[i] = cnt;
  1085. cnt += counts[i];
  1086. }
  1087. unsigned int hashlen = (4 + bucketcount + nsyms) * 4;
  1088. hashlen += maskbits / 8;
  1089. unsigned char* phash = new unsigned char[hashlen];
  1090. elfcpp::Swap<32, big_endian>::writeval(phash, bucketcount);
  1091. elfcpp::Swap<32, big_endian>::writeval(phash + 4, symindx);
  1092. elfcpp::Swap<32, big_endian>::writeval(phash + 8, maskwords);
  1093. elfcpp::Swap<32, big_endian>::writeval(phash + 12, shift2);
  1094. unsigned char* p = phash + 16 + maskbits / 8;
  1095. for (unsigned int i = 0; i < bucketcount; ++i)
  1096. {
  1097. if (counts[i] == 0)
  1098. elfcpp::Swap<32, big_endian>::writeval(p, 0);
  1099. else
  1100. elfcpp::Swap<32, big_endian>::writeval(p, indx[i]);
  1101. p += 4;
  1102. }
  1103. for (unsigned int i = 0; i < nsyms; ++i)
  1104. {
  1105. Symbol* sym = hashed_dynsyms[i];
  1106. uint32_t hashval = dynsym_hashvals[i];
  1107. unsigned int bucket = hashval % bucketcount;
  1108. unsigned int val = ((hashval >> shift1)
  1109. & ((maskbits >> shift1) - 1));
  1110. bitmask[val] |= (static_cast<Word>(1U)) << (hashval & mask);
  1111. bitmask[val] |= (static_cast<Word>(1U)) << ((hashval >> shift2) & mask);
  1112. val = hashval & ~ 1U;
  1113. if (counts[bucket] == 1)
  1114. {
  1115. // Last element terminates the chain.
  1116. val |= 1;
  1117. }
  1118. elfcpp::Swap<32, big_endian>::writeval(p + (indx[bucket] - symindx) * 4,
  1119. val);
  1120. --counts[bucket];
  1121. sym->set_dynsym_index(indx[bucket]);
  1122. ++indx[bucket];
  1123. }
  1124. p = phash + 16;
  1125. for (unsigned int i = 0; i < maskwords; ++i)
  1126. {
  1127. elfcpp::Swap<size, big_endian>::writeval(p, bitmask[i]);
  1128. p += size / 8;
  1129. }
  1130. *phashlen = hashlen;
  1131. *pphash = phash;
  1132. }
  1133. // Verdef methods.
  1134. // Write this definition to a buffer for the output section.
  1135. template<int size, bool big_endian>
  1136. unsigned char*
  1137. Verdef::write(const Stringpool* dynpool, bool is_last, unsigned char* pb) const
  1138. {
  1139. const int verdef_size = elfcpp::Elf_sizes<size>::verdef_size;
  1140. const int verdaux_size = elfcpp::Elf_sizes<size>::verdaux_size;
  1141. elfcpp::Verdef_write<size, big_endian> vd(pb);
  1142. vd.set_vd_version(elfcpp::VER_DEF_CURRENT);
  1143. vd.set_vd_flags((this->is_base_ ? elfcpp::VER_FLG_BASE : 0)
  1144. | (this->is_weak_ ? elfcpp::VER_FLG_WEAK : 0)
  1145. | (this->is_info_ ? elfcpp::VER_FLG_INFO : 0));
  1146. vd.set_vd_ndx(this->index());
  1147. vd.set_vd_cnt(1 + this->deps_.size());
  1148. vd.set_vd_hash(Dynobj::elf_hash(this->name()));
  1149. vd.set_vd_aux(verdef_size);
  1150. vd.set_vd_next(is_last
  1151. ? 0
  1152. : verdef_size + (1 + this->deps_.size()) * verdaux_size);
  1153. pb += verdef_size;
  1154. elfcpp::Verdaux_write<size, big_endian> vda(pb);
  1155. vda.set_vda_name(dynpool->get_offset(this->name()));
  1156. vda.set_vda_next(this->deps_.empty() ? 0 : verdaux_size);
  1157. pb += verdaux_size;
  1158. Deps::const_iterator p;
  1159. unsigned int i;
  1160. for (p = this->deps_.begin(), i = 0;
  1161. p != this->deps_.end();
  1162. ++p, ++i)
  1163. {
  1164. elfcpp::Verdaux_write<size, big_endian> vda(pb);
  1165. vda.set_vda_name(dynpool->get_offset(*p));
  1166. vda.set_vda_next(i + 1 >= this->deps_.size() ? 0 : verdaux_size);
  1167. pb += verdaux_size;
  1168. }
  1169. return pb;
  1170. }
  1171. // Verneed methods.
  1172. Verneed::~Verneed()
  1173. {
  1174. for (Need_versions::iterator p = this->need_versions_.begin();
  1175. p != this->need_versions_.end();
  1176. ++p)
  1177. delete *p;
  1178. }
  1179. // Add a new version to this file reference.
  1180. Verneed_version*
  1181. Verneed::add_name(const char* name)
  1182. {
  1183. Verneed_version* vv = new Verneed_version(name);
  1184. this->need_versions_.push_back(vv);
  1185. return vv;
  1186. }
  1187. // Set the version indexes starting at INDEX.
  1188. unsigned int
  1189. Verneed::finalize(unsigned int index)
  1190. {
  1191. for (Need_versions::iterator p = this->need_versions_.begin();
  1192. p != this->need_versions_.end();
  1193. ++p)
  1194. {
  1195. (*p)->set_index(index);
  1196. ++index;
  1197. }
  1198. return index;
  1199. }
  1200. // Write this list of referenced versions to a buffer for the output
  1201. // section.
  1202. template<int size, bool big_endian>
  1203. unsigned char*
  1204. Verneed::write(const Stringpool* dynpool, bool is_last,
  1205. unsigned char* pb) const
  1206. {
  1207. const int verneed_size = elfcpp::Elf_sizes<size>::verneed_size;
  1208. const int vernaux_size = elfcpp::Elf_sizes<size>::vernaux_size;
  1209. elfcpp::Verneed_write<size, big_endian> vn(pb);
  1210. vn.set_vn_version(elfcpp::VER_NEED_CURRENT);
  1211. vn.set_vn_cnt(this->need_versions_.size());
  1212. vn.set_vn_file(dynpool->get_offset(this->filename()));
  1213. vn.set_vn_aux(verneed_size);
  1214. vn.set_vn_next(is_last
  1215. ? 0
  1216. : verneed_size + this->need_versions_.size() * vernaux_size);
  1217. pb += verneed_size;
  1218. Need_versions::const_iterator p;
  1219. unsigned int i;
  1220. for (p = this->need_versions_.begin(), i = 0;
  1221. p != this->need_versions_.end();
  1222. ++p, ++i)
  1223. {
  1224. elfcpp::Vernaux_write<size, big_endian> vna(pb);
  1225. vna.set_vna_hash(Dynobj::elf_hash((*p)->version()));
  1226. // FIXME: We need to sometimes set VER_FLG_WEAK here.
  1227. vna.set_vna_flags(0);
  1228. vna.set_vna_other((*p)->index());
  1229. vna.set_vna_name(dynpool->get_offset((*p)->version()));
  1230. vna.set_vna_next(i + 1 >= this->need_versions_.size()
  1231. ? 0
  1232. : vernaux_size);
  1233. pb += vernaux_size;
  1234. }
  1235. return pb;
  1236. }
  1237. // Versions methods.
  1238. Versions::Versions(const Version_script_info& version_script,
  1239. Stringpool* dynpool)
  1240. : defs_(), needs_(), version_table_(),
  1241. is_finalized_(false), version_script_(version_script),
  1242. needs_base_version_(true)
  1243. {
  1244. if (!this->version_script_.empty())
  1245. {
  1246. // Parse the version script, and insert each declared version into
  1247. // defs_ and version_table_.
  1248. std::vector<std::string> versions = this->version_script_.get_versions();
  1249. if (this->needs_base_version_ && !versions.empty())
  1250. this->define_base_version(dynpool);
  1251. for (size_t k = 0; k < versions.size(); ++k)
  1252. {
  1253. Stringpool::Key version_key;
  1254. const char* version = dynpool->add(versions[k].c_str(),
  1255. true, &version_key);
  1256. Verdef* const vd = new Verdef(
  1257. version,
  1258. this->version_script_.get_dependencies(version),
  1259. false, false, false, false);
  1260. this->defs_.push_back(vd);
  1261. Key key(version_key, 0);
  1262. this->version_table_.insert(std::make_pair(key, vd));
  1263. }
  1264. }
  1265. }
  1266. Versions::~Versions()
  1267. {
  1268. for (Defs::iterator p = this->defs_.begin();
  1269. p != this->defs_.end();
  1270. ++p)
  1271. delete *p;
  1272. for (Needs::iterator p = this->needs_.begin();
  1273. p != this->needs_.end();
  1274. ++p)
  1275. delete *p;
  1276. }
  1277. // Define the base version of a shared library. The base version definition
  1278. // must be the first entry in defs_. We insert it lazily so that defs_ is
  1279. // empty if no symbol versioning is used. Then layout can just drop the
  1280. // version sections.
  1281. void
  1282. Versions::define_base_version(Stringpool* dynpool)
  1283. {
  1284. // If we do any versioning at all, we always need a base version, so
  1285. // define that first. Nothing explicitly declares itself as part of base,
  1286. // so it doesn't need to be in version_table_.
  1287. gold_assert(this->defs_.empty());
  1288. const char* name = parameters->options().soname();
  1289. if (name == NULL)
  1290. name = parameters->options().output_file_name();
  1291. name = dynpool->add(name, false, NULL);
  1292. Verdef* vdbase = new Verdef(name, std::vector<std::string>(),
  1293. true, false, false, true);
  1294. this->defs_.push_back(vdbase);
  1295. this->needs_base_version_ = false;
  1296. }
  1297. // Return the dynamic object which a symbol refers to.
  1298. Dynobj*
  1299. Versions::get_dynobj_for_sym(const Symbol_table* symtab,
  1300. const Symbol* sym) const
  1301. {
  1302. if (sym->is_copied_from_dynobj())
  1303. return symtab->get_copy_source(sym);
  1304. else
  1305. {
  1306. Object* object = sym->object();
  1307. gold_assert(object->is_dynamic());
  1308. return static_cast<Dynobj*>(object);
  1309. }
  1310. }
  1311. // Record version information for a symbol going into the dynamic
  1312. // symbol table.
  1313. void
  1314. Versions::record_version(const Symbol_table* symtab,
  1315. Stringpool* dynpool, const Symbol* sym)
  1316. {
  1317. gold_assert(!this->is_finalized_);
  1318. gold_assert(sym->version() != NULL);
  1319. // A symbol defined as "sym@" is bound to an unspecified base version.
  1320. if (sym->version()[0] == '\0')
  1321. return;
  1322. Stringpool::Key version_key;
  1323. const char* version = dynpool->add(sym->version(), false, &version_key);
  1324. if (!sym->is_from_dynobj() && !sym->is_copied_from_dynobj())
  1325. {
  1326. this->add_def(dynpool, sym, version, version_key);
  1327. }
  1328. else
  1329. {
  1330. // This is a version reference.
  1331. Dynobj* dynobj = this->get_dynobj_for_sym(symtab, sym);
  1332. this->add_need(dynpool, dynobj->soname(), version, version_key);
  1333. }
  1334. }
  1335. // We've found a symbol SYM defined in version VERSION.
  1336. void
  1337. Versions::add_def(Stringpool* dynpool, const Symbol* sym, const char* version,
  1338. Stringpool::Key version_key)
  1339. {
  1340. Key k(version_key, 0);
  1341. Version_base* const vbnull = NULL;
  1342. std::pair<Version_table::iterator, bool> ins =
  1343. this->version_table_.insert(std::make_pair(k, vbnull));
  1344. if (!ins.second)
  1345. {
  1346. // We already have an entry for this version.
  1347. Version_base* vb = ins.first->second;
  1348. // We have now seen a symbol in this version, so it is not
  1349. // weak.
  1350. gold_assert(vb != NULL);
  1351. vb->clear_weak();
  1352. }
  1353. else
  1354. {
  1355. // If we are creating a shared object, it is an error to
  1356. // find a definition of a symbol with a version which is not
  1357. // in the version script.
  1358. if (parameters->options().shared())
  1359. gold_error(_("symbol %s has undefined version %s"),
  1360. sym->demangled_name().c_str(), version);
  1361. // When creating a regular executable, automatically define
  1362. // a new version.
  1363. if (this->needs_base_version_)
  1364. this->define_base_version(dynpool);
  1365. Verdef* vd = new Verdef(version, std::vector<std::string>(),
  1366. false, false, false, false);
  1367. this->defs_.push_back(vd);
  1368. ins.first->second = vd;
  1369. }
  1370. }
  1371. // Add a reference to version NAME in file FILENAME.
  1372. void
  1373. Versions::add_need(Stringpool* dynpool, const char* filename, const char* name,
  1374. Stringpool::Key name_key)
  1375. {
  1376. Stringpool::Key filename_key;
  1377. filename = dynpool->add(filename, true, &filename_key);
  1378. Key k(name_key, filename_key);
  1379. Version_base* const vbnull = NULL;
  1380. std::pair<Version_table::iterator, bool> ins =
  1381. this->version_table_.insert(std::make_pair(k, vbnull));
  1382. if (!ins.second)
  1383. {
  1384. // We already have an entry for this filename/version.
  1385. return;
  1386. }
  1387. // See whether we already have this filename. We don't expect many
  1388. // version references, so we just do a linear search. This could be
  1389. // replaced by a hash table.
  1390. Verneed* vn = NULL;
  1391. for (Needs::iterator p = this->needs_.begin();
  1392. p != this->needs_.end();
  1393. ++p)
  1394. {
  1395. if ((*p)->filename() == filename)
  1396. {
  1397. vn = *p;
  1398. break;
  1399. }
  1400. }
  1401. if (vn == NULL)
  1402. {
  1403. // Create base version definition lazily for shared library.
  1404. if (parameters->options().shared() && this->needs_base_version_)
  1405. this->define_base_version(dynpool);
  1406. // We have a new filename.
  1407. vn = new Verneed(filename);
  1408. this->needs_.push_back(vn);
  1409. }
  1410. ins.first->second = vn->add_name(name);
  1411. }
  1412. // Set the version indexes. Create a new dynamic version symbol for
  1413. // each new version definition.
  1414. unsigned int
  1415. Versions::finalize(Symbol_table* symtab, unsigned int dynsym_index,
  1416. std::vector<Symbol*>* syms)
  1417. {
  1418. gold_assert(!this->is_finalized_);
  1419. unsigned int vi = 1;
  1420. for (Defs::iterator p = this->defs_.begin();
  1421. p != this->defs_.end();
  1422. ++p)
  1423. {
  1424. (*p)->set_index(vi);
  1425. ++vi;
  1426. // Create a version symbol if necessary.
  1427. if (!(*p)->is_symbol_created())
  1428. {
  1429. Symbol* vsym = symtab->define_as_constant((*p)->name(),
  1430. (*p)->name(),
  1431. Symbol_table::PREDEFINED,
  1432. 0, 0,
  1433. elfcpp::STT_OBJECT,
  1434. elfcpp::STB_GLOBAL,
  1435. elfcpp::STV_DEFAULT, 0,
  1436. false, false);
  1437. vsym->set_needs_dynsym_entry();
  1438. vsym->set_dynsym_index(dynsym_index);
  1439. vsym->set_is_default();
  1440. ++dynsym_index;
  1441. syms->push_back(vsym);
  1442. // The name is already in the dynamic pool.
  1443. }
  1444. }
  1445. // Index 1 is used for global symbols.
  1446. if (vi == 1)
  1447. {
  1448. gold_assert(this->defs_.empty());
  1449. vi = 2;
  1450. }
  1451. for (Needs::iterator p = this->needs_.begin();
  1452. p != this->needs_.end();
  1453. ++p)
  1454. vi = (*p)->finalize(vi);
  1455. this->is_finalized_ = true;
  1456. return dynsym_index;
  1457. }
  1458. // Return the version index to use for a symbol. This does two hash
  1459. // table lookups: one in DYNPOOL and one in this->version_table_.
  1460. // Another approach alternative would be store a pointer in SYM, which
  1461. // would increase the size of the symbol table. Or perhaps we could
  1462. // use a hash table from dynamic symbol pointer values to Version_base
  1463. // pointers.
  1464. unsigned int
  1465. Versions::version_index(const Symbol_table* symtab, const Stringpool* dynpool,
  1466. const Symbol* sym) const
  1467. {
  1468. Stringpool::Key version_key;
  1469. const char* version = dynpool->find(sym->version(), &version_key);
  1470. gold_assert(version != NULL);
  1471. Key k;
  1472. if (!sym->is_from_dynobj() && !sym->is_copied_from_dynobj())
  1473. {
  1474. k = Key(version_key, 0);
  1475. }
  1476. else
  1477. {
  1478. Dynobj* dynobj = this->get_dynobj_for_sym(symtab, sym);
  1479. Stringpool::Key filename_key;
  1480. const char* filename = dynpool->find(dynobj->soname(), &filename_key);
  1481. gold_assert(filename != NULL);
  1482. k = Key(version_key, filename_key);
  1483. }
  1484. Version_table::const_iterator p = this->version_table_.find(k);
  1485. gold_assert(p != this->version_table_.end());
  1486. return p->second->index();
  1487. }
  1488. // Return an allocated buffer holding the contents of the symbol
  1489. // version section.
  1490. template<int size, bool big_endian>
  1491. void
  1492. Versions::symbol_section_contents(const Symbol_table* symtab,
  1493. const Stringpool* dynpool,
  1494. unsigned int local_symcount,
  1495. const std::vector<Symbol*>& syms,
  1496. unsigned char** pp,
  1497. unsigned int* psize) const
  1498. {
  1499. gold_assert(this->is_finalized_);
  1500. unsigned int sz = (local_symcount + syms.size()) * 2;
  1501. unsigned char* pbuf = new unsigned char[sz];
  1502. for (unsigned int i = 0; i < local_symcount; ++i)
  1503. elfcpp::Swap<16, big_endian>::writeval(pbuf + i * 2,
  1504. elfcpp::VER_NDX_LOCAL);
  1505. for (std::vector<Symbol*>::const_iterator p = syms.begin();
  1506. p != syms.end();
  1507. ++p)
  1508. {
  1509. unsigned int version_index;
  1510. const char* version = (*p)->version();
  1511. if (version == NULL)
  1512. {
  1513. if ((*p)->is_defined() && !(*p)->is_from_dynobj())
  1514. version_index = elfcpp::VER_NDX_GLOBAL;
  1515. else
  1516. version_index = elfcpp::VER_NDX_LOCAL;
  1517. }
  1518. else if (version[0] == '\0')
  1519. version_index = elfcpp::VER_NDX_GLOBAL;
  1520. else
  1521. version_index = this->version_index(symtab, dynpool, *p);
  1522. // If the symbol was defined as foo@V1 instead of foo@@V1, add
  1523. // the hidden bit.
  1524. if ((*p)->version() != NULL
  1525. && (*p)->is_defined()
  1526. && !(*p)->is_default()
  1527. && !(*p)->from_dyn())
  1528. version_index |= elfcpp::VERSYM_HIDDEN;
  1529. elfcpp::Swap<16, big_endian>::writeval(pbuf + (*p)->dynsym_index() * 2,
  1530. version_index);
  1531. }
  1532. *pp = pbuf;
  1533. *psize = sz;
  1534. }
  1535. // Return an allocated buffer holding the contents of the version
  1536. // definition section.
  1537. template<int size, bool big_endian>
  1538. void
  1539. Versions::def_section_contents(const Stringpool* dynpool,
  1540. unsigned char** pp, unsigned int* psize,
  1541. unsigned int* pentries) const
  1542. {
  1543. gold_assert(this->is_finalized_);
  1544. gold_assert(!this->defs_.empty());
  1545. const int verdef_size = elfcpp::Elf_sizes<size>::verdef_size;
  1546. const int verdaux_size = elfcpp::Elf_sizes<size>::verdaux_size;
  1547. unsigned int sz = 0;
  1548. for (Defs::const_iterator p = this->defs_.begin();
  1549. p != this->defs_.end();
  1550. ++p)
  1551. {
  1552. sz += verdef_size + verdaux_size;
  1553. sz += (*p)->count_dependencies() * verdaux_size;
  1554. }
  1555. unsigned char* pbuf = new unsigned char[sz];
  1556. unsigned char* pb = pbuf;
  1557. Defs::const_iterator p;
  1558. unsigned int i;
  1559. for (p = this->defs_.begin(), i = 0;
  1560. p != this->defs_.end();
  1561. ++p, ++i)
  1562. pb = (*p)->write<size, big_endian>(dynpool,
  1563. i + 1 >= this->defs_.size(),
  1564. pb);
  1565. gold_assert(static_cast<unsigned int>(pb - pbuf) == sz);
  1566. *pp = pbuf;
  1567. *psize = sz;
  1568. *pentries = this->defs_.size();
  1569. }
  1570. // Return an allocated buffer holding the contents of the version
  1571. // reference section.
  1572. template<int size, bool big_endian>
  1573. void
  1574. Versions::need_section_contents(const Stringpool* dynpool,
  1575. unsigned char** pp, unsigned int* psize,
  1576. unsigned int* pentries) const
  1577. {
  1578. gold_assert(this->is_finalized_);
  1579. gold_assert(!this->needs_.empty());
  1580. const int verneed_size = elfcpp::Elf_sizes<size>::verneed_size;
  1581. const int vernaux_size = elfcpp::Elf_sizes<size>::vernaux_size;
  1582. unsigned int sz = 0;
  1583. for (Needs::const_iterator p = this->needs_.begin();
  1584. p != this->needs_.end();
  1585. ++p)
  1586. {
  1587. sz += verneed_size;
  1588. sz += (*p)->count_versions() * vernaux_size;
  1589. }
  1590. unsigned char* pbuf = new unsigned char[sz];
  1591. unsigned char* pb = pbuf;
  1592. Needs::const_iterator p;
  1593. unsigned int i;
  1594. for (p = this->needs_.begin(), i = 0;
  1595. p != this->needs_.end();
  1596. ++p, ++i)
  1597. pb = (*p)->write<size, big_endian>(dynpool,
  1598. i + 1 >= this->needs_.size(),
  1599. pb);
  1600. gold_assert(static_cast<unsigned int>(pb - pbuf) == sz);
  1601. *pp = pbuf;
  1602. *psize = sz;
  1603. *pentries = this->needs_.size();
  1604. }
  1605. // Instantiate the templates we need. We could use the configure
  1606. // script to restrict this to only the ones for implemented targets.
  1607. #ifdef HAVE_TARGET_32_LITTLE
  1608. template
  1609. class Sized_dynobj<32, false>;
  1610. #endif
  1611. #ifdef HAVE_TARGET_32_BIG
  1612. template
  1613. class Sized_dynobj<32, true>;
  1614. #endif
  1615. #ifdef HAVE_TARGET_64_LITTLE
  1616. template
  1617. class Sized_dynobj<64, false>;
  1618. #endif
  1619. #ifdef HAVE_TARGET_64_BIG
  1620. template
  1621. class Sized_dynobj<64, true>;
  1622. #endif
  1623. #ifdef HAVE_TARGET_32_LITTLE
  1624. template
  1625. void
  1626. Versions::symbol_section_contents<32, false>(
  1627. const Symbol_table*,
  1628. const Stringpool*,
  1629. unsigned int,
  1630. const std::vector<Symbol*>&,
  1631. unsigned char**,
  1632. unsigned int*) const;
  1633. #endif
  1634. #ifdef HAVE_TARGET_32_BIG
  1635. template
  1636. void
  1637. Versions::symbol_section_contents<32, true>(
  1638. const Symbol_table*,
  1639. const Stringpool*,
  1640. unsigned int,
  1641. const std::vector<Symbol*>&,
  1642. unsigned char**,
  1643. unsigned int*) const;
  1644. #endif
  1645. #ifdef HAVE_TARGET_64_LITTLE
  1646. template
  1647. void
  1648. Versions::symbol_section_contents<64, false>(
  1649. const Symbol_table*,
  1650. const Stringpool*,
  1651. unsigned int,
  1652. const std::vector<Symbol*>&,
  1653. unsigned char**,
  1654. unsigned int*) const;
  1655. #endif
  1656. #ifdef HAVE_TARGET_64_BIG
  1657. template
  1658. void
  1659. Versions::symbol_section_contents<64, true>(
  1660. const Symbol_table*,
  1661. const Stringpool*,
  1662. unsigned int,
  1663. const std::vector<Symbol*>&,
  1664. unsigned char**,
  1665. unsigned int*) const;
  1666. #endif
  1667. #ifdef HAVE_TARGET_32_LITTLE
  1668. template
  1669. void
  1670. Versions::def_section_contents<32, false>(
  1671. const Stringpool*,
  1672. unsigned char**,
  1673. unsigned int*,
  1674. unsigned int*) const;
  1675. #endif
  1676. #ifdef HAVE_TARGET_32_BIG
  1677. template
  1678. void
  1679. Versions::def_section_contents<32, true>(
  1680. const Stringpool*,
  1681. unsigned char**,
  1682. unsigned int*,
  1683. unsigned int*) const;
  1684. #endif
  1685. #ifdef HAVE_TARGET_64_LITTLE
  1686. template
  1687. void
  1688. Versions::def_section_contents<64, false>(
  1689. const Stringpool*,
  1690. unsigned char**,
  1691. unsigned int*,
  1692. unsigned int*) const;
  1693. #endif
  1694. #ifdef HAVE_TARGET_64_BIG
  1695. template
  1696. void
  1697. Versions::def_section_contents<64, true>(
  1698. const Stringpool*,
  1699. unsigned char**,
  1700. unsigned int*,
  1701. unsigned int*) const;
  1702. #endif
  1703. #ifdef HAVE_TARGET_32_LITTLE
  1704. template
  1705. void
  1706. Versions::need_section_contents<32, false>(
  1707. const Stringpool*,
  1708. unsigned char**,
  1709. unsigned int*,
  1710. unsigned int*) const;
  1711. #endif
  1712. #ifdef HAVE_TARGET_32_BIG
  1713. template
  1714. void
  1715. Versions::need_section_contents<32, true>(
  1716. const Stringpool*,
  1717. unsigned char**,
  1718. unsigned int*,
  1719. unsigned int*) const;
  1720. #endif
  1721. #ifdef HAVE_TARGET_64_LITTLE
  1722. template
  1723. void
  1724. Versions::need_section_contents<64, false>(
  1725. const Stringpool*,
  1726. unsigned char**,
  1727. unsigned int*,
  1728. unsigned int*) const;
  1729. #endif
  1730. #ifdef HAVE_TARGET_64_BIG
  1731. template
  1732. void
  1733. Versions::need_section_contents<64, true>(
  1734. const Stringpool*,
  1735. unsigned char**,
  1736. unsigned int*,
  1737. unsigned int*) const;
  1738. #endif
  1739. } // End namespace gold.