1 // object.cc -- support for an object file for linking in 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 "libiberty.h"
31 #include "target-select.h"
32 #include "dwarf_reader.h"
45 // Initialize the symtab_xindex_ array. Find the SHT_SYMTAB_SHNDX
46 // section and read it in. SYMTAB_SHNDX is the index of the symbol
47 // table we care about.
49 template<int size, bool big_endian>
51 Xindex::initialize_symtab_xindex(Object* object, unsigned int symtab_shndx)
53 if (!this->symtab_xindex_.empty())
56 gold_assert(symtab_shndx != 0);
58 // Look through the sections in reverse order, on the theory that it
59 // is more likely to be near the end than the beginning.
60 unsigned int i = object->shnum();
64 if (object->section_type(i) == elfcpp::SHT_SYMTAB_SHNDX
65 && this->adjust_shndx(object->section_link(i)) == symtab_shndx)
67 this->read_symtab_xindex<size, big_endian>(object, i, NULL);
72 object->error(_("missing SHT_SYMTAB_SHNDX section"));
75 // Read in the symtab_xindex_ array, given the section index of the
76 // SHT_SYMTAB_SHNDX section. If PSHDRS is not NULL, it points at the
79 template<int size, bool big_endian>
81 Xindex::read_symtab_xindex(Object* object, unsigned int xindex_shndx,
82 const unsigned char* pshdrs)
84 section_size_type bytecount;
85 const unsigned char* contents;
87 contents = object->section_contents(xindex_shndx, &bytecount, false);
90 const unsigned char* p = (pshdrs
92 * elfcpp::Elf_sizes<size>::shdr_size));
93 typename elfcpp::Shdr<size, big_endian> shdr(p);
94 bytecount = convert_to_section_size_type(shdr.get_sh_size());
95 contents = object->get_view(shdr.get_sh_offset(), bytecount, true, false);
98 gold_assert(this->symtab_xindex_.empty());
99 this->symtab_xindex_.reserve(bytecount / 4);
100 for (section_size_type i = 0; i < bytecount; i += 4)
102 unsigned int shndx = elfcpp::Swap<32, big_endian>::readval(contents + i);
103 // We preadjust the section indexes we save.
104 this->symtab_xindex_.push_back(this->adjust_shndx(shndx));
108 // Symbol symndx has a section of SHN_XINDEX; return the real section
112 Xindex::sym_xindex_to_shndx(Object* object, unsigned int symndx)
114 if (symndx >= this->symtab_xindex_.size())
116 object->error(_("symbol %u out of range for SHT_SYMTAB_SHNDX section"),
118 return elfcpp::SHN_UNDEF;
120 unsigned int shndx = this->symtab_xindex_[symndx];
121 if (shndx < elfcpp::SHN_LORESERVE || shndx >= object->shnum())
123 object->error(_("extended index for symbol %u out of range: %u"),
125 return elfcpp::SHN_UNDEF;
132 // Set the target based on fields in the ELF file header.
135 Object::set_target(int machine, int size, bool big_endian, int osabi,
138 Target* target = select_target(machine, size, big_endian, osabi, abiversion);
140 gold_fatal(_("%s: unsupported ELF machine number %d"),
141 this->name().c_str(), machine);
142 this->target_ = target;
145 // Report an error for this object file. This is used by the
146 // elfcpp::Elf_file interface, and also called by the Object code
150 Object::error(const char* format, ...) const
153 va_start(args, format);
155 if (vasprintf(&buf, format, args) < 0)
158 gold_error(_("%s: %s"), this->name().c_str(), buf);
162 // Return a view of the contents of a section.
165 Object::section_contents(unsigned int shndx, section_size_type* plen,
168 Location loc(this->do_section_contents(shndx));
169 *plen = convert_to_section_size_type(loc.data_size);
170 return this->get_view(loc.file_offset, *plen, true, cache);
173 // Read the section data into SD. This is code common to Sized_relobj
174 // and Sized_dynobj, so we put it into Object.
176 template<int size, bool big_endian>
178 Object::read_section_data(elfcpp::Elf_file<size, big_endian, Object>* elf_file,
179 Read_symbols_data* sd)
181 const int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
183 // Read the section headers.
184 const off_t shoff = elf_file->shoff();
185 const unsigned int shnum = this->shnum();
186 sd->section_headers = this->get_lasting_view(shoff, shnum * shdr_size,
189 // Read the section names.
190 const unsigned char* pshdrs = sd->section_headers->data();
191 const unsigned char* pshdrnames = pshdrs + elf_file->shstrndx() * shdr_size;
192 typename elfcpp::Shdr<size, big_endian> shdrnames(pshdrnames);
194 if (shdrnames.get_sh_type() != elfcpp::SHT_STRTAB)
195 this->error(_("section name section has wrong type: %u"),
196 static_cast<unsigned int>(shdrnames.get_sh_type()));
198 sd->section_names_size =
199 convert_to_section_size_type(shdrnames.get_sh_size());
200 sd->section_names = this->get_lasting_view(shdrnames.get_sh_offset(),
201 sd->section_names_size, false,
205 // If NAME is the name of a special .gnu.warning section, arrange for
206 // the warning to be issued. SHNDX is the section index. Return
207 // whether it is a warning section.
210 Object::handle_gnu_warning_section(const char* name, unsigned int shndx,
211 Symbol_table* symtab)
213 const char warn_prefix[] = ".gnu.warning.";
214 const int warn_prefix_len = sizeof warn_prefix - 1;
215 if (strncmp(name, warn_prefix, warn_prefix_len) == 0)
217 // Read the section contents to get the warning text. It would
218 // be nicer if we only did this if we have to actually issue a
219 // warning. Unfortunately, warnings are issued as we relocate
220 // sections. That means that we can not lock the object then,
221 // as we might try to issue the same warning multiple times
223 section_size_type len;
224 const unsigned char* contents = this->section_contents(shndx, &len,
226 std::string warning(reinterpret_cast<const char*>(contents), len);
227 symtab->add_warning(name + warn_prefix_len, this, warning);
233 // Class Sized_relobj.
235 template<int size, bool big_endian>
236 Sized_relobj<size, big_endian>::Sized_relobj(
237 const std::string& name,
238 Input_file* input_file,
240 const elfcpp::Ehdr<size, big_endian>& ehdr)
241 : Relobj(name, input_file, offset),
242 elf_file_(this, ehdr),
244 local_symbol_count_(0),
245 output_local_symbol_count_(0),
246 output_local_dynsym_count_(0),
248 local_symbol_offset_(0),
249 local_dynsym_offset_(0),
251 local_got_offsets_(),
256 template<int size, bool big_endian>
257 Sized_relobj<size, big_endian>::~Sized_relobj()
261 // Set up an object file based on the file header. This sets up the
262 // target and reads the section information.
264 template<int size, bool big_endian>
266 Sized_relobj<size, big_endian>::setup(
267 const elfcpp::Ehdr<size, big_endian>& ehdr)
269 this->set_target(ehdr.get_e_machine(), size, big_endian,
270 ehdr.get_e_ident()[elfcpp::EI_OSABI],
271 ehdr.get_e_ident()[elfcpp::EI_ABIVERSION]);
273 const unsigned int shnum = this->elf_file_.shnum();
274 this->set_shnum(shnum);
277 // Find the SHT_SYMTAB section, given the section headers. The ELF
278 // standard says that maybe in the future there can be more than one
279 // SHT_SYMTAB section. Until somebody figures out how that could
280 // work, we assume there is only one.
282 template<int size, bool big_endian>
284 Sized_relobj<size, big_endian>::find_symtab(const unsigned char* pshdrs)
286 const unsigned int shnum = this->shnum();
287 this->symtab_shndx_ = 0;
290 // Look through the sections in reverse order, since gas tends
291 // to put the symbol table at the end.
292 const unsigned char* p = pshdrs + shnum * This::shdr_size;
293 unsigned int i = shnum;
294 unsigned int xindex_shndx = 0;
295 unsigned int xindex_link = 0;
299 p -= This::shdr_size;
300 typename This::Shdr shdr(p);
301 if (shdr.get_sh_type() == elfcpp::SHT_SYMTAB)
303 this->symtab_shndx_ = i;
304 if (xindex_shndx > 0 && xindex_link == i)
307 new Xindex(this->elf_file_.large_shndx_offset());
308 xindex->read_symtab_xindex<size, big_endian>(this,
311 this->set_xindex(xindex);
316 // Try to pick up the SHT_SYMTAB_SHNDX section, if there is
317 // one. This will work if it follows the SHT_SYMTAB
319 if (shdr.get_sh_type() == elfcpp::SHT_SYMTAB_SHNDX)
322 xindex_link = this->adjust_shndx(shdr.get_sh_link());
328 // Return the Xindex structure to use for object with lots of
331 template<int size, bool big_endian>
333 Sized_relobj<size, big_endian>::do_initialize_xindex()
335 gold_assert(this->symtab_shndx_ != -1U);
336 Xindex* xindex = new Xindex(this->elf_file_.large_shndx_offset());
337 xindex->initialize_symtab_xindex<size, big_endian>(this, this->symtab_shndx_);
341 // Return whether SHDR has the right type and flags to be a GNU
342 // .eh_frame section.
344 template<int size, bool big_endian>
346 Sized_relobj<size, big_endian>::check_eh_frame_flags(
347 const elfcpp::Shdr<size, big_endian>* shdr) const
349 return (shdr->get_sh_type() == elfcpp::SHT_PROGBITS
350 && (shdr->get_sh_flags() & elfcpp::SHF_ALLOC) != 0);
353 // Return whether there is a GNU .eh_frame section, given the section
354 // headers and the section names.
356 template<int size, bool big_endian>
358 Sized_relobj<size, big_endian>::find_eh_frame(
359 const unsigned char* pshdrs,
361 section_size_type names_size) const
363 const unsigned int shnum = this->shnum();
364 const unsigned char* p = pshdrs + This::shdr_size;
365 for (unsigned int i = 1; i < shnum; ++i, p += This::shdr_size)
367 typename This::Shdr shdr(p);
368 if (this->check_eh_frame_flags(&shdr))
370 if (shdr.get_sh_name() >= names_size)
372 this->error(_("bad section name offset for section %u: %lu"),
373 i, static_cast<unsigned long>(shdr.get_sh_name()));
377 const char* name = names + shdr.get_sh_name();
378 if (strcmp(name, ".eh_frame") == 0)
385 // Read the sections and symbols from an object file.
387 template<int size, bool big_endian>
389 Sized_relobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
391 this->read_section_data(&this->elf_file_, sd);
393 const unsigned char* const pshdrs = sd->section_headers->data();
395 this->find_symtab(pshdrs);
397 const unsigned char* namesu = sd->section_names->data();
398 const char* names = reinterpret_cast<const char*>(namesu);
399 if (memmem(names, sd->section_names_size, ".eh_frame", 10) != NULL)
401 if (this->find_eh_frame(pshdrs, names, sd->section_names_size))
402 this->has_eh_frame_ = true;
406 sd->symbols_size = 0;
407 sd->external_symbols_offset = 0;
408 sd->symbol_names = NULL;
409 sd->symbol_names_size = 0;
411 if (this->symtab_shndx_ == 0)
413 // No symbol table. Weird but legal.
417 // Get the symbol table section header.
418 typename This::Shdr symtabshdr(pshdrs
419 + this->symtab_shndx_ * This::shdr_size);
420 gold_assert(symtabshdr.get_sh_type() == elfcpp::SHT_SYMTAB);
422 // If this object has a .eh_frame section, we need all the symbols.
423 // Otherwise we only need the external symbols. While it would be
424 // simpler to just always read all the symbols, I've seen object
425 // files with well over 2000 local symbols, which for a 64-bit
426 // object file format is over 5 pages that we don't need to read
429 const int sym_size = This::sym_size;
430 const unsigned int loccount = symtabshdr.get_sh_info();
431 this->local_symbol_count_ = loccount;
432 this->local_values_.resize(loccount);
433 section_offset_type locsize = loccount * sym_size;
434 off_t dataoff = symtabshdr.get_sh_offset();
435 section_size_type datasize =
436 convert_to_section_size_type(symtabshdr.get_sh_size());
437 off_t extoff = dataoff + locsize;
438 section_size_type extsize = datasize - locsize;
440 off_t readoff = this->has_eh_frame_ ? dataoff : extoff;
441 section_size_type readsize = this->has_eh_frame_ ? datasize : extsize;
443 File_view* fvsymtab = this->get_lasting_view(readoff, readsize, true, false);
445 // Read the section header for the symbol names.
446 unsigned int strtab_shndx = this->adjust_shndx(symtabshdr.get_sh_link());
447 if (strtab_shndx >= this->shnum())
449 this->error(_("invalid symbol table name index: %u"), strtab_shndx);
452 typename This::Shdr strtabshdr(pshdrs + strtab_shndx * This::shdr_size);
453 if (strtabshdr.get_sh_type() != elfcpp::SHT_STRTAB)
455 this->error(_("symbol table name section has wrong type: %u"),
456 static_cast<unsigned int>(strtabshdr.get_sh_type()));
460 // Read the symbol names.
461 File_view* fvstrtab = this->get_lasting_view(strtabshdr.get_sh_offset(),
462 strtabshdr.get_sh_size(),
465 sd->symbols = fvsymtab;
466 sd->symbols_size = readsize;
467 sd->external_symbols_offset = this->has_eh_frame_ ? locsize : 0;
468 sd->symbol_names = fvstrtab;
469 sd->symbol_names_size =
470 convert_to_section_size_type(strtabshdr.get_sh_size());
473 // Return the section index of symbol SYM. Set *VALUE to its value in
474 // the object file. Set *IS_ORDINARY if this is an ordinary section
475 // index. not a special cod between SHN_LORESERVE and SHN_HIRESERVE.
476 // Note that for a symbol which is not defined in this object file,
477 // this will set *VALUE to 0 and return SHN_UNDEF; it will not return
478 // the final value of the symbol in the link.
480 template<int size, bool big_endian>
482 Sized_relobj<size, big_endian>::symbol_section_and_value(unsigned int sym,
486 section_size_type symbols_size;
487 const unsigned char* symbols = this->section_contents(this->symtab_shndx_,
491 const size_t count = symbols_size / This::sym_size;
492 gold_assert(sym < count);
494 elfcpp::Sym<size, big_endian> elfsym(symbols + sym * This::sym_size);
495 *value = elfsym.get_st_value();
497 return this->adjust_sym_shndx(sym, elfsym.get_st_shndx(), is_ordinary);
500 // Return whether to include a section group in the link. LAYOUT is
501 // used to keep track of which section groups we have already seen.
502 // INDEX is the index of the section group and SHDR is the section
503 // header. If we do not want to include this group, we set bits in
504 // OMIT for each section which should be discarded.
506 template<int size, bool big_endian>
508 Sized_relobj<size, big_endian>::include_section_group(
509 Symbol_table* symtab,
513 const elfcpp::Shdr<size, big_endian>& shdr,
514 std::vector<bool>* omit)
516 // Read the section contents.
517 const unsigned char* pcon = this->get_view(shdr.get_sh_offset(),
518 shdr.get_sh_size(), true, false);
519 const elfcpp::Elf_Word* pword =
520 reinterpret_cast<const elfcpp::Elf_Word*>(pcon);
522 // The first word contains flags. We only care about COMDAT section
523 // groups. Other section groups are always included in the link
524 // just like ordinary sections.
525 elfcpp::Elf_Word flags = elfcpp::Swap<32, big_endian>::readval(pword);
527 // Look up the group signature, which is the name of a symbol. This
528 // is a lot of effort to go to to read a string. Why didn't they
529 // just have the group signature point into the string table, rather
530 // than indirect through a symbol?
532 // Get the appropriate symbol table header (this will normally be
533 // the single SHT_SYMTAB section, but in principle it need not be).
534 const unsigned int link = this->adjust_shndx(shdr.get_sh_link());
535 typename This::Shdr symshdr(this, this->elf_file_.section_header(link));
537 // Read the symbol table entry.
538 unsigned int symndx = shdr.get_sh_info();
539 if (symndx >= symshdr.get_sh_size() / This::sym_size)
541 this->error(_("section group %u info %u out of range"),
545 off_t symoff = symshdr.get_sh_offset() + symndx * This::sym_size;
546 const unsigned char* psym = this->get_view(symoff, This::sym_size, true,
548 elfcpp::Sym<size, big_endian> sym(psym);
550 // Read the symbol table names.
551 section_size_type symnamelen;
552 const unsigned char* psymnamesu;
553 psymnamesu = this->section_contents(this->adjust_shndx(symshdr.get_sh_link()),
555 const char* psymnames = reinterpret_cast<const char*>(psymnamesu);
557 // Get the section group signature.
558 if (sym.get_st_name() >= symnamelen)
560 this->error(_("symbol %u name offset %u out of range"),
561 symndx, sym.get_st_name());
565 const char* signature = psymnames + sym.get_st_name();
567 // It seems that some versions of gas will create a section group
568 // associated with a section symbol, and then fail to give a name to
569 // the section symbol. In such a case, use the name of the section.
571 if (signature[0] == '\0' && sym.get_st_type() == elfcpp::STT_SECTION)
574 unsigned int sym_shndx = this->adjust_sym_shndx(symndx,
577 if (!is_ordinary || sym_shndx >= this->shnum())
579 this->error(_("symbol %u invalid section index %u"),
583 secname = this->section_name(sym_shndx);
584 signature = secname.c_str();
587 // Record this section group, and see whether we've already seen one
588 // with the same signature.
590 if ((flags & elfcpp::GRP_COMDAT) == 0
591 || layout->add_comdat(signature, true))
593 if (parameters->options().relocatable())
594 layout->layout_group(symtab, this, index, name, signature, shdr,
599 // This is a duplicate. We want to discard the sections in this
601 size_t count = shdr.get_sh_size() / sizeof(elfcpp::Elf_Word);
602 for (size_t i = 1; i < count; ++i)
604 elfcpp::Elf_Word secnum =
605 elfcpp::Swap<32, big_endian>::readval(pword + i);
606 if (secnum >= this->shnum())
608 this->error(_("section %u in section group %u out of range"),
612 (*omit)[secnum] = true;
618 // Whether to include a linkonce section in the link. NAME is the
619 // name of the section and SHDR is the section header.
621 // Linkonce sections are a GNU extension implemented in the original
622 // GNU linker before section groups were defined. The semantics are
623 // that we only include one linkonce section with a given name. The
624 // name of a linkonce section is normally .gnu.linkonce.T.SYMNAME,
625 // where T is the type of section and SYMNAME is the name of a symbol.
626 // In an attempt to make linkonce sections interact well with section
627 // groups, we try to identify SYMNAME and use it like a section group
628 // signature. We want to block section groups with that signature,
629 // but not other linkonce sections with that signature. We also use
630 // the full name of the linkonce section as a normal section group
633 template<int size, bool big_endian>
635 Sized_relobj<size, big_endian>::include_linkonce_section(
638 const elfcpp::Shdr<size, big_endian>&)
640 // In general the symbol name we want will be the string following
641 // the last '.'. However, we have to handle the case of
642 // .gnu.linkonce.t.__i686.get_pc_thunk.bx, which was generated by
643 // some versions of gcc. So we use a heuristic: if the name starts
644 // with ".gnu.linkonce.t.", we use everything after that. Otherwise
645 // we look for the last '.'. We can't always simply skip
646 // ".gnu.linkonce.X", because we have to deal with cases like
647 // ".gnu.linkonce.d.rel.ro.local".
648 const char* const linkonce_t = ".gnu.linkonce.t.";
650 if (strncmp(name, linkonce_t, strlen(linkonce_t)) == 0)
651 symname = name + strlen(linkonce_t);
653 symname = strrchr(name, '.') + 1;
654 bool include1 = layout->add_comdat(symname, false);
655 bool include2 = layout->add_comdat(name, true);
656 return include1 && include2;
659 // Lay out the input sections. We walk through the sections and check
660 // whether they should be included in the link. If they should, we
661 // pass them to the Layout object, which will return an output section
664 template<int size, bool big_endian>
666 Sized_relobj<size, big_endian>::do_layout(Symbol_table* symtab,
668 Read_symbols_data* sd)
670 const unsigned int shnum = this->shnum();
674 // Get the section headers.
675 const unsigned char* pshdrs = sd->section_headers->data();
677 // Get the section names.
678 const unsigned char* pnamesu = sd->section_names->data();
679 const char* pnames = reinterpret_cast<const char*>(pnamesu);
681 // For each section, record the index of the reloc section if any.
682 // Use 0 to mean that there is no reloc section, -1U to mean that
683 // there is more than one.
684 std::vector<unsigned int> reloc_shndx(shnum, 0);
685 std::vector<unsigned int> reloc_type(shnum, elfcpp::SHT_NULL);
686 // Skip the first, dummy, section.
687 pshdrs += This::shdr_size;
688 for (unsigned int i = 1; i < shnum; ++i, pshdrs += This::shdr_size)
690 typename This::Shdr shdr(pshdrs);
692 unsigned int sh_type = shdr.get_sh_type();
693 if (sh_type == elfcpp::SHT_REL || sh_type == elfcpp::SHT_RELA)
695 unsigned int target_shndx = this->adjust_shndx(shdr.get_sh_info());
696 if (target_shndx == 0 || target_shndx >= shnum)
698 this->error(_("relocation section %u has bad info %u"),
703 if (reloc_shndx[target_shndx] != 0)
704 reloc_shndx[target_shndx] = -1U;
707 reloc_shndx[target_shndx] = i;
708 reloc_type[target_shndx] = sh_type;
713 std::vector<Map_to_output>& map_sections(this->map_to_output());
714 map_sections.resize(shnum);
716 // If we are only linking for symbols, then there is nothing else to
718 if (this->input_file()->just_symbols())
720 delete sd->section_headers;
721 sd->section_headers = NULL;
722 delete sd->section_names;
723 sd->section_names = NULL;
727 // Whether we've seen a .note.GNU-stack section.
728 bool seen_gnu_stack = false;
729 // The flags of a .note.GNU-stack section.
730 uint64_t gnu_stack_flags = 0;
732 // Keep track of which sections to omit.
733 std::vector<bool> omit(shnum, false);
735 // Keep track of reloc sections when emitting relocations.
736 const bool relocatable = parameters->options().relocatable();
737 const bool emit_relocs = (relocatable
738 || parameters->options().emit_relocs());
739 std::vector<unsigned int> reloc_sections;
741 // Keep track of .eh_frame sections.
742 std::vector<unsigned int> eh_frame_sections;
744 // Skip the first, dummy, section.
745 pshdrs = sd->section_headers->data() + This::shdr_size;
746 for (unsigned int i = 1; i < shnum; ++i, pshdrs += This::shdr_size)
748 typename This::Shdr shdr(pshdrs);
750 if (shdr.get_sh_name() >= sd->section_names_size)
752 this->error(_("bad section name offset for section %u: %lu"),
753 i, static_cast<unsigned long>(shdr.get_sh_name()));
757 const char* name = pnames + shdr.get_sh_name();
759 if (this->handle_gnu_warning_section(name, i, symtab))
765 // The .note.GNU-stack section is special. It gives the
766 // protection flags that this object file requires for the stack
768 if (strcmp(name, ".note.GNU-stack") == 0)
770 seen_gnu_stack = true;
771 gnu_stack_flags |= shdr.get_sh_flags();
775 bool discard = omit[i];
778 if (shdr.get_sh_type() == elfcpp::SHT_GROUP)
780 if (!this->include_section_group(symtab, layout, i, name, shdr,
784 else if ((shdr.get_sh_flags() & elfcpp::SHF_GROUP) == 0
785 && Layout::is_linkonce(name))
787 if (!this->include_linkonce_section(layout, name, shdr))
794 // Do not include this section in the link.
795 map_sections[i].output_section = NULL;
799 // When doing a relocatable link we are going to copy input
800 // reloc sections into the output. We only want to copy the
801 // ones associated with sections which are not being discarded.
802 // However, we don't know that yet for all sections. So save
803 // reloc sections and process them later.
805 && (shdr.get_sh_type() == elfcpp::SHT_REL
806 || shdr.get_sh_type() == elfcpp::SHT_RELA))
808 reloc_sections.push_back(i);
812 if (relocatable && shdr.get_sh_type() == elfcpp::SHT_GROUP)
815 // The .eh_frame section is special. It holds exception frame
816 // information that we need to read in order to generate the
817 // exception frame header. We process these after all the other
818 // sections so that the exception frame reader can reliably
819 // determine which sections are being discarded, and discard the
820 // corresponding information.
822 && strcmp(name, ".eh_frame") == 0
823 && this->check_eh_frame_flags(&shdr))
825 eh_frame_sections.push_back(i);
830 Output_section* os = layout->layout(this, i, name, shdr,
831 reloc_shndx[i], reloc_type[i],
834 map_sections[i].output_section = os;
835 map_sections[i].offset = offset;
837 // If this section requires special handling, and if there are
838 // relocs that apply to it, then we must do the special handling
839 // before we apply the relocs.
840 if (offset == -1 && reloc_shndx[i] != 0)
841 this->set_relocs_must_follow_section_writes();
844 layout->layout_gnu_stack(seen_gnu_stack, gnu_stack_flags);
846 // When doing a relocatable link handle the reloc sections at the
849 this->size_relocatable_relocs();
850 for (std::vector<unsigned int>::const_iterator p = reloc_sections.begin();
851 p != reloc_sections.end();
855 const unsigned char* pshdr;
856 pshdr = sd->section_headers->data() + i * This::shdr_size;
857 typename This::Shdr shdr(pshdr);
859 unsigned int data_shndx = this->adjust_shndx(shdr.get_sh_info());
860 if (data_shndx >= shnum)
862 // We already warned about this above.
866 Output_section* data_section = map_sections[data_shndx].output_section;
867 if (data_section == NULL)
869 map_sections[i].output_section = NULL;
873 Relocatable_relocs* rr = new Relocatable_relocs();
874 this->set_relocatable_relocs(i, rr);
876 Output_section* os = layout->layout_reloc(this, i, shdr, data_section,
878 map_sections[i].output_section = os;
879 map_sections[i].offset = -1;
882 // Handle the .eh_frame sections at the end.
883 for (std::vector<unsigned int>::const_iterator p = eh_frame_sections.begin();
884 p != eh_frame_sections.end();
887 gold_assert(this->has_eh_frame_);
888 gold_assert(sd->external_symbols_offset != 0);
891 const unsigned char *pshdr;
892 pshdr = sd->section_headers->data() + i * This::shdr_size;
893 typename This::Shdr shdr(pshdr);
896 Output_section* os = layout->layout_eh_frame(this,
899 sd->symbol_names->data(),
900 sd->symbol_names_size,
905 map_sections[i].output_section = os;
906 map_sections[i].offset = offset;
908 // If this section requires special handling, and if there are
909 // relocs that apply to it, then we must do the special handling
910 // before we apply the relocs.
911 if (offset == -1 && reloc_shndx[i] != 0)
912 this->set_relocs_must_follow_section_writes();
915 delete sd->section_headers;
916 sd->section_headers = NULL;
917 delete sd->section_names;
918 sd->section_names = NULL;
921 // Add the symbols to the symbol table.
923 template<int size, bool big_endian>
925 Sized_relobj<size, big_endian>::do_add_symbols(Symbol_table* symtab,
926 Read_symbols_data* sd)
928 if (sd->symbols == NULL)
930 gold_assert(sd->symbol_names == NULL);
934 const int sym_size = This::sym_size;
935 size_t symcount = ((sd->symbols_size - sd->external_symbols_offset)
937 if (symcount * sym_size != sd->symbols_size - sd->external_symbols_offset)
939 this->error(_("size of symbols is not multiple of symbol size"));
943 this->symbols_.resize(symcount);
945 const char* sym_names =
946 reinterpret_cast<const char*>(sd->symbol_names->data());
947 symtab->add_from_relobj(this,
948 sd->symbols->data() + sd->external_symbols_offset,
949 symcount, this->local_symbol_count_,
950 sym_names, sd->symbol_names_size,
955 delete sd->symbol_names;
956 sd->symbol_names = NULL;
959 // First pass over the local symbols. Here we add their names to
960 // *POOL and *DYNPOOL, and we store the symbol value in
961 // THIS->LOCAL_VALUES_. This function is always called from a
962 // singleton thread. This is followed by a call to
963 // finalize_local_symbols.
965 template<int size, bool big_endian>
967 Sized_relobj<size, big_endian>::do_count_local_symbols(Stringpool* pool,
970 gold_assert(this->symtab_shndx_ != -1U);
971 if (this->symtab_shndx_ == 0)
973 // This object has no symbols. Weird but legal.
977 // Read the symbol table section header.
978 const unsigned int symtab_shndx = this->symtab_shndx_;
979 typename This::Shdr symtabshdr(this,
980 this->elf_file_.section_header(symtab_shndx));
981 gold_assert(symtabshdr.get_sh_type() == elfcpp::SHT_SYMTAB);
983 // Read the local symbols.
984 const int sym_size = This::sym_size;
985 const unsigned int loccount = this->local_symbol_count_;
986 gold_assert(loccount == symtabshdr.get_sh_info());
987 off_t locsize = loccount * sym_size;
988 const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
989 locsize, true, true);
991 // Read the symbol names.
992 const unsigned int strtab_shndx =
993 this->adjust_shndx(symtabshdr.get_sh_link());
994 section_size_type strtab_size;
995 const unsigned char* pnamesu = this->section_contents(strtab_shndx,
998 const char* pnames = reinterpret_cast<const char*>(pnamesu);
1000 // Loop over the local symbols.
1002 const std::vector<Map_to_output>& mo(this->map_to_output());
1003 unsigned int shnum = this->shnum();
1004 unsigned int count = 0;
1005 unsigned int dyncount = 0;
1006 // Skip the first, dummy, symbol.
1008 for (unsigned int i = 1; i < loccount; ++i, psyms += sym_size)
1010 elfcpp::Sym<size, big_endian> sym(psyms);
1012 Symbol_value<size>& lv(this->local_values_[i]);
1015 unsigned int shndx = this->adjust_sym_shndx(i, sym.get_st_shndx(),
1017 lv.set_input_shndx(shndx, is_ordinary);
1019 if (sym.get_st_type() == elfcpp::STT_SECTION)
1020 lv.set_is_section_symbol();
1021 else if (sym.get_st_type() == elfcpp::STT_TLS)
1022 lv.set_is_tls_symbol();
1024 // Save the input symbol value for use in do_finalize_local_symbols().
1025 lv.set_input_value(sym.get_st_value());
1027 // Decide whether this symbol should go into the output file.
1029 if (shndx < shnum && mo[shndx].output_section == NULL)
1031 lv.set_no_output_symtab_entry();
1032 gold_assert(!lv.needs_output_dynsym_entry());
1036 if (sym.get_st_type() == elfcpp::STT_SECTION)
1038 lv.set_no_output_symtab_entry();
1039 gold_assert(!lv.needs_output_dynsym_entry());
1043 if (sym.get_st_name() >= strtab_size)
1045 this->error(_("local symbol %u section name out of range: %u >= %u"),
1046 i, sym.get_st_name(),
1047 static_cast<unsigned int>(strtab_size));
1048 lv.set_no_output_symtab_entry();
1052 // Add the symbol to the symbol table string pool.
1053 const char* name = pnames + sym.get_st_name();
1054 pool->add(name, true, NULL);
1057 // If needed, add the symbol to the dynamic symbol table string pool.
1058 if (lv.needs_output_dynsym_entry())
1060 dynpool->add(name, true, NULL);
1065 this->output_local_symbol_count_ = count;
1066 this->output_local_dynsym_count_ = dyncount;
1069 // Finalize the local symbols. Here we set the final value in
1070 // THIS->LOCAL_VALUES_ and set their output symbol table indexes.
1071 // This function is always called from a singleton thread. The actual
1072 // output of the local symbols will occur in a separate task.
1074 template<int size, bool big_endian>
1076 Sized_relobj<size, big_endian>::do_finalize_local_symbols(unsigned int index,
1079 gold_assert(off == static_cast<off_t>(align_address(off, size >> 3)));
1081 const unsigned int loccount = this->local_symbol_count_;
1082 this->local_symbol_offset_ = off;
1084 const std::vector<Map_to_output>& mo(this->map_to_output());
1085 unsigned int shnum = this->shnum();
1087 for (unsigned int i = 1; i < loccount; ++i)
1089 Symbol_value<size>& lv(this->local_values_[i]);
1092 unsigned int shndx = lv.input_shndx(&is_ordinary);
1094 // Set the output symbol value.
1098 if (shndx == elfcpp::SHN_ABS || shndx == elfcpp::SHN_COMMON)
1099 lv.set_output_value(lv.input_value());
1102 this->error(_("unknown section index %u for local symbol %u"),
1104 lv.set_output_value(0);
1111 this->error(_("local symbol %u section index %u out of range"),
1116 Output_section* os = mo[shndx].output_section;
1120 lv.set_output_value(0);
1123 else if (mo[shndx].offset == -1)
1125 // This is a SHF_MERGE section or one which otherwise
1126 // requires special handling. We get the output address
1127 // of the start of the merged section. If this is not a
1128 // section symbol, we can then determine the final
1129 // value. If it is a section symbol, we can not, as in
1130 // that case we have to consider the addend to determine
1131 // the value to use in a relocation.
1132 if (!lv.is_section_symbol())
1133 lv.set_output_value(os->output_address(this, shndx,
1137 section_offset_type start =
1138 os->starting_output_address(this, shndx);
1139 Merged_symbol_value<size>* msv =
1140 new Merged_symbol_value<size>(lv.input_value(), start);
1141 lv.set_merged_symbol_value(msv);
1144 else if (lv.is_tls_symbol())
1145 lv.set_output_value(os->tls_offset()
1147 + lv.input_value());
1149 lv.set_output_value(os->address()
1151 + lv.input_value());
1154 if (lv.needs_output_symtab_entry())
1156 lv.set_output_symtab_index(index);
1163 // Set the output dynamic symbol table indexes for the local variables.
1165 template<int size, bool big_endian>
1167 Sized_relobj<size, big_endian>::do_set_local_dynsym_indexes(unsigned int index)
1169 const unsigned int loccount = this->local_symbol_count_;
1170 for (unsigned int i = 1; i < loccount; ++i)
1172 Symbol_value<size>& lv(this->local_values_[i]);
1173 if (lv.needs_output_dynsym_entry())
1175 lv.set_output_dynsym_index(index);
1182 // Set the offset where local dynamic symbol information will be stored.
1183 // Returns the count of local symbols contributed to the symbol table by
1186 template<int size, bool big_endian>
1188 Sized_relobj<size, big_endian>::do_set_local_dynsym_offset(off_t off)
1190 gold_assert(off == static_cast<off_t>(align_address(off, size >> 3)));
1191 this->local_dynsym_offset_ = off;
1192 return this->output_local_dynsym_count_;
1195 // Write out the local symbols.
1197 template<int size, bool big_endian>
1199 Sized_relobj<size, big_endian>::write_local_symbols(
1201 const Stringpool* sympool,
1202 const Stringpool* dynpool,
1203 Output_symtab_xindex* symtab_xindex,
1204 Output_symtab_xindex* dynsym_xindex)
1206 if (parameters->options().strip_all()
1207 && this->output_local_dynsym_count_ == 0)
1210 gold_assert(this->symtab_shndx_ != -1U);
1211 if (this->symtab_shndx_ == 0)
1213 // This object has no symbols. Weird but legal.
1217 // Read the symbol table section header.
1218 const unsigned int symtab_shndx = this->symtab_shndx_;
1219 typename This::Shdr symtabshdr(this,
1220 this->elf_file_.section_header(symtab_shndx));
1221 gold_assert(symtabshdr.get_sh_type() == elfcpp::SHT_SYMTAB);
1222 const unsigned int loccount = this->local_symbol_count_;
1223 gold_assert(loccount == symtabshdr.get_sh_info());
1225 // Read the local symbols.
1226 const int sym_size = This::sym_size;
1227 off_t locsize = loccount * sym_size;
1228 const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
1229 locsize, true, false);
1231 // Read the symbol names.
1232 const unsigned int strtab_shndx =
1233 this->adjust_shndx(symtabshdr.get_sh_link());
1234 section_size_type strtab_size;
1235 const unsigned char* pnamesu = this->section_contents(strtab_shndx,
1238 const char* pnames = reinterpret_cast<const char*>(pnamesu);
1240 // Get views into the output file for the portions of the symbol table
1241 // and the dynamic symbol table that we will be writing.
1242 off_t output_size = this->output_local_symbol_count_ * sym_size;
1243 unsigned char* oview = NULL;
1244 if (output_size > 0)
1245 oview = of->get_output_view(this->local_symbol_offset_, output_size);
1247 off_t dyn_output_size = this->output_local_dynsym_count_ * sym_size;
1248 unsigned char* dyn_oview = NULL;
1249 if (dyn_output_size > 0)
1250 dyn_oview = of->get_output_view(this->local_dynsym_offset_,
1253 const std::vector<Map_to_output>& mo(this->map_to_output());
1255 gold_assert(this->local_values_.size() == loccount);
1257 unsigned char* ov = oview;
1258 unsigned char* dyn_ov = dyn_oview;
1260 for (unsigned int i = 1; i < loccount; ++i, psyms += sym_size)
1262 elfcpp::Sym<size, big_endian> isym(psyms);
1264 Symbol_value<size>& lv(this->local_values_[i]);
1267 unsigned int st_shndx = this->adjust_sym_shndx(i, isym.get_st_shndx(),
1271 gold_assert(st_shndx < mo.size());
1272 if (mo[st_shndx].output_section == NULL)
1274 st_shndx = mo[st_shndx].output_section->out_shndx();
1275 if (st_shndx >= elfcpp::SHN_LORESERVE)
1277 if (lv.needs_output_symtab_entry())
1278 symtab_xindex->add(lv.output_symtab_index(), st_shndx);
1279 if (lv.needs_output_dynsym_entry())
1280 dynsym_xindex->add(lv.output_dynsym_index(), st_shndx);
1281 st_shndx = elfcpp::SHN_XINDEX;
1285 // Write the symbol to the output symbol table.
1286 if (!parameters->options().strip_all()
1287 && lv.needs_output_symtab_entry())
1289 elfcpp::Sym_write<size, big_endian> osym(ov);
1291 gold_assert(isym.get_st_name() < strtab_size);
1292 const char* name = pnames + isym.get_st_name();
1293 osym.put_st_name(sympool->get_offset(name));
1294 osym.put_st_value(this->local_values_[i].value(this, 0));
1295 osym.put_st_size(isym.get_st_size());
1296 osym.put_st_info(isym.get_st_info());
1297 osym.put_st_other(isym.get_st_other());
1298 osym.put_st_shndx(st_shndx);
1303 // Write the symbol to the output dynamic symbol table.
1304 if (lv.needs_output_dynsym_entry())
1306 gold_assert(dyn_ov < dyn_oview + dyn_output_size);
1307 elfcpp::Sym_write<size, big_endian> osym(dyn_ov);
1309 gold_assert(isym.get_st_name() < strtab_size);
1310 const char* name = pnames + isym.get_st_name();
1311 osym.put_st_name(dynpool->get_offset(name));
1312 osym.put_st_value(this->local_values_[i].value(this, 0));
1313 osym.put_st_size(isym.get_st_size());
1314 osym.put_st_info(isym.get_st_info());
1315 osym.put_st_other(isym.get_st_other());
1316 osym.put_st_shndx(st_shndx);
1323 if (output_size > 0)
1325 gold_assert(ov - oview == output_size);
1326 of->write_output_view(this->local_symbol_offset_, output_size, oview);
1329 if (dyn_output_size > 0)
1331 gold_assert(dyn_ov - dyn_oview == dyn_output_size);
1332 of->write_output_view(this->local_dynsym_offset_, dyn_output_size,
1337 // Set *INFO to symbolic information about the offset OFFSET in the
1338 // section SHNDX. Return true if we found something, false if we
1341 template<int size, bool big_endian>
1343 Sized_relobj<size, big_endian>::get_symbol_location_info(
1346 Symbol_location_info* info)
1348 if (this->symtab_shndx_ == 0)
1351 section_size_type symbols_size;
1352 const unsigned char* symbols = this->section_contents(this->symtab_shndx_,
1356 unsigned int symbol_names_shndx =
1357 this->adjust_shndx(this->section_link(this->symtab_shndx_));
1358 section_size_type names_size;
1359 const unsigned char* symbol_names_u =
1360 this->section_contents(symbol_names_shndx, &names_size, false);
1361 const char* symbol_names = reinterpret_cast<const char*>(symbol_names_u);
1363 const int sym_size = This::sym_size;
1364 const size_t count = symbols_size / sym_size;
1366 const unsigned char* p = symbols;
1367 for (size_t i = 0; i < count; ++i, p += sym_size)
1369 elfcpp::Sym<size, big_endian> sym(p);
1371 if (sym.get_st_type() == elfcpp::STT_FILE)
1373 if (sym.get_st_name() >= names_size)
1374 info->source_file = "(invalid)";
1376 info->source_file = symbol_names + sym.get_st_name();
1381 unsigned int st_shndx = this->adjust_sym_shndx(i, sym.get_st_shndx(),
1384 && st_shndx == shndx
1385 && static_cast<off_t>(sym.get_st_value()) <= offset
1386 && (static_cast<off_t>(sym.get_st_value() + sym.get_st_size())
1389 if (sym.get_st_name() > names_size)
1390 info->enclosing_symbol_name = "(invalid)";
1393 info->enclosing_symbol_name = symbol_names + sym.get_st_name();
1394 if (parameters->options().do_demangle())
1396 char* demangled_name = cplus_demangle(
1397 info->enclosing_symbol_name.c_str(),
1398 DMGL_ANSI | DMGL_PARAMS);
1399 if (demangled_name != NULL)
1401 info->enclosing_symbol_name.assign(demangled_name);
1402 free(demangled_name);
1413 // Input_objects methods.
1415 // Add a regular relocatable object to the list. Return false if this
1416 // object should be ignored.
1419 Input_objects::add_object(Object* obj)
1421 // Set the global target from the first object file we recognize.
1422 Target* target = obj->target();
1423 if (!parameters->target_valid())
1424 set_parameters_target(target);
1425 else if (target != ¶meters->target())
1427 obj->error(_("incompatible target"));
1431 // Print the filename if the -t/--trace option is selected.
1432 if (parameters->options().trace())
1433 gold_info("%s", obj->name().c_str());
1435 if (!obj->is_dynamic())
1436 this->relobj_list_.push_back(static_cast<Relobj*>(obj));
1439 // See if this is a duplicate SONAME.
1440 Dynobj* dynobj = static_cast<Dynobj*>(obj);
1441 const char* soname = dynobj->soname();
1443 std::pair<Unordered_set<std::string>::iterator, bool> ins =
1444 this->sonames_.insert(soname);
1447 // We have already seen a dynamic object with this soname.
1451 this->dynobj_list_.push_back(dynobj);
1453 // If this is -lc, remember the directory in which we found it.
1454 // We use this when issuing warnings about undefined symbols: as
1455 // a heuristic, we don't warn about system libraries found in
1456 // the same directory as -lc.
1457 if (strncmp(soname, "libc.so", 7) == 0)
1459 const char* object_name = dynobj->name().c_str();
1460 const char* base = lbasename(object_name);
1461 if (base != object_name)
1462 this->system_library_directory_.assign(object_name,
1463 base - 1 - object_name);
1470 // Return whether an object was found in the system library directory.
1473 Input_objects::found_in_system_library_directory(const Object* object) const
1475 return (!this->system_library_directory_.empty()
1476 && object->name().compare(0,
1477 this->system_library_directory_.size(),
1478 this->system_library_directory_) == 0);
1481 // For each dynamic object, record whether we've seen all of its
1482 // explicit dependencies.
1485 Input_objects::check_dynamic_dependencies() const
1487 for (Dynobj_list::const_iterator p = this->dynobj_list_.begin();
1488 p != this->dynobj_list_.end();
1491 const Dynobj::Needed& needed((*p)->needed());
1492 bool found_all = true;
1493 for (Dynobj::Needed::const_iterator pneeded = needed.begin();
1494 pneeded != needed.end();
1497 if (this->sonames_.find(*pneeded) == this->sonames_.end())
1503 (*p)->set_has_unknown_needed_entries(!found_all);
1507 // Relocate_info methods.
1509 // Return a string describing the location of a relocation. This is
1510 // only used in error messages.
1512 template<int size, bool big_endian>
1514 Relocate_info<size, big_endian>::location(size_t, off_t offset) const
1516 // See if we can get line-number information from debugging sections.
1517 std::string filename;
1518 std::string file_and_lineno; // Better than filename-only, if available.
1520 Sized_dwarf_line_info<size, big_endian> line_info(this->object);
1521 // This will be "" if we failed to parse the debug info for any reason.
1522 file_and_lineno = line_info.addr2line(this->data_shndx, offset);
1524 std::string ret(this->object->name());
1526 Symbol_location_info info;
1527 if (this->object->get_symbol_location_info(this->data_shndx, offset, &info))
1529 ret += " in function ";
1530 ret += info.enclosing_symbol_name;
1532 filename = info.source_file;
1535 if (!file_and_lineno.empty())
1536 ret += file_and_lineno;
1539 if (!filename.empty())
1542 ret += this->object->section_name(this->data_shndx);
1544 // Offsets into sections have to be positive.
1545 snprintf(buf, sizeof(buf), "+0x%lx", static_cast<long>(offset));
1552 } // End namespace gold.
1557 using namespace gold;
1559 // Read an ELF file with the header and return the appropriate
1560 // instance of Object.
1562 template<int size, bool big_endian>
1564 make_elf_sized_object(const std::string& name, Input_file* input_file,
1565 off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr)
1567 int et = ehdr.get_e_type();
1568 if (et == elfcpp::ET_REL)
1570 Sized_relobj<size, big_endian>* obj =
1571 new Sized_relobj<size, big_endian>(name, input_file, offset, ehdr);
1575 else if (et == elfcpp::ET_DYN)
1577 Sized_dynobj<size, big_endian>* obj =
1578 new Sized_dynobj<size, big_endian>(name, input_file, offset, ehdr);
1584 gold_error(_("%s: unsupported ELF file type %d"),
1590 } // End anonymous namespace.
1595 // Read an ELF file and return the appropriate instance of Object.
1598 make_elf_object(const std::string& name, Input_file* input_file, off_t offset,
1599 const unsigned char* p, section_offset_type bytes)
1601 if (bytes < elfcpp::EI_NIDENT)
1603 gold_error(_("%s: ELF file too short"), name.c_str());
1607 int v = p[elfcpp::EI_VERSION];
1608 if (v != elfcpp::EV_CURRENT)
1610 if (v == elfcpp::EV_NONE)
1611 gold_error(_("%s: invalid ELF version 0"), name.c_str());
1613 gold_error(_("%s: unsupported ELF version %d"), name.c_str(), v);
1617 int c = p[elfcpp::EI_CLASS];
1618 if (c == elfcpp::ELFCLASSNONE)
1620 gold_error(_("%s: invalid ELF class 0"), name.c_str());
1623 else if (c != elfcpp::ELFCLASS32
1624 && c != elfcpp::ELFCLASS64)
1626 gold_error(_("%s: unsupported ELF class %d"), name.c_str(), c);
1630 int d = p[elfcpp::EI_DATA];
1631 if (d == elfcpp::ELFDATANONE)
1633 gold_error(_("%s: invalid ELF data encoding"), name.c_str());
1636 else if (d != elfcpp::ELFDATA2LSB
1637 && d != elfcpp::ELFDATA2MSB)
1639 gold_error(_("%s: unsupported ELF data encoding %d"), name.c_str(), d);
1643 bool big_endian = d == elfcpp::ELFDATA2MSB;
1645 if (c == elfcpp::ELFCLASS32)
1647 if (bytes < elfcpp::Elf_sizes<32>::ehdr_size)
1649 gold_error(_("%s: ELF file too short"), name.c_str());
1654 #ifdef HAVE_TARGET_32_BIG
1655 elfcpp::Ehdr<32, true> ehdr(p);
1656 return make_elf_sized_object<32, true>(name, input_file,
1659 gold_error(_("%s: not configured to support "
1660 "32-bit big-endian object"),
1667 #ifdef HAVE_TARGET_32_LITTLE
1668 elfcpp::Ehdr<32, false> ehdr(p);
1669 return make_elf_sized_object<32, false>(name, input_file,
1672 gold_error(_("%s: not configured to support "
1673 "32-bit little-endian object"),
1681 if (bytes < elfcpp::Elf_sizes<64>::ehdr_size)
1683 gold_error(_("%s: ELF file too short"), name.c_str());
1688 #ifdef HAVE_TARGET_64_BIG
1689 elfcpp::Ehdr<64, true> ehdr(p);
1690 return make_elf_sized_object<64, true>(name, input_file,
1693 gold_error(_("%s: not configured to support "
1694 "64-bit big-endian object"),
1701 #ifdef HAVE_TARGET_64_LITTLE
1702 elfcpp::Ehdr<64, false> ehdr(p);
1703 return make_elf_sized_object<64, false>(name, input_file,
1706 gold_error(_("%s: not configured to support "
1707 "64-bit little-endian object"),
1715 // Instantiate the templates we need.
1717 #ifdef HAVE_TARGET_32_LITTLE
1720 Object::read_section_data<32, false>(elfcpp::Elf_file<32, false, Object>*,
1721 Read_symbols_data*);
1724 #ifdef HAVE_TARGET_32_BIG
1727 Object::read_section_data<32, true>(elfcpp::Elf_file<32, true, Object>*,
1728 Read_symbols_data*);
1731 #ifdef HAVE_TARGET_64_LITTLE
1734 Object::read_section_data<64, false>(elfcpp::Elf_file<64, false, Object>*,
1735 Read_symbols_data*);
1738 #ifdef HAVE_TARGET_64_BIG
1741 Object::read_section_data<64, true>(elfcpp::Elf_file<64, true, Object>*,
1742 Read_symbols_data*);
1745 #ifdef HAVE_TARGET_32_LITTLE
1747 class Sized_relobj<32, false>;
1750 #ifdef HAVE_TARGET_32_BIG
1752 class Sized_relobj<32, true>;
1755 #ifdef HAVE_TARGET_64_LITTLE
1757 class Sized_relobj<64, false>;
1760 #ifdef HAVE_TARGET_64_BIG
1762 class Sized_relobj<64, true>;
1765 #ifdef HAVE_TARGET_32_LITTLE
1767 struct Relocate_info<32, false>;
1770 #ifdef HAVE_TARGET_32_BIG
1772 struct Relocate_info<32, true>;
1775 #ifdef HAVE_TARGET_64_LITTLE
1777 struct Relocate_info<64, false>;
1780 #ifdef HAVE_TARGET_64_BIG
1782 struct Relocate_info<64, true>;
1785 } // End namespace gold.