dynobj.cc 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999
  1. // dynobj.cc -- dynamic object support for gold
  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. #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. unsigned int hashlen = ((2
  810. + bucketcount
  811. + local_dynsym_count
  812. + dynsym_count)
  813. * 4);
  814. unsigned char* phash = new unsigned char[hashlen];
  815. if (parameters->target().is_big_endian())
  816. {
  817. #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
  818. Dynobj::sized_create_elf_hash_table<true>(bucket, chain, phash,
  819. hashlen);
  820. #else
  821. gold_unreachable();
  822. #endif
  823. }
  824. else
  825. {
  826. #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
  827. Dynobj::sized_create_elf_hash_table<false>(bucket, chain, phash,
  828. hashlen);
  829. #else
  830. gold_unreachable();
  831. #endif
  832. }
  833. *pphash = phash;
  834. *phashlen = hashlen;
  835. }
  836. // Fill in an ELF hash table.
  837. template<bool big_endian>
  838. void
  839. Dynobj::sized_create_elf_hash_table(const std::vector<uint32_t>& bucket,
  840. const std::vector<uint32_t>& chain,
  841. unsigned char* phash,
  842. unsigned int hashlen)
  843. {
  844. unsigned char* p = phash;
  845. const unsigned int bucketcount = bucket.size();
  846. const unsigned int chaincount = chain.size();
  847. elfcpp::Swap<32, big_endian>::writeval(p, bucketcount);
  848. p += 4;
  849. elfcpp::Swap<32, big_endian>::writeval(p, chaincount);
  850. p += 4;
  851. for (unsigned int i = 0; i < bucketcount; ++i)
  852. {
  853. elfcpp::Swap<32, big_endian>::writeval(p, bucket[i]);
  854. p += 4;
  855. }
  856. for (unsigned int i = 0; i < chaincount; ++i)
  857. {
  858. elfcpp::Swap<32, big_endian>::writeval(p, chain[i]);
  859. p += 4;
  860. }
  861. gold_assert(static_cast<unsigned int>(p - phash) == hashlen);
  862. }
  863. // The hash function used for the GNU hash table. This hash function
  864. // must not change, as the dynamic linker uses it also.
  865. uint32_t
  866. Dynobj::gnu_hash(const char* name)
  867. {
  868. const unsigned char* nameu = reinterpret_cast<const unsigned char*>(name);
  869. uint32_t h = 5381;
  870. unsigned char c;
  871. while ((c = *nameu++) != '\0')
  872. h = (h << 5) + h + c;
  873. return h;
  874. }
  875. // Create a GNU hash table, setting *PPHASH and *PHASHLEN. GNU hash
  876. // tables are an extension to ELF which are recognized by the GNU
  877. // dynamic linker. They are referenced using dynamic tag DT_GNU_HASH.
  878. // TARGET is the target. DYNSYMS is a vector with all the global
  879. // symbols which will be going into the dynamic symbol table.
  880. // LOCAL_DYNSYM_COUNT is the number of local symbols in the dynamic
  881. // symbol table.
  882. void
  883. Dynobj::create_gnu_hash_table(const std::vector<Symbol*>& dynsyms,
  884. unsigned int local_dynsym_count,
  885. unsigned char** pphash,
  886. unsigned int* phashlen)
  887. {
  888. const unsigned int count = dynsyms.size();
  889. // Sort the dynamic symbols into two vectors. Symbols which we do
  890. // not want to put into the hash table we store into
  891. // UNHASHED_DYNSYMS. Symbols which we do want to store we put into
  892. // HASHED_DYNSYMS. DYNSYM_HASHVALS is parallel to HASHED_DYNSYMS,
  893. // and records the hash codes.
  894. std::vector<Symbol*> unhashed_dynsyms;
  895. unhashed_dynsyms.reserve(count);
  896. std::vector<Symbol*> hashed_dynsyms;
  897. hashed_dynsyms.reserve(count);
  898. std::vector<uint32_t> dynsym_hashvals;
  899. dynsym_hashvals.reserve(count);
  900. for (unsigned int i = 0; i < count; ++i)
  901. {
  902. Symbol* sym = dynsyms[i];
  903. if (!sym->needs_dynsym_value()
  904. && (sym->is_undefined()
  905. || sym->is_from_dynobj()
  906. || sym->is_forced_local()))
  907. unhashed_dynsyms.push_back(sym);
  908. else
  909. {
  910. hashed_dynsyms.push_back(sym);
  911. dynsym_hashvals.push_back(Dynobj::gnu_hash(sym->name()));
  912. }
  913. }
  914. // Put the unhashed symbols at the start of the global portion of
  915. // the dynamic symbol table.
  916. const unsigned int unhashed_count = unhashed_dynsyms.size();
  917. unsigned int unhashed_dynsym_index = local_dynsym_count;
  918. for (unsigned int i = 0; i < unhashed_count; ++i)
  919. {
  920. unhashed_dynsyms[i]->set_dynsym_index(unhashed_dynsym_index);
  921. ++unhashed_dynsym_index;
  922. }
  923. // For the actual data generation we call out to a templatized
  924. // function.
  925. int size = parameters->target().get_size();
  926. bool big_endian = parameters->target().is_big_endian();
  927. if (size == 32)
  928. {
  929. if (big_endian)
  930. {
  931. #ifdef HAVE_TARGET_32_BIG
  932. Dynobj::sized_create_gnu_hash_table<32, true>(hashed_dynsyms,
  933. dynsym_hashvals,
  934. unhashed_dynsym_index,
  935. pphash,
  936. phashlen);
  937. #else
  938. gold_unreachable();
  939. #endif
  940. }
  941. else
  942. {
  943. #ifdef HAVE_TARGET_32_LITTLE
  944. Dynobj::sized_create_gnu_hash_table<32, false>(hashed_dynsyms,
  945. dynsym_hashvals,
  946. unhashed_dynsym_index,
  947. pphash,
  948. phashlen);
  949. #else
  950. gold_unreachable();
  951. #endif
  952. }
  953. }
  954. else if (size == 64)
  955. {
  956. if (big_endian)
  957. {
  958. #ifdef HAVE_TARGET_64_BIG
  959. Dynobj::sized_create_gnu_hash_table<64, true>(hashed_dynsyms,
  960. dynsym_hashvals,
  961. unhashed_dynsym_index,
  962. pphash,
  963. phashlen);
  964. #else
  965. gold_unreachable();
  966. #endif
  967. }
  968. else
  969. {
  970. #ifdef HAVE_TARGET_64_LITTLE
  971. Dynobj::sized_create_gnu_hash_table<64, false>(hashed_dynsyms,
  972. dynsym_hashvals,
  973. unhashed_dynsym_index,
  974. pphash,
  975. phashlen);
  976. #else
  977. gold_unreachable();
  978. #endif
  979. }
  980. }
  981. else
  982. gold_unreachable();
  983. }
  984. // Create the actual data for a GNU hash table. This is just a copy
  985. // of the code from the old GNU linker.
  986. template<int size, bool big_endian>
  987. void
  988. Dynobj::sized_create_gnu_hash_table(
  989. const std::vector<Symbol*>& hashed_dynsyms,
  990. const std::vector<uint32_t>& dynsym_hashvals,
  991. unsigned int unhashed_dynsym_count,
  992. unsigned char** pphash,
  993. unsigned int* phashlen)
  994. {
  995. if (hashed_dynsyms.empty())
  996. {
  997. // Special case for the empty hash table.
  998. unsigned int hashlen = 5 * 4 + size / 8;
  999. unsigned char* phash = new unsigned char[hashlen];
  1000. // One empty bucket.
  1001. elfcpp::Swap<32, big_endian>::writeval(phash, 1);
  1002. // Symbol index above unhashed symbols.
  1003. elfcpp::Swap<32, big_endian>::writeval(phash + 4, unhashed_dynsym_count);
  1004. // One word for bitmask.
  1005. elfcpp::Swap<32, big_endian>::writeval(phash + 8, 1);
  1006. // Only bloom filter.
  1007. elfcpp::Swap<32, big_endian>::writeval(phash + 12, 0);
  1008. // No valid hashes.
  1009. elfcpp::Swap<size, big_endian>::writeval(phash + 16, 0);
  1010. // No hashes in only bucket.
  1011. elfcpp::Swap<32, big_endian>::writeval(phash + 16 + size / 8, 0);
  1012. *phashlen = hashlen;
  1013. *pphash = phash;
  1014. return;
  1015. }
  1016. const unsigned int bucketcount =
  1017. Dynobj::compute_bucket_count(dynsym_hashvals, true);
  1018. const unsigned int nsyms = hashed_dynsyms.size();
  1019. uint32_t maskbitslog2 = 1;
  1020. uint32_t x = nsyms >> 1;
  1021. while (x != 0)
  1022. {
  1023. ++maskbitslog2;
  1024. x >>= 1;
  1025. }
  1026. if (maskbitslog2 < 3)
  1027. maskbitslog2 = 5;
  1028. else if (((1U << (maskbitslog2 - 2)) & nsyms) != 0)
  1029. maskbitslog2 += 3;
  1030. else
  1031. maskbitslog2 += 2;
  1032. uint32_t shift1;
  1033. if (size == 32)
  1034. shift1 = 5;
  1035. else
  1036. {
  1037. if (maskbitslog2 == 5)
  1038. maskbitslog2 = 6;
  1039. shift1 = 6;
  1040. }
  1041. uint32_t mask = (1U << shift1) - 1U;
  1042. uint32_t shift2 = maskbitslog2;
  1043. uint32_t maskbits = 1U << maskbitslog2;
  1044. uint32_t maskwords = 1U << (maskbitslog2 - shift1);
  1045. typedef typename elfcpp::Elf_types<size>::Elf_WXword Word;
  1046. std::vector<Word> bitmask(maskwords);
  1047. std::vector<uint32_t> counts(bucketcount);
  1048. std::vector<uint32_t> indx(bucketcount);
  1049. uint32_t symindx = unhashed_dynsym_count;
  1050. // Count the number of times each hash bucket is used.
  1051. for (unsigned int i = 0; i < nsyms; ++i)
  1052. ++counts[dynsym_hashvals[i] % bucketcount];
  1053. unsigned int cnt = symindx;
  1054. for (unsigned int i = 0; i < bucketcount; ++i)
  1055. {
  1056. indx[i] = cnt;
  1057. cnt += counts[i];
  1058. }
  1059. unsigned int hashlen = (4 + bucketcount + nsyms) * 4;
  1060. hashlen += maskbits / 8;
  1061. unsigned char* phash = new unsigned char[hashlen];
  1062. elfcpp::Swap<32, big_endian>::writeval(phash, bucketcount);
  1063. elfcpp::Swap<32, big_endian>::writeval(phash + 4, symindx);
  1064. elfcpp::Swap<32, big_endian>::writeval(phash + 8, maskwords);
  1065. elfcpp::Swap<32, big_endian>::writeval(phash + 12, shift2);
  1066. unsigned char* p = phash + 16 + maskbits / 8;
  1067. for (unsigned int i = 0; i < bucketcount; ++i)
  1068. {
  1069. if (counts[i] == 0)
  1070. elfcpp::Swap<32, big_endian>::writeval(p, 0);
  1071. else
  1072. elfcpp::Swap<32, big_endian>::writeval(p, indx[i]);
  1073. p += 4;
  1074. }
  1075. for (unsigned int i = 0; i < nsyms; ++i)
  1076. {
  1077. Symbol* sym = hashed_dynsyms[i];
  1078. uint32_t hashval = dynsym_hashvals[i];
  1079. unsigned int bucket = hashval % bucketcount;
  1080. unsigned int val = ((hashval >> shift1)
  1081. & ((maskbits >> shift1) - 1));
  1082. bitmask[val] |= (static_cast<Word>(1U)) << (hashval & mask);
  1083. bitmask[val] |= (static_cast<Word>(1U)) << ((hashval >> shift2) & mask);
  1084. val = hashval & ~ 1U;
  1085. if (counts[bucket] == 1)
  1086. {
  1087. // Last element terminates the chain.
  1088. val |= 1;
  1089. }
  1090. elfcpp::Swap<32, big_endian>::writeval(p + (indx[bucket] - symindx) * 4,
  1091. val);
  1092. --counts[bucket];
  1093. sym->set_dynsym_index(indx[bucket]);
  1094. ++indx[bucket];
  1095. }
  1096. p = phash + 16;
  1097. for (unsigned int i = 0; i < maskwords; ++i)
  1098. {
  1099. elfcpp::Swap<size, big_endian>::writeval(p, bitmask[i]);
  1100. p += size / 8;
  1101. }
  1102. *phashlen = hashlen;
  1103. *pphash = phash;
  1104. }
  1105. // Verdef methods.
  1106. // Write this definition to a buffer for the output section.
  1107. template<int size, bool big_endian>
  1108. unsigned char*
  1109. Verdef::write(const Stringpool* dynpool, bool is_last, unsigned char* pb) const
  1110. {
  1111. const int verdef_size = elfcpp::Elf_sizes<size>::verdef_size;
  1112. const int verdaux_size = elfcpp::Elf_sizes<size>::verdaux_size;
  1113. elfcpp::Verdef_write<size, big_endian> vd(pb);
  1114. vd.set_vd_version(elfcpp::VER_DEF_CURRENT);
  1115. vd.set_vd_flags((this->is_base_ ? elfcpp::VER_FLG_BASE : 0)
  1116. | (this->is_weak_ ? elfcpp::VER_FLG_WEAK : 0)
  1117. | (this->is_info_ ? elfcpp::VER_FLG_INFO : 0));
  1118. vd.set_vd_ndx(this->index());
  1119. vd.set_vd_cnt(1 + this->deps_.size());
  1120. vd.set_vd_hash(Dynobj::elf_hash(this->name()));
  1121. vd.set_vd_aux(verdef_size);
  1122. vd.set_vd_next(is_last
  1123. ? 0
  1124. : verdef_size + (1 + this->deps_.size()) * verdaux_size);
  1125. pb += verdef_size;
  1126. elfcpp::Verdaux_write<size, big_endian> vda(pb);
  1127. vda.set_vda_name(dynpool->get_offset(this->name()));
  1128. vda.set_vda_next(this->deps_.empty() ? 0 : verdaux_size);
  1129. pb += verdaux_size;
  1130. Deps::const_iterator p;
  1131. unsigned int i;
  1132. for (p = this->deps_.begin(), i = 0;
  1133. p != this->deps_.end();
  1134. ++p, ++i)
  1135. {
  1136. elfcpp::Verdaux_write<size, big_endian> vda(pb);
  1137. vda.set_vda_name(dynpool->get_offset(*p));
  1138. vda.set_vda_next(i + 1 >= this->deps_.size() ? 0 : verdaux_size);
  1139. pb += verdaux_size;
  1140. }
  1141. return pb;
  1142. }
  1143. // Verneed methods.
  1144. Verneed::~Verneed()
  1145. {
  1146. for (Need_versions::iterator p = this->need_versions_.begin();
  1147. p != this->need_versions_.end();
  1148. ++p)
  1149. delete *p;
  1150. }
  1151. // Add a new version to this file reference.
  1152. Verneed_version*
  1153. Verneed::add_name(const char* name)
  1154. {
  1155. Verneed_version* vv = new Verneed_version(name);
  1156. this->need_versions_.push_back(vv);
  1157. return vv;
  1158. }
  1159. // Set the version indexes starting at INDEX.
  1160. unsigned int
  1161. Verneed::finalize(unsigned int index)
  1162. {
  1163. for (Need_versions::iterator p = this->need_versions_.begin();
  1164. p != this->need_versions_.end();
  1165. ++p)
  1166. {
  1167. (*p)->set_index(index);
  1168. ++index;
  1169. }
  1170. return index;
  1171. }
  1172. // Write this list of referenced versions to a buffer for the output
  1173. // section.
  1174. template<int size, bool big_endian>
  1175. unsigned char*
  1176. Verneed::write(const Stringpool* dynpool, bool is_last,
  1177. unsigned char* pb) const
  1178. {
  1179. const int verneed_size = elfcpp::Elf_sizes<size>::verneed_size;
  1180. const int vernaux_size = elfcpp::Elf_sizes<size>::vernaux_size;
  1181. elfcpp::Verneed_write<size, big_endian> vn(pb);
  1182. vn.set_vn_version(elfcpp::VER_NEED_CURRENT);
  1183. vn.set_vn_cnt(this->need_versions_.size());
  1184. vn.set_vn_file(dynpool->get_offset(this->filename()));
  1185. vn.set_vn_aux(verneed_size);
  1186. vn.set_vn_next(is_last
  1187. ? 0
  1188. : verneed_size + this->need_versions_.size() * vernaux_size);
  1189. pb += verneed_size;
  1190. Need_versions::const_iterator p;
  1191. unsigned int i;
  1192. for (p = this->need_versions_.begin(), i = 0;
  1193. p != this->need_versions_.end();
  1194. ++p, ++i)
  1195. {
  1196. elfcpp::Vernaux_write<size, big_endian> vna(pb);
  1197. vna.set_vna_hash(Dynobj::elf_hash((*p)->version()));
  1198. // FIXME: We need to sometimes set VER_FLG_WEAK here.
  1199. vna.set_vna_flags(0);
  1200. vna.set_vna_other((*p)->index());
  1201. vna.set_vna_name(dynpool->get_offset((*p)->version()));
  1202. vna.set_vna_next(i + 1 >= this->need_versions_.size()
  1203. ? 0
  1204. : vernaux_size);
  1205. pb += vernaux_size;
  1206. }
  1207. return pb;
  1208. }
  1209. // Versions methods.
  1210. Versions::Versions(const Version_script_info& version_script,
  1211. Stringpool* dynpool)
  1212. : defs_(), needs_(), version_table_(),
  1213. is_finalized_(false), version_script_(version_script),
  1214. needs_base_version_(parameters->options().shared())
  1215. {
  1216. if (!this->version_script_.empty())
  1217. {
  1218. // Parse the version script, and insert each declared version into
  1219. // defs_ and version_table_.
  1220. std::vector<std::string> versions = this->version_script_.get_versions();
  1221. if (this->needs_base_version_ && !versions.empty())
  1222. this->define_base_version(dynpool);
  1223. for (size_t k = 0; k < versions.size(); ++k)
  1224. {
  1225. Stringpool::Key version_key;
  1226. const char* version = dynpool->add(versions[k].c_str(),
  1227. true, &version_key);
  1228. Verdef* const vd = new Verdef(
  1229. version,
  1230. this->version_script_.get_dependencies(version),
  1231. false, false, false, false);
  1232. this->defs_.push_back(vd);
  1233. Key key(version_key, 0);
  1234. this->version_table_.insert(std::make_pair(key, vd));
  1235. }
  1236. }
  1237. }
  1238. Versions::~Versions()
  1239. {
  1240. for (Defs::iterator p = this->defs_.begin();
  1241. p != this->defs_.end();
  1242. ++p)
  1243. delete *p;
  1244. for (Needs::iterator p = this->needs_.begin();
  1245. p != this->needs_.end();
  1246. ++p)
  1247. delete *p;
  1248. }
  1249. // Define the base version of a shared library. The base version definition
  1250. // must be the first entry in defs_. We insert it lazily so that defs_ is
  1251. // empty if no symbol versioning is used. Then layout can just drop the
  1252. // version sections.
  1253. void
  1254. Versions::define_base_version(Stringpool* dynpool)
  1255. {
  1256. // If we do any versioning at all, we always need a base version, so
  1257. // define that first. Nothing explicitly declares itself as part of base,
  1258. // so it doesn't need to be in version_table_.
  1259. gold_assert(this->defs_.empty());
  1260. const char* name = parameters->options().soname();
  1261. if (name == NULL)
  1262. name = parameters->options().output_file_name();
  1263. name = dynpool->add(name, false, NULL);
  1264. Verdef* vdbase = new Verdef(name, std::vector<std::string>(),
  1265. true, false, false, true);
  1266. this->defs_.push_back(vdbase);
  1267. this->needs_base_version_ = false;
  1268. }
  1269. // Return the dynamic object which a symbol refers to.
  1270. Dynobj*
  1271. Versions::get_dynobj_for_sym(const Symbol_table* symtab,
  1272. const Symbol* sym) const
  1273. {
  1274. if (sym->is_copied_from_dynobj())
  1275. return symtab->get_copy_source(sym);
  1276. else
  1277. {
  1278. Object* object = sym->object();
  1279. gold_assert(object->is_dynamic());
  1280. return static_cast<Dynobj*>(object);
  1281. }
  1282. }
  1283. // Record version information for a symbol going into the dynamic
  1284. // symbol table.
  1285. void
  1286. Versions::record_version(const Symbol_table* symtab,
  1287. Stringpool* dynpool, const Symbol* sym)
  1288. {
  1289. gold_assert(!this->is_finalized_);
  1290. gold_assert(sym->version() != NULL);
  1291. // A symbol defined as "sym@" is bound to an unspecified base version.
  1292. if (sym->version()[0] == '\0')
  1293. return;
  1294. Stringpool::Key version_key;
  1295. const char* version = dynpool->add(sym->version(), false, &version_key);
  1296. if (!sym->is_from_dynobj() && !sym->is_copied_from_dynobj())
  1297. {
  1298. if (parameters->options().shared())
  1299. this->add_def(dynpool, sym, version, version_key);
  1300. }
  1301. else
  1302. {
  1303. // This is a version reference.
  1304. Dynobj* dynobj = this->get_dynobj_for_sym(symtab, sym);
  1305. this->add_need(dynpool, dynobj->soname(), version, version_key);
  1306. }
  1307. }
  1308. // We've found a symbol SYM defined in version VERSION.
  1309. void
  1310. Versions::add_def(Stringpool* dynpool, const Symbol* sym, const char* version,
  1311. Stringpool::Key version_key)
  1312. {
  1313. Key k(version_key, 0);
  1314. Version_base* const vbnull = NULL;
  1315. std::pair<Version_table::iterator, bool> ins =
  1316. this->version_table_.insert(std::make_pair(k, vbnull));
  1317. if (!ins.second)
  1318. {
  1319. // We already have an entry for this version.
  1320. Version_base* vb = ins.first->second;
  1321. // We have now seen a symbol in this version, so it is not
  1322. // weak.
  1323. gold_assert(vb != NULL);
  1324. vb->clear_weak();
  1325. }
  1326. else
  1327. {
  1328. // If we are creating a shared object, it is an error to
  1329. // find a definition of a symbol with a version which is not
  1330. // in the version script.
  1331. if (parameters->options().shared())
  1332. {
  1333. gold_error(_("symbol %s has undefined version %s"),
  1334. sym->demangled_name().c_str(), version);
  1335. if (this->needs_base_version_)
  1336. this->define_base_version(dynpool);
  1337. }
  1338. else
  1339. // We only insert a base version for shared library.
  1340. gold_assert(!this->needs_base_version_);
  1341. // When creating a regular executable, automatically define
  1342. // a new version.
  1343. Verdef* vd = new Verdef(version, std::vector<std::string>(),
  1344. false, false, false, false);
  1345. this->defs_.push_back(vd);
  1346. ins.first->second = vd;
  1347. }
  1348. }
  1349. // Add a reference to version NAME in file FILENAME.
  1350. void
  1351. Versions::add_need(Stringpool* dynpool, const char* filename, const char* name,
  1352. Stringpool::Key name_key)
  1353. {
  1354. Stringpool::Key filename_key;
  1355. filename = dynpool->add(filename, true, &filename_key);
  1356. Key k(name_key, filename_key);
  1357. Version_base* const vbnull = NULL;
  1358. std::pair<Version_table::iterator, bool> ins =
  1359. this->version_table_.insert(std::make_pair(k, vbnull));
  1360. if (!ins.second)
  1361. {
  1362. // We already have an entry for this filename/version.
  1363. return;
  1364. }
  1365. // See whether we already have this filename. We don't expect many
  1366. // version references, so we just do a linear search. This could be
  1367. // replaced by a hash table.
  1368. Verneed* vn = NULL;
  1369. for (Needs::iterator p = this->needs_.begin();
  1370. p != this->needs_.end();
  1371. ++p)
  1372. {
  1373. if ((*p)->filename() == filename)
  1374. {
  1375. vn = *p;
  1376. break;
  1377. }
  1378. }
  1379. if (vn == NULL)
  1380. {
  1381. // Create base version definition lazily for shared library.
  1382. if (this->needs_base_version_)
  1383. this->define_base_version(dynpool);
  1384. // We have a new filename.
  1385. vn = new Verneed(filename);
  1386. this->needs_.push_back(vn);
  1387. }
  1388. ins.first->second = vn->add_name(name);
  1389. }
  1390. // Set the version indexes. Create a new dynamic version symbol for
  1391. // each new version definition.
  1392. unsigned int
  1393. Versions::finalize(Symbol_table* symtab, unsigned int dynsym_index,
  1394. std::vector<Symbol*>* syms)
  1395. {
  1396. gold_assert(!this->is_finalized_);
  1397. unsigned int vi = 1;
  1398. for (Defs::iterator p = this->defs_.begin();
  1399. p != this->defs_.end();
  1400. ++p)
  1401. {
  1402. (*p)->set_index(vi);
  1403. ++vi;
  1404. // Create a version symbol if necessary.
  1405. if (!(*p)->is_symbol_created())
  1406. {
  1407. Symbol* vsym = symtab->define_as_constant((*p)->name(),
  1408. (*p)->name(),
  1409. Symbol_table::PREDEFINED,
  1410. 0, 0,
  1411. elfcpp::STT_OBJECT,
  1412. elfcpp::STB_GLOBAL,
  1413. elfcpp::STV_DEFAULT, 0,
  1414. false, false);
  1415. vsym->set_needs_dynsym_entry();
  1416. vsym->set_dynsym_index(dynsym_index);
  1417. vsym->set_is_default();
  1418. ++dynsym_index;
  1419. syms->push_back(vsym);
  1420. // The name is already in the dynamic pool.
  1421. }
  1422. }
  1423. // Index 1 is used for global symbols.
  1424. if (vi == 1)
  1425. {
  1426. gold_assert(this->defs_.empty());
  1427. vi = 2;
  1428. }
  1429. for (Needs::iterator p = this->needs_.begin();
  1430. p != this->needs_.end();
  1431. ++p)
  1432. vi = (*p)->finalize(vi);
  1433. this->is_finalized_ = true;
  1434. return dynsym_index;
  1435. }
  1436. // Return the version index to use for a symbol. This does two hash
  1437. // table lookups: one in DYNPOOL and one in this->version_table_.
  1438. // Another approach alternative would be store a pointer in SYM, which
  1439. // would increase the size of the symbol table. Or perhaps we could
  1440. // use a hash table from dynamic symbol pointer values to Version_base
  1441. // pointers.
  1442. unsigned int
  1443. Versions::version_index(const Symbol_table* symtab, const Stringpool* dynpool,
  1444. const Symbol* sym) const
  1445. {
  1446. Stringpool::Key version_key;
  1447. const char* version = dynpool->find(sym->version(), &version_key);
  1448. gold_assert(version != NULL);
  1449. Key k;
  1450. if (!sym->is_from_dynobj() && !sym->is_copied_from_dynobj())
  1451. {
  1452. if (!parameters->options().shared())
  1453. return elfcpp::VER_NDX_GLOBAL;
  1454. k = Key(version_key, 0);
  1455. }
  1456. else
  1457. {
  1458. Dynobj* dynobj = this->get_dynobj_for_sym(symtab, sym);
  1459. Stringpool::Key filename_key;
  1460. const char* filename = dynpool->find(dynobj->soname(), &filename_key);
  1461. gold_assert(filename != NULL);
  1462. k = Key(version_key, filename_key);
  1463. }
  1464. Version_table::const_iterator p = this->version_table_.find(k);
  1465. gold_assert(p != this->version_table_.end());
  1466. return p->second->index();
  1467. }
  1468. // Return an allocated buffer holding the contents of the symbol
  1469. // version section.
  1470. template<int size, bool big_endian>
  1471. void
  1472. Versions::symbol_section_contents(const Symbol_table* symtab,
  1473. const Stringpool* dynpool,
  1474. unsigned int local_symcount,
  1475. const std::vector<Symbol*>& syms,
  1476. unsigned char** pp,
  1477. unsigned int* psize) const
  1478. {
  1479. gold_assert(this->is_finalized_);
  1480. unsigned int sz = (local_symcount + syms.size()) * 2;
  1481. unsigned char* pbuf = new unsigned char[sz];
  1482. for (unsigned int i = 0; i < local_symcount; ++i)
  1483. elfcpp::Swap<16, big_endian>::writeval(pbuf + i * 2,
  1484. elfcpp::VER_NDX_LOCAL);
  1485. for (std::vector<Symbol*>::const_iterator p = syms.begin();
  1486. p != syms.end();
  1487. ++p)
  1488. {
  1489. unsigned int version_index;
  1490. const char* version = (*p)->version();
  1491. if (version == NULL)
  1492. {
  1493. if ((*p)->is_defined() && !(*p)->is_from_dynobj())
  1494. version_index = elfcpp::VER_NDX_GLOBAL;
  1495. else
  1496. version_index = elfcpp::VER_NDX_LOCAL;
  1497. }
  1498. else if (version[0] == '\0')
  1499. version_index = elfcpp::VER_NDX_GLOBAL;
  1500. else
  1501. version_index = this->version_index(symtab, dynpool, *p);
  1502. // If the symbol was defined as foo@V1 instead of foo@@V1, add
  1503. // the hidden bit.
  1504. if ((*p)->version() != NULL && !(*p)->is_default())
  1505. version_index |= elfcpp::VERSYM_HIDDEN;
  1506. elfcpp::Swap<16, big_endian>::writeval(pbuf + (*p)->dynsym_index() * 2,
  1507. version_index);
  1508. }
  1509. *pp = pbuf;
  1510. *psize = sz;
  1511. }
  1512. // Return an allocated buffer holding the contents of the version
  1513. // definition section.
  1514. template<int size, bool big_endian>
  1515. void
  1516. Versions::def_section_contents(const Stringpool* dynpool,
  1517. unsigned char** pp, unsigned int* psize,
  1518. unsigned int* pentries) const
  1519. {
  1520. gold_assert(this->is_finalized_);
  1521. gold_assert(!this->defs_.empty());
  1522. const int verdef_size = elfcpp::Elf_sizes<size>::verdef_size;
  1523. const int verdaux_size = elfcpp::Elf_sizes<size>::verdaux_size;
  1524. unsigned int sz = 0;
  1525. for (Defs::const_iterator p = this->defs_.begin();
  1526. p != this->defs_.end();
  1527. ++p)
  1528. {
  1529. sz += verdef_size + verdaux_size;
  1530. sz += (*p)->count_dependencies() * verdaux_size;
  1531. }
  1532. unsigned char* pbuf = new unsigned char[sz];
  1533. unsigned char* pb = pbuf;
  1534. Defs::const_iterator p;
  1535. unsigned int i;
  1536. for (p = this->defs_.begin(), i = 0;
  1537. p != this->defs_.end();
  1538. ++p, ++i)
  1539. pb = (*p)->write<size, big_endian>(dynpool,
  1540. i + 1 >= this->defs_.size(),
  1541. pb);
  1542. gold_assert(static_cast<unsigned int>(pb - pbuf) == sz);
  1543. *pp = pbuf;
  1544. *psize = sz;
  1545. *pentries = this->defs_.size();
  1546. }
  1547. // Return an allocated buffer holding the contents of the version
  1548. // reference section.
  1549. template<int size, bool big_endian>
  1550. void
  1551. Versions::need_section_contents(const Stringpool* dynpool,
  1552. unsigned char** pp, unsigned int* psize,
  1553. unsigned int* pentries) const
  1554. {
  1555. gold_assert(this->is_finalized_);
  1556. gold_assert(!this->needs_.empty());
  1557. const int verneed_size = elfcpp::Elf_sizes<size>::verneed_size;
  1558. const int vernaux_size = elfcpp::Elf_sizes<size>::vernaux_size;
  1559. unsigned int sz = 0;
  1560. for (Needs::const_iterator p = this->needs_.begin();
  1561. p != this->needs_.end();
  1562. ++p)
  1563. {
  1564. sz += verneed_size;
  1565. sz += (*p)->count_versions() * vernaux_size;
  1566. }
  1567. unsigned char* pbuf = new unsigned char[sz];
  1568. unsigned char* pb = pbuf;
  1569. Needs::const_iterator p;
  1570. unsigned int i;
  1571. for (p = this->needs_.begin(), i = 0;
  1572. p != this->needs_.end();
  1573. ++p, ++i)
  1574. pb = (*p)->write<size, big_endian>(dynpool,
  1575. i + 1 >= this->needs_.size(),
  1576. pb);
  1577. gold_assert(static_cast<unsigned int>(pb - pbuf) == sz);
  1578. *pp = pbuf;
  1579. *psize = sz;
  1580. *pentries = this->needs_.size();
  1581. }
  1582. // Instantiate the templates we need. We could use the configure
  1583. // script to restrict this to only the ones for implemented targets.
  1584. #ifdef HAVE_TARGET_32_LITTLE
  1585. template
  1586. class Sized_dynobj<32, false>;
  1587. #endif
  1588. #ifdef HAVE_TARGET_32_BIG
  1589. template
  1590. class Sized_dynobj<32, true>;
  1591. #endif
  1592. #ifdef HAVE_TARGET_64_LITTLE
  1593. template
  1594. class Sized_dynobj<64, false>;
  1595. #endif
  1596. #ifdef HAVE_TARGET_64_BIG
  1597. template
  1598. class Sized_dynobj<64, true>;
  1599. #endif
  1600. #ifdef HAVE_TARGET_32_LITTLE
  1601. template
  1602. void
  1603. Versions::symbol_section_contents<32, false>(
  1604. const Symbol_table*,
  1605. const Stringpool*,
  1606. unsigned int,
  1607. const std::vector<Symbol*>&,
  1608. unsigned char**,
  1609. unsigned int*) const;
  1610. #endif
  1611. #ifdef HAVE_TARGET_32_BIG
  1612. template
  1613. void
  1614. Versions::symbol_section_contents<32, true>(
  1615. const Symbol_table*,
  1616. const Stringpool*,
  1617. unsigned int,
  1618. const std::vector<Symbol*>&,
  1619. unsigned char**,
  1620. unsigned int*) const;
  1621. #endif
  1622. #ifdef HAVE_TARGET_64_LITTLE
  1623. template
  1624. void
  1625. Versions::symbol_section_contents<64, false>(
  1626. const Symbol_table*,
  1627. const Stringpool*,
  1628. unsigned int,
  1629. const std::vector<Symbol*>&,
  1630. unsigned char**,
  1631. unsigned int*) const;
  1632. #endif
  1633. #ifdef HAVE_TARGET_64_BIG
  1634. template
  1635. void
  1636. Versions::symbol_section_contents<64, true>(
  1637. const Symbol_table*,
  1638. const Stringpool*,
  1639. unsigned int,
  1640. const std::vector<Symbol*>&,
  1641. unsigned char**,
  1642. unsigned int*) const;
  1643. #endif
  1644. #ifdef HAVE_TARGET_32_LITTLE
  1645. template
  1646. void
  1647. Versions::def_section_contents<32, false>(
  1648. const Stringpool*,
  1649. unsigned char**,
  1650. unsigned int*,
  1651. unsigned int*) const;
  1652. #endif
  1653. #ifdef HAVE_TARGET_32_BIG
  1654. template
  1655. void
  1656. Versions::def_section_contents<32, true>(
  1657. const Stringpool*,
  1658. unsigned char**,
  1659. unsigned int*,
  1660. unsigned int*) const;
  1661. #endif
  1662. #ifdef HAVE_TARGET_64_LITTLE
  1663. template
  1664. void
  1665. Versions::def_section_contents<64, false>(
  1666. const Stringpool*,
  1667. unsigned char**,
  1668. unsigned int*,
  1669. unsigned int*) const;
  1670. #endif
  1671. #ifdef HAVE_TARGET_64_BIG
  1672. template
  1673. void
  1674. Versions::def_section_contents<64, true>(
  1675. const Stringpool*,
  1676. unsigned char**,
  1677. unsigned int*,
  1678. unsigned int*) const;
  1679. #endif
  1680. #ifdef HAVE_TARGET_32_LITTLE
  1681. template
  1682. void
  1683. Versions::need_section_contents<32, false>(
  1684. const Stringpool*,
  1685. unsigned char**,
  1686. unsigned int*,
  1687. unsigned int*) const;
  1688. #endif
  1689. #ifdef HAVE_TARGET_32_BIG
  1690. template
  1691. void
  1692. Versions::need_section_contents<32, true>(
  1693. const Stringpool*,
  1694. unsigned char**,
  1695. unsigned int*,
  1696. unsigned int*) const;
  1697. #endif
  1698. #ifdef HAVE_TARGET_64_LITTLE
  1699. template
  1700. void
  1701. Versions::need_section_contents<64, false>(
  1702. const Stringpool*,
  1703. unsigned char**,
  1704. unsigned int*,
  1705. unsigned int*) const;
  1706. #endif
  1707. #ifdef HAVE_TARGET_64_BIG
  1708. template
  1709. void
  1710. Versions::need_section_contents<64, true>(
  1711. const Stringpool*,
  1712. unsigned char**,
  1713. unsigned int*,
  1714. unsigned int*) const;
  1715. #endif
  1716. } // End namespace gold.