1 // dynobj.cc -- dynamic object support for gold
3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
29 #include "parameters.h"
39 // Sets up the default soname_ to use, in the (rare) cases we never
40 // see a DT_SONAME entry.
42 Dynobj::Dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
)
43 : Object(name
, input_file
, true, offset
),
45 unknown_needed_(UNKNOWN_NEEDED_UNSET
)
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.
52 this->soname_
= this->input_file()->found_name();
53 if (this->offset() != 0)
55 std::string::size_type open_paren
= this->name().find('(');
56 std::string::size_type close_paren
= this->name().find(')');
57 if (open_paren
!= std::string::npos
&& close_paren
!= std::string::npos
)
59 // It's an archive, and name() is of the form 'foo.a(bar.so)'.
60 this->soname_
= this->name().substr(open_paren
+ 1,
61 close_paren
- (open_paren
+ 1));
66 // Class Sized_dynobj.
68 template<int size
, bool big_endian
>
69 Sized_dynobj
<size
, big_endian
>::Sized_dynobj(
70 const std::string
& name
,
71 Input_file
* input_file
,
73 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
74 : Dynobj(name
, input_file
, offset
),
81 template<int size
, bool big_endian
>
83 Sized_dynobj
<size
, big_endian
>::setup(
84 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
86 this->set_target(ehdr
.get_e_machine(), size
, big_endian
,
87 ehdr
.get_e_ident()[elfcpp::EI_OSABI
],
88 ehdr
.get_e_ident()[elfcpp::EI_ABIVERSION
]);
90 const unsigned int shnum
= this->elf_file_
.shnum();
91 this->set_shnum(shnum
);
94 // Find the SHT_DYNSYM section and the various version sections, and
95 // the dynamic section, given the section headers.
97 template<int size
, bool big_endian
>
99 Sized_dynobj
<size
, big_endian
>::find_dynsym_sections(
100 const unsigned char* pshdrs
,
101 unsigned int* pdynsym_shndx
,
102 unsigned int* pversym_shndx
,
103 unsigned int* pverdef_shndx
,
104 unsigned int* pverneed_shndx
,
105 unsigned int* pdynamic_shndx
)
107 *pdynsym_shndx
= -1U;
108 *pversym_shndx
= -1U;
109 *pverdef_shndx
= -1U;
110 *pverneed_shndx
= -1U;
111 *pdynamic_shndx
= -1U;
113 const unsigned int shnum
= this->shnum();
114 const unsigned char* p
= pshdrs
;
115 for (unsigned int i
= 0; i
< shnum
; ++i
, p
+= This::shdr_size
)
117 typename
This::Shdr
shdr(p
);
120 switch (shdr
.get_sh_type())
122 case elfcpp::SHT_DYNSYM
:
125 case elfcpp::SHT_GNU_versym
:
128 case elfcpp::SHT_GNU_verdef
:
131 case elfcpp::SHT_GNU_verneed
:
134 case elfcpp::SHT_DYNAMIC
:
146 this->error(_("unexpected duplicate type %u section: %u, %u"),
147 shdr
.get_sh_type(), *pi
, i
);
153 // Read the contents of section SHNDX. PSHDRS points to the section
154 // headers. TYPE is the expected section type. LINK is the expected
155 // section link. Store the data in *VIEW and *VIEW_SIZE. The
156 // section's sh_info field is stored in *VIEW_INFO.
158 template<int size
, bool big_endian
>
160 Sized_dynobj
<size
, big_endian
>::read_dynsym_section(
161 const unsigned char* pshdrs
,
166 section_size_type
* view_size
,
167 unsigned int* view_info
)
177 typename
This::Shdr
shdr(pshdrs
+ shndx
* This::shdr_size
);
179 gold_assert(shdr
.get_sh_type() == type
);
181 if (shdr
.get_sh_link() != link
)
182 this->error(_("unexpected link in section %u header: %u != %u"),
183 shndx
, shdr
.get_sh_link(), link
);
185 *view
= this->get_lasting_view(shdr
.get_sh_offset(), shdr
.get_sh_size(),
187 *view_size
= convert_to_section_size_type(shdr
.get_sh_size());
188 *view_info
= shdr
.get_sh_info();
191 // Read the dynamic tags. Set the soname field if this shared object
192 // has a DT_SONAME tag. Record the DT_NEEDED tags. PSHDRS points to
193 // the section headers. DYNAMIC_SHNDX is the section index of the
194 // SHT_DYNAMIC section. STRTAB_SHNDX, STRTAB, and STRTAB_SIZE are the
195 // section index and contents of a string table which may be the one
196 // associated with the SHT_DYNAMIC section.
198 template<int size
, bool big_endian
>
200 Sized_dynobj
<size
, big_endian
>::read_dynamic(const unsigned char* pshdrs
,
201 unsigned int dynamic_shndx
,
202 unsigned int strtab_shndx
,
203 const unsigned char* strtabu
,
206 typename
This::Shdr
dynamicshdr(pshdrs
+ dynamic_shndx
* This::shdr_size
);
207 gold_assert(dynamicshdr
.get_sh_type() == elfcpp::SHT_DYNAMIC
);
209 const off_t dynamic_size
= dynamicshdr
.get_sh_size();
210 const unsigned char* pdynamic
= this->get_view(dynamicshdr
.get_sh_offset(),
211 dynamic_size
, false);
213 const unsigned int link
= dynamicshdr
.get_sh_link();
214 if (link
!= strtab_shndx
)
216 if (link
>= this->shnum())
218 this->error(_("DYNAMIC section %u link out of range: %u"),
219 dynamic_shndx
, link
);
223 typename
This::Shdr
strtabshdr(pshdrs
+ link
* This::shdr_size
);
224 if (strtabshdr
.get_sh_type() != elfcpp::SHT_STRTAB
)
226 this->error(_("DYNAMIC section %u link %u is not a strtab"),
227 dynamic_shndx
, link
);
231 strtab_size
= strtabshdr
.get_sh_size();
232 strtabu
= this->get_view(strtabshdr
.get_sh_offset(), strtab_size
, false);
235 const char* const strtab
= reinterpret_cast<const char*>(strtabu
);
237 for (const unsigned char* p
= pdynamic
;
238 p
< pdynamic
+ dynamic_size
;
241 typename
This::Dyn
dyn(p
);
243 switch (dyn
.get_d_tag())
245 case elfcpp::DT_NULL
:
246 // We should always see DT_NULL at the end of the dynamic
250 case elfcpp::DT_SONAME
:
252 off_t val
= dyn
.get_d_val();
253 if (val
>= strtab_size
)
254 this->error(_("DT_SONAME value out of range: %lld >= %lld"),
255 static_cast<long long>(val
),
256 static_cast<long long>(strtab_size
));
258 this->set_soname_string(strtab
+ val
);
262 case elfcpp::DT_NEEDED
:
264 off_t val
= dyn
.get_d_val();
265 if (val
>= strtab_size
)
266 this->error(_("DT_NEEDED value out of range: %lld >= %lld"),
267 static_cast<long long>(val
),
268 static_cast<long long>(strtab_size
));
270 this->add_needed(strtab
+ val
);
279 this->error(_("missing DT_NULL in dynamic segment"));
282 // Read the symbols and sections from a dynamic object. We read the
283 // dynamic symbols, not the normal symbols.
285 template<int size
, bool big_endian
>
287 Sized_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
289 this->read_section_data(&this->elf_file_
, sd
);
291 const unsigned char* const pshdrs
= sd
->section_headers
->data();
293 unsigned int dynsym_shndx
;
294 unsigned int versym_shndx
;
295 unsigned int verdef_shndx
;
296 unsigned int verneed_shndx
;
297 unsigned int dynamic_shndx
;
298 this->find_dynsym_sections(pshdrs
, &dynsym_shndx
, &versym_shndx
,
299 &verdef_shndx
, &verneed_shndx
, &dynamic_shndx
);
301 unsigned int strtab_shndx
= -1U;
304 sd
->symbols_size
= 0;
305 sd
->external_symbols_offset
= 0;
306 sd
->symbol_names
= NULL
;
307 sd
->symbol_names_size
= 0;
309 if (dynsym_shndx
!= -1U)
311 // Get the dynamic symbols.
312 typename
This::Shdr
dynsymshdr(pshdrs
+ dynsym_shndx
* This::shdr_size
);
313 gold_assert(dynsymshdr
.get_sh_type() == elfcpp::SHT_DYNSYM
);
315 sd
->symbols
= this->get_lasting_view(dynsymshdr
.get_sh_offset(),
316 dynsymshdr
.get_sh_size(), false);
318 convert_to_section_size_type(dynsymshdr
.get_sh_size());
320 // Get the symbol names.
321 strtab_shndx
= dynsymshdr
.get_sh_link();
322 if (strtab_shndx
>= this->shnum())
324 this->error(_("invalid dynamic symbol table name index: %u"),
328 typename
This::Shdr
strtabshdr(pshdrs
+ strtab_shndx
* This::shdr_size
);
329 if (strtabshdr
.get_sh_type() != elfcpp::SHT_STRTAB
)
331 this->error(_("dynamic symbol table name section "
332 "has wrong type: %u"),
333 static_cast<unsigned int>(strtabshdr
.get_sh_type()));
337 sd
->symbol_names
= this->get_lasting_view(strtabshdr
.get_sh_offset(),
338 strtabshdr
.get_sh_size(),
340 sd
->symbol_names_size
=
341 convert_to_section_size_type(strtabshdr
.get_sh_size());
343 // Get the version information.
346 this->read_dynsym_section(pshdrs
, versym_shndx
, elfcpp::SHT_GNU_versym
,
347 dynsym_shndx
, &sd
->versym
, &sd
->versym_size
,
350 // We require that the version definition and need section link
351 // to the same string table as the dynamic symbol table. This
352 // is not a technical requirement, but it always happens in
353 // practice. We could change this if necessary.
355 this->read_dynsym_section(pshdrs
, verdef_shndx
, elfcpp::SHT_GNU_verdef
,
356 strtab_shndx
, &sd
->verdef
, &sd
->verdef_size
,
359 this->read_dynsym_section(pshdrs
, verneed_shndx
, elfcpp::SHT_GNU_verneed
,
360 strtab_shndx
, &sd
->verneed
, &sd
->verneed_size
,
364 // Read the SHT_DYNAMIC section to find whether this shared object
365 // has a DT_SONAME tag and to record any DT_NEEDED tags. This
366 // doesn't really have anything to do with reading the symbols, but
367 // this is a convenient place to do it.
368 if (dynamic_shndx
!= -1U)
369 this->read_dynamic(pshdrs
, dynamic_shndx
, strtab_shndx
,
370 (sd
->symbol_names
== NULL
372 : sd
->symbol_names
->data()),
373 sd
->symbol_names_size
);
376 // Lay out the input sections for a dynamic object. We don't want to
377 // include sections from a dynamic object, so all that we actually do
378 // here is check for .gnu.warning sections.
380 template<int size
, bool big_endian
>
382 Sized_dynobj
<size
, big_endian
>::do_layout(Symbol_table
* symtab
,
384 Read_symbols_data
* sd
)
386 const unsigned int shnum
= this->shnum();
390 // Get the section headers.
391 const unsigned char* pshdrs
= sd
->section_headers
->data();
393 // Get the section names.
394 const unsigned char* pnamesu
= sd
->section_names
->data();
395 const char* pnames
= reinterpret_cast<const char*>(pnamesu
);
397 // Skip the first, dummy, section.
398 pshdrs
+= This::shdr_size
;
399 for (unsigned int i
= 1; i
< shnum
; ++i
, pshdrs
+= This::shdr_size
)
401 typename
This::Shdr
shdr(pshdrs
);
403 if (shdr
.get_sh_name() >= sd
->section_names_size
)
405 this->error(_("bad section name offset for section %u: %lu"),
406 i
, static_cast<unsigned long>(shdr
.get_sh_name()));
410 const char* name
= pnames
+ shdr
.get_sh_name();
412 this->handle_gnu_warning_section(name
, i
, symtab
);
415 delete sd
->section_headers
;
416 sd
->section_headers
= NULL
;
417 delete sd
->section_names
;
418 sd
->section_names
= NULL
;
421 // Add an entry to the vector mapping version numbers to version
424 template<int size
, bool big_endian
>
426 Sized_dynobj
<size
, big_endian
>::set_version_map(
427 Version_map
* version_map
,
429 const char* name
) const
431 if (ndx
>= version_map
->size())
432 version_map
->resize(ndx
+ 1);
433 if ((*version_map
)[ndx
] != NULL
)
434 this->error(_("duplicate definition for version %u"), ndx
);
435 (*version_map
)[ndx
] = name
;
438 // Add mappings for the version definitions to VERSION_MAP.
440 template<int size
, bool big_endian
>
442 Sized_dynobj
<size
, big_endian
>::make_verdef_map(
443 Read_symbols_data
* sd
,
444 Version_map
* version_map
) const
446 if (sd
->verdef
== NULL
)
449 const char* names
= reinterpret_cast<const char*>(sd
->symbol_names
->data());
450 section_size_type names_size
= sd
->symbol_names_size
;
452 const unsigned char* pverdef
= sd
->verdef
->data();
453 section_size_type verdef_size
= sd
->verdef_size
;
454 const unsigned int count
= sd
->verdef_info
;
456 const unsigned char* p
= pverdef
;
457 for (unsigned int i
= 0; i
< count
; ++i
)
459 elfcpp::Verdef
<size
, big_endian
> verdef(p
);
461 if (verdef
.get_vd_version() != elfcpp::VER_DEF_CURRENT
)
463 this->error(_("unexpected verdef version %u"),
464 verdef
.get_vd_version());
468 const section_size_type vd_ndx
= verdef
.get_vd_ndx();
470 // The GNU linker clears the VERSYM_HIDDEN bit. I'm not
473 // The first Verdaux holds the name of this version. Subsequent
474 // ones are versions that this one depends upon, which we don't
476 const section_size_type vd_cnt
= verdef
.get_vd_cnt();
479 this->error(_("verdef vd_cnt field too small: %u"),
480 static_cast<unsigned int>(vd_cnt
));
484 const section_size_type vd_aux
= verdef
.get_vd_aux();
485 if ((p
- pverdef
) + vd_aux
>= verdef_size
)
487 this->error(_("verdef vd_aux field out of range: %u"),
488 static_cast<unsigned int>(vd_aux
));
492 const unsigned char* pvda
= p
+ vd_aux
;
493 elfcpp::Verdaux
<size
, big_endian
> verdaux(pvda
);
495 const section_size_type vda_name
= verdaux
.get_vda_name();
496 if (vda_name
>= names_size
)
498 this->error(_("verdaux vda_name field out of range: %u"),
499 static_cast<unsigned int>(vda_name
));
503 this->set_version_map(version_map
, vd_ndx
, names
+ vda_name
);
505 const section_size_type vd_next
= verdef
.get_vd_next();
506 if ((p
- pverdef
) + vd_next
>= verdef_size
)
508 this->error(_("verdef vd_next field out of range: %u"),
509 static_cast<unsigned int>(vd_next
));
517 // Add mappings for the required versions to VERSION_MAP.
519 template<int size
, bool big_endian
>
521 Sized_dynobj
<size
, big_endian
>::make_verneed_map(
522 Read_symbols_data
* sd
,
523 Version_map
* version_map
) const
525 if (sd
->verneed
== NULL
)
528 const char* names
= reinterpret_cast<const char*>(sd
->symbol_names
->data());
529 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
;
535 const unsigned char* p
= pverneed
;
536 for (unsigned int i
= 0; i
< count
; ++i
)
538 elfcpp::Verneed
<size
, big_endian
> verneed(p
);
540 if (verneed
.get_vn_version() != elfcpp::VER_NEED_CURRENT
)
542 this->error(_("unexpected verneed version %u"),
543 verneed
.get_vn_version());
547 const section_size_type vn_aux
= verneed
.get_vn_aux();
549 if ((p
- pverneed
) + vn_aux
>= verneed_size
)
551 this->error(_("verneed vn_aux field out of range: %u"),
552 static_cast<unsigned int>(vn_aux
));
556 const unsigned int vn_cnt
= verneed
.get_vn_cnt();
557 const unsigned char* pvna
= p
+ vn_aux
;
558 for (unsigned int j
= 0; j
< vn_cnt
; ++j
)
560 elfcpp::Vernaux
<size
, big_endian
> vernaux(pvna
);
562 const unsigned int vna_name
= vernaux
.get_vna_name();
563 if (vna_name
>= names_size
)
565 this->error(_("vernaux vna_name field out of range: %u"),
566 static_cast<unsigned int>(vna_name
));
570 this->set_version_map(version_map
, vernaux
.get_vna_other(),
573 const section_size_type vna_next
= vernaux
.get_vna_next();
574 if ((pvna
- pverneed
) + vna_next
>= verneed_size
)
576 this->error(_("verneed vna_next field out of range: %u"),
577 static_cast<unsigned int>(vna_next
));
584 const section_size_type vn_next
= verneed
.get_vn_next();
585 if ((p
- pverneed
) + vn_next
>= verneed_size
)
587 this->error(_("verneed vn_next field out of range: %u"),
588 static_cast<unsigned int>(vn_next
));
596 // Create a vector mapping version numbers to version strings.
598 template<int size
, bool big_endian
>
600 Sized_dynobj
<size
, big_endian
>::make_version_map(
601 Read_symbols_data
* sd
,
602 Version_map
* version_map
) const
604 if (sd
->verdef
== NULL
&& sd
->verneed
== NULL
)
607 // A guess at the maximum version number we will see. If this is
608 // wrong we will be less efficient but still correct.
609 version_map
->reserve(sd
->verdef_info
+ sd
->verneed_info
* 10);
611 this->make_verdef_map(sd
, version_map
);
612 this->make_verneed_map(sd
, version_map
);
615 // Add the dynamic symbols to the symbol table.
617 template<int size
, bool big_endian
>
619 Sized_dynobj
<size
, big_endian
>::do_add_symbols(Symbol_table
* symtab
,
620 Read_symbols_data
* sd
)
622 if (sd
->symbols
== NULL
)
624 gold_assert(sd
->symbol_names
== NULL
);
625 gold_assert(sd
->versym
== NULL
&& sd
->verdef
== NULL
626 && sd
->verneed
== NULL
);
630 const int sym_size
= This::sym_size
;
631 const size_t symcount
= sd
->symbols_size
/ sym_size
;
632 gold_assert(sd
->external_symbols_offset
== 0);
633 if (symcount
* sym_size
!= sd
->symbols_size
)
635 this->error(_("size of dynamic symbols is not multiple of symbol size"));
639 Version_map version_map
;
640 this->make_version_map(sd
, &version_map
);
642 const char* sym_names
=
643 reinterpret_cast<const char*>(sd
->symbol_names
->data());
644 symtab
->add_from_dynobj(this, sd
->symbols
->data(), symcount
,
645 sym_names
, sd
->symbol_names_size
,
648 : sd
->versym
->data()),
654 delete sd
->symbol_names
;
655 sd
->symbol_names
= NULL
;
656 if (sd
->versym
!= NULL
)
661 if (sd
->verdef
!= NULL
)
666 if (sd
->verneed
!= NULL
)
672 // This is normally the last time we will read any data from this
674 this->clear_view_cache_marks();
677 // Given a vector of hash codes, compute the number of hash buckets to
681 Dynobj::compute_bucket_count(const std::vector
<uint32_t>& hashcodes
,
682 bool for_gnu_hash_table
)
684 // FIXME: Implement optional hash table optimization.
686 // Array used to determine the number of hash table buckets to use
687 // based on the number of symbols there are. If there are fewer
688 // than 3 symbols we use 1 bucket, fewer than 17 symbols we use 3
689 // buckets, fewer than 37 we use 17 buckets, and so forth. We never
690 // use more than 32771 buckets. This is straight from the old GNU
692 static const unsigned int buckets
[] =
694 1, 3, 17, 37, 67, 97, 131, 197, 263, 521, 1031, 2053, 4099, 8209,
697 const int buckets_count
= sizeof buckets
/ sizeof buckets
[0];
699 unsigned int symcount
= hashcodes
.size();
700 unsigned int ret
= 1;
701 for (int i
= 0; i
< buckets_count
; ++i
)
703 if (symcount
< buckets
[i
])
708 if (for_gnu_hash_table
&& ret
< 2)
714 // The standard ELF hash function. This hash function must not
715 // change, as the dynamic linker uses it also.
718 Dynobj::elf_hash(const char* name
)
720 const unsigned char* nameu
= reinterpret_cast<const unsigned char*>(name
);
723 while ((c
= *nameu
++) != '\0')
726 uint32_t g
= h
& 0xf0000000;
730 // The ELF ABI says h &= ~g, but using xor is equivalent in
731 // this case (since g was set from h) and may save one
739 // Create a standard ELF hash table, setting *PPHASH and *PHASHLEN.
740 // DYNSYMS is a vector with all the global dynamic symbols.
741 // LOCAL_DYNSYM_COUNT is the number of local symbols in the dynamic
745 Dynobj::create_elf_hash_table(const std::vector
<Symbol
*>& dynsyms
,
746 unsigned int local_dynsym_count
,
747 unsigned char** pphash
,
748 unsigned int* phashlen
)
750 unsigned int dynsym_count
= dynsyms
.size();
752 // Get the hash values for all the symbols.
753 std::vector
<uint32_t> dynsym_hashvals(dynsym_count
);
754 for (unsigned int i
= 0; i
< dynsym_count
; ++i
)
755 dynsym_hashvals
[i
] = Dynobj::elf_hash(dynsyms
[i
]->name());
757 const unsigned int bucketcount
=
758 Dynobj::compute_bucket_count(dynsym_hashvals
, false);
760 std::vector
<uint32_t> bucket(bucketcount
);
761 std::vector
<uint32_t> chain(local_dynsym_count
+ dynsym_count
);
763 for (unsigned int i
= 0; i
< dynsym_count
; ++i
)
765 unsigned int dynsym_index
= dynsyms
[i
]->dynsym_index();
766 unsigned int bucketpos
= dynsym_hashvals
[i
] % bucketcount
;
767 chain
[dynsym_index
] = bucket
[bucketpos
];
768 bucket
[bucketpos
] = dynsym_index
;
771 unsigned int hashlen
= ((2
776 unsigned char* phash
= new unsigned char[hashlen
];
778 if (parameters
->target().is_big_endian())
780 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
781 Dynobj::sized_create_elf_hash_table
<true>(bucket
, chain
, phash
,
789 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
790 Dynobj::sized_create_elf_hash_table
<false>(bucket
, chain
, phash
,
801 // Fill in an ELF hash table.
803 template<bool big_endian
>
805 Dynobj::sized_create_elf_hash_table(const std::vector
<uint32_t>& bucket
,
806 const std::vector
<uint32_t>& chain
,
807 unsigned char* phash
,
808 unsigned int hashlen
)
810 unsigned char* p
= phash
;
812 const unsigned int bucketcount
= bucket
.size();
813 const unsigned int chaincount
= chain
.size();
815 elfcpp::Swap
<32, big_endian
>::writeval(p
, bucketcount
);
817 elfcpp::Swap
<32, big_endian
>::writeval(p
, chaincount
);
820 for (unsigned int i
= 0; i
< bucketcount
; ++i
)
822 elfcpp::Swap
<32, big_endian
>::writeval(p
, bucket
[i
]);
826 for (unsigned int i
= 0; i
< chaincount
; ++i
)
828 elfcpp::Swap
<32, big_endian
>::writeval(p
, chain
[i
]);
832 gold_assert(static_cast<unsigned int>(p
- phash
) == hashlen
);
835 // The hash function used for the GNU hash table. This hash function
836 // must not change, as the dynamic linker uses it also.
839 Dynobj::gnu_hash(const char* name
)
841 const unsigned char* nameu
= reinterpret_cast<const unsigned char*>(name
);
844 while ((c
= *nameu
++) != '\0')
845 h
= (h
<< 5) + h
+ c
;
849 // Create a GNU hash table, setting *PPHASH and *PHASHLEN. GNU hash
850 // tables are an extension to ELF which are recognized by the GNU
851 // dynamic linker. They are referenced using dynamic tag DT_GNU_HASH.
852 // TARGET is the target. DYNSYMS is a vector with all the global
853 // symbols which will be going into the dynamic symbol table.
854 // LOCAL_DYNSYM_COUNT is the number of local symbols in the dynamic
858 Dynobj::create_gnu_hash_table(const std::vector
<Symbol
*>& dynsyms
,
859 unsigned int local_dynsym_count
,
860 unsigned char** pphash
,
861 unsigned int* phashlen
)
863 const unsigned int count
= dynsyms
.size();
865 // Sort the dynamic symbols into two vectors. Symbols which we do
866 // not want to put into the hash table we store into
867 // UNHASHED_DYNSYMS. Symbols which we do want to store we put into
868 // HASHED_DYNSYMS. DYNSYM_HASHVALS is parallel to HASHED_DYNSYMS,
869 // and records the hash codes.
871 std::vector
<Symbol
*> unhashed_dynsyms
;
872 unhashed_dynsyms
.reserve(count
);
874 std::vector
<Symbol
*> hashed_dynsyms
;
875 hashed_dynsyms
.reserve(count
);
877 std::vector
<uint32_t> dynsym_hashvals
;
878 dynsym_hashvals
.reserve(count
);
880 for (unsigned int i
= 0; i
< count
; ++i
)
882 Symbol
* sym
= dynsyms
[i
];
884 // FIXME: Should put on unhashed_dynsyms if the symbol is
886 if (sym
->is_undefined())
887 unhashed_dynsyms
.push_back(sym
);
890 hashed_dynsyms
.push_back(sym
);
891 dynsym_hashvals
.push_back(Dynobj::gnu_hash(sym
->name()));
895 // Put the unhashed symbols at the start of the global portion of
896 // the dynamic symbol table.
897 const unsigned int unhashed_count
= unhashed_dynsyms
.size();
898 unsigned int unhashed_dynsym_index
= local_dynsym_count
;
899 for (unsigned int i
= 0; i
< unhashed_count
; ++i
)
901 unhashed_dynsyms
[i
]->set_dynsym_index(unhashed_dynsym_index
);
902 ++unhashed_dynsym_index
;
905 // For the actual data generation we call out to a templatized
907 int size
= parameters
->target().get_size();
908 bool big_endian
= parameters
->target().is_big_endian();
913 #ifdef HAVE_TARGET_32_BIG
914 Dynobj::sized_create_gnu_hash_table
<32, true>(hashed_dynsyms
,
916 unhashed_dynsym_index
,
925 #ifdef HAVE_TARGET_32_LITTLE
926 Dynobj::sized_create_gnu_hash_table
<32, false>(hashed_dynsyms
,
928 unhashed_dynsym_index
,
940 #ifdef HAVE_TARGET_64_BIG
941 Dynobj::sized_create_gnu_hash_table
<64, true>(hashed_dynsyms
,
943 unhashed_dynsym_index
,
952 #ifdef HAVE_TARGET_64_LITTLE
953 Dynobj::sized_create_gnu_hash_table
<64, false>(hashed_dynsyms
,
955 unhashed_dynsym_index
,
967 // Create the actual data for a GNU hash table. This is just a copy
968 // of the code from the old GNU linker.
970 template<int size
, bool big_endian
>
972 Dynobj::sized_create_gnu_hash_table(
973 const std::vector
<Symbol
*>& hashed_dynsyms
,
974 const std::vector
<uint32_t>& dynsym_hashvals
,
975 unsigned int unhashed_dynsym_count
,
976 unsigned char** pphash
,
977 unsigned int* phashlen
)
979 if (hashed_dynsyms
.empty())
981 // Special case for the empty hash table.
982 unsigned int hashlen
= 5 * 4 + size
/ 8;
983 unsigned char* phash
= new unsigned char[hashlen
];
985 elfcpp::Swap
<32, big_endian
>::writeval(phash
, 1);
986 // Symbol index above unhashed symbols.
987 elfcpp::Swap
<32, big_endian
>::writeval(phash
+ 4, unhashed_dynsym_count
);
988 // One word for bitmask.
989 elfcpp::Swap
<32, big_endian
>::writeval(phash
+ 8, 1);
990 // Only bloom filter.
991 elfcpp::Swap
<32, big_endian
>::writeval(phash
+ 12, 0);
993 elfcpp::Swap
<size
, big_endian
>::writeval(phash
+ 16, 0);
994 // No hashes in only bucket.
995 elfcpp::Swap
<32, big_endian
>::writeval(phash
+ 16 + size
/ 8, 0);
1003 const unsigned int bucketcount
=
1004 Dynobj::compute_bucket_count(dynsym_hashvals
, true);
1006 const unsigned int nsyms
= hashed_dynsyms
.size();
1008 uint32_t maskbitslog2
= 1;
1009 uint32_t x
= nsyms
>> 1;
1015 if (maskbitslog2
< 3)
1017 else if (((1U << (maskbitslog2
- 2)) & nsyms
) != 0)
1027 if (maskbitslog2
== 5)
1031 uint32_t mask
= (1U << shift1
) - 1U;
1032 uint32_t shift2
= maskbitslog2
;
1033 uint32_t maskbits
= 1U << maskbitslog2
;
1034 uint32_t maskwords
= 1U << (maskbitslog2
- shift1
);
1036 typedef typename
elfcpp::Elf_types
<size
>::Elf_WXword Word
;
1037 std::vector
<Word
> bitmask(maskwords
);
1038 std::vector
<uint32_t> counts(bucketcount
);
1039 std::vector
<uint32_t> indx(bucketcount
);
1040 uint32_t symindx
= unhashed_dynsym_count
;
1042 // Count the number of times each hash bucket is used.
1043 for (unsigned int i
= 0; i
< nsyms
; ++i
)
1044 ++counts
[dynsym_hashvals
[i
] % bucketcount
];
1046 unsigned int cnt
= symindx
;
1047 for (unsigned int i
= 0; i
< bucketcount
; ++i
)
1053 unsigned int hashlen
= (4 + bucketcount
+ nsyms
) * 4;
1054 hashlen
+= maskbits
/ 8;
1055 unsigned char* phash
= new unsigned char[hashlen
];
1057 elfcpp::Swap
<32, big_endian
>::writeval(phash
, bucketcount
);
1058 elfcpp::Swap
<32, big_endian
>::writeval(phash
+ 4, symindx
);
1059 elfcpp::Swap
<32, big_endian
>::writeval(phash
+ 8, maskwords
);
1060 elfcpp::Swap
<32, big_endian
>::writeval(phash
+ 12, shift2
);
1062 unsigned char* p
= phash
+ 16 + maskbits
/ 8;
1063 for (unsigned int i
= 0; i
< bucketcount
; ++i
)
1066 elfcpp::Swap
<32, big_endian
>::writeval(p
, 0);
1068 elfcpp::Swap
<32, big_endian
>::writeval(p
, indx
[i
]);
1072 for (unsigned int i
= 0; i
< nsyms
; ++i
)
1074 Symbol
* sym
= hashed_dynsyms
[i
];
1075 uint32_t hashval
= dynsym_hashvals
[i
];
1077 unsigned int bucket
= hashval
% bucketcount
;
1078 unsigned int val
= ((hashval
>> shift1
)
1079 & ((maskbits
>> shift1
) - 1));
1080 bitmask
[val
] |= (static_cast<Word
>(1U)) << (hashval
& mask
);
1081 bitmask
[val
] |= (static_cast<Word
>(1U)) << ((hashval
>> shift2
) & mask
);
1082 val
= hashval
& ~ 1U;
1083 if (counts
[bucket
] == 1)
1085 // Last element terminates the chain.
1088 elfcpp::Swap
<32, big_endian
>::writeval(p
+ (indx
[bucket
] - symindx
) * 4,
1092 sym
->set_dynsym_index(indx
[bucket
]);
1097 for (unsigned int i
= 0; i
< maskwords
; ++i
)
1099 elfcpp::Swap
<size
, big_endian
>::writeval(p
, bitmask
[i
]);
1103 *phashlen
= hashlen
;
1109 // Write this definition to a buffer for the output section.
1111 template<int size
, bool big_endian
>
1113 Verdef::write(const Stringpool
* dynpool
, bool is_last
, unsigned char* pb
) const
1115 const int verdef_size
= elfcpp::Elf_sizes
<size
>::verdef_size
;
1116 const int verdaux_size
= elfcpp::Elf_sizes
<size
>::verdaux_size
;
1118 elfcpp::Verdef_write
<size
, big_endian
> vd(pb
);
1119 vd
.set_vd_version(elfcpp::VER_DEF_CURRENT
);
1120 vd
.set_vd_flags((this->is_base_
? elfcpp::VER_FLG_BASE
: 0)
1121 | (this->is_weak_
? elfcpp::VER_FLG_WEAK
: 0));
1122 vd
.set_vd_ndx(this->index());
1123 vd
.set_vd_cnt(1 + this->deps_
.size());
1124 vd
.set_vd_hash(Dynobj::elf_hash(this->name()));
1125 vd
.set_vd_aux(verdef_size
);
1126 vd
.set_vd_next(is_last
1128 : verdef_size
+ (1 + this->deps_
.size()) * verdaux_size
);
1131 elfcpp::Verdaux_write
<size
, big_endian
> vda(pb
);
1132 vda
.set_vda_name(dynpool
->get_offset(this->name()));
1133 vda
.set_vda_next(this->deps_
.empty() ? 0 : verdaux_size
);
1136 Deps::const_iterator p
;
1138 for (p
= this->deps_
.begin(), i
= 0;
1139 p
!= this->deps_
.end();
1142 elfcpp::Verdaux_write
<size
, big_endian
> vda(pb
);
1143 vda
.set_vda_name(dynpool
->get_offset(*p
));
1144 vda
.set_vda_next(i
+ 1 >= this->deps_
.size() ? 0 : verdaux_size
);
1155 for (Need_versions::iterator p
= this->need_versions_
.begin();
1156 p
!= this->need_versions_
.end();
1161 // Add a new version to this file reference.
1164 Verneed::add_name(const char* name
)
1166 Verneed_version
* vv
= new Verneed_version(name
);
1167 this->need_versions_
.push_back(vv
);
1171 // Set the version indexes starting at INDEX.
1174 Verneed::finalize(unsigned int index
)
1176 for (Need_versions::iterator p
= this->need_versions_
.begin();
1177 p
!= this->need_versions_
.end();
1180 (*p
)->set_index(index
);
1186 // Write this list of referenced versions to a buffer for the output
1189 template<int size
, bool big_endian
>
1191 Verneed::write(const Stringpool
* dynpool
, bool is_last
,
1192 unsigned char* pb
) const
1194 const int verneed_size
= elfcpp::Elf_sizes
<size
>::verneed_size
;
1195 const int vernaux_size
= elfcpp::Elf_sizes
<size
>::vernaux_size
;
1197 elfcpp::Verneed_write
<size
, big_endian
> vn(pb
);
1198 vn
.set_vn_version(elfcpp::VER_NEED_CURRENT
);
1199 vn
.set_vn_cnt(this->need_versions_
.size());
1200 vn
.set_vn_file(dynpool
->get_offset(this->filename()));
1201 vn
.set_vn_aux(verneed_size
);
1202 vn
.set_vn_next(is_last
1204 : verneed_size
+ this->need_versions_
.size() * vernaux_size
);
1207 Need_versions::const_iterator p
;
1209 for (p
= this->need_versions_
.begin(), i
= 0;
1210 p
!= this->need_versions_
.end();
1213 elfcpp::Vernaux_write
<size
, big_endian
> vna(pb
);
1214 vna
.set_vna_hash(Dynobj::elf_hash((*p
)->version()));
1215 // FIXME: We need to sometimes set VER_FLG_WEAK here.
1216 vna
.set_vna_flags(0);
1217 vna
.set_vna_other((*p
)->index());
1218 vna
.set_vna_name(dynpool
->get_offset((*p
)->version()));
1219 vna
.set_vna_next(i
+ 1 >= this->need_versions_
.size()
1228 // Versions methods.
1230 Versions::Versions(const Version_script_info
& version_script
,
1231 Stringpool
* dynpool
)
1232 : defs_(), needs_(), version_table_(),
1233 is_finalized_(false), version_script_(version_script
)
1235 // We always need a base version, so define that first. Nothing
1236 // explicitly declares itself as part of base, so it doesn't need to
1237 // be in version_table_.
1238 // FIXME: Should use soname here when creating a shared object. Is
1239 // this fixme still valid? It looks like it's doing the right thing
1241 if (parameters
->options().shared())
1243 const char* name
= dynpool
->add(parameters
->options().output_file_name(),
1245 Verdef
* vdbase
= new Verdef(name
, std::vector
<std::string
>(),
1247 this->defs_
.push_back(vdbase
);
1250 if (!this->version_script_
.empty())
1252 // Parse the version script, and insert each declared version into
1253 // defs_ and version_table_.
1254 std::vector
<std::string
> versions
= this->version_script_
.get_versions();
1255 for (size_t k
= 0; k
< versions
.size(); ++k
)
1257 Stringpool::Key version_key
;
1258 const char* version
= dynpool
->add(versions
[k
].c_str(),
1259 true, &version_key
);
1260 Verdef
* const vd
= new Verdef(
1262 this->version_script_
.get_dependencies(version
),
1263 false, false, false);
1264 this->defs_
.push_back(vd
);
1265 Key
key(version_key
, 0);
1266 this->version_table_
.insert(std::make_pair(key
, vd
));
1271 Versions::~Versions()
1273 for (Defs::iterator p
= this->defs_
.begin();
1274 p
!= this->defs_
.end();
1278 for (Needs::iterator p
= this->needs_
.begin();
1279 p
!= this->needs_
.end();
1284 // Return the dynamic object which a symbol refers to.
1287 Versions::get_dynobj_for_sym(const Symbol_table
* symtab
,
1288 const Symbol
* sym
) const
1290 if (sym
->is_copied_from_dynobj())
1291 return symtab
->get_copy_source(sym
);
1294 Object
* object
= sym
->object();
1295 gold_assert(object
->is_dynamic());
1296 return static_cast<Dynobj
*>(object
);
1300 // Record version information for a symbol going into the dynamic
1304 Versions::record_version(const Symbol_table
* symtab
,
1305 Stringpool
* dynpool
, const Symbol
* sym
)
1307 gold_assert(!this->is_finalized_
);
1308 gold_assert(sym
->version() != NULL
);
1310 Stringpool::Key version_key
;
1311 const char* version
= dynpool
->add(sym
->version(), false, &version_key
);
1313 if (!sym
->is_from_dynobj() && !sym
->is_copied_from_dynobj())
1315 if (parameters
->options().shared())
1316 this->add_def(sym
, version
, version_key
);
1320 // This is a version reference.
1321 Dynobj
* dynobj
= this->get_dynobj_for_sym(symtab
, sym
);
1322 this->add_need(dynpool
, dynobj
->soname(), version
, version_key
);
1326 // We've found a symbol SYM defined in version VERSION.
1329 Versions::add_def(const Symbol
* sym
, const char* version
,
1330 Stringpool::Key version_key
)
1332 Key
k(version_key
, 0);
1333 Version_base
* const vbnull
= NULL
;
1334 std::pair
<Version_table::iterator
, bool> ins
=
1335 this->version_table_
.insert(std::make_pair(k
, vbnull
));
1339 // We already have an entry for this version.
1340 Version_base
* vb
= ins
.first
->second
;
1342 // We have now seen a symbol in this version, so it is not
1344 gold_assert(vb
!= NULL
);
1349 // If we are creating a shared object, it is an error to
1350 // find a definition of a symbol with a version which is not
1351 // in the version script.
1352 if (parameters
->options().shared())
1354 gold_error(_("symbol %s has undefined version %s"),
1355 sym
->demangled_name().c_str(), version
);
1359 // When creating a regular executable, automatically define
1361 Verdef
* vd
= new Verdef(version
, std::vector
<std::string
>(),
1362 false, false, false);
1363 this->defs_
.push_back(vd
);
1364 ins
.first
->second
= vd
;
1368 // Add a reference to version NAME in file FILENAME.
1371 Versions::add_need(Stringpool
* dynpool
, const char* filename
, const char* name
,
1372 Stringpool::Key name_key
)
1374 Stringpool::Key filename_key
;
1375 filename
= dynpool
->add(filename
, true, &filename_key
);
1377 Key
k(name_key
, filename_key
);
1378 Version_base
* const vbnull
= NULL
;
1379 std::pair
<Version_table::iterator
, bool> ins
=
1380 this->version_table_
.insert(std::make_pair(k
, vbnull
));
1384 // We already have an entry for this filename/version.
1388 // See whether we already have this filename. We don't expect many
1389 // version references, so we just do a linear search. This could be
1390 // replaced by a hash table.
1392 for (Needs::iterator p
= this->needs_
.begin();
1393 p
!= this->needs_
.end();
1396 if ((*p
)->filename() == filename
)
1405 // We have a new filename.
1406 vn
= new Verneed(filename
);
1407 this->needs_
.push_back(vn
);
1410 ins
.first
->second
= vn
->add_name(name
);
1413 // Set the version indexes. Create a new dynamic version symbol for
1414 // each new version definition.
1417 Versions::finalize(Symbol_table
* symtab
, unsigned int dynsym_index
,
1418 std::vector
<Symbol
*>* syms
)
1420 gold_assert(!this->is_finalized_
);
1422 unsigned int vi
= 1;
1424 for (Defs::iterator p
= this->defs_
.begin();
1425 p
!= this->defs_
.end();
1428 (*p
)->set_index(vi
);
1431 // Create a version symbol if necessary.
1432 if (!(*p
)->is_symbol_created())
1434 Symbol
* vsym
= symtab
->define_as_constant((*p
)->name(),
1438 elfcpp::STV_DEFAULT
, 0,
1440 vsym
->set_needs_dynsym_entry();
1441 vsym
->set_dynsym_index(dynsym_index
);
1443 syms
->push_back(vsym
);
1444 // The name is already in the dynamic pool.
1448 // Index 1 is used for global symbols.
1451 gold_assert(this->defs_
.empty());
1455 for (Needs::iterator p
= this->needs_
.begin();
1456 p
!= this->needs_
.end();
1458 vi
= (*p
)->finalize(vi
);
1460 this->is_finalized_
= true;
1462 return dynsym_index
;
1465 // Return the version index to use for a symbol. This does two hash
1466 // table lookups: one in DYNPOOL and one in this->version_table_.
1467 // Another approach alternative would be store a pointer in SYM, which
1468 // would increase the size of the symbol table. Or perhaps we could
1469 // use a hash table from dynamic symbol pointer values to Version_base
1473 Versions::version_index(const Symbol_table
* symtab
, const Stringpool
* dynpool
,
1474 const Symbol
* sym
) const
1476 Stringpool::Key version_key
;
1477 const char* version
= dynpool
->find(sym
->version(), &version_key
);
1478 gold_assert(version
!= NULL
);
1481 if (!sym
->is_from_dynobj() && !sym
->is_copied_from_dynobj())
1483 if (!parameters
->options().shared())
1484 return elfcpp::VER_NDX_GLOBAL
;
1485 k
= Key(version_key
, 0);
1489 Dynobj
* dynobj
= this->get_dynobj_for_sym(symtab
, sym
);
1491 Stringpool::Key filename_key
;
1492 const char* filename
= dynpool
->find(dynobj
->soname(), &filename_key
);
1493 gold_assert(filename
!= NULL
);
1495 k
= Key(version_key
, filename_key
);
1498 Version_table::const_iterator p
= this->version_table_
.find(k
);
1499 gold_assert(p
!= this->version_table_
.end());
1501 return p
->second
->index();
1504 // Return an allocated buffer holding the contents of the symbol
1507 template<int size
, bool big_endian
>
1509 Versions::symbol_section_contents(const Symbol_table
* symtab
,
1510 const Stringpool
* dynpool
,
1511 unsigned int local_symcount
,
1512 const std::vector
<Symbol
*>& syms
,
1514 unsigned int* psize
) const
1516 gold_assert(this->is_finalized_
);
1518 unsigned int sz
= (local_symcount
+ syms
.size()) * 2;
1519 unsigned char* pbuf
= new unsigned char[sz
];
1521 for (unsigned int i
= 0; i
< local_symcount
; ++i
)
1522 elfcpp::Swap
<16, big_endian
>::writeval(pbuf
+ i
* 2,
1523 elfcpp::VER_NDX_LOCAL
);
1525 for (std::vector
<Symbol
*>::const_iterator p
= syms
.begin();
1529 unsigned int version_index
;
1530 const char* version
= (*p
)->version();
1531 if (version
== NULL
)
1532 version_index
= elfcpp::VER_NDX_GLOBAL
;
1534 version_index
= this->version_index(symtab
, dynpool
, *p
);
1535 // If the symbol was defined as foo@V1 instead of foo@@V1, add
1537 if ((*p
)->version() != NULL
&& !(*p
)->is_default())
1538 version_index
|= elfcpp::VERSYM_HIDDEN
;
1539 elfcpp::Swap
<16, big_endian
>::writeval(pbuf
+ (*p
)->dynsym_index() * 2,
1547 // Return an allocated buffer holding the contents of the version
1548 // definition section.
1550 template<int size
, bool big_endian
>
1552 Versions::def_section_contents(const Stringpool
* dynpool
,
1553 unsigned char** pp
, unsigned int* psize
,
1554 unsigned int* pentries
) const
1556 gold_assert(this->is_finalized_
);
1557 gold_assert(!this->defs_
.empty());
1559 const int verdef_size
= elfcpp::Elf_sizes
<size
>::verdef_size
;
1560 const int verdaux_size
= elfcpp::Elf_sizes
<size
>::verdaux_size
;
1562 unsigned int sz
= 0;
1563 for (Defs::const_iterator p
= this->defs_
.begin();
1564 p
!= this->defs_
.end();
1567 sz
+= verdef_size
+ verdaux_size
;
1568 sz
+= (*p
)->count_dependencies() * verdaux_size
;
1571 unsigned char* pbuf
= new unsigned char[sz
];
1573 unsigned char* pb
= pbuf
;
1574 Defs::const_iterator p
;
1576 for (p
= this->defs_
.begin(), i
= 0;
1577 p
!= this->defs_
.end();
1579 pb
= (*p
)->write
<size
, big_endian
>(dynpool
,
1580 i
+ 1 >= this->defs_
.size(),
1583 gold_assert(static_cast<unsigned int>(pb
- pbuf
) == sz
);
1587 *pentries
= this->defs_
.size();
1590 // Return an allocated buffer holding the contents of the version
1591 // reference section.
1593 template<int size
, bool big_endian
>
1595 Versions::need_section_contents(const Stringpool
* dynpool
,
1596 unsigned char** pp
, unsigned int *psize
,
1597 unsigned int *pentries
) const
1599 gold_assert(this->is_finalized_
);
1600 gold_assert(!this->needs_
.empty());
1602 const int verneed_size
= elfcpp::Elf_sizes
<size
>::verneed_size
;
1603 const int vernaux_size
= elfcpp::Elf_sizes
<size
>::vernaux_size
;
1605 unsigned int sz
= 0;
1606 for (Needs::const_iterator p
= this->needs_
.begin();
1607 p
!= this->needs_
.end();
1611 sz
+= (*p
)->count_versions() * vernaux_size
;
1614 unsigned char* pbuf
= new unsigned char[sz
];
1616 unsigned char* pb
= pbuf
;
1617 Needs::const_iterator p
;
1619 for (p
= this->needs_
.begin(), i
= 0;
1620 p
!= this->needs_
.end();
1622 pb
= (*p
)->write
<size
, big_endian
>(dynpool
,
1623 i
+ 1 >= this->needs_
.size(),
1626 gold_assert(static_cast<unsigned int>(pb
- pbuf
) == sz
);
1630 *pentries
= this->needs_
.size();
1633 // Instantiate the templates we need. We could use the configure
1634 // script to restrict this to only the ones for implemented targets.
1636 #ifdef HAVE_TARGET_32_LITTLE
1638 class Sized_dynobj
<32, false>;
1641 #ifdef HAVE_TARGET_32_BIG
1643 class Sized_dynobj
<32, true>;
1646 #ifdef HAVE_TARGET_64_LITTLE
1648 class Sized_dynobj
<64, false>;
1651 #ifdef HAVE_TARGET_64_BIG
1653 class Sized_dynobj
<64, true>;
1656 #ifdef HAVE_TARGET_32_LITTLE
1659 Versions::symbol_section_contents
<32, false>(
1660 const Symbol_table
*,
1663 const std::vector
<Symbol
*>&,
1665 unsigned int*) const;
1668 #ifdef HAVE_TARGET_32_BIG
1671 Versions::symbol_section_contents
<32, true>(
1672 const Symbol_table
*,
1675 const std::vector
<Symbol
*>&,
1677 unsigned int*) const;
1680 #ifdef HAVE_TARGET_64_LITTLE
1683 Versions::symbol_section_contents
<64, false>(
1684 const Symbol_table
*,
1687 const std::vector
<Symbol
*>&,
1689 unsigned int*) const;
1692 #ifdef HAVE_TARGET_64_BIG
1695 Versions::symbol_section_contents
<64, true>(
1696 const Symbol_table
*,
1699 const std::vector
<Symbol
*>&,
1701 unsigned int*) const;
1704 #ifdef HAVE_TARGET_32_LITTLE
1707 Versions::def_section_contents
<32, false>(
1711 unsigned int*) const;
1714 #ifdef HAVE_TARGET_32_BIG
1717 Versions::def_section_contents
<32, true>(
1721 unsigned int*) const;
1724 #ifdef HAVE_TARGET_64_LITTLE
1727 Versions::def_section_contents
<64, false>(
1731 unsigned int*) const;
1734 #ifdef HAVE_TARGET_64_BIG
1737 Versions::def_section_contents
<64, true>(
1741 unsigned int*) const;
1744 #ifdef HAVE_TARGET_32_LITTLE
1747 Versions::need_section_contents
<32, false>(
1751 unsigned int*) const;
1754 #ifdef HAVE_TARGET_32_BIG
1757 Versions::need_section_contents
<32, true>(
1761 unsigned int*) const;
1764 #ifdef HAVE_TARGET_64_LITTLE
1767 Versions::need_section_contents
<64, false>(
1771 unsigned int*) const;
1774 #ifdef HAVE_TARGET_64_BIG
1777 Versions::need_section_contents
<64, true>(
1781 unsigned int*) const;
1784 } // End namespace gold.