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