1 // object.cc -- support for an object file for linking in gold
10 #include "target-select.h"
19 // Class Sized_object.
21 template<int size, bool big_endian>
22 Sized_object<size, big_endian>::Sized_object(
23 const std::string& name,
24 Input_file* input_file,
26 const elfcpp::Ehdr<size, big_endian>& ehdr)
27 : Object(name, input_file, false, offset),
28 section_headers_(NULL),
29 flags_(ehdr.get_e_flags()),
30 shoff_(ehdr.get_e_shoff()),
33 local_symbol_count_(0),
34 output_local_symbol_count_(0),
36 local_symbol_offset_(0),
39 if (ehdr.get_e_ehsize() != This::ehdr_size)
41 fprintf(stderr, _("%s: %s: bad e_ehsize field (%d != %d)\n"),
42 program_name, this->name().c_str(), ehdr.get_e_ehsize(),
46 if (ehdr.get_e_shentsize() != This::shdr_size)
48 fprintf(stderr, _("%s: %s: bad e_shentsize field (%d != %d)\n"),
49 program_name, this->name().c_str(), ehdr.get_e_shentsize(),
55 template<int size, bool big_endian>
56 Sized_object<size, big_endian>::~Sized_object()
60 // Read the section header for section SHNUM.
62 template<int size, bool big_endian>
63 inline const unsigned char*
64 Sized_object<size, big_endian>::section_header(unsigned int shnum)
66 assert(shnum < this->shnum());
67 off_t symtabshdroff = this->shoff_ + shnum * This::shdr_size;
68 return this->get_view(symtabshdroff, This::shdr_size);
71 // Return the name of section SHNUM.
73 template<int size, bool big_endian>
75 Sized_object<size, big_endian>::do_section_name(unsigned int shnum)
77 Task_lock_obj<Object> tl(*this);
79 // Read the section names.
80 typename This::Shdr shdrnames(this->section_header(this->shstrndx_));
81 const unsigned char* pnamesu = this->get_view(shdrnames.get_sh_offset(),
82 shdrnames.get_sh_size());
83 const char* pnames = reinterpret_cast<const char*>(pnamesu);
85 typename This::Shdr shdr(this->section_header(shnum));
86 if (shdr.get_sh_name() >= shdrnames.get_sh_size())
89 _("%s: %s: bad section name offset for section %u: %lu\n"),
90 program_name, this->name().c_str(), shnum,
91 static_cast<unsigned long>(shdr.get_sh_name()));
95 return std::string(pnames + shdr.get_sh_name());
98 // Set up an object file bsaed on the file header. This sets up the
99 // target and reads the section information.
101 template<int size, bool big_endian>
103 Sized_object<size, big_endian>::setup(
104 const elfcpp::Ehdr<size, big_endian>& ehdr)
106 int machine = ehdr.get_e_machine();
107 Target* target = select_target(machine, size, big_endian,
108 ehdr.get_e_ident()[elfcpp::EI_OSABI],
109 ehdr.get_e_ident()[elfcpp::EI_ABIVERSION]);
112 fprintf(stderr, _("%s: %s: unsupported ELF machine number %d\n"),
113 program_name, this->name().c_str(), machine);
116 this->set_target(target);
118 unsigned int shnum = ehdr.get_e_shnum();
119 unsigned int shstrndx = ehdr.get_e_shstrndx();
120 if ((shnum == 0 || shstrndx == elfcpp::SHN_XINDEX)
121 && this->shoff_ != 0)
123 typename This::Shdr shdr(this->section_header(0));
125 shnum = shdr.get_sh_size();
126 if (shstrndx == elfcpp::SHN_XINDEX)
127 shstrndx = shdr.get_sh_link();
129 this->set_shnum(shnum);
130 this->shstrndx_ = shstrndx;
135 // We store the section headers in a File_view until do_read_symbols.
136 this->section_headers_ = this->get_lasting_view(this->shoff_,
137 shnum * This::shdr_size);
139 // Find the SHT_SYMTAB section. The ELF standard says that maybe in
140 // the future there can be more than one SHT_SYMTAB section. Until
141 // somebody figures out how that could work, we assume there is only
143 const unsigned char* p = this->section_headers_->data();
145 // Skip the first section, which is always empty.
146 p += This::shdr_size;
147 for (unsigned int i = 1; i < shnum; ++i, p += This::shdr_size)
149 typename This::Shdr shdr(p);
150 if (shdr.get_sh_type() == elfcpp::SHT_SYMTAB)
152 this->symtab_shnum_ = i;
158 // Read the sections and symbols from an object file.
160 template<int size, bool big_endian>
162 Sized_object<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
164 // Transfer our view of the section headers to SD.
165 sd->section_headers = this->section_headers_;
166 this->section_headers_ = NULL;
168 // Read the section names.
169 const unsigned char* pshdrs = sd->section_headers->data();
170 const unsigned char* pshdrnames = pshdrs + this->shstrndx_ * This::shdr_size;
171 typename This::Shdr shdrnames(pshdrnames);
172 sd->section_names_size = shdrnames.get_sh_size();
173 sd->section_names = this->get_lasting_view(shdrnames.get_sh_offset(),
174 sd->section_names_size);
176 if (this->symtab_shnum_ == 0)
178 // No symbol table. Weird but legal.
180 sd->symbols_size = 0;
181 sd->symbol_names = NULL;
182 sd->symbol_names_size = 0;
186 // Get the symbol table section header.
187 typename This::Shdr symtabshdr(pshdrs
188 + this->symtab_shnum_ * This::shdr_size);
189 assert(symtabshdr.get_sh_type() == elfcpp::SHT_SYMTAB);
191 // We only need the external symbols.
192 const int sym_size = This::sym_size;
193 const unsigned int loccount = symtabshdr.get_sh_info();
194 this->local_symbol_count_ = loccount;
195 off_t locsize = loccount * sym_size;
196 off_t extoff = symtabshdr.get_sh_offset() + locsize;
197 off_t extsize = symtabshdr.get_sh_size() - locsize;
199 // Read the symbol table.
200 File_view* fvsymtab = this->get_lasting_view(extoff, extsize);
202 // Read the section header for the symbol names.
203 unsigned int shnum = this->shnum();
204 unsigned int strtab_shnum = symtabshdr.get_sh_link();
205 if (strtab_shnum == 0 || strtab_shnum >= shnum)
207 fprintf(stderr, _("%s: %s: invalid symbol table name index: %u\n"),
208 program_name, this->name().c_str(), strtab_shnum);
211 typename This::Shdr strtabshdr(pshdrs + strtab_shnum * This::shdr_size);
212 if (strtabshdr.get_sh_type() != elfcpp::SHT_STRTAB)
215 _("%s: %s: symbol table name section has wrong type: %u\n"),
216 program_name, this->name().c_str(),
217 static_cast<unsigned int>(strtabshdr.get_sh_type()));
221 // Read the symbol names.
222 File_view* fvstrtab = this->get_lasting_view(strtabshdr.get_sh_offset(),
223 strtabshdr.get_sh_size());
225 sd->symbols = fvsymtab;
226 sd->symbols_size = extsize;
227 sd->symbol_names = fvstrtab;
228 sd->symbol_names_size = strtabshdr.get_sh_size();
231 // Return whether to include a section group in the link. LAYOUT is
232 // used to keep track of which section groups we have already seen.
233 // INDEX is the index of the section group and SHDR is the section
234 // header. If we do not want to include this group, we set bits in
235 // OMIT for each section which should be discarded.
237 template<int size, bool big_endian>
239 Sized_object<size, big_endian>::include_section_group(
242 const elfcpp::Shdr<size, big_endian>& shdr,
243 std::vector<bool>* omit)
245 // Read the section contents.
246 const unsigned char* pcon = this->get_view(shdr.get_sh_offset(),
248 const elfcpp::Elf_Word* pword =
249 reinterpret_cast<const elfcpp::Elf_Word*>(pcon);
251 // The first word contains flags. We only care about COMDAT section
252 // groups. Other section groups are always included in the link
253 // just like ordinary sections.
254 elfcpp::Elf_Word flags = elfcpp::read_elf_word<big_endian>(pword);
255 if ((flags & elfcpp::GRP_COMDAT) == 0)
258 // Look up the group signature, which is the name of a symbol. This
259 // is a lot of effort to go to to read a string. Why didn't they
260 // just use the name of the SHT_GROUP section as the group
263 // Get the appropriate symbol table header (this will normally be
264 // the single SHT_SYMTAB section, but in principle it need not be).
265 if (shdr.get_sh_link() >= this->shnum())
267 fprintf(stderr, _("%s: %s: section group %u link %u out of range\n"),
268 program_name, this->name().c_str(), index, shdr.get_sh_link());
272 typename This::Shdr symshdr(this->section_header(shdr.get_sh_link()));
274 // Read the symbol table entry.
275 if (shdr.get_sh_info() >= symshdr.get_sh_size() / This::sym_size)
277 fprintf(stderr, _("%s: %s: section group %u info %u out of range\n"),
278 program_name, this->name().c_str(), index, shdr.get_sh_info());
281 off_t symoff = symshdr.get_sh_offset() + shdr.get_sh_info() * This::sym_size;
282 const unsigned char* psym = this->get_view(symoff, This::sym_size);
283 elfcpp::Sym<size, big_endian> sym(psym);
285 // Read the section header for the symbol table names.
286 if (symshdr.get_sh_link() >= this->shnum())
288 fprintf(stderr, _("%s; %s: symtab section %u link %u out of range\n"),
289 program_name, this->name().c_str(), shdr.get_sh_link(),
290 symshdr.get_sh_link());
294 typename This::Shdr symnamehdr(this->section_header(symshdr.get_sh_link()));
296 // Read the symbol table names.
297 const unsigned char *psymnamesu = this->get_view(symnamehdr.get_sh_offset(),
298 symnamehdr.get_sh_size());
299 const char* psymnames = reinterpret_cast<const char*>(psymnamesu);
301 // Get the section group signature.
302 if (sym.get_st_name() >= symnamehdr.get_sh_size())
304 fprintf(stderr, _("%s: %s: symbol %u name offset %u out of range\n"),
305 program_name, this->name().c_str(), shdr.get_sh_info(),
310 const char* signature = psymnames + sym.get_st_name();
312 // It seems that some versions of gas will create a section group
313 // associated with a section symbol, and then fail to give a name to
314 // the section symbol. In such a case, use the name of the section.
316 if (signature[0] == '\0'
317 && sym.get_st_type() == elfcpp::STT_SECTION
318 && sym.get_st_shndx() < this->shnum())
320 typename This::Shdr shdrnames(this->section_header(this->shstrndx_));
321 const unsigned char* pnamesu = this->get_view(shdrnames.get_sh_offset(),
322 shdrnames.get_sh_size());
323 const char* pnames = reinterpret_cast<const char*>(pnamesu);
325 typename This::Shdr sechdr(this->section_header(sym.get_st_shndx()));
326 if (sechdr.get_sh_name() >= shdrnames.get_sh_size())
329 _("%s: %s: bad section name offset for section %u: %lu\n"),
330 program_name, this->name().c_str(), sym.get_st_shndx(),
331 static_cast<unsigned long>(sechdr.get_sh_name()));
335 signature = pnames + sechdr.get_sh_name();
338 // Record this section group, and see whether we've already seen one
339 // with the same signature.
340 if (layout->add_comdat(signature, true))
343 // This is a duplicate. We want to discard the sections in this
345 size_t count = shdr.get_sh_size() / sizeof(elfcpp::Elf_Word);
346 for (size_t i = 1; i < count; ++i)
348 elfcpp::Elf_Word secnum = elfcpp::read_elf_word<big_endian>(pword + i);
349 if (secnum >= this->shnum())
352 _("%s: %s: section %u in section group %u out of range"),
353 program_name, this->name().c_str(), secnum,
357 (*omit)[secnum] = true;
363 // Whether to include a linkonce section in the link. NAME is the
364 // name of the section and SHDR is the section header.
366 // Linkonce sections are a GNU extension implemented in the original
367 // GNU linker before section groups were defined. The semantics are
368 // that we only include one linkonce section with a given name. The
369 // name of a linkonce section is normally .gnu.linkonce.T.SYMNAME,
370 // where T is the type of section and SYMNAME is the name of a symbol.
371 // In an attempt to make linkonce sections interact well with section
372 // groups, we try to identify SYMNAME and use it like a section group
373 // signature. We want to block section groups with that signature,
374 // but not other linkonce sections with that signature. We also use
375 // the full name of the linkonce section as a normal section group
378 template<int size, bool big_endian>
380 Sized_object<size, big_endian>::include_linkonce_section(
383 const elfcpp::Shdr<size, big_endian>&)
385 const char* symname = strrchr(name, '.') + 1;
386 bool include1 = layout->add_comdat(symname, false);
387 bool include2 = layout->add_comdat(name, true);
388 return include1 && include2;
391 // Lay out the input sections. We walk through the sections and check
392 // whether they should be included in the link. If they should, we
393 // pass them to the Layout object, which will return an output section
396 template<int size, bool big_endian>
398 Sized_object<size, big_endian>::do_layout(Layout* layout,
399 Read_symbols_data* sd)
401 unsigned int shnum = this->shnum();
405 // Get the section headers.
406 const unsigned char* pshdrs = sd->section_headers->data();
408 // Get the section names.
409 const unsigned char* pnamesu = sd->section_names->data();
410 const char* pnames = reinterpret_cast<const char*>(pnamesu);
412 std::vector<Map_to_output>& map_sections(this->map_to_output());
413 map_sections.resize(shnum);
415 // Keep track of which sections to omit.
416 std::vector<bool> omit(shnum, false);
418 for (unsigned int i = 0; i < shnum; ++i, pshdrs += This::shdr_size)
420 typename This::Shdr shdr(pshdrs);
422 if (shdr.get_sh_name() >= sd->section_names_size)
425 _("%s: %s: bad section name offset for section %u: %lu\n"),
426 program_name, this->name().c_str(), i,
427 static_cast<unsigned long>(shdr.get_sh_name()));
431 const char* name = pnames + shdr.get_sh_name();
433 bool discard = omit[i];
436 if (shdr.get_sh_type() == elfcpp::SHT_GROUP)
438 if (!this->include_section_group(layout, i, shdr, &omit))
441 else if (Layout::is_linkonce(name))
443 if (!this->include_linkonce_section(layout, name, shdr))
450 // Do not include this section in the link.
451 map_sections[i].output_section = NULL;
456 Output_section* os = layout->layout(this, i, name, shdr, &offset);
458 map_sections[i].output_section = os;
459 map_sections[i].offset = offset;
462 delete sd->section_headers;
463 sd->section_headers = NULL;
464 delete sd->section_names;
465 sd->section_names = NULL;
468 // Add the symbols to the symbol table.
470 template<int size, bool big_endian>
472 Sized_object<size, big_endian>::do_add_symbols(Symbol_table* symtab,
473 Read_symbols_data* sd)
475 if (sd->symbols == NULL)
477 assert(sd->symbol_names == NULL);
481 const int sym_size = This::sym_size;
482 size_t symcount = sd->symbols_size / sym_size;
483 if (symcount * sym_size != sd->symbols_size)
486 _("%s: %s: size of symbols is not multiple of symbol size\n"),
487 program_name, this->name().c_str());
491 this->symbols_ = new Symbol*[symcount];
493 const unsigned char* psyms = sd->symbols->data();
494 const elfcpp::Sym<size, big_endian>* syms =
495 reinterpret_cast<const elfcpp::Sym<size, big_endian>*>(psyms);
496 const char* sym_names =
497 reinterpret_cast<const char*>(sd->symbol_names->data());
498 symtab->add_from_object(this, syms, symcount, sym_names,
499 sd->symbol_names_size, this->symbols_);
503 delete sd->symbol_names;
504 sd->symbol_names = NULL;
507 // Finalize the local symbols. Here we record the file offset at
508 // which they should be output, we add their names to *POOL, and we
509 // add their values to THIS->VALUES_. Return the new file offset.
510 // This function is always called from the main thread. The actual
511 // output of the local symbols will occur in a separate task.
513 template<int size, bool big_endian>
515 Sized_object<size, big_endian>::do_finalize_local_symbols(off_t off,
518 if (this->symtab_shnum_ == 0)
520 // This object has no symbols. Weird but legal.
524 off = align_address(off, size >> 3);
526 this->local_symbol_offset_ = off;
528 // Read the symbol table section header.
529 typename This::Shdr symtabshdr(this->section_header(this->symtab_shnum_));
530 assert(symtabshdr.get_sh_type() == elfcpp::SHT_SYMTAB);
532 // Read the local symbols.
533 const int sym_size = This::sym_size;
534 const unsigned int loccount = this->local_symbol_count_;
535 assert(loccount == symtabshdr.get_sh_info());
536 off_t locsize = loccount * sym_size;
537 const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
540 this->values_ = new typename elfcpp::Elf_types<size>::Elf_Addr[loccount];
542 // Read the section header for the symbol names.
543 typename This::Shdr strtabshdr(
544 this->section_header(symtabshdr.get_sh_link()));
545 assert(strtabshdr.get_sh_type() == elfcpp::SHT_STRTAB);
547 // Read the symbol names.
548 const unsigned char* pnamesu = this->get_view(strtabshdr.get_sh_offset(),
549 strtabshdr.get_sh_size());
550 const char* pnames = reinterpret_cast<const char*>(pnamesu);
552 // Loop over the local symbols.
554 std::vector<Map_to_output>& mo(this->map_to_output());
555 unsigned int shnum = this->shnum();
556 unsigned int count = 0;
557 // Skip the first, dummy, symbol.
559 for (unsigned int i = 1; i < loccount; ++i, psyms += sym_size)
561 elfcpp::Sym<size, big_endian> sym(psyms);
563 unsigned int shndx = sym.get_st_shndx();
565 if (shndx >= elfcpp::SHN_LORESERVE)
567 if (shndx == elfcpp::SHN_ABS)
568 this->values_[i] = sym.get_st_value();
571 // FIXME: Handle SHN_XINDEX.
573 _("%s: %s: unknown section index %u "
574 "for local symbol %u\n"),
575 program_name, this->name().c_str(), shndx, i);
584 _("%s: %s: local symbol %u section index %u "
586 program_name, this->name().c_str(), i, shndx);
590 if (mo[shndx].output_section == NULL)
592 this->values_[i] = 0;
596 this->values_[i] = (mo[shndx].output_section->address()
598 + sym.get_st_value());
601 pool->add(pnames + sym.get_st_name());
606 this->output_local_symbol_count_ = count;
611 // Write out the local symbols.
613 template<int size, bool big_endian>
615 Sized_object<size, big_endian>::write_local_symbols(Output_file* of,
616 const Stringpool* sympool)
618 if (this->symtab_shnum_ == 0)
620 // This object has no symbols. Weird but legal.
624 // Read the symbol table section header.
625 typename This::Shdr symtabshdr(this->section_header(this->symtab_shnum_));
626 assert(symtabshdr.get_sh_type() == elfcpp::SHT_SYMTAB);
627 const unsigned int loccount = this->local_symbol_count_;
628 assert(loccount == symtabshdr.get_sh_info());
630 // Read the local symbols.
631 const int sym_size = This::sym_size;
632 off_t locsize = loccount * sym_size;
633 const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
636 // Read the section header for the symbol names.
637 typename This::Shdr strtabshdr(
638 this->section_header(symtabshdr.get_sh_link()));
639 assert(strtabshdr.get_sh_type() == elfcpp::SHT_STRTAB);
641 // Read the symbol names.
642 const unsigned char* pnamesu = this->get_view(strtabshdr.get_sh_offset(),
643 strtabshdr.get_sh_size());
644 const char* pnames = reinterpret_cast<const char*>(pnamesu);
646 // Get a view into the output file.
647 off_t output_size = this->output_local_symbol_count_ * sym_size;
648 unsigned char* oview = of->get_output_view(this->local_symbol_offset_,
651 std::vector<Map_to_output>& mo(this->map_to_output());
654 unsigned char* ov = oview;
655 for (unsigned int i = 1; i < loccount; ++i, psyms += sym_size)
657 elfcpp::Sym<size, big_endian> isym(psyms);
658 elfcpp::Sym_write<size, big_endian> osym(ov);
660 unsigned int st_shndx = isym.get_st_shndx();
661 if (st_shndx < elfcpp::SHN_LORESERVE)
663 assert(st_shndx < mo.size());
664 if (mo[st_shndx].output_section == NULL)
666 st_shndx = mo[st_shndx].output_section->out_shndx();
669 osym.put_st_name(sympool->get_offset(pnames + isym.get_st_name()));
670 osym.put_st_value(this->values_[i]);
671 osym.put_st_size(isym.get_st_size());
672 osym.put_st_info(isym.get_st_info());
673 osym.put_st_other(isym.get_st_other());
674 osym.put_st_shndx(st_shndx);
679 assert(ov - oview == output_size);
681 of->write_output_view(this->local_symbol_offset_, output_size, oview);
684 // Input_objects methods.
687 Input_objects::add_object(Object* obj)
689 this->object_list_.push_back(obj);
691 Target* target = obj->target();
692 if (this->target_ == NULL)
693 this->target_ = target;
694 else if (this->target_ != target)
696 fprintf(stderr, "%s: %s: incompatible target\n",
697 program_name, obj->name().c_str());
701 if (obj->is_dynamic())
702 this->any_dynamic_ = true;
705 // Relocate_info methods.
707 // Return a string describing the location of a relocation. This is
708 // only used in error messages.
710 template<int size, bool big_endian>
712 Relocate_info<size, big_endian>::location(size_t relnum, off_t) const
714 std::string ret(this->object->name());
717 snprintf(buf, sizeof buf, "%zu", relnum);
719 ret += " in reloc section ";
720 snprintf(buf, sizeof buf, "%u", this->reloc_shndx);
722 ret += " (" + this->object->section_name(this->reloc_shndx);
723 ret += ") for section ";
724 snprintf(buf, sizeof buf, "%u", this->data_shndx);
726 ret += " (" + this->object->section_name(this->data_shndx) + ")";
730 } // End namespace gold.
735 using namespace gold;
737 // Read an ELF file with the header and return the appropriate
738 // instance of Object.
740 template<int size, bool big_endian>
742 make_elf_sized_object(const std::string& name, Input_file* input_file,
743 off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr)
745 int et = ehdr.get_e_type();
746 if (et != elfcpp::ET_REL && et != elfcpp::ET_DYN)
748 fprintf(stderr, "%s: %s: unsupported ELF type %d\n",
749 program_name, name.c_str(), static_cast<int>(et));
753 if (et == elfcpp::ET_REL)
755 Sized_object<size, big_endian>* obj =
756 new Sized_object<size, big_endian>(name, input_file, offset, ehdr);
763 fprintf(stderr, _("%s: %s: dynamic objects are not yet supported\n"),
764 program_name, name.c_str());
766 // Sized_dynobj<size, big_endian>* obj =
767 // new Sized_dynobj<size, big_endian>(this->input_.name(), input_file,
774 } // End anonymous namespace.
779 // Read an ELF file and return the appropriate instance of Object.
782 make_elf_object(const std::string& name, Input_file* input_file, off_t offset,
783 const unsigned char* p, off_t bytes)
785 if (bytes < elfcpp::EI_NIDENT)
787 fprintf(stderr, _("%s: %s: ELF file too short\n"),
788 program_name, name.c_str());
792 int v = p[elfcpp::EI_VERSION];
793 if (v != elfcpp::EV_CURRENT)
795 if (v == elfcpp::EV_NONE)
796 fprintf(stderr, _("%s: %s: invalid ELF version 0\n"),
797 program_name, name.c_str());
799 fprintf(stderr, _("%s: %s: unsupported ELF version %d\n"),
800 program_name, name.c_str(), v);
804 int c = p[elfcpp::EI_CLASS];
805 if (c == elfcpp::ELFCLASSNONE)
807 fprintf(stderr, _("%s: %s: invalid ELF class 0\n"),
808 program_name, name.c_str());
811 else if (c != elfcpp::ELFCLASS32
812 && c != elfcpp::ELFCLASS64)
814 fprintf(stderr, _("%s: %s: unsupported ELF class %d\n"),
815 program_name, name.c_str(), c);
819 int d = p[elfcpp::EI_DATA];
820 if (d == elfcpp::ELFDATANONE)
822 fprintf(stderr, _("%s: %s: invalid ELF data encoding\n"),
823 program_name, name.c_str());
826 else if (d != elfcpp::ELFDATA2LSB
827 && d != elfcpp::ELFDATA2MSB)
829 fprintf(stderr, _("%s: %s: unsupported ELF data encoding %d\n"),
830 program_name, name.c_str(), d);
834 bool big_endian = d == elfcpp::ELFDATA2MSB;
836 if (c == elfcpp::ELFCLASS32)
838 if (bytes < elfcpp::Elf_sizes<32>::ehdr_size)
840 fprintf(stderr, _("%s: %s: ELF file too short\n"),
841 program_name, name.c_str());
846 elfcpp::Ehdr<32, true> ehdr(p);
847 return make_elf_sized_object<32, true>(name, input_file,
852 elfcpp::Ehdr<32, false> ehdr(p);
853 return make_elf_sized_object<32, false>(name, input_file,
859 if (bytes < elfcpp::Elf_sizes<32>::ehdr_size)
861 fprintf(stderr, _("%s: %s: ELF file too short\n"),
862 program_name, name.c_str());
867 elfcpp::Ehdr<64, true> ehdr(p);
868 return make_elf_sized_object<64, true>(name, input_file,
873 elfcpp::Ehdr<64, false> ehdr(p);
874 return make_elf_sized_object<64, false>(name, input_file,
880 // Instantiate the templates we need. We could use the configure
881 // script to restrict this to only the ones for implemented targets.
884 class Sized_object<32, false>;
887 class Sized_object<32, true>;
890 class Sized_object<64, false>;
893 class Sized_object<64, true>;
896 struct Relocate_info<32, false>;
899 struct Relocate_info<32, true>;
902 struct Relocate_info<64, false>;
905 struct Relocate_info<64, true>;
907 } // End namespace gold.